]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix annoying editor focus jumping with Ctrl+Shift+D/M 57/1457/1
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 30 Jan 2018 11:10:31 +0000 (13:10 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 13 Feb 2018 20:49:38 +0000 (22:49 +0200)
refs #7733

Change-Id: Ie3fd1bb97b67de77b3a6e82bc5690835caec08e2
(cherry picked from commit de6536eb0ff08cf9b3f75a25b35ff44b33a6038b)

bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenDeclaration.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLDefinition.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/OpenSCLModule.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/CreateModuleDialog.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/modulebrowser/SCLModuleBrowser.java

index 878d8e24fcf0d86821db1d4b85af70fa88480e71..421328c164222346da2c9eb073f222afe841c601 100644 (file)
@@ -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;
     }
index bc7f9feac702b7951de422c3a254469eeea78cac..33fb30d4be124956e9b8ed76f3e53f90e9e7c010 100644 (file)
@@ -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));
     }
 
 }
index a0208e5b24d28f2dc0696f512062920af53e281a..b2df02fb4f0dc22e661926b34a8eac157c8f4b30 100644 (file)
@@ -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));
     }
 
 }
index 875c9ace459a589ca9ed9b91629133ad2bedc173..7dcfc2f0e65fdc19c270260f9ee5e1f656d88e7b 100644 (file)
@@ -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(),
index 97bfc9fb8ed3de929960a15558023c9f63115570..90d297c1a246b07a2c680e0d24dc09fa5f520f79 100644 (file)
@@ -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);
             }
         });