diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/application/options')
6 files changed, 241 insertions, 23 deletions
diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTableWithPreviewPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTableWithPreviewPanel.java index f978d5f6dcdb..59736bc0e4b2 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTableWithPreviewPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTableWithPreviewPanel.java @@ -18,6 +18,7 @@ package com.intellij.application.options.codeStyle; import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; import com.intellij.ui.SpeedSearchComparator; import com.intellij.ui.TreeTableSpeedSearch; @@ -378,7 +379,7 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle this.groupName = groupName; try { - Class styleSettingsClass = clazz == null ? CodeStyleSettings.class : clazz; + Class styleSettingsClass = clazz == null ? CommonCodeStyleSettings.class : clazz; this.field = styleSettingsClass.getField(fieldName); } catch (NoSuchFieldException e) { diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.form b/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.form new file mode 100644 index 000000000000..67f579a77ff5 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.form @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.application.options.codeStyle.RightMarginForm"> + <grid id="27dc6" binding="myTopPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <margin top="0" left="0" bottom="0" right="0"/> + <constraints> + <xy x="20" y="20" width="500" height="400"/> + </constraints> + <properties/> + <border type="none"/> + <children> + <component id="12cf8" class="com.intellij.ui.components.JBLabel"> + <constraints> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text resource-bundle="messages/ApplicationBundle" key="editbox.right.margin.columns"/> + </properties> + </component> + <vspacer id="1265c"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> + </constraints> + </vspacer> + <component id="78fe" class="javax.swing.JTextField" binding="myRightMarginField"> + <constraints> + <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <preferred-size width="50" height="-1"/> + </grid> + </constraints> + <properties> + <horizontalAlignment value="2"/> + </properties> + </component> + <component id="5ef52" class="javax.swing.JCheckBox" binding="myDefaultGeneralCheckBox" default-binding="true"> + <constraints> + <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text resource-bundle="messages/ApplicationBundle" key="settings.code.style.default.general"/> + </properties> + </component> + </children> + </grid> +</form> diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.java new file mode 100644 index 000000000000..70c747dc11ca --- /dev/null +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/RightMarginForm.java @@ -0,0 +1,120 @@ +/* + * Copyright 2000-2014 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.application.options.codeStyle; + +import com.intellij.lang.Language; +import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +/** + * Can be used for languages which do not use standard "Wrapping and Braces" panel. + * <p> + * <strong>Note</strong>: besides adding the panel to UI it is necessary to make sure that language's own + * <code>LanguageCodeStyleSettingsProvider</code> explicitly supports RIGHT_MARGIN field in <code>customizeSettings()</code> + * method as shown below: + * <pre> + * public void customizeSettings(...) { + * if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) { + * consumer.showStandardOptions("RIGHT_MARGIN"); + * } + * } + * </pre> + * @author Rustam Vishnyakov + */ +public class RightMarginForm { + private JTextField myRightMarginField; + private JCheckBox myDefaultGeneralCheckBox; + private JPanel myTopPanel; + private final Language myLanguage; + private final int myDefaultRightMargin; + + public RightMarginForm(@NotNull Language language, @NotNull CodeStyleSettings settings) { + myLanguage = language; + myDefaultRightMargin = settings.RIGHT_MARGIN; + myDefaultGeneralCheckBox.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if (myDefaultGeneralCheckBox.isSelected()) { + myRightMarginField.setText(Integer.toString(myDefaultRightMargin)); + myRightMarginField.setEnabled(false); + } + else { + myRightMarginField.setEnabled(true); + } + } + }); + } + + public void reset(@NotNull CodeStyleSettings settings) { + CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage); + if (langSettings != settings && langSettings.RIGHT_MARGIN >= 0) { + myDefaultGeneralCheckBox.setSelected(false); + myRightMarginField.setText(Integer.toString(langSettings.RIGHT_MARGIN)); + } + else { + myDefaultGeneralCheckBox.setSelected(true); + myRightMarginField.setText(Integer.toString(settings.RIGHT_MARGIN)); + if (langSettings == settings) { + myDefaultGeneralCheckBox.setEnabled(false); + myRightMarginField.setEnabled(false); + } + } + } + + public void apply(@NotNull CodeStyleSettings settings) { + CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage); + if (langSettings != settings) { + if (myDefaultGeneralCheckBox.isSelected()) { + langSettings.RIGHT_MARGIN = -1; + } + else { + langSettings.RIGHT_MARGIN = getFieldRightMargin(settings.RIGHT_MARGIN); + } + } + } + + public boolean isModified(@NotNull CodeStyleSettings settings) { + CommonCodeStyleSettings langSettings = settings.getCommonSettings(myLanguage); + if (myDefaultGeneralCheckBox.isSelected()) { + return langSettings.RIGHT_MARGIN >= 0; + } + else { + return langSettings.RIGHT_MARGIN != getFieldRightMargin(settings.RIGHT_MARGIN); + } + } + + private int getFieldRightMargin(int fallBackValue) { + String strValue = myRightMarginField.getText(); + if (!strValue.trim().isEmpty()) { + try { + return Integer.parseInt(strValue); + } + catch (NumberFormatException e) { + myRightMarginField.setText(Integer.toString(fallBackValue)); + } + } + return fallBackValue; + } + + public JPanel getTopPanel() { + return myTopPanel; + } +} diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java index fa14958132d0..145ae1094e0b 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java @@ -165,7 +165,7 @@ public class ArrangementMatchingRulesControl extends JBTable { } final List<ArrangementSectionRule> result = ContainerUtil.newArrayList(); - final List<StdArrangementMatchRule> currentRules = ContainerUtil.newArrayList(); + final List<StdArrangementMatchRule> buffer = ContainerUtil.newArrayList(); String currentSectionStart = null; for (int i = 0; i < getModel().getSize(); i++) { Object element = getModel().getElementAt(i); @@ -174,15 +174,12 @@ public class ArrangementMatchingRulesControl extends JBTable { mySectionRuleManager == null ? null : mySectionRuleManager.getSectionRuleData((StdArrangementMatchRule)element); if (sectionRule != null) { if (sectionRule.isSectionStart()) { - if (currentSectionStart != null) { - result.add(ArrangementSectionRule.create(currentSectionStart, null, currentRules)); - currentRules.clear(); - } + appendBufferedSectionRules(result, buffer, currentSectionStart); currentSectionStart = sectionRule.getText(); } else { - result.add(ArrangementSectionRule.create(StringUtil.notNullize(currentSectionStart), sectionRule.getText(), currentRules)); - currentRules.clear(); + result.add(ArrangementSectionRule.create(StringUtil.notNullize(currentSectionStart), sectionRule.getText(), buffer)); + buffer.clear(); currentSectionStart = null; } } @@ -190,17 +187,34 @@ public class ArrangementMatchingRulesControl extends JBTable { result.add(ArrangementSectionRule.create((StdArrangementMatchRule)element)); } else { - currentRules.add((StdArrangementMatchRule)element); + buffer.add((StdArrangementMatchRule)element); } } } - if (currentSectionStart != null) { - result.add(ArrangementSectionRule.create(currentSectionStart, null, currentRules)); - } + appendBufferedSectionRules(result, buffer, currentSectionStart); return result; } + private static void appendBufferedSectionRules(@NotNull List<ArrangementSectionRule> result, + @NotNull List<StdArrangementMatchRule> buffer, + @Nullable String currentSectionStart) { + if (currentSectionStart == null) { + return; + } + + if (buffer.isEmpty()) { + result.add(ArrangementSectionRule.create(currentSectionStart, null)); + } + else { + result.add(ArrangementSectionRule.create(currentSectionStart, null, buffer.get(0))); + for (int j = 1; j < buffer.size(); j++) { + result.add(ArrangementSectionRule.create(buffer.get(j))); + } + buffer.clear(); + } + } + @Override protected void processMouseEvent(MouseEvent e) { int id = e.getID(); diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form index 9872c7c624aa..db23ce17b2c3 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.form @@ -3,7 +3,7 @@ <grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <xy x="20" y="20" width="500" height="527"/> + <xy x="20" y="20" width="500" height="585"/> </constraints> <properties/> <border type="none"/> @@ -108,7 +108,7 @@ <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> </constraints> </vspacer> - <grid id="eb8d0" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="10"> + <grid id="eb8d0" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="10"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> @@ -119,7 +119,7 @@ </clientProperties> <border type="none" title-resource-bundle="messages/ApplicationBundle" title-key="group.tab.closing.policy"/> <children> - <grid id="5a5a7" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="5a5a7" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> @@ -129,7 +129,9 @@ <children> <component id="527a6" class="javax.swing.JLabel"> <constraints> - <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> + <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <preferred-size width="60" height="27"/> + </grid> </constraints> <properties> <text resource-bundle="messages/ApplicationBundle" key="editbox.tab.limit"/> @@ -138,19 +140,38 @@ <component id="16477" class="javax.swing.JTextField" binding="myEditorTabLimitField"> <constraints> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"> - <preferred-size width="30" height="-1"/> + <preferred-size width="30" height="27"/> </grid> </constraints> <properties> <text value="15"/> </properties> </component> + <component id="2479d" class="javax.swing.JLabel"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/> + </constraints> + <properties> + <text resource-bundle="messages/ApplicationBundle" key="editbox.tab.title.limit"/> + </properties> + </component> + <component id="3499c" class="javax.swing.JTextField" binding="myTabTitleLimitField"> + <constraints> + <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"> + <preferred-size width="30" height="27"/> + </grid> + </constraints> + <properties> + <columns value="2"/> + <text value="30"/> + </properties> + </component> </children> </grid> <grid id="9b723" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> @@ -184,7 +205,7 @@ <grid id="611cc" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="2"> <margin top="10" left="0" bottom="0" right="0"/> <constraints> - <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> </constraints> <properties/> <border type="none"/> diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java index 4e1de817255a..35a34085d035 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.java @@ -45,6 +45,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { private JCheckBox myShowCloseButtonOnCheckBox; private JCheckBox myShowDirectoryInTabCheckBox; private JRadioButton myActivateRightNeighbouringTabRadioButton; + private JTextField myTabTitleLimitField; public EditorTabsConfigurable() { myEditorTabPlacement.setModel(new DefaultComboBoxModel(new Object[]{ @@ -119,6 +120,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { myHideKnownExtensions.setSelected(uiSettings.HIDE_KNOWN_EXTENSION_IN_TABS); myShowDirectoryInTabCheckBox.setSelected(uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES); myEditorTabLimitField.setText(Integer.toString(uiSettings.EDITOR_TAB_LIMIT)); + myTabTitleLimitField.setText(Integer.toString(uiSettings.EDITOR_TAB_TITLE_LIMIT)); myShowCloseButtonOnCheckBox.setSelected(uiSettings.SHOW_CLOSE_BUTTON); if (uiSettings.CLOSE_NON_MODIFIED_FILES_FIRST) { @@ -171,14 +173,29 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { uiSettings.ACTIVATE_RIGHT_EDITOR_ON_CLOSE = myActivateRightNeighbouringTabRadioButton.isSelected(); String temp = myEditorTabLimitField.getText(); - if(temp.trim().length() > 0){ + if (temp.trim().length() > 0) { try { int newEditorTabLimit = Integer.parseInt(temp); - if(newEditorTabLimit>0&&newEditorTabLimit!=uiSettings.EDITOR_TAB_LIMIT){ - uiSettings.EDITOR_TAB_LIMIT=newEditorTabLimit; + if (newEditorTabLimit > 0 && newEditorTabLimit != uiSettings.EDITOR_TAB_LIMIT) { + uiSettings.EDITOR_TAB_LIMIT = newEditorTabLimit; uiSettingsChanged = true; } - }catch (NumberFormatException ignored){} + } + catch (NumberFormatException ignored) { + } + } + temp = myTabTitleLimitField.getText(); + if (temp.trim().length() > 0) { + try { + int newTabTitleLimit = Integer.parseInt(temp); + newTabTitleLimit = Math.max(25, Math.min(100, newTabTitleLimit)); + if (newTabTitleLimit != uiSettings.EDITOR_TAB_TITLE_LIMIT){ + uiSettings.EDITOR_TAB_TITLE_LIMIT = newTabTitleLimit; + uiSettingsChanged = true; + } + } + catch (NumberFormatException ignored) { + } } if(uiSettingsChanged){ uiSettings.fireUISettingsChanged(); @@ -191,6 +208,7 @@ public class EditorTabsConfigurable implements EditorOptionsProvider { boolean isModified = isModified(myCbModifiedTabsMarkedWithAsterisk, uiSettings.MARK_MODIFIED_TABS_WITH_ASTERISK); isModified |= isModified(myShowTabsTooltipsCheckBox, uiSettings.SHOW_TABS_TOOLTIPS); isModified |= isModified(myEditorTabLimitField, uiSettings.EDITOR_TAB_LIMIT); + isModified |= isModified(myTabTitleLimitField, uiSettings.EDITOR_TAB_TITLE_LIMIT); int tabPlacement = ((Integer)myEditorTabPlacement.getSelectedItem()).intValue(); isModified |= tabPlacement != uiSettings.EDITOR_TAB_PLACEMENT; isModified |= myHideKnownExtensions.isSelected() != uiSettings.HIDE_KNOWN_EXTENSION_IN_TABS; |