diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/application')
7 files changed, 161 insertions, 25 deletions
diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java index 8e8eba54cbf9..6c65209d1122 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeCompletionPanel.java @@ -28,8 +28,10 @@ import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.ui.components.JBCheckBox; import org.intellij.lang.annotations.MagicConstant; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.event.ActionEvent; @@ -56,7 +58,7 @@ public class CodeCompletionPanel { private static final String CASE_SENSITIVE_FIRST_LETTER = ApplicationBundle.message("combobox.autocomplete.case.sensitive.first.letter"); private static final String[] CASE_VARIANTS = {CASE_SENSITIVE_ALL, CASE_SENSITIVE_NONE, CASE_SENSITIVE_FIRST_LETTER}; - public CodeCompletionPanel(){ + public CodeCompletionPanel() { //noinspection unchecked myCaseSensitiveCombo.setModel(new DefaultComboBoxModel(CASE_VARIANTS)); @@ -73,7 +75,7 @@ public class CodeCompletionPanel { myCbAutocompletion.addActionListener( new ActionListener() { @Override - public void actionPerformed(ActionEvent event) { + public void actionPerformed(@NotNull ActionEvent event) { boolean selected = myCbAutocompletion.isSelected(); myCbSelectByChars.setEnabled(selected); } @@ -83,7 +85,7 @@ public class CodeCompletionPanel { myCbAutopopupJavaDoc.addActionListener( new ActionListener() { @Override - public void actionPerformed(ActionEvent event) { + public void actionPerformed(@NotNull ActionEvent event) { myAutopopupJavaDocField.setEnabled(myCbAutopopupJavaDoc.isSelected()); } } @@ -92,7 +94,7 @@ public class CodeCompletionPanel { myCbParameterInfoPopup.addActionListener( new ActionListener() { @Override - public void actionPerformed(ActionEvent event) { + public void actionPerformed(@NotNull ActionEvent event) { myParameterInfoDelayField.setEnabled(myCbParameterInfoPopup.isSelected()); } } @@ -205,16 +207,8 @@ public class CodeCompletionPanel { } private static int getIntegerValue(String s, int defaultValue) { - int value = defaultValue; - try { - value = Integer.parseInt(s); - if(value < 0) { - return defaultValue; - } - } - catch (NumberFormatException ignored) { - } - return value; + int value = StringUtilRt.parseInt(s, defaultValue); + return value < 0 ? defaultValue : value; } @MagicConstant(intValues = {CodeInsightSettings.ALL, CodeInsightSettings.NONE, CodeInsightSettings.FIRST_LETTER}) diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java index f7c1fd4c7e2d..2b142a4bffb2 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleAbstractPanel.java @@ -201,7 +201,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { private int getAdjustedRightMargin() { int result = getRightMargin(); - return result > 0 ? result : CodeStyleFacade.getInstance(ProjectUtil.guessCurrentProject(getPanel())).getRightMargin(); + return result > 0 ? result : CodeStyleFacade.getInstance(ProjectUtil.guessCurrentProject(getPanel())).getRightMargin(getDefaultLanguage()); } protected abstract int getRightMargin(); @@ -226,7 +226,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { catch (ConfigurationException ignore) { } CodeStyleSettings clone = mySettings.clone(); - clone.RIGHT_MARGIN = getAdjustedRightMargin(); + clone.setRightMargin(getDefaultLanguage(), getAdjustedRightMargin()); CodeStyleSettingsManager.getInstance(project).setTemporarySettings(clone); PsiFile formatted; try { @@ -267,7 +267,7 @@ public abstract class CodeStyleAbstractPanel implements Disposable { Document document = documentManager.getDocument(psiFile); if (document != null) { CodeStyleSettings clone = mySettings.clone(); - clone.RIGHT_MARGIN = getAdjustedRightMargin(); + clone.setRightMargin(getDefaultLanguage(), getAdjustedRightMargin()); CodeStyleSettingsManager.getInstance(project).setTemporarySettings(clone); try { CodeStyleManager.getInstance(project).reformat(psiFile); diff --git a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSettingsUtilImpl.java b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSettingsUtilImpl.java index 640fcac38652..418cc3ccef6d 100644 --- a/platform/lang-impl/src/com/intellij/application/options/CodeStyleSettingsUtilImpl.java +++ b/platform/lang-impl/src/com/intellij/application/options/CodeStyleSettingsUtilImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -23,7 +23,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager; public class CodeStyleSettingsUtilImpl extends CodeStyleSettingsUtil { /** - * Shows code style settings sutable for the project passed. I.e. it shows project code style page if one + * Shows code style settings suitable for the project passed. I.e. it shows project code style page if one * is configured to use own code style scheme or global one in other case. * @param project * @return Returns true if settings were modified during editing session. diff --git a/platform/lang-impl/src/com/intellij/application/options/ModuleAwareProjectConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/ModuleAwareProjectConfigurable.java index f7d8ab8e7df1..b005b5e158fd 100644 --- a/platform/lang-impl/src/com/intellij/application/options/ModuleAwareProjectConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/ModuleAwareProjectConfigurable.java @@ -35,7 +35,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.border.EmptyBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; @@ -116,8 +115,7 @@ public abstract class ModuleAwareProjectConfigurable<T extends UnnamedConfigurab for (Module module : modules) { final T configurable = createModuleConfigurable(module); myModuleConfigurables.put(module, configurable); - final JComponent component = new JBScrollPane(configurable.createComponent()); - component.setBorder(new EmptyBorder(0, 0, 0, 0)); + final JComponent component = configurable.createComponent(); cardPanel.add(component, module.getName()); } moduleList.addListSelectionListener(new ListSelectionListener() { 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 099830e15902..f978d5f6dcdb 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 @@ -340,6 +340,16 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle addOption(fieldName, title, null, options, values); } + protected void addOption(@NotNull String fieldName, + @NotNull String title, + @Nullable String groupName, + int minValue, + int maxValue, + int defaultValue, + String defaultValueText) { + myOptions.add(new IntOption(null, fieldName, title, groupName, null, null, minValue, maxValue, defaultValue, defaultValueText)); + } + protected void addOption(@NotNull String fieldName, @NotNull String title, @Nullable String groupName) { myOptions.add(new BooleanOption(null, fieldName, title, groupName, null, null)); } @@ -469,6 +479,78 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle } } + private class IntOption extends Option { + + private final int myMinValue; + private final int myMaxValue; + private final int myDefaultValue; + @Nullable private String myDefaultValueText; + + public IntOption(Class<? extends CustomCodeStyleSettings> clazz, + @NotNull String fieldName, + @NotNull String title, + @Nullable String groupName, + @Nullable OptionAnchor anchor, + @Nullable String anchorFiledName, + int minValue, + int maxValue, + int defaultValue, + @Nullable String defaultValueText) { + super(clazz, fieldName, title, groupName, anchor, anchorFiledName); + myMinValue = minValue; + myMaxValue = maxValue; + myDefaultValue = defaultValue; + myDefaultValueText = defaultValueText; + } + + @Override + public Object getValue(CodeStyleSettings settings) { + try { + int value = field.getInt(getSettings(settings)); + return value == myDefaultValue && myDefaultValueText != null ? myDefaultValueText : value; + } + catch (IllegalAccessException e) { + return null; + } + } + + @Override + public void setValue(Object value, CodeStyleSettings settings) { + //noinspection EmptyCatchBlock + try { + if (myDefaultValueText != null && !myDefaultValueText.equals(value)) { + field.setInt(getSettings(settings), ((Integer)value).intValue()); + } + else { + field.setInt(getSettings(settings), -1); + } + } + catch (IllegalAccessException e) { + } + } + + public int getMinValue() { + return myMinValue; + } + + public int getMaxValue() { + return myMaxValue; + } + + public int getDefaultValue() { + return myDefaultValue; + } + + public boolean isDefaultText(Object value) { + return myDefaultValueText != null && myDefaultValueText.equals(value); + } + + @Nullable + public String getDefaultValueText() { + return myDefaultValueText; + } + } + @SuppressWarnings({"HardCodedStringLiteral"}) public final ColumnInfo TITLE = new ColumnInfo("TITLE") { @Override @@ -604,6 +686,7 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle private final JLabel myComboBox = new JLabel(); private final JCheckBox myCheckBox = new JCheckBox(); private final JPanel myEmptyLabel = new JPanel(); + private final JLabel myIntLabel = new JLabel(); @Override public Component getTableCellRendererComponent(JTable table, @@ -636,6 +719,10 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle myComboBox.setEnabled(isEnabled); return myComboBox; } + else if (value instanceof Integer) { + myIntLabel.setText(value.toString()); + return myIntLabel; + } myCheckBox.putClientProperty("JComponent.sizeVariant", "small"); myComboBox.putClientProperty("JComponent.sizeVariant", "small"); @@ -645,12 +732,55 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle } } + private static class MyIntOptionEditor extends JTextField { + private int myMinValue; + private int myMaxValue; + private int myDefaultValue; + private String myDefaultValueText; + + private MyIntOptionEditor() { + super(); + } + + public Object getPresentableValue() { + int value = validateAndGetIntOption(); + return value == myDefaultValue && myDefaultValueText != null ? myDefaultValueText : value; + } + + private int validateAndGetIntOption() { + try { + int value = Integer.parseInt(getText()); + return value >= myMinValue && value <= myMaxValue ? value : myDefaultValue; + } + catch (NumberFormatException nfe) { + return myDefaultValue; + } + } + + public void setMinValue(int minValue) { + myMinValue = minValue; + } + + public void setMaxValue(int maxValue) { + myMaxValue = maxValue; + } + + public void setDefaultValue(int defaultValue) { + myDefaultValue = defaultValue; + } + + public void setDefaultValueText(String defaultValueText) { + myDefaultValueText = defaultValueText; + } + } + /** * @author Konstantin Bulenkov */ private class MyValueEditor extends AbstractTableCellEditor { private final JCheckBox myBooleanEditor = new JCheckBox(); private JBComboBoxTableCellEditorComponent myOptionsEditor = new JBComboBoxTableCellEditorComponent(); + private MyIntOptionEditor myIntOptionsEditor = new MyIntOptionEditor(); private Component myCurrentEditor = null; private MyTreeNode myCurrentNode = null; @@ -684,6 +814,9 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle else if (myCurrentEditor == myBooleanEditor) { return myBooleanEditor.isSelected() ? Boolean.TRUE : Boolean.FALSE; } + else if (myCurrentEditor == myIntOptionsEditor) { + return myIntOptionsEditor.getPresentableValue(); + } return null; } @@ -702,6 +835,15 @@ public abstract class OptionTableWithPreviewPanel extends MultilanguageCodeStyle myBooleanEditor.setSelected(node.getValue() == Boolean.TRUE); myBooleanEditor.setEnabled(node.isEnabled()); } + else if (node.getKey() instanceof IntOption) { + IntOption intOption = (IntOption)node.getKey(); + myCurrentEditor = myIntOptionsEditor; + myIntOptionsEditor.setText(intOption.isDefaultText(node.getValue()) ? "" : node.getValue().toString()); + myIntOptionsEditor.setMinValue(intOption.getMinValue()); + myIntOptionsEditor.setMaxValue(intOption.getMaxValue()); + myIntOptionsEditor.setDefaultValue(intOption.getDefaultValue()); + myIntOptionsEditor.setDefaultValueText(intOption.getDefaultValueText()); + } else { myCurrentEditor = myOptionsEditor; myOptionsEditor.setCell(table, row, column); diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java index 1b270874101e..c192d0e2893a 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java @@ -32,6 +32,8 @@ public class WrappingAndBracesPanel extends OptionTableWithPreviewPanel { @Override protected void initTables() { + addOption("RIGHT_MARGIN", ApplicationBundle.message("editbox.right.margin.columns"), null, 0, 999, -1, ApplicationBundle.message("settings.code.style.default.general")); + addOption("KEEP_LINE_BREAKS", ApplicationBundle.message("wrapping.keep.line.breaks"), WRAPPING_KEEP); addOption("KEEP_FIRST_COLUMN_COMMENT", ApplicationBundle.message("wrapping.keep.comment.at.first.column"), WRAPPING_KEEP); addOption("KEEP_CONTROL_STATEMENT_IN_ONE_LINE", ApplicationBundle.message("checkbox.keep.when.reformatting.control.statement.in.one.line"), WRAPPING_KEEP); diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java index 2cabcabf74ad..a5551086daaf 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorSmartKeysConfigurable.java @@ -161,7 +161,7 @@ public class EditorSmartKeysConfigurable extends CompositeConfigurable<UnnamedCo myCbSurroundSelectionOnTyping.setSelected(codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED); - myCbIndentingBackspace.setSelected(codeInsightSettings.INDENTING_BACKSPACE); + myCbIndentingBackspace.setSelected(codeInsightSettings.SMART_BACKSPACE == CodeInsightSettings.AUTOINDENT); super.reset(); } @@ -182,7 +182,7 @@ public class EditorSmartKeysConfigurable extends CompositeConfigurable<UnnamedCo codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED = myCbSurroundSelectionOnTyping.isSelected(); editorSettings.setCamelWords(myCbCamelWords.isSelected()); codeInsightSettings.REFORMAT_ON_PASTE = getReformatPastedBlockValue(); - codeInsightSettings.INDENTING_BACKSPACE = myCbIndentingBackspace.isSelected(); + codeInsightSettings.SMART_BACKSPACE = myCbIndentingBackspace.isSelected() ? CodeInsightSettings.AUTOINDENT : CodeInsightSettings.OFF; super.apply(); } @@ -208,7 +208,7 @@ public class EditorSmartKeysConfigurable extends CompositeConfigurable<UnnamedCo isModified |= isModified(myCbSurroundSelectionOnTyping, codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED); - isModified |= isModified(myCbIndentingBackspace, codeInsightSettings.INDENTING_BACKSPACE); + isModified |= isModified(myCbIndentingBackspace, codeInsightSettings.SMART_BACKSPACE == CodeInsightSettings.AUTOINDENT); return isModified; |