remember selected tab in "customize context view"
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 4 Sep 2015 14:30:48 +0000 (17:30 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 4 Sep 2015 14:39:48 +0000 (17:39 +0300)
java/debugger/impl/src/com/intellij/debugger/actions/CustomizeContextViewAction.java

index 23c0afda60db76b542563f651158041720a95ea7..3ee7212275910c397fbb377115ede839ab3b9698 100644 (file)
@@ -40,6 +40,8 @@ import javax.swing.*;
 import java.util.List;
 
 public class CustomizeContextViewAction extends XDebuggerTreeActionBase {
+  private static int ourLastSelectedTabIndex = 0;
+
   @Override
   public void actionPerformed(AnActionEvent e) {
     perform(null, "", e);
@@ -49,40 +51,66 @@ public class CustomizeContextViewAction extends XDebuggerTreeActionBase {
   protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
     final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
     Disposable disposable = Disposer.newDisposable();
-    SingleConfigurableEditor editor = new SingleConfigurableEditor(project, new TabbedConfigurable(disposable) {
+    final MyTabbedConfigurable configurable = new MyTabbedConfigurable(disposable);
+    SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable) {
       @Override
-      protected List<Configurable> createConfigurables() {
-        return JavaDebuggerSettings.createDataViewsConfigurable();
+      protected void doOKAction() {
+        //noinspection AssignmentToStaticFieldFromInstanceMethod
+        ourLastSelectedTabIndex = configurable.getSelectedIndex();
+        super.doOKAction();
       }
 
       @Override
-      public void apply() throws ConfigurationException {
-        super.apply();
-        NodeRendererSettings.getInstance().fireRenderersChanged();
+      public void doCancelAction() {
+        //noinspection AssignmentToStaticFieldFromInstanceMethod
+        ourLastSelectedTabIndex = configurable.getSelectedIndex();
+        super.doCancelAction();
       }
+    };
+    Disposer.register(editor.getDisposable(), disposable);
+    editor.show();
+  }
 
-      @Override
-      public String getDisplayName() {
-        return DebuggerBundle.message("title.customize.data.views");
-      }
+  private static class MyTabbedConfigurable extends TabbedConfigurable {
+    public MyTabbedConfigurable(@NotNull Disposable parent) {
+      super(parent);
+    }
 
-      @Override
-      public String getHelpTopic() {
-        return "reference.debug.customize.data.view";
-      }
+    @Override
+    protected List<Configurable> createConfigurables() {
+      return JavaDebuggerSettings.createDataViewsConfigurable();
+    }
 
-      @Override
-      protected void createConfigurableTabs() {
-        for (Configurable configurable : getConfigurables()) {
-          JComponent component = configurable.createComponent();
-          assert component != null;
-          component.setBorder(JBUI.Borders.empty(8, 8));
-          myTabbedPane.addTab(configurable.getDisplayName(), component);
-        }
+    @Override
+    public void apply() throws ConfigurationException {
+      super.apply();
+      NodeRendererSettings.getInstance().fireRenderersChanged();
+    }
+
+    @Override
+    public String getDisplayName() {
+      return DebuggerBundle.message("title.customize.data.views");
+    }
+
+    @Override
+    public String getHelpTopic() {
+      return "reference.debug.customize.data.view";
+    }
+
+    @Override
+    protected void createConfigurableTabs() {
+      for (Configurable configurable : getConfigurables()) {
+        JComponent component = configurable.createComponent();
+        assert component != null;
+        component.setBorder(JBUI.Borders.empty(8, 8));
+        myTabbedPane.addTab(configurable.getDisplayName(), component);
       }
-    });
-    Disposer.register(editor.getDisposable(), disposable);
-    editor.show();
+      myTabbedPane.setSelectedIndex(ourLastSelectedTabIndex);
+    }
+
+    int getSelectedIndex() {
+      return myTabbedPane.getSelectedIndex();
+    }
   }
 
   @Override