@@ -85,30 +85,6 @@ protected JavaEditor(Base base, String path, EditorState state,
8585 debugger = new Debugger (this );
8686 inspector = new VariableInspector (this );
8787
88- // Add show usage option
89- JMenuItem showUsageItem = new JMenuItem (Language .text ("editor.popup.show_usage" ));
90- showUsageItem .addActionListener (new ActionListener () {
91- public void actionPerformed (ActionEvent e ) {
92- handleShowUsage ();
93- }
94- });
95- getTextArea ().getRightClickPopup ().add (showUsageItem );
96-
97- // add refactor option
98- JMenuItem renameItem = new JMenuItem (Language .text ("editor.popup.rename" ));
99- renameItem .addActionListener (new ActionListener () {
100- public void actionPerformed (ActionEvent e ) {
101- handleRefactor ();
102- }
103- });
104-
105- // TODO: Add support for word select on right click and rename.
106- // ta.customPainter.addMouseListener(new MouseAdapter() {
107- // public void mouseClicked(MouseEvent evt) {
108- // System.out.println(evt);
109- // }
110- // });
111- textarea .getRightClickPopup ().add (renameItem );
11288 // set action on frame close
11389 // addWindowListener(new WindowAdapter() {
11490 // @Override
@@ -117,7 +93,6 @@ public void actionPerformed(ActionEvent e) {
11793 // }
11894 // });
11995
120- Toolkit .setMenuMnemonics (textarea .getRightClickPopup ());
12196
12297// // load settings from theme.txt
12398// breakpointColor = mode.getColor("breakpoint.bgcolor");
@@ -153,6 +128,8 @@ public void actionPerformed(ActionEvent e) {
153128
154129 initPDEX ();
155130
131+ Toolkit .setMenuMnemonics (textarea .getRightClickPopup ());
132+
156133 // ensure completion is hidden when editor loses focus
157134 addWindowFocusListener (new WindowFocusListener () {
158135 public void windowLostFocus (WindowEvent e ) {
@@ -173,60 +150,11 @@ public void caretUpdate(CaretEvent e) {
173150 public PdePreprocessor createPreprocessor (final String sketchName ) {
174151 return new PdePreprocessor (sketchName );
175152 }
176-
153+
177154
178155 protected void initPDEX () {
179156 preprocessingService = new PreprocessingService (this );
180157 pdex = new PDEX (this , preprocessingService );
181-
182- // Add ctrl+click listener
183- getJavaTextArea ().getPainter ().addMouseListener (new MouseAdapter () {
184- public void mouseReleased (MouseEvent evt ) {
185- if (evt .getButton () == MouseEvent .BUTTON1 ) {
186- if ((evt .isControlDown () && !Platform .isMacOS ()) || evt .isMetaDown ()) {
187- handleCtrlClick (evt );
188- }
189- } else if (evt .getButton () == MouseEvent .BUTTON2 ) {
190- handleCtrlClick (evt );
191- }
192- }
193- });
194-
195- sketchChanged ();
196-
197- for (SketchCode code : getSketch ().getCode ()) {
198- Document document = code .getDocument ();
199- addDocumentListener (document );
200- }
201- }
202-
203-
204- public void addDocumentListener (Document doc ) {
205- if (doc != null ) doc .addDocumentListener (sketchChangedListener );
206- }
207-
208-
209- protected final DocumentListener sketchChangedListener = new DocumentListener () {
210- @ Override
211- public void insertUpdate (DocumentEvent e ) {
212- sketchChanged ();
213- }
214-
215- @ Override
216- public void removeUpdate (DocumentEvent e ) {
217- sketchChanged ();
218- }
219-
220- @ Override
221- public void changedUpdate (DocumentEvent e ) {
222- sketchChanged ();
223- }
224- };
225-
226-
227- protected void sketchChanged () {
228- pdex .notifySketchChanged ();
229- preprocessingService .notifySketchChanged ();
230158 }
231159
232160
@@ -257,7 +185,7 @@ public void rebuild() {
257185 if (preprocessingService != null ) {
258186 if (hasJavaTabsChanged ) {
259187 preprocessingService .handleHasJavaTabsChange (hasJavaTabs );
260- pdex .handleHasJavaTabsChange (hasJavaTabs );
188+ pdex .hasJavaTabsChanged (hasJavaTabs );
261189 if (hasJavaTabs ) {
262190 setProblemList (Collections .emptyList ());
263191 }
@@ -266,7 +194,7 @@ public void rebuild() {
266194 int currentTabCount = sketch .getCodeCount ();
267195 if (currentTabCount != previousTabCount ) {
268196 previousTabCount = currentTabCount ;
269- sketchChanged ();
197+ pdex . sketchChanged ();
270198 }
271199 }
272200 }
@@ -2298,8 +2226,8 @@ public void setCode(SketchCode code) {
22982226 super .setCode (code );
22992227
23002228 Document newDoc = code .getDocument ();
2301- if (oldDoc != newDoc && preprocessingService != null ) {
2302- addDocumentListener (newDoc );
2229+ if (oldDoc != newDoc && pdex != null ) {
2230+ pdex . documentChanged (newDoc );
23032231 }
23042232
23052233 // set line background colors for tab
@@ -2717,36 +2645,6 @@ public void updateErrorToggle(boolean hasErrors) {
27172645 }
27182646
27192647
2720- /** Handle refactor operation */
2721- private void handleRefactor () {
2722- int startOffset = getSelectionStart ();
2723- int stopOffset = getSelectionStop ();
2724- int tabIndex = sketch .getCurrentCodeIndex ();
2725-
2726- pdex .handleRename (tabIndex , startOffset , stopOffset );
2727- }
2728-
2729-
2730- /** Handle show usage operation */
2731- private void handleShowUsage () {
2732- int startOffset = getSelectionStart ();
2733- int stopOffset = getSelectionStop ();
2734- int tabIndex = sketch .getCurrentCodeIndex ();
2735-
2736- pdex .handleShowUsage (tabIndex , startOffset , stopOffset );
2737- }
2738-
2739-
2740- /** Handle ctrl+click */
2741- private void handleCtrlClick (MouseEvent evt ) {
2742- int off = getJavaTextArea ().xyToOffset (evt .getX (), evt .getY ());
2743- if (off < 0 ) return ;
2744- int tabIndex = sketch .getCurrentCodeIndex ();
2745-
2746- pdex .handleCtrlClick (tabIndex , off );
2747- }
2748-
2749-
27502648 public boolean hasJavaTabs () {
27512649 return hasJavaTabs ;
27522650 }
@@ -2781,7 +2679,7 @@ protected void applyPreferences() {
27812679 jmode .loadPreferences ();
27822680 Messages .log ("Applying prefs" );
27832681 // trigger it once to refresh UI
2784- sketchChanged ();
2682+ pdex . preferencesChanged ();
27852683 }
27862684 }
27872685
0 commit comments