IDEA-19061 Integrate the Rearranger-plugin into core-IDE
authorDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 13 Nov 2012 12:35:36 +0000 (16:35 +0400)
committerDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 13 Nov 2012 12:36:02 +0000 (16:36 +0400)
Context menu for matching rules editing

platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/ArrangementConstants.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/action/EditArrangementRuleAction.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesPanel.java
platform/platform-resources-en/src/messages/ApplicationBundle.properties
platform/platform-resources/src/idea/LangActions.xml

index 31bada03209ec3b5ee58252697abaf8347fcf9d3..eed611df289103702f6569b6faea299b6875adf3 100644 (file)
@@ -29,8 +29,8 @@ public class ArrangementConstants {
 
   public static final DataKey<ArrangementMatchingRulesControl> MATCHING_RULES_CONTROL_KEY = DataKey.create("Arrangement.RuleEditor");
 
-  @NonNls public static final String ACTION_GROUP_RULE_EDITOR_CONTEXT_MENU       = "Arrangement.RuleEditor.Context.Menu";
-  @NonNls public static final String ACTION_GROUP_MATCHING_RULES_CONTROL_TOOLBAR = "Arrangement.RuleEditor.ToolBar";
+  @NonNls public static final String ACTION_GROUP_MATCHING_RULES_CONTEXT_MENU    = "Arrangement.Rule.Match.Control.Context.Menu";
+  @NonNls public static final String ACTION_GROUP_MATCHING_RULES_CONTROL_TOOLBAR = "Arrangement.Rule.Match.Control.ToolBar";
 
   @NonNls public static final String RULE_EDITOR_PLACE                    = "Arrangement.RuleEditor.Place";
   @NonNls public static final String MATCHING_RULES_CONTROL_TOOLBAR_PLACE = "Arrangement.Rule.Match.Control.ToolBar.Place";
index 1ffb6f44b2ec04868a03d9ae3f84f98dfb66a210..3667916c286bcfcbe4f837e651df09d5cefe39cf 100644 (file)
  */
 package com.intellij.application.options.codeStyle.arrangement.action;
 
+import com.intellij.application.options.codeStyle.arrangement.ArrangementConstants;
+import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.Toggleable;
 import com.intellij.openapi.application.ApplicationBundle;
 import com.intellij.openapi.project.DumbAware;
+import gnu.trove.TIntArrayList;
 
 /**
  * @author Denis Zhdanov
@@ -31,9 +34,23 @@ public class EditArrangementRuleAction extends AnAction implements DumbAware, To
     getTemplatePresentation().setText(ApplicationBundle.message("arrangement.action.rule.edit.text"));
     getTemplatePresentation().setDescription(ApplicationBundle.message("arrangement.action.rule.edit.description"));
   }
-  
+
+  @Override
+  public void update(AnActionEvent e) {
+    ArrangementMatchingRulesControl control = ArrangementConstants.MATCHING_RULES_CONTROL_KEY.getData(e.getDataContext());
+    e.getPresentation().setEnabled(control != null && control.getSelectedModelRows().size() == 1);
+  }
+
   @Override
   public void actionPerformed(AnActionEvent e) {
-    // TODO den implement
+    ArrangementMatchingRulesControl control = ArrangementConstants.MATCHING_RULES_CONTROL_KEY.getData(e.getDataContext());
+    if (control == null) {
+      return;
+    }
+    TIntArrayList rows = control.getSelectedModelRows();
+    if (rows.size() != 1) {
+      return;
+    }
+    control.showEditor(rows.get(0));
   }
 }
index f1d6bd3dde053b22d5cde4bb77cf185619bb7f27..03aa69933e25ddfa2bed068cce1318709c9b9478 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.application.options.codeStyle.arrangement.ArrangementConstan
 import com.intellij.application.options.codeStyle.arrangement.ArrangementNodeDisplayManager;
 import com.intellij.application.options.codeStyle.arrangement.color.ArrangementColorsProvider;
 import com.intellij.application.options.codeStyle.arrangement.util.TitleWithToolbar;
+import com.intellij.ide.ui.customization.CustomizationUtil;
 import com.intellij.openapi.actionSystem.DataProvider;
 import com.intellij.openapi.application.ApplicationBundle;
 import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule;
@@ -70,6 +71,9 @@ public class ArrangementMatchingRulesPanel extends JPanel implements DataProvide
     };
     myControl = new ArrangementMatchingRulesControl(displayManager, colorsProvider, settingsFilter, callback);
     scrollPane.setViewportView(myControl);
+    CustomizationUtil.installPopupHandler(
+      myControl, ArrangementConstants.ACTION_GROUP_MATCHING_RULES_CONTEXT_MENU, ArrangementConstants.RULE_EDITOR_PLACE
+    );
 
     TitleWithToolbar top = new TitleWithToolbar(
       ApplicationBundle.message("arrangement.settings.section.match"),
index dc1d680e5f1ffe6a9bceafd6f0ee07a1ad9adafd..3773961d4e55e95c1178777a75ceb1452dce7324 100644 (file)
@@ -561,8 +561,8 @@ arrangement.text.modifier=Modifier
 arrangement.text.negate=Negate
 arrangement.action.rule.add.text=Add rule
 arrangement.action.rule.add.description=Add new arrangement rule
-arrangement.action.rule.remove.text=Remove rule
-arrangement.action.rule.remove.description=Remove selected arrangement rule
+arrangement.action.rule.remove.text=Remove rule(s)
+arrangement.action.rule.remove.description=Remove selected arrangement rule(s)
 arrangement.action.rule.edit.text=Edit rule
 arrangement.action.rule.edit.description=Edit selected arrangement rule
 arrangement.action.rule.move.up.text=Move up
index 9dd10fa6fa8779ffcdbe320c6480e92ae52a2939..e92b7899abc0b7d598afb9151f74071eb62805f9 100644 (file)
             class="com.intellij.application.options.codeStyle.arrangement.action.MoveArrangementRuleDownAction"
             icon="AllIcons.ToolbarDecorator.MoveDown"/>
     
-    <group id="Arrangement.RuleEditor.Context.Menu">
+    <group id="Arrangement.Rule.Match.Control.Context.Menu">
       <reference ref="Arrangement.Rule.Add"/>
       <reference ref="Arrangement.Rule.Remove"/>
       <reference ref="Arrangement.Rule.Edit"/>
     </group>
     
-    <group id="Arrangement.RuleEditor.ToolBar">
+    <group id="Arrangement.Rule.Match.Control.ToolBar">
       <reference ref="Arrangement.Rule.Add"/>
       <reference ref="Arrangement.Rule.Remove"/>
       <reference ref="Arrangement.Rule.Move.Up"/>