X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Feditor2%2FOpenSCLDefinition.java;fp=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Feditor2%2FOpenSCLDefinition.java;h=7731bf2acdccb3ba5a74ab1d535e72ab15099742;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLDefinition.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLDefinition.java new file mode 100644 index 000000000..7731bf2ac --- /dev/null +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLDefinition.java @@ -0,0 +1,48 @@ +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; +import org.simantics.scl.compiler.elaboration.modules.SCLValue; +import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.ui.browser.SCLDefinitionSelectionDialog; + +public class OpenSCLDefinition extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + SCLDefinitionSelectionDialog dialog = new SCLDefinitionSelectionDialog( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); + if(dialog.open() == SCLDefinitionSelectionDialog.OK) { + SCLValue value = (SCLValue)dialog.getFirstResult(); + if(value != null) + openDefinition(value); + } + return null; + } + + public static void openDefinition(SCLValue value) { + openDefinition(value.getName().module, value.definitionLocation); + } + + public static void openDefinition(String moduleName, long location) { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if(page == null) + return; + SCLModuleEditorInput input = new StandardSCLModuleEditorInput(moduleName); + try { + SCLModuleEditor2 editor = (SCLModuleEditor2)page.openEditor(input, "org.simantics.scl.ui.editor2"); + if(location != Locations.NO_LOCATION) { + int begin = Locations.beginOf(location); + int end = Locations.endOf(location); + editor.selectAndReveal(begin, end-begin); + } + } catch (PartInitException e) { + e.printStackTrace(); + } + } + +}