From 36d2fe7929185f33b07ba8495b3ad5ab472768d1 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Wed, 9 Sep 2009 13:04:57 +0400 Subject: [PATCH] fixed [RUBY-4207] : TODO's only highlight with the default color --- .../com/intellij/psi/search/TodoAttributes.java | 41 +++++++++++++-- .../colors/ColorAndFontDescriptionPanel.java | 13 ++++- .../ide/todo/configurable/PatternDialog.java | 58 +++++++++++++++++++--- .../src/messages/IdeBundle.properties | 1 + 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/platform/lang-api/src/com/intellij/psi/search/TodoAttributes.java b/platform/lang-api/src/com/intellij/psi/search/TodoAttributes.java index 8db311b2b9..6b01e30176 100644 --- a/platform/lang-api/src/com/intellij/psi/search/TodoAttributes.java +++ b/platform/lang-api/src/com/intellij/psi/search/TodoAttributes.java @@ -37,11 +37,14 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { private Icon myIcon; private TextAttributes myTextAttributes = new TextAttributes(); + private boolean myShouldUseCustomColors; + @NonNls private static final String ATTRIBUTE_ICON = "icon"; @NonNls private static final String ICON_DEFAULT = "default"; @NonNls private static final String ICON_QUESTION = "question"; @NonNls private static final String ICON_IMPORTANT = "important"; @NonNls private static final String ELEMENT_OPTION = "option"; + @NonNls private static final String USE_CUSTOM_COLORS_ATT = "useCustomColors"; public TodoAttributes() { } @@ -56,19 +59,26 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { } public TextAttributes getTextAttributes() { + return shouldUseCustomTodoColor() + ? getCustomizedTextAttributes() + : getDefaultColorSchemeTextAttributes(); + } + + public TextAttributes getCustomizedTextAttributes() { return myTextAttributes; } + public void setIcon(Icon icon) { myIcon = icon; } public static TodoAttributes createDefault() { - TextAttributes textAttributes = createDefaultTextAttributes(); + final TextAttributes textAttributes = getDefaultColorSchemeTextAttributes(); return new TodoAttributes(DEFAULT_ICON, textAttributes); } - private static TextAttributes createDefaultTextAttributes() { + private static TextAttributes getDefaultColorSchemeTextAttributes() { return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES); } @@ -89,7 +99,15 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { } myTextAttributes.readExternal(element); if (element.getChild(ELEMENT_OPTION) == null) { - myTextAttributes = createDefaultTextAttributes(); + myTextAttributes = getDefaultColorSchemeTextAttributes(); + } + + // default color setting + final String useCustomColors = element.getAttributeValue(USE_CUSTOM_COLORS_ATT); + if (useCustomColors == null) { + myShouldUseCustomColors = false; + } else { + myShouldUseCustomColors = Boolean.valueOf(useCustomColors).booleanValue(); } } @@ -109,6 +127,9 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { } element.setAttribute(ATTRIBUTE_ICON, icon); myTextAttributes.writeExternal(element); + + // default color setting + element.setAttribute(USE_CUSTOM_COLORS_ATT, Boolean.toString(shouldUseCustomTodoColor())); } public boolean equals(Object o) { @@ -119,7 +140,7 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { if (myIcon != attributes.myIcon) return false; if (myTextAttributes != null ? !myTextAttributes.equals(attributes.myTextAttributes) : attributes.myTextAttributes != null) return false; - + if (myShouldUseCustomColors != attributes.myShouldUseCustomColors) return false; return true; } @@ -127,14 +148,26 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable { int result; result = myIcon != null ? myIcon.hashCode() : 0; result = 29 * result + (myTextAttributes != null ? myTextAttributes.hashCode() : 0); + result = 29 * result + (Boolean.valueOf(myShouldUseCustomColors).hashCode()); return result; } + + public boolean shouldUseCustomTodoColor() { + return myShouldUseCustomColors; + } + + public void setUseCustomTodoColor(boolean useCustomColors) { + myShouldUseCustomColors = useCustomColors; + } + + public TodoAttributes clone() { try { TextAttributes textAttributes = myTextAttributes.clone(); TodoAttributes attributes = (TodoAttributes)super.clone(); attributes.myTextAttributes = textAttributes; + attributes.myShouldUseCustomColors = myShouldUseCustomColors; return attributes; } catch (CloneNotSupportedException e) { diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java index 2228e8c652..5093814cc2 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java @@ -40,6 +40,7 @@ public class ColorAndFontDescriptionPanel extends JPanel { private final JCheckBox myCbItalic = new JCheckBox(ApplicationBundle.message("checkbox.font.italic")); private boolean updatingEffects; private ActionListener myActionListener; + private JLabel myLabelFont; public ColorAndFontDescriptionPanel() { @@ -77,7 +78,8 @@ public class ColorAndFontDescriptionPanel extends JPanel { gbConstraints.gridwidth = 1; gbConstraints.gridy = 1; gbConstraints.gridx = 1; - panel.add(new JLabel(ApplicationBundle.message("label.font.type")), gbConstraints); + myLabelFont = new JLabel(ApplicationBundle.message("label.font.type")); + panel.add(myLabelFont, gbConstraints); gbConstraints.gridx = 2; panel.add(myCbBold, gbConstraints); gbConstraints.gridx = 3; @@ -262,6 +264,7 @@ public class ColorAndFontDescriptionPanel extends JPanel { } public void resetDefault() { + myLabelFont.setEnabled(false); myCbBold.setSelected(false); myCbBold.setEnabled(false); myCbItalic.setSelected(false); @@ -273,6 +276,12 @@ public class ColorAndFontDescriptionPanel extends JPanel { myEffectsCombo.setEnabled(false); } + //public void disableControlls(final boolean disabled) { + // myCbBold.setEnabled(!disabled); + // myCbItalic.setEnabled(!disabled); + // myCbItalic.setEnabled(!disabled); + //} + private static void updateColorChooser(JCheckBox checkBox, ColorPanel colorPanel, boolean isEnabled, @@ -291,12 +300,14 @@ public class ColorAndFontDescriptionPanel extends JPanel { public void reset(ColorAndFontDescription description) { if (description.isFontEnabled()) { + myLabelFont.setEnabled(true); myCbBold.setEnabled(true); myCbItalic.setEnabled(true); int fontType = description.getFontType(); myCbBold.setSelected((fontType & Font.BOLD) != 0); myCbItalic.setSelected((fontType & Font.ITALIC) != 0); } else { + myLabelFont.setEnabled(false); myCbBold.setSelected(false); myCbBold.setEnabled(false); myCbItalic.setSelected(false); diff --git a/platform/lang-impl/src/com/intellij/ide/todo/configurable/PatternDialog.java b/platform/lang-impl/src/com/intellij/ide/todo/configurable/PatternDialog.java index d167805e9c..0d107443d6 100644 --- a/platform/lang-impl/src/com/intellij/ide/todo/configurable/PatternDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/todo/configurable/PatternDialog.java @@ -13,6 +13,8 @@ import com.intellij.ide.IdeBundle; import javax.swing.*; import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; /** * @author Vladimir Kondratyev @@ -25,21 +27,29 @@ class PatternDialog extends DialogWrapper{ private final JTextField myPatternStringField; private final ColorAndFontDescriptionPanel myColorAndFontDescriptionPanel; private final ColorAndFontDescription myColorAndFontDescription; + private JCheckBox myUsedDefaultColorsCeckBox; - public PatternDialog(Component parent,TodoPattern pattern){ - super(parent,true); + public PatternDialog(Component parent, TodoPattern pattern){ + super(parent, true); + + final TodoAttributes attrs = pattern.getAttributes(); myPattern=pattern; myIconComboBox=new JComboBox( new Icon[]{TodoAttributes.DEFAULT_ICON,TodoAttributes.QUESTION_ICON,TodoAttributes.IMPORTANT_ICON} ); - myIconComboBox.setSelectedItem(pattern.getAttributes().getIcon()); + myIconComboBox.setSelectedItem(attrs.getIcon()); myIconComboBox.setRenderer(new TodoTypeListCellRenderer()); myCaseSensitiveCheckBox=new JCheckBox(IdeBundle.message("checkbox.case.sensitive"),pattern.isCaseSensitive()); myPatternStringField=new JTextField(pattern.getPatternString()); + + // use default colors check box + myUsedDefaultColorsCeckBox = new JCheckBox(IdeBundle.message("checkbox.todo.use.default.colors")); + myUsedDefaultColorsCeckBox.setSelected(!attrs.shouldUseCustomTodoColor()); + myColorAndFontDescriptionPanel = new ColorAndFontDescriptionPanel(); - TextAttributes attributes = myPattern.getAttributes().getTextAttributes(); + TextAttributes attributes = myPattern.getAttributes().getCustomizedTextAttributes(); myColorAndFontDescription = new TextAttributesDescription(null, null, attributes, null, EditorColorsManager.getInstance().getGlobalScheme(), null, null) { @@ -54,9 +64,28 @@ class PatternDialog extends DialogWrapper{ myColorAndFontDescriptionPanel.reset(myColorAndFontDescription); + updateCustomColorsPanel(); + myUsedDefaultColorsCeckBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + updateCustomColorsPanel(); + } + }); + init(); } + private void updateCustomColorsPanel() { + final boolean useCustomColors = useCustomTodoColor(); + + if (useCustomColors) { + // restore controls + myColorAndFontDescriptionPanel.reset(myColorAndFontDescription); + } else { + // disable controls + myColorAndFontDescriptionPanel.resetDefault(); + } + } + public JComponent getPreferredFocusedComponent(){ return myPatternStringField; } @@ -64,12 +93,22 @@ class PatternDialog extends DialogWrapper{ protected void doOKAction(){ myPattern.setPatternString(myPatternStringField.getText().trim()); myPattern.setCaseSensitive(myCaseSensitiveCheckBox.isSelected()); - myPattern.getAttributes().setIcon((Icon)myIconComboBox.getSelectedItem()); - myColorAndFontDescriptionPanel.apply(myColorAndFontDescription, null); + final TodoAttributes attrs = myPattern.getAttributes(); + attrs.setIcon((Icon)myIconComboBox.getSelectedItem()); + attrs.setUseCustomTodoColor(useCustomTodoColor()); + + if (useCustomTodoColor()) { + myColorAndFontDescriptionPanel.apply(myColorAndFontDescription, null); + } super.doOKAction(); } + + private boolean useCustomTodoColor() { + return !myUsedDefaultColorsCeckBox.isSelected(); + } + protected JComponent createCenterPanel(){ JPanel panel=new JPanel(new GridBagLayout()); @@ -106,6 +145,13 @@ class PatternDialog extends DialogWrapper{ gb.gridy++; gb.gridx = 0; + gb.fill = GridBagConstraints.HORIZONTAL; + gb.gridwidth = GridBagConstraints.REMAINDER; + gb.weightx = 1; + panel.add(myUsedDefaultColorsCeckBox, gb); + + gb.gridy++; + gb.gridx = 0; gb.gridwidth = GridBagConstraints.REMAINDER; gb.weightx = 1; panel.add(myColorAndFontDescriptionPanel, gb); diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 0ca0c6b447..2159c2cb3c 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -602,6 +602,7 @@ group.todo.filter.patterns=Patterns column.todo.filters.name=Name column.todo.filter.patterns=Patterns checkbox.case.sensitive=Case Sensitive +checkbox.todo.use.default.colors=Use color scheme TODO default colors label.todo.pattern=Pattern: label.todo.icon=Icon: column.todo.patterns.icon=Icon -- 2.11.4.GIT