OSDN Git Service

changed comment region
authorquiver2k <quiver2k@users.sourceforge.jp>
Wed, 19 Aug 2009 15:41:51 +0000 (00:41 +0900)
committerquiver2k <quiver2k@users.sourceforge.jp>
Wed, 19 Aug 2009 15:41:51 +0000 (00:41 +0900)
jp.sourceforge.moreemacs/plugin.xml
jp.sourceforge.moreemacs/src/jp/sourceforge/moreemacs/handlers/CommentRegionExecution.java

index 4c44348..8a2b18c 100644 (file)
       </key>\r
       <key\r
             commandId="jp.sourceforge.moreemacs.NewLine"\r
-            contextId="org.eclipse.ui.contexts.window"\r
+            contextId="org.eclipse.ui.textEditorScope"\r
             schemeId="jp.sourceforge.moreemacs.moreEmacsAcceleratorConfiguration"\r
             sequence="M1+M">\r
       </key>\r
             schemeId="jp.sourceforge.moreemacs.moreEmacsAcceleratorConfiguration"\r
             sequence="M1+C M1+C">\r
       </key>\r
+      <key\r
+            commandId="jp.sourceforge.moreemacs.CommentRegion"\r
+            contextId="org.eclipse.ui.textEditorScope"\r
+            schemeId="jp.sourceforge.moreemacs.moreEmacsAcceleratorConfiguration"\r
+            sequence="M1+U M1+C M1+C">\r
+      </key>\r
    </extension>\r
 \r
 </plugin>\r
index d1059d1..262bf7a 100644 (file)
@@ -1,6 +1,7 @@
 package jp.sourceforge.moreemacs.handlers;\r
 \r
 import org.eclipse.core.commands.Command;\r
+import org.eclipse.jface.text.ITextSelection;\r
 import org.eclipse.ui.commands.ICommandService;\r
 import org.eclipse.ui.handlers.IHandlerService;\r
 \r
@@ -8,21 +9,30 @@ import org.eclipse.ui.handlers.IHandlerService;
 public final class CommentRegionExecution extends TextEditorExecution {\r
     @Override\r
     public void execute() throws Exception {\r
+        Command command = getEnabledToggleCommentCommand();\r
+        if(command == null) {\r
+            return;\r
+        }\r
+        // if the selection is empty, the marked region will be new selection.\r
+        getSelection(true);\r
+        \r
+        IHandlerService handlerService =\r
+            (IHandlerService)textEditor.getSite().getService(IHandlerService.class);\r
+        handlerService.executeCommand(command.getId(), null);\r
+\r
+        ITextSelection selection = getSelection(false);\r
+        textViewer.setSelectedRange(selection.getOffset()+selection.getLength(), 0);\r
+    }\r
+    \r
+    private Command getEnabledToggleCommentCommand() {\r
         ICommandService commandService =\r
             (ICommandService)textEditor.getSite().getService(ICommandService.class);\r
         for(Command command: commandService.getDefinedCommands()) {\r
-            if(!isEnabledToggleCommentCommand(command)) {\r
-                continue;\r
+            if(isEnabledToggleCommentCommand(command)) {\r
+                return command;\r
             }\r
-            \r
-            // if the selection is empty, the marked region will be new selection.\r
-            getSelection(true);\r
-            \r
-            IHandlerService handlerService =\r
-                (IHandlerService)textEditor.getSite().getService(IHandlerService.class);\r
-            handlerService.executeCommand(command.getId(), null);\r
-            return;\r
         }\r
+        return null;\r
     }\r
     \r
     private boolean isEnabledToggleCommentCommand(Command command) {\r