return text.substring(startPos, endPos);\r
}\r
\r
- public static String extractAt(String text, int caretPos) {\r
+ public static String extractIdentifierOrSymbolAt(String text, int caretPos) {\r
String result = extractIdentifierAt(text, caretPos);\r
if(!result.isEmpty())\r
return result;\r
return extractSymbolAt(text, caretPos);\r
}\r
-\r
\r
+ private static String extractLineAt(String text, int caretPos) {\r
+ int startPos = caretPos;\r
+ while(startPos > 0 && !isNewline(text.charAt(startPos-1)))\r
+ --startPos;\r
+ int endPos = caretPos;\r
+ while(endPos < text.length() && !isNewline(text.charAt(endPos)))\r
+ ++endPos;\r
+ return text.substring(startPos, endPos);\r
+ }\r
+ \r
+ private static boolean isNewline(char c) {\r
+ return c=='\n' || c=='\r';\r
+ }\r
+\r
@Override\r
public Object execute(ExecutionEvent event) throws ExecutionException {\r
IEditorPart editor = \r
return null;\r
SCLModuleEditor2 moduleEditor = (SCLModuleEditor2)editor;\r
StyledText styledText = (StyledText)moduleEditor.getAdapter(Control.class);\r
- String identifierAtCaret = extractAt(styledText.getText(), styledText.getCaretOffset());\r
- if(identifierAtCaret.isEmpty())\r
- return null;\r
- SCLTextEditorEnvironment editorEnvironment = moduleEditor.getSCLTextEditorEnvironment();\r
- editorEnvironment.updateEnvironment(moduleEditor.getDocument());\r
- SCLValue value = editorEnvironment.getValue(identifierAtCaret);\r
- if(value != null)\r
- OpenSCLDefinition.openDefinition(value);\r
+ String text = styledText.getText();\r
+ int caretOffset = styledText.getCaretOffset();\r
+ \r
+ // Find the line where the caret is\r
+ String lineAtCaret = extractLineAt(text, caretOffset);\r
+ if(lineAtCaret.startsWith("import ") || lineAtCaret.startsWith("include ")) {\r
+ int p1 = lineAtCaret.indexOf('"', 6);\r
+ int p2 = lineAtCaret.indexOf('"', p1+1);\r
+ String moduleName = lineAtCaret.substring(p1+1, p2);\r
+ OpenSCLModule.openModule(moduleName);\r
+ }\r
+ else {\r
+ // Try to find an identifier at caret\r
+ String identifierAtCaret = extractIdentifierOrSymbolAt(text, caretOffset);\r
+ if(identifierAtCaret.isEmpty())\r
+ return null;\r
+ SCLTextEditorEnvironment editorEnvironment = moduleEditor.getSCLTextEditorEnvironment();\r
+ editorEnvironment.updateEnvironment(moduleEditor.getDocument());\r
+ SCLValue value = editorEnvironment.getValue(identifierAtCaret);\r
+ if(value != null)\r
+ OpenSCLDefinition.openDefinition(value);\r
+ }\r
return null;\r
}\r
\r
-package org.simantics.scl.ui.editor2;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.PlatformUI;\r
-\r
-public class OpenSCLModule extends AbstractHandler {\r
-\r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- SCLModuleSelectionDialog dialog = new SCLModuleSelectionDialog(\r
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());\r
- if(dialog.open() == SCLModuleSelectionDialog.OK) {\r
- String moduleName = (String)dialog.getFirstResult();\r
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();\r
- if(page == null)\r
- return null;\r
- SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);\r
- try {\r
- page.openEditor(input, "org.simantics.scl.ui.editor2");\r
- } catch (PartInitException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return null;\r
- }\r
-\r
-}\r
+package org.simantics.scl.ui.editor2;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+public class OpenSCLModule extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ SCLModuleSelectionDialog dialog = new SCLModuleSelectionDialog(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ if(dialog.open() == SCLModuleSelectionDialog.OK) {
+ String moduleName = (String)dialog.getFirstResult();
+ openModule(moduleName);
+ }
+ return null;
+ }
+
+ public static void openModule(String moduleName) {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(page == null)
+ return;
+ SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName);
+ try {
+ page.openEditor(input, "org.simantics.scl.ui.editor2");
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+
+}