From f02c735efd33121c44c675049d81e009f2acc18e Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 21 Dec 2015 16:09:47 +0300 Subject: [PATCH] Remove obsolete registry properties --- .../actions/ShowStructureSettingsAction.java | 6 +- .../options/CodeStyleSchemesConfigurable.java | 25 +- .../options/codeStyle/CodeStyleMainPanel.java | 6 +- .../util/scopeChooser/EditScopesDialog.java | 12 - .../src/com/intellij/openapi/ui/Banner.java | 4 +- .../intellij/openapi/ui/DetailsComponent.java | 58 +- .../ide/actions/ShowSettingsUtilImpl.java | 56 +- .../options/newEditor/IdeSettingsDialog.java | 305 ----- .../options/newEditor/OptionsEditor.java | 1144 ----------------- .../newEditor/OptionsEditorDialog.java | 316 ----- .../options/newEditor/OptionsTree.java | 981 -------------- .../options/newEditor/SettingsDialog.java | 4 +- .../options/newEditor/SettingsSearch.java | 15 +- .../util/resources/misc/registry.properties | 5 - .../edu/PyCharmEduInitialConfigurator.java | 3 - 15 files changed, 32 insertions(+), 2908 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/openapi/options/newEditor/IdeSettingsDialog.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorDialog.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java diff --git a/java/idea-ui/src/com/intellij/ide/actions/ShowStructureSettingsAction.java b/java/idea-ui/src/com/intellij/ide/actions/ShowStructureSettingsAction.java index 39da71b4e714..e6ce665906c9 100644 --- a/java/idea-ui/src/com/intellij/ide/actions/ShowStructureSettingsAction.java +++ b/java/idea-ui/src/com/intellij/ide/actions/ShowStructureSettingsAction.java @@ -20,7 +20,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.options.ex.SingleConfigurableEditor; -import com.intellij.openapi.options.newEditor.OptionsEditorDialog; +import com.intellij.openapi.options.newEditor.SettingsDialog; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -40,7 +40,7 @@ public class ShowStructureSettingsAction extends AnAction implements DumbAware { static void showDialog(Project project) { if (Registry.is("ide.new.project.settings")) { - new SingleConfigurableEditor(project, ProjectStructureConfigurable.getInstance(project), OptionsEditorDialog.DIMENSION_KEY) { + new SingleConfigurableEditor(project, ProjectStructureConfigurable.getInstance(project), SettingsDialog.DIMENSION_KEY) { @NotNull @Override protected DialogStyle getStyle() { @@ -50,7 +50,7 @@ public class ShowStructureSettingsAction extends AnAction implements DumbAware { } else { ShowSettingsUtil - .getInstance().editConfigurable(project, OptionsEditorDialog.DIMENSION_KEY, ProjectStructureConfigurable.getInstance(project)); + .getInstance().editConfigurable(project, SettingsDialog.DIMENSION_KEY, ProjectStructureConfigurable.getInstance(project)); } } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java index 154900f428a8..9925189f703c 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSchemesConfigurable.java @@ -23,7 +23,6 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.codeStyle.CodeStyleScheme; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; @@ -55,10 +54,7 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent. public JComponent createComponent() { myModel = ensureModel(); - if (Registry.is("ide.new.settings.dialog")) { - return myPanels == null || myPanels.isEmpty() ? null : myPanels.get(0).createComponent(); - } - return myRootSchemesPanel.getPanel(); + return myPanels == null || myPanels.isEmpty() ? null : myPanels.get(0).createComponent(); } @Override @@ -235,15 +231,12 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent. } } - if (Registry.is("ide.new.settings.dialog")) { - int size = myPanels.size(); - Configurable[] result = new Configurable[size > 0 ? size - 1 : 0]; - for (int i = 0; i < result.length; i++) { - result[i] = myPanels.get(i + 1); - } - return result; + int size = myPanels.size(); + Configurable[] result = new Configurable[size > 0 ? size - 1 : 0]; + for (int i = 0; i < result.length; i++) { + result[i] = myPanels.get(i + 1); } - return myPanels.toArray(new Configurable[myPanels.size()]); + return result; } private CodeStyleSchemesModel ensureModel() { @@ -301,10 +294,8 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent. @Override public boolean isModified() { if (myModel != null) { - if (Registry.is("ide.new.settings.dialog")) { - if (myPanels != null && myPanels.size() > 0 && myPanels.get(0).isModified()) { - return true; - } + if (myPanels != null && myPanels.size() > 0 && myPanels.get(0).isModified()) { + return true; } boolean schemeListModified = myModel.isSchemeListModified(); if (schemeListModified) { diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java index 6d155c9f4ed6..bec159831858 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleMainPanel.java @@ -23,11 +23,11 @@ import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.codeStyle.CodeStyleScheme; import com.intellij.psi.codeStyle.CodeStyleSchemes; import com.intellij.ui.components.labels.SwingActionLink; import com.intellij.util.Alarm; +import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -115,9 +115,7 @@ public class CodeStyleMainPanel extends JPanel implements TabbedLanguageCodeStyl JPanel top = new JPanel(new BorderLayout()); top.add(BorderLayout.WEST, mySchemesPanel.getPanel()); top.add(BorderLayout.EAST, link); - if (Registry.is("ide.new.settings.view")) { - top.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - } + top.setBorder(JBUI.Borders.empty(10)); add(top, BorderLayout.NORTH); add(mySettingsPanel, BorderLayout.CENTER); diff --git a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/EditScopesDialog.java b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/EditScopesDialog.java index 236c6fd717fa..2ad0dd011eca 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/EditScopesDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/scopeChooser/EditScopesDialog.java @@ -21,14 +21,11 @@ import com.intellij.openapi.options.newEditor.SettingsDialog; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.InputValidator; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.registry.Registry; import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.PackageSet; import org.jetbrains.annotations.Nullable; -import javax.swing.*; - /** * User: anna * Date: 03-Jul-2006 @@ -48,15 +45,6 @@ public class EditScopesDialog extends SettingsDialog { myCheckShared = checkShared; } - @Override - protected JComponent createCenterPanel() { - JComponent component = super.createCenterPanel(); - if (!Registry.is("ide.new.settings.view")) { - component.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - } - return component; - } - @Override public void doOKAction() { Object selectedObject = myConfigurable.getSelectedObject(); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/Banner.java b/platform/platform-api/src/com/intellij/openapi/ui/Banner.java index c9a8dab429f4..b722cd456aaa 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Banner.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Banner.java @@ -18,12 +18,12 @@ package com.intellij.openapi.ui; import com.intellij.icons.AllIcons; import com.intellij.openapi.options.OptionsBundle; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.RelativeFont; import com.intellij.ui.components.labels.LinkLabel; import com.intellij.ui.components.labels.LinkListener; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.util.containers.HashMap; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.PlatformColors; import org.jetbrains.annotations.NotNull; @@ -47,7 +47,7 @@ class Banner extends NonOpaquePanel implements PropertyChangeListener{ public Banner() { setLayout(new BorderLayout()); - setBorder(new EmptyBorder(2, Registry.is("ide.new.settings.dialog") ? 12 : 6, 2, 4)); + setBorder(JBUI.Borders.empty(2, 12, 2, 4)); myProjectIcon.setVisible(false); myProjectIcon.setBorder(new EmptyBorder(0, 12, 0, 4)); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DetailsComponent.java b/platform/platform-api/src/com/intellij/openapi/ui/DetailsComponent.java index 00440b0dd8a6..00d8bae5c238 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DetailsComponent.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DetailsComponent.java @@ -17,7 +17,6 @@ package com.intellij.openapi.ui; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.components.panels.Wrapper; import com.intellij.util.ArrayUtil; @@ -30,7 +29,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; -import java.awt.geom.GeneralPath; import java.util.ArrayList; public class DetailsComponent { @@ -61,61 +59,7 @@ public class DetailsComponent { public DetailsComponent(boolean detailsEnabled, boolean paintBorder) { myDetailsEnabled = detailsEnabled; myPaintBorder = paintBorder; - myComponent = new JPanel(new BorderLayout()) { - @Override - protected void paintComponent(final Graphics g) { - if (NullableComponent.Check.isNull(myContent) || !myDetailsEnabled) return; - - GraphicsConfig c = null; - Insets insets = null; - final int leftX; - final int rightX; - final int rightY; - if (!Registry.is("ide.new.settings.dialog")) { - c = new GraphicsConfig(g); - c.setAntialiasing(true); - - insets = getInsets(); - if (insets == null) { - insets = new Insets(0, 0, 0, 0); - } - - g.setColor(UIUtil.getFocusedFillColor()); - - final Rectangle banner = myBanner.getBounds(); - final GeneralPath header = new GeneralPath(); - - leftX = insets.left; - final int leftY = insets.top; - rightX = insets.left + getWidth() - 1 - insets.right; - rightY = banner.y + banner.height; - - header.moveTo(leftX, rightY); - int arc = 8; - header.lineTo(leftX, leftY + arc); - header.quadTo(leftX, leftY, leftX + arc, leftY); - header.lineTo(rightX - arc, leftY); - header.quadTo(rightX, leftY, rightX, leftY + arc); - header.lineTo(rightX, rightY); - header.closePath(); - - c.getG().fill(header); - - g.setColor(UIUtil.getFocusedBoundsColor()); - - c.getG().draw(header); - - - if (myPaintBorder) { - final int down = getHeight() - insets.top - insets.bottom - 1; - g.drawLine(leftX, rightY, leftX, down); - g.drawLine(rightX, rightY, rightX, down); - g.drawLine(leftX, down, rightX, down); - } - c.restore(); - } - } - }; + myComponent = new JPanel(new BorderLayout()); myComponent.setOpaque(false); myContentGutter.setOpaque(false); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java index e4e76786759e..81e91e3332a0 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java @@ -16,21 +16,16 @@ package com.intellij.ide.actions; import com.intellij.ide.ui.search.SearchUtil; -import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurableGroup; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.options.TabbedConfigurable; import com.intellij.openapi.options.ex.*; -import com.intellij.openapi.options.newEditor.IdeSettingsDialog; -import com.intellij.openapi.options.newEditor.OptionsEditor; -import com.intellij.openapi.options.newEditor.OptionsEditorDialog; import com.intellij.openapi.options.newEditor.SettingsDialog; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.navigation.Place; import com.intellij.util.ui.update.Activatable; @@ -59,34 +54,15 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil { public static DialogWrapper getDialog(@Nullable Project project, @NotNull ConfigurableGroup[] groups, @Nullable Configurable toSelect) { project = getProject(project); final ConfigurableGroup[] filteredGroups = filterEmptyGroups(groups); - if (Registry.is("ide.new.settings.dialog")) { - return Registry.is("ide.new.settings.view") - ? new SettingsDialog(project, filteredGroups, toSelect, null) - : new IdeSettingsDialog(project, filteredGroups, toSelect); - } - //noinspection deprecation - return Registry.is("ide.perProjectModality") - ? new OptionsEditorDialog(project, filteredGroups, toSelect, true) - : new OptionsEditorDialog(project, filteredGroups, toSelect); + return new SettingsDialog(project, filteredGroups, toSelect, null); } @NotNull public static ConfigurableGroup[] getConfigurableGroups(@Nullable Project project, boolean withIdeSettings) { - if (Registry.is("ide.new.settings.dialog")) { - if (!withIdeSettings) { - project = getProject(project); - } - return new ConfigurableGroup[]{ConfigurableExtensionPointUtil.getConfigurableGroup(project, withIdeSettings)}; + if (!withIdeSettings) { + project = getProject(project); } - ConfigurableGroup[] groups = !withIdeSettings - ? new ConfigurableGroup[]{new ProjectConfigurablesGroup(getProject(project))} - : (project == null) - ? new ConfigurableGroup[]{new IdeConfigurablesGroup()} - : new ConfigurableGroup[]{ - new ProjectConfigurablesGroup(project), - new IdeConfigurablesGroup()}; - - return groups; + return new ConfigurableGroup[]{ConfigurableExtensionPointUtil.getConfigurableGroup(project, withIdeSettings)}; } @NotNull @@ -162,21 +138,7 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil { group = filterEmptyGroups(group); final Configurable configurable2Select = id2Select == null ? null : new ConfigurableVisitor.ByID(id2Select).find(group); - if (Registry.is("ide.new.settings.view")) { - new SettingsDialog(getProject(project), group, configurable2Select, filter).show(); - return; - } - final DialogWrapper dialog = getDialog(project, group, configurable2Select); - - new UiNotifyConnector.Once(dialog.getContentPane(), new Activatable.Adapter() { - @Override - public void showNotify() { - final OptionsEditor editor = (OptionsEditor)((DataProvider)dialog).getData(OptionsEditor.KEY.getName()); - LOG.assertTrue(editor != null); - editor.select(configurable2Select, filter); - } - }); - dialog.show(); + new SettingsDialog(getProject(project), group, configurable2Select, filter).show(); } @Override @@ -250,14 +212,10 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil { boolean showApplyButton) { final DialogWrapper editor; if (parent == null) { - editor = Registry.is("ide.new.settings.view") - ? new SettingsDialog(project, dimensionKey, configurable, showApplyButton, false) - : new SingleConfigurableEditor(project, configurable, dimensionKey, showApplyButton); + editor = new SettingsDialog(project, dimensionKey, configurable, showApplyButton, false); } else { - editor = Registry.is("ide.new.settings.view") - ? new SettingsDialog(parent, dimensionKey, configurable, showApplyButton, false) - : new SingleConfigurableEditor(parent, configurable, dimensionKey, showApplyButton); + editor = new SettingsDialog(parent, dimensionKey, configurable, showApplyButton, false); } if (advancedInitialization != null) { new UiNotifyConnector.Once(editor.getContentPane(), new Activatable.Adapter() { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/IdeSettingsDialog.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/IdeSettingsDialog.java deleted file mode 100644 index a3686892fcef..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/IdeSettingsDialog.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.options.newEditor; - -import com.intellij.CommonBundle; -import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.help.HelpManager; -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurableGroup; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SearchableConfigurable; -import com.intellij.openapi.options.ex.ConfigurableVisitor; -import com.intellij.openapi.project.DumbModePermission; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Disposer; -import com.intellij.ui.Gray; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.JBColor; -import com.intellij.ui.border.CustomLineBorder; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.Collection; -import java.util.Map; - -/** - * @author Konstantin Bulenkov - */ -public class IdeSettingsDialog extends DialogWrapper implements DataProvider { - private Project myProject; - private ConfigurableGroup[] myGroups; - private Configurable myPreselected; - private OptionsEditor myEditor; - - private ApplyAction myApplyAction; - public static final String DIMENSION_KEY = "OptionsEditor"; - @NonNls static final String LAST_SELECTED_CONFIGURABLE = "options.lastSelected"; - - /** - * This constructor should be eliminated after the new modality approach - * will have been checked. See a {@code Registry} key ide.perProjectModality - * - * @deprecated - */ - public IdeSettingsDialog(Project project, ConfigurableGroup[] groups, - @Nullable Configurable preselectedConfigurable, boolean applicationModalIfPossible) { - super(project, true, applicationModalIfPossible); - init(project, groups, preselectedConfigurable != null ? preselectedConfigurable : findLastSavedConfigurable(groups, project)); - } - - /** - * This constructor should be eliminated after the new modality approach - * will have been checked. See a {@code Registry} key ide.perProjectModality - * - * @deprecated - */ - public IdeSettingsDialog(Project project, ConfigurableGroup[] groups, - @NotNull String preselectedConfigurableDisplayName, boolean applicationModalIfPossible) { - super(project, true, applicationModalIfPossible); - init(project, groups, getPreselectedByDisplayName(groups, preselectedConfigurableDisplayName, project)); - } - - public IdeSettingsDialog(Project project, ConfigurableGroup[] groups, @Nullable Configurable preselectedConfigurable) { - super(project, true); - init(project, groups, preselectedConfigurable != null ? preselectedConfigurable : findLastSavedConfigurable(groups, project)); - } - - public IdeSettingsDialog(Project project, ConfigurableGroup[] groups, @NotNull String preselectedConfigurableDisplayName) { - super(project, true); - init(project, groups, getPreselectedByDisplayName(groups, preselectedConfigurableDisplayName, project)); - } - - @Override - public void show() { - DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() { - @Override - public void run() { - IdeSettingsDialog.super.show(); - } - }); - } - - @Nullable - @Override - protected Border createContentPaneBorder() { - return IdeBorderFactory.createEmptyBorder(0); - } - - private void init(final Project project, final ConfigurableGroup[] groups, @Nullable final Configurable preselected) { - myProject = project; - myGroups = groups; - myPreselected = preselected; - - setTitle(CommonBundle.settingsTitle()); - - init(); - } - - @Nullable - private static Configurable getPreselectedByDisplayName(final ConfigurableGroup[] groups, final String preselectedConfigurableDisplayName, - final Project project) { - Configurable result = new ConfigurableVisitor.ByName(preselectedConfigurableDisplayName).find(groups); - - return result == null ? findLastSavedConfigurable(groups, project) : result; - } - - @Override - public boolean isTypeAheadEnabled() { - return true; - } - - @Nullable - @Override - protected JComponent createSouthPanel() { - final JComponent panel = super.createSouthPanel(); - CustomLineBorder line = new CustomLineBorder(new JBColor(Gray._153.withAlpha(128), Gray._100.withAlpha(128)), 1, 0, 0, 0); - panel.setBorder(new CompoundBorder(line, new EmptyBorder(8, 12, 8, 12))); - return panel; - } - - protected JComponent createCenterPanel() { - myEditor = new OptionsEditor(myProject, myGroups, myPreselected); - myEditor.getContext().addColleague(new OptionsEditorColleague.Adapter() { - @Override - public ActionCallback onModifiedAdded(final Configurable configurable) { - updateStatus(); - return ActionCallback.DONE; - } - - @Override - public ActionCallback onModifiedRemoved(final Configurable configurable) { - updateStatus(); - return ActionCallback.DONE; - } - - @Override - public ActionCallback onErrorsChanged() { - updateStatus(); - return ActionCallback.DONE; - } - }); - Disposer.register(myDisposable, myEditor); - return myEditor; - } - - public boolean updateStatus() { - myApplyAction.setEnabled(myEditor.canApply()); - - final Map errors = myEditor.getContext().getErrors(); - if (errors.size() == 0) { - setErrorText(null); - } - else { - String text = "Changes were not applied because of an error"; - - final String errorMessage = getErrorMessage(errors); - if (errorMessage != null) { - text += "
" + errorMessage; - } - - setErrorText(text); - } - - return errors.size() == 0; - } - - @Nullable - private static String getErrorMessage(final Map errors) { - final Collection values = errors.values(); - final ConfigurationException[] exceptions = values.toArray(new ConfigurationException[values.size()]); - if (exceptions.length > 0) { - return exceptions[0].getMessage(); - } - return null; - } - - @Override - protected String getDimensionServiceKey() { - return DIMENSION_KEY; - } - - @Override - public void doOKAction() { - myEditor.flushModifications(); - - if (myEditor.canApply()) { - myEditor.apply(); - if (!updateStatus()) return; - } - - saveCurrentConfigurable(); - - ApplicationManager.getApplication().saveAll(); - - super.doOKAction(); - } - - - private void saveCurrentConfigurable() { - final Configurable current = myEditor.getContext().getCurrentConfigurable(); - if (current == null) return; - - final PropertiesComponent props = PropertiesComponent.getInstance(myProject); - - if (current instanceof SearchableConfigurable) { - props.setValue(LAST_SELECTED_CONFIGURABLE, ((SearchableConfigurable)current).getId()); - } - else { - props.setValue(LAST_SELECTED_CONFIGURABLE, current.getClass().getName()); - } - } - - @Nullable - private static Configurable findLastSavedConfigurable(ConfigurableGroup[] groups, final Project project) { - final String id = PropertiesComponent.getInstance(project).getValue(LAST_SELECTED_CONFIGURABLE); - if (id == null) return null; - - return new ConfigurableVisitor.ByID(id).find(groups); - } - - @Override - public void doCancelAction(final AWTEvent source) { - if (source instanceof KeyEvent || source instanceof ActionEvent) { - if (myEditor.getContext().isHoldingFilter()) { - myEditor.clearFilter(); - return; - } - } - - super.doCancelAction(source); - } - - @Override - public void doCancelAction() { - saveCurrentConfigurable(); - super.doCancelAction(); - } - - @NotNull - @Override - protected Action[] createActions() { - myApplyAction = new ApplyAction(); - return new Action[]{getOKAction(), getCancelAction(), myApplyAction, getHelpAction()}; - } - - @Override - protected void doHelpAction() { - final String topic = myEditor.getHelpTopic(); - if (topic != null) { - HelpManager.getInstance().invokeHelp(topic); - } - } - - @Override - public JComponent getPreferredFocusedComponent() { - return myEditor.getPreferredFocusedComponent(); - } - - public Object getData(@NonNls String dataId) { - if (OptionsEditor.KEY.is(dataId)) { - return myEditor; - } - return myEditor == null ? null : myEditor.getData(dataId); - } - - private class ApplyAction extends AbstractAction { - public ApplyAction() { - super(CommonBundle.getApplyButtonText()); - setEnabled(false); - } - - public void actionPerformed(final ActionEvent e) { - myEditor.apply(); - myEditor.revalidate(); - myEditor.repaint(); - updateStatus(); - } - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java deleted file mode 100644 index 723953d1aca3..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditor.java +++ /dev/null @@ -1,1144 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.options.newEditor; - -import com.intellij.CommonBundle; -import com.intellij.ide.util.PropertiesComponent; -import com.intellij.internal.statistic.UsageTrigger; -import com.intellij.internal.statistic.beans.ConvertUsagesUtil; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.actionSystem.ex.AnActionListener; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ex.ApplicationEx; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.options.*; -import com.intellij.openapi.options.ex.ConfigurableWrapper; -import com.intellij.openapi.options.ex.Settings; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DetailsComponent; -import com.intellij.openapi.ui.LoadingDecorator; -import com.intellij.openapi.ui.NullableComponent; -import com.intellij.openapi.ui.Splitter; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.EdtRunnable; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.ui.LightColors; -import com.intellij.ui.OnePixelSplitter; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.components.GradientViewport; -import com.intellij.ui.components.labels.LinkLabel; -import com.intellij.ui.components.panels.NonOpaquePanel; -import com.intellij.ui.components.panels.Wrapper; -import com.intellij.ui.navigation.History; -import com.intellij.ui.navigation.Place; -import com.intellij.ui.treeStructure.SimpleNode; -import com.intellij.ui.treeStructure.filtered.FilteringTreeBuilder; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; -import com.intellij.util.ui.update.Activatable; -import com.intellij.util.ui.update.MergingUpdateQueue; -import com.intellij.util.ui.update.UiNotifyConnector; -import com.intellij.util.ui.update.Update; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.AWTEventListener; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.*; -import java.util.List; - -public class OptionsEditor extends JPanel implements DataProvider, Place.Navigator, Disposable, AWTEventListener { - public static DataKey KEY = DataKey.create("options.editor"); - - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.options.newEditor.OptionsEditor"); - - @NonNls private static final String MAIN_SPLITTER_PROPORTION = "options.splitter.main.proportions"; - @NonNls private static final String DETAILS_SPLITTER_PROPORTION = "options.splitter.details.proportions"; - - @NonNls private static final String NOT_A_NEW_COMPONENT = "component.was.already.instantiated"; - - private final History myHistory = new History(this); - - private final OptionsTree myTree; - private final SettingsTreeView myTreeView; - private final SettingsSearch mySearch; - private final Splitter myMainSplitter; - //[back/forward] JComponent myToolbarComponent; - - private final DetailsComponent myOwnDetails = - new DetailsComponent().setEmptyContentText("Select configuration element in the tree to edit its settings"); - private final ContentWrapper myContentWrapper = new ContentWrapper(); - - - private final Map myConfigurable2Content = new HashMap(); - private final Map myConfigurable2LoadCallback = new HashMap(); - - private final MergingUpdateQueue myModificationChecker; - - private final SpotlightPainter mySpotlightPainter = new SpotlightPainter(myOwnDetails.getContentGutter(), this) { - void updateNow() { - Configurable configurable = getContext().getCurrentConfigurable(); - update(myFilter, configurable, myConfigurable2Content.containsKey(configurable) ? myContentWrapper : null); - } - }; - private final LoadingDecorator myLoadingDecorator; - private final SettingsFilter myFilter; - - private final Wrapper mySearchWrapper = new Wrapper(); - private final JPanel myLeftSide; - - //[back/forward] private ActionToolbar myToolbar; - private Window myWindow; - private final PropertiesComponent myProperties; - private volatile boolean myDisposed; - - final Settings mySettings; - - public OptionsEditor(Project project, ConfigurableGroup[] groups, Configurable preselectedConfigurable) { - myProperties = PropertiesComponent.getInstance(project); - - mySettings = new Settings(groups) { - @Override - protected ActionCallback selectImpl(Configurable configurable) { - return OptionsEditor.this.select(configurable, ""); - } - }; - - mySearch = new SettingsSearch() { - @Override - protected void onTextKeyEvent(final KeyEvent e) { - if (myTreeView != null) { - myTreeView.myTree.processKeyEvent(e); - } - else { - myTree.processTextEvent(e); - } - } - - @Override - void delegateKeyEvent(KeyEvent event) { - myFilter.myDocumentWasChanged = false; - try { - super.delegateKeyEvent(event); - } - finally { - if (myFilter.myDocumentWasChanged && !isFilterFieldVisible()) { - setFilterFieldVisible(true, false, false); - } - } - } - }; - if (Registry.is("ide.new.settings.dialog")) { - mySearch.setBackground(UIUtil.SIDE_PANEL_BACKGROUND); - mySearch.setBorder(new EmptyBorder(5, 10, 2, 10)); - } - - myFilter = new SettingsFilter(project, groups, mySearch) { - @Override - Configurable getConfigurable(SimpleNode node) { - if (node instanceof OptionsTree.EditorNode) { - return ((OptionsTree.EditorNode)node).getConfigurable(); - } - return SettingsTreeView.getConfigurable(node); - } - - @Override - SimpleNode findNode(Configurable configurable) { - return myTreeView != null - ? myTreeView.findNode(configurable) - : myTree.findNodeFor(configurable); - } - - @Override - void updateSpotlight(boolean now) { - if (!now) { - mySpotlightPainter.updateLater(); - } - else { - mySpotlightPainter.updateNow(); - } - } - }; - - if (Registry.is("ide.new.settings.dialog")) { - myTreeView = new SettingsTreeView(myFilter, groups); - myTreeView.myTree.addKeyListener(mySearch); - myTree = null; - } - else { - myTreeView = null; - myTree = new OptionsTree(myFilter, groups); - myTree.addKeyListener(mySearch); - } - - getContext().addColleague(myTreeView != null ? myTreeView : myTree); - Disposer.register(this, myTreeView != null ? myTreeView : myTree); - - /* [back/forward] - final DefaultActionGroup toolbarActions = new DefaultActionGroup(); - toolbarActions.add(new BackAction(myTree)); - toolbarActions.add(new ForwardAction(myTree)); - toolbarActions.addSeparator(); - toolbarActions.add(new ShowSearchFieldAction(this)); - myToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, true); - myToolbar.setTargetComponent(this); - myToolbarComponent = myToolbar.getComponent(); - - myHistory.addListener(new HistoryListener.Adapter() { - @Override - public void navigationFinished(final Place from, final Place to) { - UIUtil.invokeLaterIfNeeded(new Runnable() { - public void run() { - if (myToolbarComponent.isShowing()) { - myToolbar.updateActionsImmediately(); - } - } - }); - } - }, this); - */ - - - myLeftSide = new JPanel(new BorderLayout()) { - @Override - public Dimension getMinimumSize() { - Dimension dimension = super.getMinimumSize(); - JComponent component = myTreeView != null ? myTreeView : myTree; - dimension.width = Math.max(component.getMinimumSize().width, mySearchWrapper.getPreferredSize().width); - return dimension; - } - }; - - /* [back/forward] - - final NonOpaquePanel toolbarPanel = new NonOpaquePanel(new BorderLayout()); - toolbarPanel.add(myToolbarComponent, BorderLayout.WEST); - toolbarPanel.add(mySearchWrapper, BorderLayout.CENTER); - */ - - myLeftSide.add(mySearchWrapper, BorderLayout.NORTH); - myLeftSide.add(myTreeView != null ? myTreeView : myTree, BorderLayout.CENTER); - - setLayout(new BorderLayout()); - - myMainSplitter = Registry.is("ide.new.settings.dialog") ? new OnePixelSplitter(false) : new Splitter(false); - myMainSplitter.setFirstComponent(myLeftSide); - - myLoadingDecorator = new LoadingDecorator(myOwnDetails.getComponent(), this, 150); - myMainSplitter.setSecondComponent(myLoadingDecorator.getComponent()); - - - myMainSplitter.setProportion(readProportion(0.3f, MAIN_SPLITTER_PROPORTION)); - myContentWrapper.mySplitter.setProportion(readProportion(0.2f, DETAILS_SPLITTER_PROPORTION)); - - add(myMainSplitter, BorderLayout.CENTER); - - MyColleague colleague = new MyColleague(); - getContext().addColleague(colleague); - - if (preselectedConfigurable != null) { - selectInTree(preselectedConfigurable); - } - else { - if (myTreeView != null) { - myTreeView.selectFirst(); - } - else { - myTree.selectFirst(); - } - } - - Toolkit.getDefaultToolkit().addAWTEventListener(this, - AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); - - ActionManager.getInstance().addAnActionListener(new AnActionListener() { - @Override - public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { - } - - @Override - public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { - queueModificationCheck(); - } - - @Override - public void beforeEditorTyping(char c, DataContext dataContext) { - } - }, this); - - myModificationChecker = new MergingUpdateQueue("OptionsModificationChecker", 1000, false, this, this, this); - - /* - String visible = PropertiesComponent.getInstance(myProject).getValue(SEARCH_VISIBLE); - if (visible == null) { - visible = "true"; - } - */ - - setFilterFieldVisible(true, false, false); - - new UiNotifyConnector.Once(this, new Activatable() { - @Override - public void showNotify() { - myWindow = SwingUtilities.getWindowAncestor(OptionsEditor.this); - } - - @Override - public void hideNotify() { - } - }); - } - - private ActionCallback selectInTree(Configurable configurable) { - return myTreeView != null - ? myTreeView.select(configurable) - : myTree.select(configurable); - } - - /** @see #select(Configurable) */ - @Deprecated - public ActionCallback select(Class configurableClass) { - final Configurable configurable = findConfigurable(configurableClass); - if (configurable == null) { - return ActionCallback.REJECTED; - } - return select(configurable); - } - - /** @see #findConfigurableById(String) */ - @Deprecated - @Nullable - public T findConfigurable(Class configurableClass) { - return myTreeView != null - ? myTreeView.findConfigurable(configurableClass) - : myTree.findConfigurable(configurableClass); - } - - @Nullable - public SearchableConfigurable findConfigurableById(@NotNull String configurableId) { - return myTreeView != null - ? myTreeView.findConfigurableById(configurableId) - : myTree.findConfigurableById(configurableId); - } - - public ActionCallback clearSearchAndSelect(Configurable configurable) { - clearFilter(); - return select(configurable, ""); - } - - public ActionCallback select(Configurable configurable) { - if (myFilter.getFilterText().isEmpty()) { - return select(configurable, ""); - } - else { - return myFilter.update(true, true); - } - } - - public ActionCallback select(Configurable configurable, final String text) { - myFilter.update(text, false, true); - return selectInTree(configurable); - } - - private float readProportion(final float defaultValue, final String propertyName) { - float proportion = defaultValue; - try { - final String p = myProperties.getValue(propertyName); - if (p != null) { - proportion = Float.valueOf(p); - } - } - catch (NumberFormatException e) { - LOG.debug(e); - } - return proportion; - } - - private ActionCallback processSelected(final Configurable configurable, final Configurable oldConfigurable) { - if (isShowing(configurable)) return ActionCallback.DONE; - - final ActionCallback result = new ActionCallback(); - - if (configurable == null) { - myOwnDetails.setContent(null); - - myFilter.updateSpotlight(true); - checkModified(oldConfigurable); - - result.setDone(); - - } else { - getUiFor(configurable).doWhenDone(new EdtRunnable() { - @Override - public void runEdt() { - if (myDisposed) return; - - final Configurable current = getContext().getCurrentConfigurable(); - if (current != configurable) { - result.setRejected(); - return; - } - - myHistory.pushQueryPlace(); - - updateDetails(); - - myOwnDetails.setContent(myContentWrapper); - myOwnDetails.setBannerMinHeight(mySearchWrapper.getHeight()); - myOwnDetails.setText(getBannerText(configurable)); - if (myTreeView != null) { - myOwnDetails.forProject(myTreeView.findConfigurableProject(configurable)); - } - else if (Registry.is("ide.new.settings.dialog")) { - myOwnDetails.forProject(myTree.getConfigurableProject(configurable)); - } - - final ConfigurableContent content = myConfigurable2Content.get(current); - - content.setText(getBannerText(configurable)); - content.setBannerActions(new Action[] {new ResetAction(configurable)}); - - content.updateBannerActions(); - - myLoadingDecorator.stopLoading(); - - myFilter.updateSpotlight(false); - - checkModified(oldConfigurable); - checkModified(configurable); - - FilteringTreeBuilder builder = myTreeView != null ? myTreeView.myBuilder : myTree.myBuilder; - if (builder.getSelectedElements().size() == 0) { - select(configurable).notify(result); - } else { - result.setDone(); - } - } - }); - } - - return result; - } - - private static void assertIsDispatchThread() { - ApplicationManager.getApplication().assertIsDispatchThread(); - } - - private ActionCallback getUiFor(final Configurable configurable) { - assertIsDispatchThread(); - - if (myDisposed) { - return ActionCallback.REJECTED; - } - - final ActionCallback result = new ActionCallback(); - - if (!myConfigurable2Content.containsKey(configurable)) { - - final ActionCallback readyCallback = myConfigurable2LoadCallback.get(configurable); - if (readyCallback != null) { - return readyCallback; - } - - myConfigurable2LoadCallback.put(configurable, result); - myLoadingDecorator.startLoading(false); - final Application app = ApplicationManager.getApplication(); - Runnable action = new Runnable() { - @Override - public void run() { - app.runReadAction(new Runnable() { - @Override - public void run() { - ((ApplicationEx)app).runEdtSafeAction(new Runnable() { - @Override - public void run() { - if (myFilter.myProject.isDisposed()) { - result.setRejected(); - } - else { - initConfigurable(configurable).notifyWhenDone(result); - } - } - }); - } - }); - } - }; - if (app.isUnitTestMode()) { - action.run(); - } - else { - app.executeOnPooledThread(action); - } - } - else { - result.setDone(); - } - - return result; - } - - private ActionCallback initConfigurable(@NotNull final Configurable configurable) { - final ActionCallback result = new ActionCallback(); - - final ConfigurableContent content = new Simple(configurable); - - if (!myConfigurable2Content.containsKey(configurable)) { - if (configurable instanceof Place.Navigator) { - ((Place.Navigator)configurable).setHistory(myHistory); - } - configurable.reset(); - } - - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - if (myDisposed) return; - myConfigurable2Content.put(configurable, content); - result.setDone(); - } - }); - - return result; - } - - private String[] getBannerText(Configurable configurable) { - if (myTreeView != null) { - return myTreeView.getPathNames(configurable); - } - final List list = myTree.getPathToRoot(configurable); - final String[] result = new String[list.size()]; - int add = 0; - for (int i = list.size() - 1; i >=0; i--) { - result[add++] = list.get(i).getDisplayName().replace('\n', ' '); - } - return result; - } - - private void checkModified(final Configurable configurable) { - fireModification(configurable); - } - - private void fireModification(final Configurable actual) { - - Collection toCheck = collectAllParentsAndSiblings(actual); - - for (Configurable configurable : toCheck) { - fireModificationForItem(configurable); - } - - } - - private Collection collectAllParentsAndSiblings(final Configurable actual) { - ArrayList result = new ArrayList(); - Configurable nearestParent = getContext().getParentConfigurable(actual); - - if (nearestParent != null) { - Configurable parent = nearestParent; - while (parent != null) { - result.add(parent); - parent = getContext().getParentConfigurable(parent); - } - - result.addAll(getContext().getChildren(nearestParent)); - } else { - result.add(actual); - } - - - return result; - } - - private void fireModificationForItem(final Configurable configurable) { - if (configurable != null) { - if (!myConfigurable2Content.containsKey(configurable) && ConfigurableWrapper.hasOwnContent(configurable)) { - - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - if (myDisposed) return; - initConfigurable(configurable).doWhenDone(new Runnable() { - @Override - public void run() { - if (myDisposed) return; - fireModificationInt(configurable); - } - }); - } - }); - } - }); - } - else if (myConfigurable2Content.containsKey(configurable)) { - fireModificationInt(configurable); - } - } - } - - private void fireModificationInt(final Configurable configurable) { - if (configurable.isModified()) { - getContext().fireModifiedAdded(configurable, null); - } else if (!configurable.isModified() && !getContext().getErrors().containsKey(configurable)) { - getContext().fireModifiedRemoved(configurable, null); - } - } - - private void updateDetails() { - final Configurable current = getContext().getCurrentConfigurable(); - - assert current != null; - - final ConfigurableContent content = myConfigurable2Content.get(current); - content.set(myContentWrapper); - } - - private boolean isShowing(Configurable configurable) { - final ConfigurableContent content = myConfigurable2Content.get(configurable); - return content != null && content.isShowing(); - } - - @Nullable - public String getHelpTopic() { - Configurable current = getContext().getCurrentConfigurable(); - while (current != null) { - String topic = current.getHelpTopic(); - if (topic != null) return topic; - current = getContext().getParentConfigurable(current); - } - return null; - } - - public boolean isFilterFieldVisible() { - return mySearch.getParent() == mySearchWrapper; - } - - public void setFilterFieldVisible(final boolean visible, boolean requestFocus, boolean checkFocus) { - if (isFilterFieldVisible() && checkFocus && requestFocus && !isSearchFieldFocused()) { - UIUtil.requestFocus(mySearch); - return; - } - - mySearchWrapper.setContent(visible ? mySearch : null); - - myLeftSide.revalidate(); - myLeftSide.repaint(); - - if (visible && requestFocus) { - UIUtil.requestFocus(mySearch); - } - } - - public boolean isSearchFieldFocused() { - return mySearch.getTextEditor().isFocusOwner(); - } - - private class ResetAction extends AbstractAction { - Configurable myConfigurable; - - ResetAction(final Configurable configurable) { - myConfigurable = configurable; - putValue(NAME, "Reset"); - putValue(SHORT_DESCRIPTION, "Rollback changes for this configuration element"); - } - - @Override - public void actionPerformed(final ActionEvent e) { - reset(myConfigurable, true); - checkModified(myConfigurable); - } - - @Override - public boolean isEnabled() { - return myFilter.myContext.isModified(myConfigurable) || getContext().getErrors().containsKey(myConfigurable); - } - } - - private static class ContentWrapper extends NonOpaquePanel { - - private final JLabel myErrorLabel; - - private JComponent mySimpleContent; - private ConfigurationException myException; - - - private JComponent myMaster; - private JComponent myToolbar; - private DetailsComponent myDetails; - - private final Splitter mySplitter = new Splitter(false); - private JPanel myLeft = new JPanel(new BorderLayout()); - public float myLastSplitterProportion; - - private ContentWrapper() { - setLayout(new BorderLayout()); - myErrorLabel = new JLabel(); - myErrorLabel.setOpaque(true); - myErrorLabel.setBackground(LightColors.RED); - - myLeft = new JPanel(new BorderLayout()); - - mySplitter.addPropertyChangeListener(Splitter.PROP_PROPORTION, new PropertyChangeListener() { - @Override - public void propertyChange(final PropertyChangeEvent evt) { - myLastSplitterProportion = ((Float)evt.getNewValue()).floatValue(); - } - }); - } - - void setContent(JComponent c, ConfigurationException e, boolean scrollable) { - if (c != null && mySimpleContent == c && myException == e) return; - - removeAll(); - - if (c != null) { - if (scrollable) { - JScrollPane scroll = ScrollPaneFactory.createScrollPane(null, true); - scroll.setViewport(new GradientViewport(c, JBUI.insets(5), false)); - scroll.getVerticalScrollBar().setUnitIncrement(JBUI.scale(10)); - add(scroll, BorderLayout.CENTER); - } - else { - add(c, BorderLayout.CENTER); - } - } - - if (e != null) { - myErrorLabel.setText(UIUtil.toHtml(e.getMessage())); - add(myErrorLabel, BorderLayout.NORTH); - } - - mySimpleContent = c; - myException = e; - - myMaster = null; - myToolbar = null; - myDetails = null; - mySplitter.setFirstComponent(null); - mySplitter.setSecondComponent(null); - } - - void setContent(JComponent master, JComponent toolbar, DetailsComponent details, ConfigurationException e) { - if (myMaster == master && myToolbar == toolbar && myDetails == details && myException == e) return; - - myMaster = master; - myToolbar = toolbar; - myDetails = details; - myException = e; - - - removeAll(); - myLeft.removeAll(); - - myLeft.add(myToolbar, BorderLayout.NORTH); - myLeft.add(myMaster, BorderLayout.CENTER); - - myDetails.setBannerMinHeight(myToolbar.getPreferredSize().height); - - mySplitter.setFirstComponent(myLeft); - mySplitter.setSecondComponent(myDetails.getComponent()); - mySplitter.setProportion(myLastSplitterProportion); - - add(mySplitter, BorderLayout.CENTER); - - mySimpleContent = null; - } - - - @Override - public boolean isNull() { - final boolean superNull = super.isNull(); - if (superNull) return superNull; - - if (myMaster == null) { - return NullableComponent.Check.isNull(mySimpleContent); - } else { - return NullableComponent.Check.isNull(myMaster); - } - } - } - - public void reset(Configurable configurable, boolean notify) { - configurable.reset(); - if (notify) { - getContext().fireReset(configurable); - } - } - - public void apply() { - Map errors = new LinkedHashMap(); - final Set modified = getContext().getModified(); - for (Configurable each : modified) { - try { - each.apply(); - UsageTrigger.trigger("ide.settings." + ConvertUsagesUtil.escapeDescriptorName(each.getDisplayName())); - if (!each.isModified()) { - getContext().fireModifiedRemoved(each, null); - } - } - catch (ConfigurationException e) { - errors.put(each, e); - LOG.debug(e); - } - } - - getContext().fireErrorsChanged(errors, null); - - if (!errors.isEmpty()) { - selectInTree(errors.keySet().iterator().next()); - } - } - - - @Override - public Object getData(@NonNls final String dataId) { - if (Settings.KEY.is(dataId)) { - return mySettings; - } - if (KEY.is(dataId)) { - return this; - } - return History.KEY.is(dataId) ? myHistory : null; - } - - public JComponent getPreferredFocusedComponent() { - return myTreeView != null ? myTreeView.myTree : mySearch;//myTree.getTree(); - } - - @Override - public Dimension getPreferredSize() { - return JBUI.size(1200, 768); - } - - @Override - public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) { - final Configurable config = (Configurable)place.getPath("configurable"); - final String filter = (String)place.getPath("filter"); - - final ActionCallback result = new ActionCallback(); - - myFilter.update(filter, false, true).doWhenDone(new Runnable() { - @Override - public void run() { - selectInTree(config).notifyWhenDone(result); - } - }); - - return result; - } - - @Override - public void queryPlace(@NotNull final Place place) { - final Configurable current = getContext().getCurrentConfigurable(); - place.putPath("configurable", current); - place.putPath("filter", myFilter.getFilterText()); - - if (current instanceof Place.Navigator) { - ((Place.Navigator)current).queryPlace(place); - } - } - - @Override - public void dispose() { - assertIsDispatchThread(); - - if (myDisposed) { - return; - } - - myDisposed = true; - - myProperties.setValue(MAIN_SPLITTER_PROPORTION, String.valueOf(myMainSplitter.getProportion())); - myProperties.setValue(DETAILS_SPLITTER_PROPORTION, String.valueOf(myContentWrapper.myLastSplitterProportion)); - - Toolkit.getDefaultToolkit().removeAWTEventListener(this); - - - final Set configurables = new HashSet(); - configurables.addAll(myConfigurable2Content.keySet()); - configurables.addAll(myConfigurable2LoadCallback.keySet()); - for (final Configurable each : configurables) { - ActionCallback loadCb = myConfigurable2LoadCallback.get(each); - if (loadCb != null) { - loadCb.doWhenProcessed(new Runnable() { - @Override - public void run() { - assertIsDispatchThread(); - each.disposeUIResources(); - } - }); - } else { - each.disposeUIResources(); - } - } - - Disposer.clearOwnFields(this); - } - - public OptionsEditorContext getContext() { - return myFilter.myContext; - } - - private class MyColleague extends OptionsEditorColleague.Adapter { - @Override - public ActionCallback onSelected(final Configurable configurable, final Configurable oldConfigurable) { - return processSelected(configurable, oldConfigurable); - } - - @Override - public ActionCallback onModifiedRemoved(final Configurable configurable) { - return updateIfCurrent(configurable); - } - - @Override - public ActionCallback onModifiedAdded(final Configurable configurable) { - return updateIfCurrent(configurable); - } - - @Override - public ActionCallback onErrorsChanged() { - return updateIfCurrent(getContext().getCurrentConfigurable()); - } - - private ActionCallback updateIfCurrent(final Configurable configurable) { - if (getContext().getCurrentConfigurable() == configurable && configurable != null) { - updateDetails(); - final ConfigurableContent content = myConfigurable2Content.get(configurable); - content.updateBannerActions(); - return ActionCallback.DONE; - } else { - return ActionCallback.REJECTED; - } - } - } - - public void flushModifications() { - fireModification(getContext().getCurrentConfigurable()); - } - - public boolean canApply() { - return !getContext().getModified().isEmpty(); - } - - @Override - public void eventDispatched(final AWTEvent event) { - if (event.getID() == MouseEvent.MOUSE_PRESSED || event.getID() == MouseEvent.MOUSE_RELEASED || event.getID() == MouseEvent.MOUSE_DRAGGED) { - final MouseEvent me = (MouseEvent)event; - if (SwingUtilities.isDescendingFrom(me.getComponent(), SwingUtilities.getWindowAncestor(myContentWrapper)) || isPopupOverEditor(me.getComponent())) { - queueModificationCheck(); - } - } - else if (event.getID() == KeyEvent.KEY_PRESSED || event.getID() == KeyEvent.KEY_RELEASED) { - final KeyEvent ke = (KeyEvent)event; - if (SwingUtilities.isDescendingFrom(ke.getComponent(), myContentWrapper)) { - queueModificationCheck(); - } - } - } - - private void queueModificationCheck() { - final Configurable configurable = getContext().getCurrentConfigurable(); - myModificationChecker.queue(new Update(this) { - @Override - public void run() { - checkModified(configurable); - } - - @Override - public boolean isExpired() { - return getContext().getCurrentConfigurable() != configurable; - } - }); - } - - private boolean isPopupOverEditor(Component c) { - final Window wnd = SwingUtilities.getWindowAncestor(c); - return (wnd instanceof JWindow || wnd instanceof JDialog && ((JDialog)wnd).getModalityType() == Dialog.ModalityType.MODELESS) && myWindow != null && wnd.getParent() == myWindow; - } - - private abstract static class ConfigurableContent { - abstract void set(ContentWrapper wrapper); - - abstract boolean isShowing(); - - abstract void setBannerActions(Action[] actions); - - abstract void updateBannerActions(); - - abstract void setText(final String[] bannerText); - } - - /** - * Returns default view for the specified configurable. - * It uses the configurable identifier to retrieve description. - * - * @param searchable the configurable that does not have any view - * @return default view for the specified configurable - */ - private JComponent createDefaultComponent(SearchableConfigurable searchable) { - JPanel panel = new JPanel(new BorderLayout(0, 9)); - try { - panel.add(BorderLayout.NORTH, new JLabel(getDefaultDescription(searchable))); - } - catch (AssertionError error) { - return null; // description is not set - } - if (searchable instanceof Configurable.Composite) { - JPanel box = new JPanel(); - box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS)); - panel.add(BorderLayout.CENTER, box); - - Configurable.Composite composite = (Configurable.Composite)searchable; - for (final Configurable configurable : composite.getConfigurables()) { - LinkLabel label = new LinkLabel(configurable.getDisplayName(), null) { - @Override - public void doClick() { - select(configurable, null); - } - }; - label.setBorder(BorderFactory.createEmptyBorder(1, 17, 3, 1)); - box.add(label); - } - } - return panel; - } - - @NotNull - private static String getDefaultDescription(SearchableConfigurable configurable) { - String key = configurable.getId() + ".settings.description"; - if (configurable instanceof ConfigurableWrapper) { - ConfigurableWrapper wrapper = (ConfigurableWrapper) configurable; - ResourceBundle resourceBundle = wrapper.getExtensionPoint().findBundle(); - if (resourceBundle != null) { - return CommonBundle.message(resourceBundle, key); - } - } - return OptionsBundle.message(key); - } - - private class Simple extends ConfigurableContent { - JComponent myComponent; - Configurable myConfigurable; - - Simple(final Configurable configurable) { - myConfigurable = configurable; - myComponent = configurable.createComponent(); - if (myComponent == null && configurable instanceof SearchableConfigurable) { - myComponent = createDefaultComponent((SearchableConfigurable)configurable); - } - if (myComponent != null) { - final Object clientProperty = myComponent.getClientProperty(NOT_A_NEW_COMPONENT); - if (clientProperty != null && ApplicationManager.getApplication().isInternal()) { - LOG.warn("Settings component for " + configurable.getClass()+ " must be created anew, not reused, in createComponent() and destroyed in disposeUIResources()"); - } - else { - myComponent.putClientProperty(NOT_A_NEW_COMPONENT, Boolean.TRUE); - } - } - } - - @Override - void set(final ContentWrapper wrapper) { - myOwnDetails.setDetailsModeEnabled(true); - boolean noScroll = ConfigurableWrapper.isNoScroll(myConfigurable) || - ConfigurableWrapper.cast(MasterDetails.class, myConfigurable) != null; - wrapper.setContent(myComponent, getContext().getErrors().get(myConfigurable), !noScroll); - } - - @Override - boolean isShowing() { - return myComponent != null && myComponent.isShowing(); - } - - @Override - void setBannerActions(final Action[] actions) { - myOwnDetails.setBannerActions(actions); - } - - @Override - void updateBannerActions() { - myOwnDetails.updateBannerActions(); - } - - @Override - void setText(final String[] bannerText) { - myOwnDetails.setText(bannerText); - } - } - - private class Details extends ConfigurableContent { - MasterDetails myConfigurable; - DetailsComponent myDetails; - JComponent myMaster; - JComponent myToolbar; - - Details(final MasterDetails configurable) { - myConfigurable = configurable; - myConfigurable.initUi(); - myDetails = myConfigurable.getDetails(); - myMaster = myConfigurable.getMaster(); - myToolbar = myConfigurable.getToolbar(); - } - - @Override - void set(final ContentWrapper wrapper) { - myOwnDetails.setDetailsModeEnabled(false); - myDetails.setPrefix(getBannerText((Configurable)myConfigurable)); - wrapper.setContent(myMaster, myToolbar, myDetails, getContext().getErrors().get(myConfigurable)); - } - - @Override - void setBannerActions(final Action[] actions) { - myDetails.setBannerActions(actions); - } - - @Override - boolean isShowing() { - return myDetails.getComponent().isShowing(); - } - - @Override - void updateBannerActions() { - myDetails.updateBannerActions(); - } - - @Override - void setText(final String[] bannerText) { - myDetails.update(); - } - } - - public void clearFilter() { - mySearch.setText(""); - } - - @Override - public void setHistory(final History history) { - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorDialog.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorDialog.java deleted file mode 100644 index aacd52774776..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsEditorDialog.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.options.newEditor; - -import com.intellij.CommonBundle; -import com.intellij.ide.ui.search.SearchUtil; -import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.help.HelpManager; -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurableGroup; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.SearchableConfigurable; -import com.intellij.openapi.options.ex.Settings; -import com.intellij.openapi.project.DumbModePermission; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Disposer; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -public class OptionsEditorDialog extends DialogWrapper implements DataProvider{ - - private Project myProject; - private ConfigurableGroup[] myGroups; - private Configurable myPreselected; - private OptionsEditor myEditor; - - private ApplyAction myApplyAction; - public static final String DIMENSION_KEY = "OptionsEditor"; - @NonNls static final String LAST_SELECTED_CONFIGURABLE = "options.lastSelected"; - - /** This constructor should be eliminated after the new modality approach - * will have been checked. See a {@code Registry} key ide.perProjectModality - * @deprecated - */ - public OptionsEditorDialog(Project project, ConfigurableGroup[] groups, - @Nullable Configurable preselectedConfigurable, boolean applicationModalIfPossible) { - super(project, true, applicationModalIfPossible); - init(project, groups, preselectedConfigurable != null ? preselectedConfigurable : findLastSavedConfigurable(groups, project)); - } - - /** This constructor should be eliminated after the new modality approach - * will have been checked. See a {@code Registry} key ide.perProjectModality - * @deprecated - */ - public OptionsEditorDialog(Project project, ConfigurableGroup[] groups, - @NotNull String preselectedConfigurableDisplayName, boolean applicationModalIfPossible) { - super(project, true, applicationModalIfPossible); - init(project, groups, getPreselectedByDisplayName(groups, preselectedConfigurableDisplayName, project)); - } - - public OptionsEditorDialog(Project project, ConfigurableGroup[] groups, @Nullable Configurable preselectedConfigurable) { - super(project, true); - init(project, groups, preselectedConfigurable != null ? preselectedConfigurable : findLastSavedConfigurable(groups, project)); - } - - public OptionsEditorDialog(Project project, ConfigurableGroup[] groups, @NotNull String preselectedConfigurableDisplayName) { - super(project, true); - init(project, groups, getPreselectedByDisplayName(groups, preselectedConfigurableDisplayName, project)); - } - - private void init(final Project project, final ConfigurableGroup[] groups, @Nullable final Configurable preselected) { - myProject = project; - myGroups = groups; - myPreselected = preselected; - - setTitle(CommonBundle.settingsTitle()); - - init(); - } - - @Override - public void show() { - DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() { - @Override - public void run() { - OptionsEditorDialog.super.show(); - } - }); - } - - @Nullable - private static Configurable getPreselectedByDisplayName(final ConfigurableGroup[] groups, final String preselectedConfigurableDisplayName, - final Project project) { - Configurable result = findPreselectedByDisplayName(preselectedConfigurableDisplayName, groups); - - return result == null ? findLastSavedConfigurable(groups, project) : result; - } - - @Override - public boolean isTypeAheadEnabled() { - return true; - } - - protected JComponent createCenterPanel() { - myEditor = new OptionsEditor(myProject, myGroups, myPreselected); - myEditor.getContext().addColleague(new OptionsEditorColleague.Adapter() { - @Override - public ActionCallback onModifiedAdded(final Configurable configurable) { - updateStatus(); - return ActionCallback.DONE; - } - - @Override - public ActionCallback onModifiedRemoved(final Configurable configurable) { - updateStatus(); - return ActionCallback.DONE; - } - - @Override - public ActionCallback onErrorsChanged() { - updateStatus(); - return ActionCallback.DONE; - } - }); - Disposer.register(myDisposable, myEditor); - return myEditor; - } - - public boolean updateStatus() { - myApplyAction.setEnabled(myEditor.canApply()); - - final Map errors = myEditor.getContext().getErrors(); - if (errors.size() == 0) { - setErrorText(null); - } else { - String text = "Changes were not applied because of an error"; - - final String errorMessage = getErrorMessage(errors); - if (errorMessage != null) { - text += "
" + errorMessage; - } - - setErrorText(text); - } - - return errors.size() == 0; - } - - @Nullable - private static String getErrorMessage(final Map errors) { - final Collection values = errors.values(); - final ConfigurationException[] exceptions = values.toArray(new ConfigurationException[values.size()]); - if (exceptions.length > 0) { - return exceptions[0].getMessage(); - } - return null; - } - - @Override - protected String getDimensionServiceKey() { - return DIMENSION_KEY; - } - - @Override - protected void doOKAction() { - myEditor.flushModifications(); - - if (myEditor.canApply()) { - myEditor.apply(); - if (!updateStatus()) return; - } - - saveCurrentConfigurable(); - - ApplicationManager.getApplication().saveAll(); - - super.doOKAction(); - } - - - private void saveCurrentConfigurable() { - final Configurable current = myEditor.getContext().getCurrentConfigurable(); - if (current == null) return; - - final PropertiesComponent props = PropertiesComponent.getInstance(myProject); - - if (current instanceof SearchableConfigurable) { - props.setValue(LAST_SELECTED_CONFIGURABLE, ((SearchableConfigurable)current).getId()); - } else { - props.setValue(LAST_SELECTED_CONFIGURABLE, current.getClass().getName()); - } - } - - @Nullable - private static Configurable findLastSavedConfigurable(ConfigurableGroup[] groups, final Project project) { - final String id = PropertiesComponent.getInstance(project).getValue(LAST_SELECTED_CONFIGURABLE); - if (id == null) return null; - - return findConfigurableInGroups(id, groups); - } - - @Nullable - private static Configurable findConfigurableInGroups(String id, Configurable.Composite... groups) { - // avoid unnecessary group expand: check top-level configurables in all groups before looking at children - for (Configurable.Composite group : groups) { - final Configurable[] configurables = group.getConfigurables(); - for (Configurable c : configurables) { - if (c instanceof SearchableConfigurable && id.equals(((SearchableConfigurable)c).getId())) { - return c; - } else if (id.equals(c.getClass().getName())) { - return c; - } - } - } - for (Configurable.Composite group : groups) { - final Configurable[] configurables = group.getConfigurables(); - for (Configurable c : configurables) { - if (c instanceof Configurable.Composite) { - Configurable result = findConfigurableInGroups(id, (Configurable.Composite)c); - if (result != null) { - return result; - } - } - } - } - return null; - } - - @Nullable - private static Configurable findPreselectedByDisplayName(final String preselectedConfigurableDisplayName, ConfigurableGroup[] groups) { - final List all = SearchUtil.expand(groups); - for (Configurable each : all) { - if (preselectedConfigurableDisplayName.equals(each.getDisplayName())) return each; - } - return null; - } - - @Override - public void doCancelAction(final AWTEvent source) { - if (source instanceof KeyEvent || source instanceof ActionEvent) { - if (myEditor.getContext().isHoldingFilter()) { - myEditor.clearFilter(); - return; - } - } - - super.doCancelAction(source); - } - - @Override - public void doCancelAction() { - saveCurrentConfigurable(); - super.doCancelAction(); - } - - @NotNull - @Override - protected Action[] createActions() { - myApplyAction = new ApplyAction(); - return new Action[] {getOKAction(), getCancelAction(), myApplyAction, getHelpAction()}; - } - - @Override - protected void doHelpAction() { - final String topic = myEditor.getHelpTopic(); - if (topic != null) { - HelpManager.getInstance().invokeHelp(topic); - } - } - - @Override - public JComponent getPreferredFocusedComponent() { - return myEditor.getPreferredFocusedComponent(); - } - - public Object getData(@NonNls String dataId) { - if (Settings.KEY.is(dataId)) { - return myEditor.mySettings; - } - if (OptionsEditor.KEY.is(dataId)) { - return myEditor; - } - return null; - } - - private class ApplyAction extends AbstractAction { - public ApplyAction() { - super(CommonBundle.getApplyButtonText()); - setEnabled(false); - } - - public void actionPerformed(final ActionEvent e) { - myEditor.apply(); - myEditor.revalidate(); - myEditor.repaint(); - } - } - -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java deleted file mode 100644 index 5579651fe705..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java +++ /dev/null @@ -1,981 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.options.newEditor; - -import com.intellij.icons.AllIcons; -import com.intellij.ide.util.treeView.NodeDescriptor; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurableGroup; -import com.intellij.openapi.options.OptionsBundle; -import com.intellij.openapi.options.SearchableConfigurable; -import com.intellij.openapi.options.ex.ConfigurableWrapper; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.ActionCallback; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; -import com.intellij.ui.*; -import com.intellij.ui.components.panels.NonOpaquePanel; -import com.intellij.ui.treeStructure.*; -import com.intellij.ui.treeStructure.filtered.FilteringTreeBuilder; -import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure; -import com.intellij.util.ui.GraphicsUtil; -import com.intellij.util.ui.UIUtil; -import com.intellij.util.ui.tree.TreeUtil; -import com.intellij.util.ui.update.MergingUpdateQueue; -import com.intellij.util.ui.update.Update; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.event.TreeExpansionEvent; -import javax.swing.event.TreeExpansionListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.plaf.TreeUI; -import javax.swing.plaf.basic.BasicTreeUI; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; - -public class OptionsTree extends JPanel implements Disposable, OptionsEditorColleague { - private final SettingsFilter myFilter; - final SimpleTree myTree; - List myGroups; - FilteringTreeBuilder myBuilder; - Root myRoot; - - Map myConfigurable2Node = new HashMap(); - - MergingUpdateQueue mySelection; - private final OptionsTree.Renderer myRenderer; - - public OptionsTree(SettingsFilter filter, ConfigurableGroup... groups) { - myFilter = filter; - myGroups = Arrays.asList(groups); - - myRoot = new Root(); - final SimpleTreeStructure structure = new SimpleTreeStructure() { - public Object getRootElement() { - return myRoot; - } - }; - - myTree = new MyTree(); - TreeUtil.installActions(myTree); - myTree.setBorder(new EmptyBorder(0, 1, 0, 0)); - - myTree.setRowHeight(-1); - myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - myRenderer = new Renderer(); - myTree.setCellRenderer(myRenderer); - myTree.setRootVisible(false); - myTree.setShowsRootHandles(false); - myBuilder = new MyBuilder(structure); - myBuilder.setFilteringMerge(300, null); - Disposer.register(this, myBuilder); - - setLayout(new BorderLayout()); - - myTree.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(final ComponentEvent e) { - myBuilder.revalidateTree(); - } - - @Override - public void componentMoved(final ComponentEvent e) { - myBuilder.revalidateTree(); - } - - @Override - public void componentShown(final ComponentEvent e) { - myBuilder.revalidateTree(); - } - }); - - add(new StickySeparator(myTree), BorderLayout.CENTER); - - mySelection = new MergingUpdateQueue("OptionsTree", 150, false, this, this, this).setRestartTimerOnAdd(true); - myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { - public void valueChanged(final TreeSelectionEvent e) { - final TreePath path = e.getNewLeadSelectionPath(); - if (path == null) { - queueSelection(null); - } - else { - final Base base = extractNode(path.getLastPathComponent()); - queueSelection(base != null ? base.getConfigurable() : null); - } - } - }); - } - - ActionCallback select(@Nullable Configurable configurable) { - return queueSelection(configurable); - } - - public void selectFirst() { - for (ConfigurableGroup eachGroup : myGroups) { - final Configurable[] kids = eachGroup.getConfigurables(); - if (kids.length > 0) { - queueSelection(kids[0]); - return; - } - } - } - - private Configurable myQueuedConfigurable; - - ActionCallback queueSelection(final Configurable configurable) { - if (myBuilder.isSelectionBeingAdjusted()) { - return ActionCallback.REJECTED; - } - - final ActionCallback callback = new ActionCallback(); - - myQueuedConfigurable = configurable; - final Update update = new Update(this) { - public void run() { - if (configurable != myQueuedConfigurable) return; - - if (configurable == null) { - myTree.getSelectionModel().clearSelection(); - myFilter.myContext.fireSelected(null, OptionsTree.this); - } - else { - myBuilder.getReady(this).doWhenDone(new Runnable() { - @Override - public void run() { - if (configurable != myQueuedConfigurable) return; - - final EditorNode editorNode = myConfigurable2Node.get(configurable); - FilteringTreeStructure.FilteringNode editorUiNode = myBuilder.getVisibleNodeFor(editorNode); - if (editorUiNode == null) return; - - if (!myBuilder.getSelectedElements().contains(editorUiNode)) { - myBuilder.select(editorUiNode, new Runnable() { - public void run() { - fireSelected(configurable, callback); - } - }); - } else { - myBuilder.scrollSelectionToVisible(new Runnable() { - public void run() { - fireSelected(configurable, callback); - } - }, false); - } - } - }); - } - } - - @Override - public void setRejected() { - super.setRejected(); - callback.setRejected(); - } - }; - mySelection.queue(update); - return callback; - } - - private void fireSelected(Configurable configurable, final ActionCallback callback) { - myFilter.myContext.fireSelected(configurable, this).doWhenProcessed(callback.createSetDoneRunnable()); - } - - - public JTree getTree() { - return myTree; - } - - public List getPathToRoot(final Configurable configurable) { - final ArrayList path = new ArrayList(); - - EditorNode eachNode = myConfigurable2Node.get(configurable); - if (eachNode == null) return path; - - while (eachNode != null) { - path.add(eachNode.getConfigurable()); - final SimpleNode parent = eachNode.getParent(); - if (parent instanceof EditorNode) { - eachNode = (EditorNode)parent; - } - else { - break; - } - } - - return path; - } - - public SimpleNode findNodeFor(final Configurable toSelect) { - return myConfigurable2Node.get(toSelect); - } - - @Nullable - public T findConfigurable(Class configurableClass) { - for (Configurable configurable : myConfigurable2Node.keySet()) { - if (configurableClass.isInstance(configurable)) { - return configurableClass.cast(configurable); - } - } - return null; - } - - @Nullable - public SearchableConfigurable findConfigurableById(@NotNull String configurableId) { - for (Configurable configurable : myConfigurable2Node.keySet()) { - if (configurable instanceof SearchableConfigurable) { - SearchableConfigurable searchableConfigurable = (SearchableConfigurable) configurable; - if (configurableId.equals(searchableConfigurable.getId())) { - return searchableConfigurable; - } - } - } - return null; - } - - class Renderer extends GroupedElementsRenderer.Tree { - private GroupSeparator mySeparator; - private JLabel myProjectIcon; - private JLabel myHandle; - - @Override - protected void layout() { - myRendererComponent.setOpaqueActive(false); - - mySeparator = new GroupSeparator(); - myRendererComponent.add(Registry.is("ide.new.settings.dialog") ? mySeparator : mySeparatorComponent, BorderLayout.NORTH); - - final NonOpaquePanel content = new NonOpaquePanel(new BorderLayout()); - myHandle = new JLabel("", SwingConstants.CENTER); - if (!SystemInfo.isMac) { - myHandle.setBorder(new EmptyBorder(0, 2, 0, 2)); - } - myHandle.setOpaque(false); - content.add(myHandle, BorderLayout.WEST); - content.add(myComponent, BorderLayout.CENTER); - myProjectIcon = new JLabel(" ", SwingConstants.LEFT); - myProjectIcon.setOpaque(true); - content.add(myProjectIcon, BorderLayout.EAST); - myRendererComponent.add(content, BorderLayout.CENTER); - } - - public Component getTreeCellRendererComponent(final JTree tree, - final Object value, - final boolean selected, - final boolean expanded, - final boolean leaf, - final int row, - final boolean hasFocus) { - - - JComponent result; - Color fg = UIUtil.getTreeTextForeground(); - mySeparator.configure(null, false); - final Base base = extractNode(value); - if (base instanceof EditorNode) { - - final EditorNode editor = (EditorNode)base; - ConfigurableGroup group = null; - if (editor.getParent() == myRoot) { - final DefaultMutableTreeNode prevValue = ((DefaultMutableTreeNode)value).getPreviousSibling(); - if (prevValue == null || prevValue instanceof LoadingNode) { - group = editor.getGroup(); - mySeparator.configure(group, false); - } - else { - final Base prevBase = extractNode(prevValue); - if (prevBase instanceof EditorNode) { - final EditorNode prevEditor = (EditorNode)prevBase; - if (prevEditor.getGroup() != editor.getGroup()) { - group = editor.getGroup(); - mySeparator.configure(group, true); - } - } - } - } - - TreePath path = tree.getPathForRow(row); - if (path == null) { - if (value instanceof DefaultMutableTreeNode) { - path = new TreePath(((DefaultMutableTreeNode)value).getPath()); - } - } - - final boolean toStretch = tree.isVisible() && path != null; - - int forcedWidth = 2000; - if (toStretch) { - final Rectangle visibleRect = tree.getVisibleRect(); - - int nestingLevel = tree.isRootVisible() ? path.getPathCount() - 1 : path.getPathCount() - 2; - - final int left = UIUtil.getTreeLeftChildIndent(); - final int right = UIUtil.getTreeRightChildIndent(); - - final Insets treeInsets = tree.getInsets(); - - int indent = (left + right) * nestingLevel + (treeInsets != null ? treeInsets.left + treeInsets.right : 0); - - forcedWidth = visibleRect.width > 0 ? visibleRect.width - indent : forcedWidth; - } - - result = configureComponent(base.getText(), base.getText(), null, null, row == -1 || selected, group != null, - group != null ? group.getDisplayName() : null, forcedWidth - 4); - - - if (base.isError()) { - fg = JBColor.red; - } - else if (base.isModified()) { - fg = JBColor.blue; - } - - } - else { - result = configureComponent(value.toString(), null, null, null, selected, false, null, -1); - } - - if (value instanceof DefaultMutableTreeNode) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; - TreePath nodePath = new TreePath(node.getPath()); - myHandle.setIcon(((SimpleTree)tree).getHandleIcon(node, nodePath)); - } else { - myHandle.setIcon(null); - } - - - myTextLabel.setForeground(selected ? UIUtil.getTreeSelectionForeground() : fg); - - myTextLabel.setOpaque(selected); - if (Registry.is("ide.new.settings.dialog")) { - myTextLabel.setBorder(new EmptyBorder(1,2,1,0)); - } - - Project project = null; - if (base != null && Registry.is("ide.new.settings.dialog")) { - SimpleNode parent = base.getParent(); - if (parent == myRoot) { - project = getConfigurableProject(base); // show icon for top-level nodes - } - } - if (project != null) { - myProjectIcon.setBackground(selected ? getSelectionBackground() : getBackground()); - myProjectIcon.setIcon(selected ? AllIcons.General.ProjectConfigurableSelected : AllIcons.General.ProjectConfigurable); - myProjectIcon.setVisible(true); - myProjectIcon.setToolTipText(OptionsBundle.message(project.isDefault() - ? "configurable.default.project.tooltip" - : "configurable.current.project.tooltip")); - } else { - myProjectIcon.setVisible(false); - } - if (Registry.is("ide.new.settings.dialog")) { - result.setBackground(selected ? UIUtil.getTreeSelectionBackground() : UIUtil.SIDE_PANEL_BACKGROUND); - } - return result; - } - - protected JComponent createItemComponent() { - myTextLabel = new ErrorLabel(); - return myTextLabel; - } - - public boolean isUnderHandle(final Point point) { - final Point handlePoint = SwingUtilities.convertPoint(myRendererComponent, point, myHandle); - final Rectangle bounds = myHandle.getBounds(); - return bounds.x < handlePoint.x && bounds.getMaxX() >= handlePoint.x; - } - } - - @Nullable - private Base extractNode(Object object) { - if (object instanceof DefaultMutableTreeNode) { - final DefaultMutableTreeNode uiNode = (DefaultMutableTreeNode)object; - final Object o = uiNode.getUserObject(); - if (o instanceof FilteringTreeStructure.FilteringNode) { - return (Base)((FilteringTreeStructure.FilteringNode)o).getDelegate(); - } - } - - return null; - } - - abstract static class Base extends CachingSimpleNode { - - protected Base(final SimpleNode aParent) { - super(aParent); - } - - String getText() { - return null; - } - - boolean isModified() { - return false; - } - - boolean isError() { - return false; - } - - Configurable getConfigurable() { - return null; - } - } - - class Root extends Base { - - Root() { - super(null); - } - - protected SimpleNode[] buildChildren() { - List result = new ArrayList(); - for (ConfigurableGroup eachGroup : myGroups) { - result.addAll(buildGroup(eachGroup)); - } - - return result.isEmpty() ? NO_CHILDREN : result.toArray(new SimpleNode[result.size()]); - } - - private List buildGroup(final ConfigurableGroup eachGroup) { - List result = new ArrayList(); - final Configurable[] kids = eachGroup.getConfigurables(); - if (kids.length > 0) { - for (Configurable eachKid : kids) { - if (!isInvisibleNode(eachKid)) { - result.add(new EditorNode(this, eachKid, eachGroup)); - } - } - } - return sort(result); - } - } - - private static boolean isInvisibleNode(final Configurable child) { - return child instanceof SearchableConfigurable.Parent && !((SearchableConfigurable.Parent)child).isVisible(); - } - - private static List sort(List c) { - List cc = new ArrayList(c); - Collections.sort(cc, new Comparator() { - public int compare(final EditorNode o1, final EditorNode o2) { - return getConfigurableDisplayName(o1.getConfigurable()).compareToIgnoreCase(getConfigurableDisplayName(o2.getConfigurable())); - } - }); - return cc; - } - - private static String getConfigurableDisplayName(final Configurable c) { - final String name = c.getDisplayName(); - return name != null ? name : "{ Unnamed Page:" + c.getClass().getSimpleName() + " }"; - } - - private List buildChildren(final Configurable configurable, SimpleNode parent, final ConfigurableGroup group) { - if (configurable instanceof Configurable.Composite) { - final Configurable[] kids = ((Configurable.Composite)configurable).getConfigurables(); - final List result = new ArrayList(kids.length); - for (Configurable child : kids) { - result.add(new EditorNode(parent, child, group)); - myFilter.myContext.registerKid(configurable, child); - } - return result; // TODO: DECIDE IF INNERS SHOULD BE SORTED: sort(result); - } - else { - return Collections.emptyList(); - } - } - - private static final EditorNode[] EMPTY_EN_ARRAY = new EditorNode[0]; - class EditorNode extends Base { - Configurable myConfigurable; - ConfigurableGroup myGroup; - - EditorNode(SimpleNode parent, Configurable configurable, @Nullable ConfigurableGroup group) { - super(parent); - myConfigurable = configurable; - myGroup = group; - myConfigurable2Node.put(configurable, this); - addPlainText(getConfigurableDisplayName(configurable)); - } - - protected EditorNode[] buildChildren() { - List list = OptionsTree.this.buildChildren(myConfigurable, this, null); - return list.isEmpty() ? EMPTY_EN_ARRAY : list.toArray(new EditorNode[list.size()]); - } - - - @Override - public boolean isAlwaysLeaf() { - return !(myConfigurable instanceof Configurable.Composite); - } - - @Override - public boolean isContentHighlighted() { - return getParent() == myRoot; - } - - @Override - Configurable getConfigurable() { - return myConfigurable; - } - - @Override - public int getWeight() { - if (getParent() == myRoot) { - return Integer.MAX_VALUE - myGroups.indexOf(myGroup); - } - else { - return WeightBasedComparator.UNDEFINED_WEIGHT; - } - } - - public ConfigurableGroup getGroup() { - return myGroup; - } - - @Override - String getText() { - return getConfigurableDisplayName(myConfigurable).replace("\n", " "); - } - - @Override - boolean isModified() { - return myFilter.myContext.getModified().contains(myConfigurable); - } - - @Override - boolean isError() { - return myFilter.myContext.getErrors().containsKey(myConfigurable); - } - } - - public void dispose() { - myQueuedConfigurable = null; - } - - public ActionCallback onSelected(final Configurable configurable, final Configurable oldConfigurable) { - return queueSelection(configurable); - } - - public ActionCallback onModifiedAdded(final Configurable colleague) { - myTree.repaint(); - return ActionCallback.DONE; - } - - public ActionCallback onModifiedRemoved(final Configurable configurable) { - myTree.repaint(); - return ActionCallback.DONE; - } - - public ActionCallback onErrorsChanged() { - return ActionCallback.DONE; - } - - public void processTextEvent(KeyEvent e) { - myTree.processKeyEvent(e); - } - - private class MyTree extends SimpleTree { - - private MyTree() { - getInputMap().clear(); - setOpaque(true); - } - - @Override - public final String getToolTipText(MouseEvent event) { - if (event != null) { - Point point = event.getPoint(); - Component component = getDeepestRendererComponentAt(point.x, point.y); - if (component instanceof JLabel) { - JLabel label = (JLabel)component; - if (label.getIcon() != null) { - String text = label.getToolTipText(); - if (text != null) { - return text; - } - } - } - } - return super.getToolTipText(event); - } - - @Override - protected boolean paintNodes() { - return false; - } - - @Override - protected boolean highlightSingleNode() { - return false; - } - - @Override - public void setUI(final TreeUI ui) { - TreeUI actualUI = ui; - if (!(ui instanceof MyTreeUi)) { - actualUI = new MyTreeUi(); - } - super.setUI(actualUI); - } - - @Override - protected boolean isCustomUI() { - return true; - } - - @Override - protected void configureUiHelper(final TreeUIHelper helper) { - } - - @Override - public boolean getScrollableTracksViewportWidth() { - return true; - } - - - @Override - public void processKeyEvent(final KeyEvent e) { - TreePath path = myTree.getSelectionPath(); - if (path != null) { - if (e.getKeyCode() == KeyEvent.VK_LEFT) { - if (isExpanded(path)) { - collapsePath(path); - return; - } - } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - if (isCollapsed(path)) { - expandPath(path); - return; - } - } - } - - super.processKeyEvent(e); - } - - @Override - protected void processMouseEvent(final MouseEvent e) { - final MyTreeUi ui = (MyTreeUi)myTree.getUI(); - final boolean toggleNow = - e.getID() == MouseEvent.MOUSE_RELEASED && UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !ui.isToggleEvent(e); - - final boolean toggleLater = - e.getID() == MouseEvent.MOUSE_PRESSED; - - if (toggleNow || toggleLater) { - final TreePath path = getPathForLocation(e.getX(), e.getY()); - if (path != null) { - final Rectangle bounds = getPathBounds(path); - if (bounds != null && path.getLastPathComponent() instanceof DefaultMutableTreeNode) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); - final boolean selected = isPathSelected(path); - final boolean expanded = isExpanded(path); - final Component comp = - myRenderer.getTreeCellRendererComponent(this, node, selected, expanded, node.isLeaf(), getRowForPath(path), isFocusOwner()); - - comp.setBounds(bounds); - comp.validate(); - - Point point = new Point(e.getX() - bounds.x, e.getY() - bounds.y); - if (myRenderer.isUnderHandle(point)) { - if (toggleNow) { - ui.toggleExpandState(path); - e.consume(); - return; - } else if (toggleLater) { - e.consume(); - return; - } - } - } - } - } - - super.processMouseEvent(e); - } - - private class MyTreeUi extends BasicTreeUI { - - @Override - public void toggleExpandState(final TreePath path) { - super.toggleExpandState(path); - } - - @Override - public boolean isToggleEvent(final MouseEvent event) { - return super.isToggleEvent(event); - } - - @Override - protected boolean shouldPaintExpandControl(final TreePath path, - final int row, - final boolean isExpanded, - final boolean hasBeenExpanded, - final boolean isLeaf) { - return false; - } - - @Override - protected void paintHorizontalPartOfLeg(final Graphics g, - final Rectangle clipBounds, - final Insets insets, - final Rectangle bounds, - final TreePath path, - final int row, - final boolean isExpanded, - final boolean hasBeenExpanded, - final boolean isLeaf) { - - } - - @Override - protected void paintVerticalPartOfLeg(final Graphics g, final Rectangle clipBounds, final Insets insets, final TreePath path) { - } - - @Override - public void paint(Graphics g, JComponent c) { - GraphicsUtil.setupAntialiasing(g); - super.paint(g, c); - } - } - } - - private class MyBuilder extends FilteringTreeBuilder { - - List myToExpandOnResetFilter; - boolean myRefilteringNow; - boolean myWasHoldingFilter; - - public MyBuilder(SimpleTreeStructure structure) { - super(myTree, myFilter, structure, new WeightBasedComparator(false)); - myTree.addTreeExpansionListener(new TreeExpansionListener() { - public void treeExpanded(TreeExpansionEvent event) { - invalidateExpansions(); - } - - public void treeCollapsed(TreeExpansionEvent event) { - invalidateExpansions(); - } - }); - } - - private void invalidateExpansions() { - if (!myRefilteringNow) { - myToExpandOnResetFilter = null; - } - } - - @Override - protected boolean isSelectable(final Object nodeObject) { - return nodeObject instanceof EditorNode; - } - - @Override - public boolean isAutoExpandNode(final NodeDescriptor nodeDescriptor) { - return myFilter.myContext.isHoldingFilter(); - } - - @Override - public boolean isToEnsureSelectionOnFocusGained() { - return false; - } - - @Override - protected ActionCallback refilterNow(Object preferredSelection, boolean adjustSelection) { - final List toRestore = new ArrayList(); - if (myFilter.myContext.isHoldingFilter() && !myWasHoldingFilter && myToExpandOnResetFilter == null) { - myToExpandOnResetFilter = myBuilder.getUi().getExpandedElements(); - } else if (!myFilter.myContext.isHoldingFilter() && myWasHoldingFilter && myToExpandOnResetFilter != null) { - toRestore.addAll(myToExpandOnResetFilter); - myToExpandOnResetFilter = null; - } - - myWasHoldingFilter = myFilter.myContext.isHoldingFilter(); - - ActionCallback result = super.refilterNow(preferredSelection, adjustSelection); - myRefilteringNow = true; - return result.doWhenDone(new Runnable() { - public void run() { - myRefilteringNow = false; - if (!myFilter.myContext.isHoldingFilter() && getSelectedElements().isEmpty()) { - restoreExpandedState(toRestore); - } - } - }); - } - - private void restoreExpandedState(List toRestore) { - TreePath[] selected = myTree.getSelectionPaths(); - if (selected == null) { - selected = new TreePath[0]; - } - - List toCollapse = new ArrayList(); - - for (int eachRow = 0; eachRow < myTree.getRowCount(); eachRow++) { - if (!myTree.isExpanded(eachRow)) continue; - - TreePath eachVisiblePath = myTree.getPathForRow(eachRow); - if (eachVisiblePath == null) continue; - - Object eachElement = myBuilder.getElementFor(eachVisiblePath.getLastPathComponent()); - if (toRestore.contains(eachElement)) continue; - - - for (TreePath eachSelected : selected) { - if (!eachVisiblePath.isDescendant(eachSelected)) { - toCollapse.add(eachVisiblePath); - } - } - } - - for (TreePath each : toCollapse) { - myTree.collapsePath(each); - } - - } - } - - Project getConfigurableProject(Configurable configurable) { - if (configurable instanceof ConfigurableWrapper) { - ConfigurableWrapper wrapper = (ConfigurableWrapper)configurable; - return wrapper.getExtensionPoint().getProject(); - } - return getConfigurableProject(myConfigurable2Node.get(configurable)); - } - - private static Project getConfigurableProject(SimpleNode node) { - if (node == null) { - return null; - } - if (node instanceof EditorNode) { - EditorNode editor = (EditorNode)node; - Configurable configurable = editor.getConfigurable(); - if (configurable instanceof ConfigurableWrapper) { - ConfigurableWrapper wrapper = (ConfigurableWrapper)configurable; - return wrapper.getExtensionPoint().getProject(); - } - } - return getConfigurableProject(node.getParent()); - } - - private static final class GroupSeparator extends JLabel { - public static final int SPACE = 10; - - public GroupSeparator() { - setFont(UIUtil.getLabelFont()); - setFont(getFont().deriveFont(Font.BOLD)); - } - - public void configure(ConfigurableGroup group, boolean isSpaceNeeded) { - if (group == null) { - setVisible(false); - } - else { - setVisible(true); - int bottom = UIUtil.isUnderNativeMacLookAndFeel() ? 1 : 3; - int top = isSpaceNeeded - ? bottom + SPACE - : bottom; - setBorder(BorderFactory.createEmptyBorder(top, 3, bottom, 3)); - setText(group.getDisplayName()); - } - } - } - - private static final class StickySeparator extends JComponent { - private final SimpleTree myTree; - private final JScrollPane myScroller; - private final GroupSeparator mySeparator; - - public StickySeparator(SimpleTree tree) { - myTree = tree; - myScroller = ScrollPaneFactory.createScrollPane(myTree); - myScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - mySeparator = new GroupSeparator(); - add(myScroller); - } - - @Override - public void doLayout() { - myScroller.setBounds(0, 0, getWidth(), getHeight()); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - - if (Registry.is("ide.new.settings.dialog")) { - ConfigurableGroup group = getGroup(GroupSeparator.SPACE + mySeparator.getFont().getSize()); - if (group != null && group == getGroup(-GroupSeparator.SPACE)) { - mySeparator.configure(group, false); - - Rectangle bounds = myScroller.getViewport().getBounds(); - int height = mySeparator.getPreferredSize().height; - if (bounds.height > height) { - bounds.height = height; - } - g.setColor(myTree.getBackground()); - if (g instanceof Graphics2D) { - int h = bounds.height / 3; - int y = bounds.y + bounds.height - h; - g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height - h); - ((Graphics2D)g).setPaint(UIUtil.getGradientPaint( - 0, y, g.getColor(), - 0, y + h, ColorUtil.toAlpha(g.getColor(), 0))); - g.fillRect(bounds.x, y, bounds.width, h); - } - else { - g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); - } - mySeparator.setSize(bounds.width - 1, bounds.height); - mySeparator.paint(g.create(bounds.x + 1, bounds.y, bounds.width - 1, bounds.height)); - } - } - } - - private ConfigurableGroup getGroup(int offset) { - TreePath path = myTree.getClosestPathForLocation(-myTree.getX(), -myTree.getY() + offset); - SimpleNode node = myTree.getNodeFor(path); - if (node instanceof FilteringTreeStructure.FilteringNode) { - Object delegate = ((FilteringTreeStructure.FilteringNode)node).getDelegate(); - while (delegate instanceof EditorNode) { - EditorNode editor = (EditorNode)delegate; - ConfigurableGroup group = editor.getGroup(); - if (group != null) { - return group; - } - delegate = editor.getParent(); - } - } - return null; - } - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsDialog.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsDialog.java index 5e2f35c9b107..2d41df1698e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsDialog.java @@ -39,6 +39,8 @@ import java.util.ArrayList; * @author Sergey.Malenkov */ public class SettingsDialog extends DialogWrapper implements DataProvider { + public static final String DIMENSION_KEY = "SettingsEditor"; + private final String myDimensionServiceKey; private final AbstractEditor myEditor; private boolean myApplyButtonNeeded; @@ -64,7 +66,7 @@ public class SettingsDialog extends DialogWrapper implements DataProvider { public SettingsDialog(@NotNull Project project, @NotNull ConfigurableGroup[] groups, Configurable configurable, String filter) { super(project, true); - myDimensionServiceKey = "SettingsEditor"; + myDimensionServiceKey = DIMENSION_KEY; myEditor = new SettingsEditor(myDisposable, project, groups, configurable, filter); myApplyButtonNeeded = true; init(null, project); diff --git a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsSearch.java b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsSearch.java index c0eb18869d94..9d6fabedeb6b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsSearch.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/newEditor/SettingsSearch.java @@ -18,7 +18,6 @@ package com.intellij.openapi.options.newEditor; import com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder; import com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.SearchTextField; import javax.swing.KeyStroke; @@ -39,14 +38,12 @@ abstract class SettingsSearch extends SearchTextField implements KeyListener { super(false); addKeyListener(new KeyAdapter() { }); - if (Registry.is("ide.new.settings.dialog")) { - if (!SystemInfo.isMac) { - JTextField editor = getTextEditor(); - editor.putClientProperty("JTextField.variant", "search"); - if (!(editor.getUI() instanceof DarculaTextFieldUI)) { - editor.setUI((DarculaTextFieldUI)DarculaTextFieldUI.createUI(editor)); - editor.setBorder(new DarculaTextBorder()); - } + if (!SystemInfo.isMac) { + JTextField editor = getTextEditor(); + editor.putClientProperty("JTextField.variant", "search"); + if (!(editor.getUI() instanceof DarculaTextFieldUI)) { + editor.setUI((DarculaTextFieldUI)DarculaTextFieldUI.createUI(editor)); + editor.setBorder(new DarculaTextBorder()); } } } diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 7c8504af7668..0e33d9a1532f 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -520,15 +520,10 @@ console.too.much.text.buffer.ratio.description=Used for disabling of console pro when there is too much of text to process.\n\ The ratio is used against the console cycle buffer size (idea.cycle.buffer.size/theRatio=maxTextLength). -ide.settings.appearance.font.family.only=true ide.settings.keymap.input.method.enabled=false ide.settings.configurable.loading.threshold=0 ide.settings.replace.group.with.single.configurable=true ide.settings.old.style=true -ide.new.settings.view=true -ide.new.settings.view.description=New view for the Settings dialog -ide.new.settings.dialog=true -ide.new.settings.dialog.description=New settings dialog ide.new.project.settings=true ide.new.project.settings.description=Temporary key for new project settings dialog UI diff --git a/python/edu/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java b/python/edu/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java index da3ed52ac26b..99ae98e30d8b 100644 --- a/python/edu/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java +++ b/python/edu/src/com/jetbrains/python/edu/PyCharmEduInitialConfigurator.java @@ -56,7 +56,6 @@ import com.intellij.openapi.project.ProjectManagerAdapter; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.wm.*; import com.intellij.platform.DirectoryProjectConfigurator; @@ -154,8 +153,6 @@ public class PyCharmEduInitialConfigurator { codeInsightSettings.REFORMAT_ON_PASTE = CodeInsightSettings.NO_REFORMAT; - Registry.get("ide.new.settings.dialog").setValue(true); - GeneralSettings.getInstance().setShowTipsOnStartup(false); EditorSettingsExternalizable.getInstance().setVirtualSpace(false);