1
1
package ts .eclipse .ide .jsdt .internal .ui .actions ;
2
2
3
+ import org .eclipse .core .runtime .CoreException ;
3
4
import org .eclipse .jface .preference .IPreferenceStore ;
4
5
import org .eclipse .jface .text .ITextSelection ;
5
6
import org .eclipse .jface .viewers .IStructuredSelection ;
6
7
import org .eclipse .ui .IWorkbenchSite ;
7
- import org .eclipse .wst .jsdt .internal .ui .JavaScriptPlugin ;
8
- import org .eclipse .wst .jsdt .ui .PreferenceConstants ;
8
+ import org .eclipse .wst .jsdt .core .JavaScriptCore ;
9
+ import org .eclipse .wst .jsdt .internal .ui .refactoring .RefactoringMessages ;
10
+ import org .eclipse .wst .jsdt .internal .ui .text .PreferencesAdapter ;
11
+ import org .eclipse .wst .jsdt .internal .ui .util .ExceptionHandler ;
9
12
import org .eclipse .wst .jsdt .ui .actions .SelectionDispatchAction ;
10
13
14
+ import ts .eclipse .ide .core .preferences .TypeScriptCorePreferenceConstants ;
11
15
import ts .eclipse .ide .jsdt .internal .ui .editor .TypeScriptEditor ;
12
16
import ts .eclipse .ide .jsdt .internal .ui .refactoring .RenameLinkedMode ;
17
+ import ts .eclipse .ide .jsdt .internal .ui .refactoring .RenameSupport ;
18
+ import ts .resources .ITypeScriptFile ;
13
19
14
20
public class RenameTypeScriptElementAction extends SelectionDispatchAction {
15
21
@@ -38,30 +44,29 @@ public void selectionChanged(IStructuredSelection selection) {
38
44
39
45
@ Override
40
46
public void selectionChanged (ITextSelection selection ) {
41
- //if (selection.size() == 1) {
42
- // setEnabled(canEnable(selection));
43
- setEnabled (true );
44
- // return;
45
- //}
46
- //setEnabled(false);
47
+ // if (selection.size() == 1) {
48
+ // setEnabled(canEnable(selection));
49
+ setEnabled (true );
50
+ // return;
51
+ // }
52
+ // setEnabled(false);
47
53
}
48
54
49
-
50
55
@ Override
51
56
public void run (ITextSelection selection ) {
52
57
if (canRunInEditor ()) {
53
58
doRun (selection );
54
59
}
55
60
}
56
-
61
+
57
62
private boolean canRunInEditor () {
58
63
if (RenameLinkedMode .getActiveLinkedMode () != null )
59
64
return true ;
60
65
return true ;
61
66
}
62
-
67
+
63
68
private void doRun (ITextSelection selection ) {
64
- RenameLinkedMode activeLinkedMode = RenameLinkedMode .getActiveLinkedMode ();
69
+ RenameLinkedMode activeLinkedMode = RenameLinkedMode .getActiveLinkedMode ();
65
70
if (activeLinkedMode != null ) {
66
71
if (activeLinkedMode .isCaretInLinkedPosition ()) {
67
72
activeLinkedMode .startFullDialog ();
@@ -71,39 +76,53 @@ private void doRun(ITextSelection selection) {
71
76
}
72
77
}
73
78
74
- IPreferenceStore store = JavaScriptPlugin .getDefault ().getPreferenceStore ();
75
- boolean lightweight = store .getBoolean (PreferenceConstants .REFACTOR_LIGHTWEIGHT );
76
- run (selection , lightweight );
77
-
78
- // try {
79
- // IJavaElement element= getJavaElementFromEditor();
80
- // IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
81
- // boolean lightweight= store.getBoolean(PreferenceConstants.REFACTOR_LIGHTWEIGHT);
82
- // if (element != null && RefactoringAvailabilityTester.isRenameElementAvailable(element)) {
83
- // run(element, lightweight);
84
- // return;
85
- // } else if (lightweight) {
86
- // // fall back to local rename:
87
- // CorrectionCommandHandler handler= new CorrectionCommandHandler(fEditor, LinkedNamesAssistProposal.ASSIST_ID, true);
88
- // if (handler.doExecute()) {
89
- // fEditor.setStatusLineErrorMessage(RefactoringMessages.RenameJavaElementAction_started_rename_in_file);
90
- // return;
91
- // }
92
- // }
93
- // } catch (CoreException e) {
94
- // ExceptionHandler.handle(e, RefactoringMessages.RenameJavaElementAction_name, RefactoringMessages.RenameJavaElementAction_exception);
95
- // }
96
- // MessageDialog.openInformation(getShell(), RefactoringMessages.RenameJavaElementAction_name, RefactoringMessages.RenameJavaElementAction_not_available);
79
+ IPreferenceStore store = new PreferencesAdapter (JavaScriptCore .getPlugin ().getPluginPreferences ());
80
+ boolean lightweight = store .getBoolean (TypeScriptCorePreferenceConstants .REFACTOR_LIGHTWEIGHT );
81
+ try {
82
+ run (selection , lightweight );
83
+ } catch (CoreException e ) {
84
+ ExceptionHandler .handle (e , RefactoringMessages .RenameJavaElementAction_name ,
85
+ RefactoringMessages .RenameJavaElementAction_exception );
86
+ }
87
+
88
+ // try {
89
+ // IJavaElement element= getJavaElementFromEditor();
90
+ // IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
91
+ // boolean lightweight=
92
+ // store.getBoolean(PreferenceConstants.REFACTOR_LIGHTWEIGHT);
93
+ // if (element != null &&
94
+ // RefactoringAvailabilityTester.isRenameElementAvailable(element)) {
95
+ // run(element, lightweight);
96
+ // return;
97
+ // } else if (lightweight) {
98
+ // // fall back to local rename:
99
+ // CorrectionCommandHandler handler= new
100
+ // CorrectionCommandHandler(fEditor,
101
+ // LinkedNamesAssistProposal.ASSIST_ID, true);
102
+ // if (handler.doExecute()) {
103
+ // fEditor.setStatusLineErrorMessage(RefactoringMessages.RenameJavaElementAction_started_rename_in_file);
104
+ // return;
105
+ // }
106
+ // }
107
+ // } catch (CoreException e) {
108
+ // ExceptionHandler.handle(e,
109
+ // RefactoringMessages.RenameJavaElementAction_name,
110
+ // RefactoringMessages.RenameJavaElementAction_exception);
111
+ // }
112
+ // MessageDialog.openInformation(getShell(),
113
+ // RefactoringMessages.RenameJavaElementAction_name,
114
+ // RefactoringMessages.RenameJavaElementAction_not_available);
97
115
}
98
116
99
- private void run (ITextSelection selection , boolean lightweight ) {
117
+ private void run (ITextSelection selection , boolean lightweight ) throws CoreException {
100
118
if (lightweight && fEditor instanceof TypeScriptEditor ) {
101
119
new RenameLinkedMode (selection , (TypeScriptEditor ) fEditor ).start ();
102
- }
103
- /*else {
104
- RefactoringExecutionStarter.startRenameRefactoring(element, getShell());
105
- }*/
120
+ } else {
121
+ ITypeScriptFile tsFile = fEditor .getTypeScriptFile ();
122
+ final RenameSupport support = RenameSupport .create (tsFile , selection .getOffset (), selection .getText ());
123
+ if (support != null && support .preCheck ().isOK ())
124
+ support .openDialog (getShell ());
125
+ }
106
126
}
107
127
108
-
109
128
}
0 commit comments