Code style settings UI: "Set from" button moved to tabs
authorRustam.Vishnyakov <rustam.vishnyakov@gmail.com>
Tue, 24 Jan 2012 15:27:58 +0000 (19:27 +0400)
committerRustam.Vishnyakov <rustam.vishnyakov@gmail.com>
Thu, 2 Feb 2012 08:47:07 +0000 (12:47 +0400)
platform/lang-impl/src/com/intellij/application/options/TabbedLanguageCodeStylePanel.java
platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.form
platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesPanel.java

index 825f687420464268ccf6345d396f84fa0fa6b665..429361079c9c3d81a6e99416b7c46a83ea80052e 100644 (file)
@@ -28,6 +28,7 @@ import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectUtil;
 import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.IconLoader;
 import com.intellij.psi.codeStyle.*;
 import com.intellij.ui.components.JBTabbedPane;
 import org.jetbrains.annotations.NotNull;
@@ -35,8 +36,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import java.awt.event.*;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -47,6 +47,8 @@ import java.util.List;
  */
 
 public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPanel {
+  
+  private final static Icon COPY_ICON = IconLoader.getIcon("/actions/import.png");
 
   private CodeStyleAbstractPanel myActiveTab;
   private List<CodeStyleAbstractPanel> myTabs;
@@ -117,10 +119,35 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
       myTabs = new ArrayList<CodeStyleAbstractPanel>();
       myPanel.add(myTabbedPane);
       initTabs(getSettings());
+      addSetFrom();
     }
     assert !myTabs.isEmpty();
   }
 
+  private void addSetFrom() {
+    myPredefinedCodeStyles = getPredefinedStyles();
+    JLabel dummyLabel = new JLabel("");
+    myTabbedPane.addTab("Set From...", dummyLabel);
+    int dummyIndex = myTabbedPane.indexOfComponent(dummyLabel);
+    myTabbedPane.setEnabledAt(dummyIndex, false);
+    JPanel setFromPanel = new JPanel();
+    setFromPanel.setBorder(BorderFactory.createEtchedBorder());
+    setFromPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10,0));
+    JLabel setFromLabel = new JLabel("Set from...");
+    setFromPanel.add(setFromLabel);
+    final PopupMenu copyMenu = new PopupMenu();
+    setFromLabel.add(copyMenu);
+    setFromLabel.setIcon(COPY_ICON);
+    setupCopyFromMenu(copyMenu);
+    setFromLabel.addMouseListener(new MouseAdapter() {
+      @Override
+      public void mousePressed(MouseEvent e) {
+          copyMenu.show(e.getComponent(), e.getX(), e.getY());
+      }
+    });
+    myTabbedPane.setTabComponentAt(dummyIndex, setFromPanel);
+  }
+
   /**
    * Adds a tab with the given CodeStyleAbstractPanel. Tab title is taken from getTabTitle() method.
    * @param tab The panel to use in a tab.
index 036fa4dbc3898f3a1d8ad8e5f49619afe2fbddf4..533c3e4177174ef633b672156e7229e88e2d33ab 100644 (file)
@@ -20,7 +20,7 @@
           <color color="-16777216"/>
         </border>
         <children>
-          <grid id="3fa8b" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+          <grid id="3fa8b" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
             <margin top="0" left="0" bottom="0" right="0"/>
             <constraints/>
             <properties/>
                   </component>
                 </children>
               </grid>
-              <grid id="e086a" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
-                <margin top="0" left="0" bottom="0" right="0"/>
-                <constraints>
-                  <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
-                </constraints>
-                <properties/>
-                <border type="none"/>
-                <children>
-                  <component id="55b" class="javax.swing.JButton" binding="myCopyFromButton" default-binding="true">
-                    <constraints>
-                      <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
-                    </constraints>
-                    <properties>
-                      <text value="Set From..."/>
-                    </properties>
-                  </component>
-                </children>
-              </grid>
               <hspacer id="fd090">
                 <constraints>
-                  <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+                  <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
                 </constraints>
               </hspacer>
             </children>
index 7f7507795456c0d42b3467af17840d997dc5c942..44c19f2799df3197b204a77cf95ff5444a31e29d 100644 (file)
@@ -35,10 +35,8 @@ public class CodeStyleSchemesPanel{
   private final CodeStyleSchemesModel myModel;
   private JPanel myPanel;
   private JBScrollPane myJBScrollPane;
-  private JButton myCopyFromButton;
   private JButton myManageButton;
 
-  private PopupMenu myCopyFromMenu;
   private boolean myIsReset = false;
   private NewCodeStyleSettingsPanel mySettingsPanel;
   private final Font myDefaultComboFont;
@@ -75,14 +73,6 @@ public class CodeStyleSchemesPanel{
         return component;
       }
     });
-
-    myCopyFromButton.addActionListener(new ActionListener() {
-      @Override
-      public void actionPerformed(ActionEvent e) {
-        showCopyFromMenu();
-      }
-    });
-    myCopyFromButton.setEnabled(false);
     
     myManageButton.addActionListener(new ActionListener() {
       @Override
@@ -158,33 +148,8 @@ public class CodeStyleSchemesPanel{
 
   public void setCodeStyleSettingsPanel(NewCodeStyleSettingsPanel settingsPanel) {
     mySettingsPanel = settingsPanel;
-    CodeStyleAbstractPanel selectedPanel = mySettingsPanel.getSelectedPanel();
-    myCopyFromButton.setEnabled(selectedPanel != null && selectedPanel.isCopyFromMenuAvailable());
   }
 
-
-  private void showCopyFromMenu() {
-    initCopyFromMenu();
-    if (myCopyFromMenu.getItemCount() > 0) {
-      myCopyFromMenu.show(myCopyFromButton, 0, 0);
-    }
-  }
-  
-  private void initCopyFromMenu() {
-    if (myCopyFromMenu == null) {      
-      myCopyFromMenu = new PopupMenu();
-      myCopyFromButton.add(myCopyFromMenu);
-    }
-    CodeStyleAbstractPanel selectedPanel = mySettingsPanel.getSelectedPanel();
-    if (selectedPanel != null) {
-      selectedPanel.setupCopyFromMenu(myCopyFromMenu);
-      myCopyFromButton.setEnabled(myCopyFromMenu.getItemCount() > 0);
-    }
-    else {
-      myCopyFromButton.setEnabled(false);
-    }
-  }
-  
   private void showManageSchemesDialog() {
     ManageCodeStyleSchemesDialog manageSchemesDialog = new ManageCodeStyleSchemesDialog(myPanel, myModel);
     manageSchemesDialog.show();