From: jsimomaa Date: Tue, 30 Jan 2018 11:10:31 +0000 (+0200) Subject: Fix annoying editor focus jumping with Ctrl+Shift+D/M X-Git-Tag: v1.43.0~136^2~615 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=de6536eb0ff08cf9b3f75a25b35ff44b33a6038b;p=simantics%2Fplatform.git Fix annoying editor focus jumping with Ctrl+Shift+D/M refs #7733 Change-Id: Ie3fd1bb97b67de77b3a6e82bc5690835caec08e2 --- diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java index 878d8e24f..421328c16 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java @@ -9,15 +9,18 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.module.InvalidModulePathException; import org.simantics.scl.compiler.module.ModuleUtils; import org.simantics.scl.compiler.source.ModuleSource; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OpenDeclaration extends AbstractHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(OpenDeclaration.class); + private static boolean isIdentifierPart(char c) { return Character.isJavaIdentifierPart(c) || c=='.'; } @@ -93,10 +96,10 @@ public class OpenDeclaration extends AbstractHandler { String moduleName = ModuleUtils.resolveAbsolutePath(input.getModuleName(), lineAtCaret.substring(p1+1, p2)); ModuleSource source = SCLOsgi.SOURCE_REPOSITORY.getModuleSource(moduleName, null); if (source != null) { - OpenSCLModule.openModule(moduleName); + OpenSCLModule.scheduleOpenModule(moduleName); } } catch (InvalidModulePathException e) { - // Nothing to do + LOGGER.error("Could not open declaration {} {}", input.getModuleName(), lineAtCaret, e); } } else { @@ -109,7 +112,7 @@ public class OpenDeclaration extends AbstractHandler { SCLValue value = editorEnvironment.getValue(identifierAtCaret); //System.out.println("identifierAtCaret = " + identifierAtCaret + " [" + Locations.beginOf(value.definitionLocation) + ", " + Locations.endOf(value.definitionLocation) + "]"); if(value != null) - OpenSCLDefinition.openDefinition(value); + OpenSCLDefinition.scheduleOpenDefinition(value.getName().module, value.definitionLocation); } return null; } 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 index bc7f9feac..33fb30d4b 100644 --- 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 @@ -3,15 +3,20 @@ 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.swt.widgets.Display; 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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OpenSCLDefinition extends AbstractHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLDefinition.class); + @Override public Object execute(ExecutionEvent event) throws ExecutionException { SCLDefinitionSelectionDialog dialog = new SCLDefinitionSelectionDialog( @@ -19,30 +24,36 @@ public class OpenSCLDefinition extends AbstractHandler { if(dialog.open() == SCLDefinitionSelectionDialog.OK) { SCLValue value = (SCLValue)dialog.getFirstResult(); if(value != null) - openDefinition(value); + scheduleOpenDefinition(value.getName().module, value.definitionLocation); } 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); + + public static Runnable openDefinition(String moduleName, long location) { + return () -> { + 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) { + LOGGER.error("", e); } - } catch (PartInitException e) { - e.printStackTrace(); - } + }; + } + + public static void scheduleOpenDefinition(String moduleName, long location) { + Display.getCurrent().asyncExec(openDefinition(moduleName, location)); } } diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java index a0208e5b2..b2df02fb4 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java @@ -3,33 +3,44 @@ 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.swt.widgets.Display; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OpenSCLModule extends AbstractHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(OpenSCLModule.class); + @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); + scheduleOpenModule(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(); - } + public static Runnable openModule(String moduleName) { + return () -> { + 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) { + LOGGER.error("Could not open module {} ", moduleName, e); + } + }; + } + + public static void scheduleOpenModule(String moduleName) { + Display.getCurrent().asyncExec(openModule(moduleName)); } } diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/CreateModuleDialog.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/CreateModuleDialog.java index 875c9ace4..7dcfc2f0e 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/CreateModuleDialog.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/CreateModuleDialog.java @@ -175,7 +175,7 @@ public class CreateModuleDialog extends Dialog { if(bundle != null) { CreateModuleAction.createModule(bundle, packageName.getText(), moduleName.getText()); parentBrowser.refresh(); - OpenSCLModule.openModule(packageName.getText() + "/" + moduleName.getText()); + OpenSCLModule.scheduleOpenModule(packageName.getText() + "/" + moduleName.getText()); } } catch (IOException e) { ErrorDialog.openError(getParentShell(), "Module creation failed", e.getMessage(), diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java index 97bfc9fb8..90d297c1a 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java @@ -35,7 +35,7 @@ public class SCLModuleBrowser extends ViewPart { return; ModuleNameTreeEntry entry = (ModuleNameTreeEntry)((IStructuredSelection)selection).getFirstElement(); if(entry.isModule) - OpenSCLModule.openModule(entry.fullName); + OpenSCLModule.scheduleOpenModule(entry.fullName); } });