mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-131313 Restore last opened tab in Preferences | Editor | Code Style | <Language>
This commit is contained in:
+26
@@ -43,6 +43,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -62,6 +64,7 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
|
||||
private TabbedPaneWrapper myTabbedPane;
|
||||
private final PredefinedCodeStyle[] myPredefinedCodeStyles;
|
||||
private JPopupMenu myCopyFromMenu;
|
||||
private @Nullable TabChangeListener myListener;
|
||||
|
||||
protected TabbedLanguageCodeStylePanel(@Nullable Language language, CodeStyleSettings currentSettings, CodeStyleSettings settings) {
|
||||
super(language, currentSettings, settings);
|
||||
@@ -123,6 +126,17 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
|
||||
myPanel = new JPanel();
|
||||
myPanel.setLayout(new BorderLayout());
|
||||
myTabbedPane = new TabbedPaneWrapper(this);
|
||||
myTabbedPane.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (myListener != null) {
|
||||
String title = myTabbedPane.getSelectedTitle();
|
||||
if (title != null) {
|
||||
myListener.tabChanged(TabbedLanguageCodeStylePanel.this, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
myTabs = new ArrayList<CodeStyleAbstractPanel>();
|
||||
myPanel.add(myTabbedPane.getComponent());
|
||||
initTabs(getSettings());
|
||||
@@ -662,4 +676,16 @@ public abstract class TabbedLanguageCodeStylePanel extends CodeStyleAbstractPane
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface TabChangeListener {
|
||||
void tabChanged(@NotNull TabbedLanguageCodeStylePanel source, @NotNull String tabTitle);
|
||||
}
|
||||
|
||||
public void setListener(@Nullable TabChangeListener listener) {
|
||||
myListener = listener;
|
||||
}
|
||||
|
||||
public void changeTab(@NotNull String tabTitle) {
|
||||
myTabbedPane.setSelectedTitle(tabTitle);
|
||||
}
|
||||
}
|
||||
|
||||
+31
-1
@@ -18,6 +18,8 @@ package com.intellij.application.options.codeStyle;
|
||||
|
||||
import com.intellij.application.options.CodeStyleAbstractPanel;
|
||||
import com.intellij.application.options.TabbedLanguageCodeStylePanel;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
@@ -27,6 +29,7 @@ import com.intellij.psi.codeStyle.CodeStyleSchemes;
|
||||
import com.intellij.ui.components.labels.SwingActionLink;
|
||||
import com.intellij.util.Alarm;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -37,7 +40,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CodeStyleMainPanel extends JPanel {
|
||||
public class CodeStyleMainPanel extends JPanel implements TabbedLanguageCodeStylePanel.TabChangeListener {
|
||||
private final CardLayout myLayout = new CardLayout();
|
||||
private final JPanel mySettingsPanel = new JPanel(myLayout);
|
||||
|
||||
@@ -61,12 +64,16 @@ public class CodeStyleMainPanel extends JPanel {
|
||||
@NonNls
|
||||
private static final String WAIT_CARD = "CodeStyleSchemesConfigurable.$$$.Wait.placeholder.$$$";
|
||||
|
||||
private final PropertiesComponent myProperties;
|
||||
|
||||
private final static String SELECTED_TAB = "settings.code.style.selected.tab";
|
||||
|
||||
public CodeStyleMainPanel(CodeStyleSchemesModel model, CodeStyleSettingsPanelFactory factory) {
|
||||
super(new BorderLayout());
|
||||
myModel = model;
|
||||
myFactory = factory;
|
||||
mySchemesPanel = new CodeStyleSchemesPanel(model);
|
||||
myProperties = PropertiesComponent.getInstance();
|
||||
|
||||
model.addListener(new CodeStyleSettingsListener(){
|
||||
@Override
|
||||
@@ -214,6 +221,15 @@ public class CodeStyleMainPanel extends JPanel {
|
||||
NewCodeStyleSettingsPanel panel = myFactory.createPanel(scheme);
|
||||
panel.reset();
|
||||
panel.setModel(myModel);
|
||||
CodeStyleAbstractPanel settingsPanel = panel.getSelectedPanel();
|
||||
if (settingsPanel instanceof TabbedLanguageCodeStylePanel) {
|
||||
TabbedLanguageCodeStylePanel tabbedPanel = (TabbedLanguageCodeStylePanel)settingsPanel;
|
||||
tabbedPanel.setListener(this);
|
||||
String currentTab = myProperties.getValue(getSelectedTabPropertyName(tabbedPanel));
|
||||
if (currentTab != null) {
|
||||
tabbedPanel.changeTab(currentTab);
|
||||
}
|
||||
}
|
||||
mySettingsPanels.put(name, panel);
|
||||
mySettingsPanel.add(scheme.getName(), panel);
|
||||
}
|
||||
@@ -244,4 +260,18 @@ public class CodeStyleMainPanel extends JPanel {
|
||||
final NewCodeStyleSettingsPanel panel = ensurePanel(defaultScheme);
|
||||
return panel.processListOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabChanged(@NotNull TabbedLanguageCodeStylePanel source, @NotNull String tabTitle) {
|
||||
myProperties.setValue(getSelectedTabPropertyName(source), tabTitle);
|
||||
for (NewCodeStyleSettingsPanel panel : getPanels()) {
|
||||
panel.tabChanged(source, tabTitle);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getSelectedTabPropertyName(@NotNull TabbedLanguageCodeStylePanel panel) {
|
||||
Language language = panel.getDefaultLanguage();
|
||||
return SELECTED_TAB + (language != null ? "." + language.getID() : "");
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -19,6 +19,7 @@ package com.intellij.application.options.codeStyle;
|
||||
import com.intellij.application.options.CodeStyleAbstractConfigurable;
|
||||
import com.intellij.application.options.CodeStyleAbstractPanel;
|
||||
import com.intellij.application.options.OptionsContainingConfigurable;
|
||||
import com.intellij.application.options.TabbedLanguageCodeStylePanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
@@ -33,7 +34,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class NewCodeStyleSettingsPanel extends JPanel {
|
||||
public class NewCodeStyleSettingsPanel extends JPanel implements TabbedLanguageCodeStylePanel.TabChangeListener {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.application.options.codeStyle.NewCodeStyleSettingsPanel");
|
||||
|
||||
private final Configurable myTab;
|
||||
@@ -106,4 +107,12 @@ public class NewCodeStyleSettingsPanel extends JPanel {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabChanged(@NotNull TabbedLanguageCodeStylePanel source, @NotNull String tabTitle) {
|
||||
CodeStyleAbstractPanel panel = getSelectedPanel();
|
||||
if (panel instanceof TabbedLanguageCodeStylePanel && panel != source) {
|
||||
((TabbedLanguageCodeStylePanel)panel).changeTab(tabTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user