Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-07-19 04:35:05 -0400
committerMickael Istria2019-07-23 10:17:59 -0400
commitc9f6f539682c664d3584670c3450d7aee9ece04b (patch)
tree24877ab0ac298c99f09980c99297aa637142de82
parenta3b2be38834b90fe30764230803ea9390fce3334 (diff)
downloadeclipse.platform.text-c9f6f539682c664d3584670c3450d7aee9ece04b.tar.gz
eclipse.platform.text-c9f6f539682c664d3584670c3450d7aee9ece04b.tar.xz
eclipse.platform.text-c9f6f539682c664d3584670c3450d7aee9ece04b.zip
Bug 549415 - Improve colorpicker enablement in TextEditor pref page
Never disable button, so it shows the actual system color and can save a click when trying to select a new color and current is system Change-Id: I720180d4b456705b51947759fc7043e3136e4221 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java72
1 files changed, 23 insertions, 49 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
index 5f0e08f36..058204564 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
@@ -666,6 +666,11 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
this.previousColor= PreferenceConverter.getColor(fOverlayStore, colorKey);
this.isSystemDefaultKey= isSystemDefaultKey;
}
+
+ public boolean allowSystemDefault() {
+ return this.isSystemDefaultKey != null;
+ }
+
public boolean isSystemDefault() {
return this.isSystemDefaultKey != null && fOverlayStore.getBoolean(isSystemDefaultKey);
}
@@ -678,6 +683,12 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
this.previousColor= PreferenceConverter.getColor(fOverlayStore, this.colorKey);
PreferenceConverter.setValue(fOverlayStore, this.colorKey, rgb);
}
+
+ public void setSystemDefault(boolean value) {
+ if (this.isSystemDefaultKey != null) {
+ fOverlayStore.setValue(this.isSystemDefaultKey, value);
+ }
+ }
}
private OverlayPreferenceStore fOverlayStore;
@@ -784,23 +795,10 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
private void handleAppearanceColorListSelection() {
ColorEntry selectedColor= getSelectedAppearanceColorOption();
- RGB rgb= selectedColor.getRGB();
+ fAppearanceColorDefault.setVisible(selectedColor.isSystemDefaultKey != null);
+ fAppearanceColorDefault.setSelection(selectedColor.isSystemDefault());
+ RGB rgb= selectedColor.isSystemDefault() ? new RGB(0, 0, 0) : PreferenceConverter.getColor(fOverlayStore, selectedColor.colorKey);
fAppearanceColorEditor.setColorValue(rgb);
-
- updateAppearanceColorWidgets(selectedColor.isSystemDefaultKey);
- }
-
- private void updateAppearanceColorWidgets(String systemDefaultKey) {
- if (systemDefaultKey == null) {
- fAppearanceColorDefault.setSelection(false);
- fAppearanceColorDefault.setVisible(false);
- fAppearanceColorEditor.getButton().setEnabled(true);
- } else {
- boolean systemDefault= fOverlayStore.getBoolean(systemDefaultKey);
- fAppearanceColorDefault.setSelection(systemDefault);
- fAppearanceColorDefault.setVisible(true);
- fAppearanceColorEditor.getButton().setEnabled(!systemDefault);
- }
}
private Control createAppearancePage(Composite parent) {
@@ -964,38 +962,16 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
gd.horizontalAlignment= GridData.BEGINNING;
foregroundColorButton.setLayoutData(gd);
- SelectionListener colorDefaultSelectionListener= new SelectionListener() {
+ SelectionListener colorDefaultSelectionListener= new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- boolean useSystemDefaultColor= fAppearanceColorDefault.getSelection();
- fAppearanceColorEditor.getButton().setEnabled(!useSystemDefaultColor);
- ColorEntry selectedColor= getSelectedAppearanceColorOption();
- if (selectedColor.isSystemDefaultKey != null) {
- if (!useSystemDefaultColor) {
- // Update the color picker/editor's displayed color
- fAppearanceColorEditor.setColorValue(selectedColor.previousColor);
- // Disable the default color preference
- fOverlayStore.setValue(selectedColor.isSystemDefaultKey, false);
- // Set the color preference to the last user-set color
- selectedColor.setColor(selectedColor.previousColor);
- } else {
- // System Default Color set to Black as system default colors can't yet reliably be retrieved
- RGB defaultColor= new RGB(0, 0, 0);
- selectedColor.previousColor= PreferenceConverter.getColor(fOverlayStore, selectedColor.colorKey);
- // Update the color picker/editor's displayed color
- fAppearanceColorEditor.setColorValue(defaultColor);
- selectedColor.setColor(defaultColor);
- // Use/enable the default color preference
- fOverlayStore.setValue(selectedColor.isSystemDefaultKey, true);
- }
- // Make the newly set color (system default or last used color) display in the table
- fAppearanceColorTableViewer.update(selectedColor, null);
+ ColorEntry colorEntry = getSelectedAppearanceColorOption();
+ if (colorEntry.allowSystemDefault()) {
+ colorEntry.setSystemDefault(fAppearanceColorDefault.getSelection());
+ handleAppearanceColorListSelection(); // refresh color preview and checkbox state
+ fAppearanceColorTableViewer.update(colorEntry, null);
}
}
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // do nothing
- }
};
fAppearanceColorDefault= new Button(stylesComposite, SWT.CHECK);
@@ -1007,17 +983,15 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
fAppearanceColorDefault.setVisible(false);
fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener);
- foregroundColorButton.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // do nothing
- }
+ foregroundColorButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ColorEntry selectedColor= getSelectedAppearanceColorOption();
selectedColor.setColor(fAppearanceColorEditor.getColorValue());
+ selectedColor.setSystemDefault(false);
// Make the newly selected color display in the table
fAppearanceColorTableViewer.update(selectedColor, null);
+ fAppearanceColorDefault.setSelection(selectedColor.isSystemDefault());
}
});

Back to the top