[Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin OverlayPreferenceStore.java,NONE,1.1 Status
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-02-18 11:14:45
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18423/src/org/python/pydev/plugin Modified Files: PydevPrefs.java Added Files: OverlayPreferenceStore.java StatusInfo.java ColorEditor.java Log Message: Added patch to enable better color management. --- NEW FILE: OverlayPreferenceStore.java --- /******************************************************************************* * With minor modification for pydev * * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Scott Schlesier - minor changes for use in pydev *******************************************************************************/ package org.python.pydev.plugin; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.text.Assert; /** * An overlaying preference store. */ public class OverlayPreferenceStore implements IPreferenceStore { public static final class TypeDescriptor { private TypeDescriptor() { } } public static final TypeDescriptor BOOLEAN= new TypeDescriptor(); public static final TypeDescriptor DOUBLE= new TypeDescriptor(); public static final TypeDescriptor FLOAT= new TypeDescriptor(); public static final TypeDescriptor INT= new TypeDescriptor(); public static final TypeDescriptor LONG= new TypeDescriptor(); public static final TypeDescriptor STRING= new TypeDescriptor(); public static class OverlayKey { TypeDescriptor fDescriptor; String fKey; public OverlayKey(TypeDescriptor descriptor, String key) { fDescriptor= descriptor; fKey= key; } } private class PropertyListener implements IPropertyChangeListener { /* * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { OverlayKey key= findOverlayKey(event.getProperty()); if (key != null) propagateProperty(fParent, key, fStore); } } private IPreferenceStore fParent; private IPreferenceStore fStore; private OverlayKey[] fOverlayKeys; private PropertyListener fPropertyListener; private boolean fLoaded; public OverlayPreferenceStore(IPreferenceStore parent, OverlayKey[] overlayKeys) { fParent= parent; fOverlayKeys= overlayKeys; fStore= new PreferenceStore(); } private OverlayKey findOverlayKey(String key) { for (int i= 0; i < fOverlayKeys.length; i++) { if (fOverlayKeys[i].fKey.equals(key)) return fOverlayKeys[i]; } return null; } private boolean covers(String key) { return (findOverlayKey(key) != null); } private void propagateProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target) { if (orgin.isDefault(key.fKey)) { if (!target.isDefault(key.fKey)) target.setToDefault(key.fKey); return; } TypeDescriptor d= key.fDescriptor; if (BOOLEAN == d) { boolean originValue= orgin.getBoolean(key.fKey); boolean targetValue= target.getBoolean(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (DOUBLE == d) { double originValue= orgin.getDouble(key.fKey); double targetValue= target.getDouble(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (FLOAT == d) { float originValue= orgin.getFloat(key.fKey); float targetValue= target.getFloat(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (INT == d) { int originValue= orgin.getInt(key.fKey); int targetValue= target.getInt(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (LONG == d) { long originValue= orgin.getLong(key.fKey); long targetValue= target.getLong(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (STRING == d) { String originValue= orgin.getString(key.fKey); String targetValue= target.getString(key.fKey); if (targetValue != null && originValue != null && !targetValue.equals(originValue)) target.setValue(key.fKey, originValue); } } public void propagate() { for (int i= 0; i < fOverlayKeys.length; i++) propagateProperty(fStore, fOverlayKeys[i], fParent); } private void loadProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target, boolean forceInitialization) { TypeDescriptor d= key.fDescriptor; if (BOOLEAN == d) { if (forceInitialization) target.setValue(key.fKey, true); target.setValue(key.fKey, orgin.getBoolean(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultBoolean(key.fKey)); } else if (DOUBLE == d) { if (forceInitialization) target.setValue(key.fKey, 1.0D); target.setValue(key.fKey, orgin.getDouble(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultDouble(key.fKey)); } else if (FLOAT == d) { if (forceInitialization) target.setValue(key.fKey, 1.0F); target.setValue(key.fKey, orgin.getFloat(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultFloat(key.fKey)); } else if (INT == d) { if (forceInitialization) target.setValue(key.fKey, 1); target.setValue(key.fKey, orgin.getInt(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultInt(key.fKey)); } else if (LONG == d) { if (forceInitialization) target.setValue(key.fKey, 1L); target.setValue(key.fKey, orgin.getLong(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultLong(key.fKey)); } else if (STRING == d) { if (forceInitialization) target.setValue(key.fKey, "1"); //$NON-NLS-1$ target.setValue(key.fKey, orgin.getString(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultString(key.fKey)); } } public void load() { for (int i= 0; i < fOverlayKeys.length; i++) loadProperty(fParent, fOverlayKeys[i], fStore, true); fLoaded= true; } public void loadDefaults() { for (int i= 0; i < fOverlayKeys.length; i++) setToDefault(fOverlayKeys[i].fKey); } public void start() { if (fPropertyListener == null) { fPropertyListener= new PropertyListener(); fParent.addPropertyChangeListener(fPropertyListener); } } public void stop() { if (fPropertyListener != null) { fParent.removePropertyChangeListener(fPropertyListener); fPropertyListener= null; } } /* * @see IPreferenceStore#addPropertyChangeListener(IPropertyChangeListener) */ public void addPropertyChangeListener(IPropertyChangeListener listener) { fStore.addPropertyChangeListener(listener); } /* * @see IPreferenceStore#removePropertyChangeListener(IPropertyChangeListener) */ public void removePropertyChangeListener(IPropertyChangeListener listener) { fStore.removePropertyChangeListener(listener); } /* * @see IPreferenceStore#firePropertyChangeEvent(String, Object, Object) */ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { fStore.firePropertyChangeEvent(name, oldValue, newValue); } /* * @see IPreferenceStore#contains(String) */ public boolean contains(String name) { return fStore.contains(name); } /* * @see IPreferenceStore#getBoolean(String) */ public boolean getBoolean(String name) { return fStore.getBoolean(name); } /* * @see IPreferenceStore#getDefaultBoolean(String) */ public boolean getDefaultBoolean(String name) { return fStore.getDefaultBoolean(name); } /* * @see IPreferenceStore#getDefaultDouble(String) */ public double getDefaultDouble(String name) { return fStore.getDefaultDouble(name); } /* * @see IPreferenceStore#getDefaultFloat(String) */ public float getDefaultFloat(String name) { return fStore.getDefaultFloat(name); } /* * @see IPreferenceStore#getDefaultInt(String) */ public int getDefaultInt(String name) { return fStore.getDefaultInt(name); } /* * @see IPreferenceStore#getDefaultLong(String) */ public long getDefaultLong(String name) { return fStore.getDefaultLong(name); } /* * @see IPreferenceStore#getDefaultString(String) */ public String getDefaultString(String name) { return fStore.getDefaultString(name); } /* * @see IPreferenceStore#getDouble(String) */ public double getDouble(String name) { return fStore.getDouble(name); } /* * @see IPreferenceStore#getFloat(String) */ public float getFloat(String name) { return fStore.getFloat(name); } /* * @see IPreferenceStore#getInt(String) */ public int getInt(String name) { return fStore.getInt(name); } /* * @see IPreferenceStore#getLong(String) */ public long getLong(String name) { return fStore.getLong(name); } /* * @see IPreferenceStore#getString(String) */ public String getString(String name) { return fStore.getString(name); } /* * @see IPreferenceStore#isDefault(String) */ public boolean isDefault(String name) { return fStore.isDefault(name); } /* * @see IPreferenceStore#needsSaving() */ public boolean needsSaving() { return fStore.needsSaving(); } /* * @see IPreferenceStore#putValue(String, String) */ public void putValue(String name, String value) { if (covers(name)) fStore.putValue(name, value); } /* * @see IPreferenceStore#setDefault(String, double) */ public void setDefault(String name, double value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setDefault(String, float) */ public void setDefault(String name, float value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setDefault(String, int) */ public void setDefault(String name, int value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setDefault(String, long) */ public void setDefault(String name, long value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setDefault(String, String) */ public void setDefault(String name, String value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setDefault(String, boolean) */ public void setDefault(String name, boolean value) { if (covers(name)) fStore.setDefault(name, value); } /* * @see IPreferenceStore#setToDefault(String) */ public void setToDefault(String name) { fStore.setToDefault(name); } /* * @see IPreferenceStore#setValue(String, double) */ public void setValue(String name, double value) { if (covers(name)) fStore.setValue(name, value); } /* * @see IPreferenceStore#setValue(String, float) */ public void setValue(String name, float value) { if (covers(name)) fStore.setValue(name, value); } /* * @see IPreferenceStore#setValue(String, int) */ public void setValue(String name, int value) { if (covers(name)) fStore.setValue(name, value); } /* * @see IPreferenceStore#setValue(String, long) */ public void setValue(String name, long value) { if (covers(name)) fStore.setValue(name, value); } /* * @see IPreferenceStore#setValue(String, String) */ public void setValue(String name, String value) { if (covers(name)) fStore.setValue(name, value); } /* * @see IPreferenceStore#setValue(String, boolean) */ public void setValue(String name, boolean value) { if (covers(name)) fStore.setValue(name, value); } /** * The keys to add to the list of overlay keys. * <p> * Note: This method must be called before {@link #load()} is called. * </p> * * @param keys * @since 3.0 */ public void addKeys(OverlayKey[] keys) { Assert.isTrue(!fLoaded); Assert.isNotNull(keys); int overlayKeysLength= fOverlayKeys.length; OverlayKey[] result= new OverlayKey[keys.length + overlayKeysLength]; for (int i= 0, length= overlayKeysLength; i < length; i++) result[i]= fOverlayKeys[i]; for (int i= 0, length= keys.length; i < length; i++) result[overlayKeysLength + i]= keys[i]; fOverlayKeys= result; if (fLoaded) load(); } } --- NEW FILE: StatusInfo.java --- /******************************************************************************* * With minor modifications for pydev * * * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Scott Schlesier - minor changes for use in pydev *******************************************************************************/ package org.python.pydev.plugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.util.Assert; /** * A settable IStatus. * Can be an error, warning, info or ok. For error, info and warning states, * a message describes the problem. */ public class StatusInfo implements IStatus { public static final IStatus OK_STATUS= new StatusInfo(); private String fStatusMessage; private int fSeverity; /** * Creates a status set to OK (no message) */ public StatusInfo() { this(OK, null); } /** * Creates a status . * @param severity The status severity: ERROR, WARNING, INFO and OK. * @param message The message of the status. Applies only for ERROR, * WARNING and INFO. */ public StatusInfo(int severity, String message) { fStatusMessage= message; fSeverity= severity; } /** * Returns if the status' severity is OK. */ public boolean isOK() { return fSeverity == IStatus.OK; } /** * Returns if the status' severity is WARNING. */ public boolean isWarning() { return fSeverity == IStatus.WARNING; } /** * Returns if the status' severity is INFO. */ public boolean isInfo() { return fSeverity == IStatus.INFO; } /** * Returns if the status' severity is ERROR. */ public boolean isError() { return fSeverity == IStatus.ERROR; } /** * @see IStatus#getMessage */ public String getMessage() { return fStatusMessage; } /** * Sets the status to ERROR. * @param errorMessage The error message (can be empty, but not null) */ public void setError(String errorMessage) { Assert.isNotNull(errorMessage); fStatusMessage= errorMessage; fSeverity= IStatus.ERROR; } /** * Sets the status to WARNING. * @param warningMessage The warning message (can be empty, but not null) */ public void setWarning(String warningMessage) { Assert.isNotNull(warningMessage); fStatusMessage= warningMessage; fSeverity= IStatus.WARNING; } /** * Sets the status to INFO. * @param infoMessage The info message (can be empty, but not null) */ public void setInfo(String infoMessage) { Assert.isNotNull(infoMessage); fStatusMessage= infoMessage; fSeverity= IStatus.INFO; } /** * Sets the status to OK. */ public void setOK() { fStatusMessage= null; fSeverity= IStatus.OK; } /* * @see IStatus#matches(int) */ public boolean matches(int severityMask) { return (fSeverity & severityMask) != 0; } /** * Returns always <code>false</code>. * @see IStatus#isMultiStatus() */ public boolean isMultiStatus() { return false; } /* * @see IStatus#getSeverity() */ public int getSeverity() { return fSeverity; } /* * @see IStatus#getPlugin() */ public String getPlugin() { return PydevPlugin.getDefault().getBundle().getSymbolicName(); } /** * Returns always <code>null</code>. * @see IStatus#getException() */ public Throwable getException() { return null; } /** * Returns always the error severity. * @see IStatus#getCode() */ public int getCode() { return fSeverity; } /** * Returns always <code>null</code>. * @see IStatus#getChildren() */ public IStatus[] getChildren() { return new IStatus[0]; } } --- NEW FILE: ColorEditor.java --- /******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Scott Schlesier - minor changes for use in pydev *******************************************************************************/ package org.python.pydev.plugin; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.ColorDialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.jface.resource.JFaceResources; /** * A "button" of a certain color determined by the color picker. */ public class ColorEditor { private Point fExtent; private Image fImage; private RGB fColorValue; private Color fColor; private Button fButton; public ColorEditor(Composite parent) { fButton= new Button(parent, SWT.PUSH); fExtent= computeImageSize(parent); fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y); GC gc= new GC(fImage); gc.setBackground(fButton.getBackground()); gc.fillRectangle(0, 0, fExtent.x, fExtent.y); gc.dispose(); fButton.setImage(fImage); fButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog colorDialog= new ColorDialog(fButton.getShell()); colorDialog.setRGB(fColorValue); RGB newColor = colorDialog.open(); if (newColor != null) { fColorValue= newColor; updateColorImage(); } } }); fButton.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent event) { if (fImage != null) { fImage.dispose(); fImage= null; } if (fColor != null) { fColor.dispose(); fColor= null; } } }); } public RGB getColorValue() { return fColorValue; } public void setColorValue(RGB rgb) { fColorValue= rgb; updateColorImage(); } public Button getButton() { return fButton; } protected void updateColorImage() { Display display= fButton.getDisplay(); GC gc= new GC(fImage); gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4); if (fColor != null) fColor.dispose(); fColor= new Color(display, fColorValue); gc.setBackground(fColor); gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5); gc.dispose(); fButton.setImage(fImage); } protected Point computeImageSize(Control window) { GC gc= new GC(window); Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT); gc.setFont(f); int height= gc.getFontMetrics().getHeight(); gc.dispose(); Point p= new Point(height * 3 - 6, height); return p; } } Index: PydevPrefs.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPrefs.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PydevPrefs.java 20 Jan 2005 19:03:53 -0000 1.15 --- PydevPrefs.java 18 Feb 2005 11:14:33 -0000 1.16 *************** *** 1,37 **** ! /* ! * Author: atotic ! * Created: Jun 23, 2003 ! * License: Common Public License v1.0 ! */ package org.python.pydev.plugin; import org.eclipse.core.runtime.Preferences; ! import org.eclipse.jface.preference.BooleanFieldEditor; ! import org.eclipse.jface.preference.ColorFieldEditor; ! import org.eclipse.jface.preference.FieldEditorPreferencePage; ! import org.eclipse.jface.preference.IntegerFieldEditor; ! import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.jface.resource.StringConverter; ! import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.python.pydev.ui.InterpreterEditor; /** ! * Pydev preference page. * ! * <p>Uses FieldEditor framework for preference editing. ! * <p>Defaults are declared here as constants. ! * <p>There is a string constant for every prefernce you can use for access ! * <p>Framework takes care of storing of the prefs ! * <p>The meaning of preferences are documented in user docs, for details grep ! * the source for the particular string. */ ! public class PydevPrefs extends FieldEditorPreferencePage ! implements IWorkbenchPreferencePage{ ! ! // Preferences public static final String SUBSTITUTE_TABS = "SUBSTITUTE_TABS"; public static final boolean DEFAULT_SUBSTITUTE_TABS = true; --- 1,82 ---- ! /******************************************************************************* ! * Copyright (c) 2000, 2004 IBM Corporation and others. ! * All rights reserved. This program and the accompanying materials ! * are made available under the terms of the Common Public License v1.0 ! * which accompanies this distribution, and is available at ! * http://www.eclipse.org/legal/cpl-v10.html ! * ! * Contributors: ! * IBM Corporation - initial API and implementation ! * Scott Schlesier - Adapted for use in pydev ! * Fabio Zadrozny ! *******************************************************************************/ ! package org.python.pydev.plugin; + + import java.util.ArrayList; + import java.util.HashMap; + import java.util.Iterator; + import java.util.Map; + + import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; ! import org.eclipse.jface.dialogs.Dialog; ! import org.eclipse.jface.dialogs.DialogPage; ! import org.eclipse.jface.dialogs.IMessageProvider; ! import org.eclipse.jface.preference.PreferenceConverter; ! import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.StringConverter; ! import org.eclipse.swt.SWT; ! import org.eclipse.swt.events.ModifyEvent; ! import org.eclipse.swt.events.ModifyListener; ! import org.eclipse.swt.events.SelectionEvent; ! import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.RGB; + import org.eclipse.swt.layout.GridData; + import org.eclipse.swt.layout.GridLayout; + import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; + import org.eclipse.swt.widgets.Control; + import org.eclipse.swt.widgets.Label; + import org.eclipse.swt.widgets.List; + import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; + import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; + import org.eclipse.ui.help.WorkbenchHelp; + import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; + import org.eclipse.ui.texteditor.AbstractTextEditor; import org.python.pydev.ui.InterpreterEditor; + + /** ! * The preference page for setting the editor options. ! * <p> ! * This class is internal and not intended to be used by clients.</p> * ! * @since 2.1 */ ! public class PydevPrefs extends PreferencePage implements IWorkbenchPreferencePage { ! ! // Preferences ! //To add a new preference it needs to be included in ! //createAppearancePage ! //createOverlayStore ! //initializeDefaultPreferences ! //declaration of fAppearanceColorListModel if it is a color ! //constants (here) ! ! //text ! public static final String TAB_WIDTH = "TAB_WIDTH"; ! public static final int DEFAULT_TAB_WIDTH = 4; ! ! public static final String DEFAULT_EDITOR_PRINT_MARGIN_COLUMN = "80"; ! ! public static final String BLOCK_COMMENT = "BLOCK_COMMENT"; ! public static final String DEFAULT_BLOCK_COMMENT_STRING = "================================================================================"; ! ! //checkboxes public static final String SUBSTITUTE_TABS = "SUBSTITUTE_TABS"; public static final boolean DEFAULT_SUBSTITUTE_TABS = true; *************** *** 43,68 **** public static final boolean DEFAULT_GUESS_TAB_SUBSTITUTION = true; ! public static final String TAB_WIDTH = "TAB_WIDTH"; ! public static final int DEFAULT_TAB_WIDTH = 4; ! ! public static final String EDITOR_BACKGROUND_COLOR = "EDITOR_BACKGROUND_COLOR"; ! //The widget colors are not the editor actual editor defaults, but they look OK ! //Not sure how to lookup the actual editor defaults ! private static final RGB DEFAULT_EDITOR_BACKGROUND_COLOR = new RGB(255, 255, 255); ! ! public static final String EDITOR_USE_CUSTOM_BACKGROUND_COLOR = "EDITOR_USE_CUSTOM_BACKGROUND_COLOR"; ! public static final boolean DEFAULT_EDITOR_BACKGROUND_COLOR_SYSTEM_DEFAULT = false; ! ! public static final String EDITOR_CURRENT_LINE = "EDITOR_CURRENT_LINE"; private static final boolean DEFAULT_EDITOR_CURRENT_LINE = true; - public static final String EDITOR_CURRENT_LINE_COLOR = "EDITOR_CURRENT_LINE_COLOR"; - private static final RGB DEFAULT_EDITOR_CURRENT_LINE_COLOR = new RGB(233, 249, 254); public static final String CODE_COLOR = "CODE_COLOR"; private static final RGB DEFAULT_CODE_COLOR = new RGB(0, 0, 0); public static final String KEYWORD_COLOR = "KEYWORD_COLOR"; ! private static final RGB DEFAULT_KEYWORD_COLOR = new RGB(255, 119, 0); public static final String STRING_COLOR = "STRING_COLOR"; --- 88,105 ---- public static final boolean DEFAULT_GUESS_TAB_SUBSTITUTION = true; ! public static final boolean DEFAULT_EDITOR_OVERVIEW_RULER = false; ! public static final boolean DEFAULT_EDITOR_LINE_NUMBER_RULER = false; private static final boolean DEFAULT_EDITOR_CURRENT_LINE = true; + public static final boolean DEFAULT_EDITOR_PRINT_MARGIN = true; + public static final boolean DEFAULT_EDITOR_USE_CUSTOM_CARETS = false; + public static final boolean DEFAULT_EDITOR_WIDE_CARET = false; + //colors public static final String CODE_COLOR = "CODE_COLOR"; private static final RGB DEFAULT_CODE_COLOR = new RGB(0, 0, 0); public static final String KEYWORD_COLOR = "KEYWORD_COLOR"; ! private static final RGB DEFAULT_KEYWORD_COLOR = new RGB(0, 0, 255); public static final String STRING_COLOR = "STRING_COLOR"; *************** *** 70,75 **** public static final String COMMENT_COLOR = "COMMENT_COLOR"; ! private static final RGB DEFAULT_COMMENT_COLOR = new RGB(221, 0, 0); public static final String INTERPRETER_PATH = "INTERPRETER_PATH"; protected static final String DEFAULT_INTERPRETER_PATH = "python"; --- 107,123 ---- public static final String COMMENT_COLOR = "COMMENT_COLOR"; ! private static final RGB DEFAULT_COMMENT_COLOR = new RGB(192, 192, 192); ! ! private static final RGB DEFAULT_PREFERENCE_COLOR_BACKGROUND = new RGB(255, 255, 255); ! public static final boolean DEFAULT_EDITOR_BACKGROUND_COLOR_SYSTEM_DEFAULT = true; ! private static final RGB DEFAULT_EDITOR_CURRENT_LINE_COLOR = new RGB(244, 255, 255); ! public static final RGB DEFAULT_EDITOR_LINE_NUMBER_RULER_COLOR = new RGB(0, 0, 0); ! public static final RGB DEFAULT_EDITOR_PRINT_MARGIN_COLOR = new RGB(192,192,192); ! ! //see initializeDefaultColors for selection defaults ! public static final boolean DEFAULT_EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR = true; ! public static final boolean DEFAULT_EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR = true; + //no UI public static final String INTERPRETER_PATH = "INTERPRETER_PATH"; protected static final String DEFAULT_INTERPRETER_PATH = "python"; *************** *** 78,216 **** private static final RGB DEFAULT_HYPERLINK_COLOR = new RGB(0, 0, 238); - public static final String BLOCK_COMMENT = "BLOCK_COMMENT"; - public static final String DEFAULT_BLOCK_COMMENT_STRING = "================================================================================"; - public static final boolean DEFAULT_BLOCK_COMMENT = true; - public static final String CONNECT_TIMEOUT = "CONNECT_TIMEOUT"; public static final int DEFAULT_CONNECT_TIMEOUT = 20000; ! public static final String RUN_MANY_SCRIPT_LOCATION = "RUN_MANY_SCRIPT_LOCATION"; public static final String DEFAULT_RUN_MANY_SCRIPT_LOCATION = ""; ! //FieldEditors that need to be manipulated ! private ColorFieldEditor colorBackground, colorLine; ! private BooleanFieldEditor boolSysDefaultBackground, boolLine; /** ! * Initializer sets the preference store */ public PydevPrefs() { ! super(GRID); setPreferenceStore(PydevPlugin.getDefault().getPreferenceStore()); } ! ! static public Preferences getPreferences() { ! return PydevPlugin.getDefault().getPluginPreferences(); } ! public static String[] getInterpreters() { ! String interpreters = getPreferences().getString(PydevPrefs.INTERPRETER_PATH); ! return InterpreterEditor.getInterpreterList(interpreters); } ! public static String getDefaultInterpreter() { ! return getInterpreters()[0]; } ! public void init(IWorkbench workbench) { } ! /** ! * Creates the editors ! */ ! protected void createFieldEditors() { ! Composite p = getFieldEditorParent(); ! addField(new BooleanFieldEditor( ! SUBSTITUTE_TABS, "Substitute spaces for tabs?", p)); ! addField(new BooleanFieldEditor( ! GUESS_TAB_SUBSTITUTION, "Assume tab spacing when files contain tabs?", p)); ! addField(new BooleanFieldEditor( ! USE_CODE_FOLDING, "Use code folding?", p)); ! IntegerFieldEditor ife = new IntegerFieldEditor(TAB_WIDTH, "Tab length", p, 1); ! ife.setValidRange(1, 8); ! // you can't restrict widget width on IntegerFieldEditor for now ! addField(ife); ! boolSysDefaultBackground = new BooleanFieldEditor( ! EDITOR_USE_CUSTOM_BACKGROUND_COLOR, "Use custom background?", p); ! addField(boolSysDefaultBackground); ! colorBackground = new ColorFieldEditor(EDITOR_BACKGROUND_COLOR, "Background", p); ! addField(colorBackground); ! boolLine = new BooleanFieldEditor( ! EDITOR_CURRENT_LINE, "Highlight current line?", p); ! addField(boolLine); ! colorLine = new ColorFieldEditor(EDITOR_CURRENT_LINE_COLOR, "Current Line", p); ! addField(colorLine); ! addField(new ColorFieldEditor( ! CODE_COLOR, "Code", p)); ! addField(new ColorFieldEditor( ! KEYWORD_COLOR, "Keywords", p)); ! addField(new ColorFieldEditor( ! STRING_COLOR, "Strings", p)); ! addField(new ColorFieldEditor( ! COMMENT_COLOR, "Comments", p)); ! StringFieldEditor sfe = new StringFieldEditor ( BLOCK_COMMENT, "Block comment separator", 40, StringFieldEditor.VALIDATE_ON_FOCUS_LOST ,p ); ! addField(sfe); } ! protected void initialize() ! { ! super.initialize(); ! activateControls(); } ! public void propertyChange(PropertyChangeEvent e) ! { ! Object src = e.getSource(); ! if( src.equals(boolSysDefaultBackground) || ! src.equals(boolLine) ) ! { ! activateControls(); } } ! //Adjust the state of all controls on the page ! private void activateControls() ! { ! colorBackground.setEnabled( ! boolSysDefaultBackground.getBooleanValue(), ! getFieldEditorParent()); ! colorLine.setEnabled( ! boolLine.getBooleanValue(), ! getFieldEditorParent()); } /** * Sets default preference values */ protected static void initializeDefaultPreferences(Preferences prefs) { prefs.setDefault(SUBSTITUTE_TABS, DEFAULT_SUBSTITUTE_TABS); - prefs.setDefault(USE_CODE_FOLDING, DEFAULT_USE_CODE_FOLDING); prefs.setDefault(GUESS_TAB_SUBSTITUTION, DEFAULT_GUESS_TAB_SUBSTITUTION); ! prefs.setDefault(TAB_WIDTH, DEFAULT_TAB_WIDTH); prefs.setDefault(CODE_COLOR,StringConverter.asString(DEFAULT_CODE_COLOR)); prefs.setDefault(KEYWORD_COLOR,StringConverter.asString(DEFAULT_KEYWORD_COLOR)); prefs.setDefault(STRING_COLOR,StringConverter.asString(DEFAULT_STRING_COLOR)); prefs.setDefault(COMMENT_COLOR,StringConverter.asString(DEFAULT_COMMENT_COLOR)); ! prefs.setDefault(HYPERLINK_COLOR, StringConverter.asString(DEFAULT_HYPERLINK_COLOR)); ! prefs.setDefault(EDITOR_BACKGROUND_COLOR, StringConverter.asString(DEFAULT_EDITOR_BACKGROUND_COLOR)); ! prefs.setDefault(EDITOR_USE_CUSTOM_BACKGROUND_COLOR, DEFAULT_EDITOR_BACKGROUND_COLOR_SYSTEM_DEFAULT); ! prefs.setDefault(EDITOR_CURRENT_LINE, StringConverter.asString(DEFAULT_EDITOR_CURRENT_LINE)); ! prefs.setDefault(EDITOR_CURRENT_LINE_COLOR, StringConverter.asString(DEFAULT_EDITOR_CURRENT_LINE_COLOR)); ! prefs.setDefault(BLOCK_COMMENT, DEFAULT_BLOCK_COMMENT_STRING); prefs.setDefault(CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT); prefs.setDefault(RUN_MANY_SCRIPT_LOCATION, DEFAULT_RUN_MANY_SCRIPT_LOCATION); } ! } --- 126,701 ---- private static final RGB DEFAULT_HYPERLINK_COLOR = new RGB(0, 0, 238); public static final String CONNECT_TIMEOUT = "CONNECT_TIMEOUT"; public static final int DEFAULT_CONNECT_TIMEOUT = 20000; ! public static final String RUN_MANY_SCRIPT_LOCATION = "RUN_MANY_SCRIPT_LOCATION"; public static final String DEFAULT_RUN_MANY_SCRIPT_LOCATION = ""; + + + /** + * Defaults + */ + private final String[][] fAppearanceColorListModel= new String[][] { + {"Code", CODE_COLOR, null}, + {"Keywords", KEYWORD_COLOR, null}, + {"Strings", STRING_COLOR, null}, + {"Comments", COMMENT_COLOR, null}, + {"Background", AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT}, + {"Current line highlight", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, null}, + {"Line numbers", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, null}, + {"Print margin", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, null}, + {"Selection foreground", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR}, + {"Selection background", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR}, + }; + + private OverlayPreferenceStore fOverlayStore; + + private Map fCheckBoxes= new HashMap(); + private SelectionListener fCheckBoxListener= new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + Button button= (Button) e.widget; + fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection()); + } + }; + + private Map fTextFields= new HashMap(); + private ModifyListener fTextFieldListener= new ModifyListener() { + public void modifyText(ModifyEvent e) { + Text text= (Text) e.widget; + fOverlayStore.setValue((String) fTextFields.get(text), text.getText()); + } + }; ! private ArrayList fNumberFields= new ArrayList(); ! private ModifyListener fNumberFieldListener= new ModifyListener() { ! public void modifyText(ModifyEvent e) { ! numberFieldChanged((Text) e.widget); ! } ! }; ! ! private List fAppearanceColorList; ! private ColorEditor fAppearanceColorEditor; ! private Button fAppearanceColorDefault; /** ! * Tells whether the fields are initialized. ! * @since 3.0 ! */ ! private boolean fFieldsInitialized= false; ! ! /** ! * List of master/slave listeners when there's a dependency. ! * ! * @see #createDependency(Button, String, Control) ! * @since 3.0 */ + private ArrayList fMasterSlaveListeners= new ArrayList(); + + public PydevPrefs() { ! setDescription("Pydev Editor settings:"); setPreferenceStore(PydevPlugin.getDefault().getPreferenceStore()); + + fOverlayStore= createOverlayStore(); } ! ! private OverlayPreferenceStore createOverlayStore() { ! ! ArrayList overlayKeys= new ArrayList(); ! ! //text ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, TAB_WIDTH)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, BLOCK_COMMENT)); ! ! //checkbox ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SUBSTITUTE_TABS)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, GUESS_TAB_SUBSTITUTION)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, USE_CODE_FOLDING)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WIDE_CARET)); ! ! //colors ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, CODE_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, KEYWORD_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, STRING_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, COMMENT_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR)); ! overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR)); ! ! OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; ! overlayKeys.toArray(keys); ! return new OverlayPreferenceStore(getPreferenceStore(), keys); } ! /* ! * @see IWorkbenchPreferencePage#init() ! */ ! public void init(IWorkbench workbench) { } ! /* ! * @see PreferencePage#createControl(Composite) ! */ ! public void createControl(Composite parent) { ! super.createControl(parent); ! WorkbenchHelp.setHelp(getControl(), ITextEditorHelpContextIds.TEXT_EDITOR_PREFERENCE_PAGE); } ! private void handleAppearanceColorListSelection() { ! int i= fAppearanceColorList.getSelectionIndex(); ! String key= fAppearanceColorListModel[i][1]; ! RGB rgb= PreferenceConverter.getColor(fOverlayStore, key); ! fAppearanceColorEditor.setColorValue(rgb); ! updateAppearanceColorWidgets(fAppearanceColorListModel[i][2]); ! } ! ! 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) { ! Composite appearanceComposite= new Composite(parent, SWT.NONE); ! GridLayout layout= new GridLayout(); layout.numColumns= 2; ! appearanceComposite.setLayout(layout); ! ! addTextField(appearanceComposite, "Tab length:", TAB_WIDTH, 3, 0, true); ! ! addTextField(appearanceComposite, "Print margin column:", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 3, 0, true); ! addTextField(appearanceComposite, "Block comment seperator:", BLOCK_COMMENT, 50, 0, false); ! ! addCheckBox(appearanceComposite, "Substitute spaces for tabs?", SUBSTITUTE_TABS, 0); ! ! addCheckBox(appearanceComposite, "Assume tab spacing when files contain tabs?", GUESS_TAB_SUBSTITUTION, 0); ! ! addCheckBox(appearanceComposite, "Use code folding?", USE_CODE_FOLDING, 0); ! ! addCheckBox(appearanceComposite, "Show overview ruler", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, 0); ! ! addCheckBox(appearanceComposite, "Show line numbers", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, 0); ! addCheckBox(appearanceComposite, "Highlight current line", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, 0); ! ! addCheckBox(appearanceComposite, "Show print margin", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, 0); ! ! Button master= addCheckBox(appearanceComposite, "Use custom caret", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS, 0); ! ! Button slave= addCheckBox(appearanceComposite, "Enable thick caret", AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WIDE_CARET, 0); ! createDependency(master, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS, slave); ! ! Label l= new Label(appearanceComposite, SWT.LEFT ); ! GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); ! gd.horizontalSpan= 2; ! gd.heightHint= convertHeightInCharsToPixels(1) / 2; ! l.setLayoutData(gd); ! l= new Label(appearanceComposite, SWT.LEFT); ! l.setText("Appearance color options:"); ! gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); ! gd.horizontalSpan= 2; ! l.setLayoutData(gd); ! ! Composite editorComposite= new Composite(appearanceComposite, SWT.NONE); ! layout= new GridLayout(); ! layout.numColumns= 2; ! layout.marginHeight= 0; ! layout.marginWidth= 0; ! editorComposite.setLayout(layout); ! gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); ! gd.horizontalSpan= 2; ! editorComposite.setLayoutData(gd); ! ! fAppearanceColorList= new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); ! gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); ! gd.heightHint= convertHeightInCharsToPixels(5); ! fAppearanceColorList.setLayoutData(gd); ! ! Composite stylesComposite= new Composite(editorComposite, SWT.NONE); ! layout= new GridLayout(); ! layout.marginHeight= 0; ! layout.marginWidth= 0; ! layout.numColumns= 2; ! stylesComposite.setLayout(layout); ! stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); ! l= new Label(stylesComposite, SWT.LEFT); ! l.setText("Color:"); ! gd= new GridData(); ! gd.horizontalAlignment= GridData.BEGINNING; ! l.setLayoutData(gd); ! ! fAppearanceColorEditor= new ColorEditor(stylesComposite); ! Button foregroundColorButton= fAppearanceColorEditor.getButton(); ! gd= new GridData(GridData.FILL_HORIZONTAL); ! gd.horizontalAlignment= GridData.BEGINNING; ! foregroundColorButton.setLayoutData(gd); ! ! SelectionListener colorDefaultSelectionListener= new SelectionListener() { ! public void widgetSelected(SelectionEvent e) { ! boolean systemDefault= fAppearanceColorDefault.getSelection(); ! fAppearanceColorEditor.getButton().setEnabled(!systemDefault); ! ! int i= fAppearanceColorList.getSelectionIndex(); ! String key= fAppearanceColorListModel[i][2]; ! if (key != null) ! fOverlayStore.setValue(key, systemDefault); ! } ! public void widgetDefaultSelected(SelectionEvent e) {} ! }; ! fAppearanceColorDefault= new Button(stylesComposite, SWT.CHECK); ! fAppearanceColorDefault.setText("System default"); ! gd= new GridData(GridData.FILL_HORIZONTAL); ! gd.horizontalAlignment= GridData.BEGINNING; ! gd.horizontalSpan= 2; ! fAppearanceColorDefault.setLayoutData(gd); ! fAppearanceColorDefault.setVisible(false); ! fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener); ! fAppearanceColorList.addSelectionListener(new SelectionListener() { ! public void widgetDefaultSelected(SelectionEvent e) { ! // do nothing ! } ! public void widgetSelected(SelectionEvent e) { ! handleAppearanceColorListSelection(); ! } ! }); ! foregroundColorButton.addSelectionListener(new SelectionListener() { ! public void widgetDefaultSelected(SelectionEvent e) { ! // do nothing ! } ! public void widgetSelected(SelectionEvent e) { ! int i= fAppearanceColorList.getSelectionIndex(); ! String key= fAppearanceColorListModel[i][1]; ! ! PreferenceConverter.setValue(fOverlayStore, key, fAppearanceColorEditor.getColorValue()); ! } ! }); ! return appearanceComposite; ! } ! ! /* ! * @see PreferencePage#createContents(Composite) ! */ ! protected Control createContents(Composite parent) { ! initializeDefaultColors(); ! ! fOverlayStore.load(); ! fOverlayStore.start(); ! Control control= createAppearancePage(parent); ! ! initialize(); ! Dialog.applyDialogFont(control); ! return control; ! } ! ! private void initialize() { ! initializeFields(); ! ! for (int i= 0; i < fAppearanceColorListModel.length; i++) ! fAppearanceColorList.add(fAppearanceColorListModel[i][0]); ! fAppearanceColorList.getDisplay().asyncExec(new Runnable() { ! public void run() { ! if (fAppearanceColorList != null && !fAppearanceColorList.isDisposed()) { ! fAppearanceColorList.select(0); ! handleAppearanceColorListSelection(); ! } ! } ! }); ! } ! ! private void initializeFields() { ! ! Iterator e= fCheckBoxes.keySet().iterator(); ! while (e.hasNext()) { ! Button b= (Button) e.next(); ! String key= (String) fCheckBoxes.get(b); ! b.setSelection(fOverlayStore.getBoolean(key)); ! } ! ! e= fTextFields.keySet().iterator(); ! while (e.hasNext()) { ! Text t= (Text) e.next(); ! String key= (String) fTextFields.get(t); ! t.setText(fOverlayStore.getString(key)); ! } ! ! fFieldsInitialized= true; ! updateStatus(validatePositiveNumber("0")); ! ! // Update slaves ! Iterator iter= fMasterSlaveListeners.iterator(); ! while (iter.hasNext()) { ! SelectionListener listener= (SelectionListener)iter.next(); ! listener.widgetSelected(null); ! } ! } ! ! private void initializeDefaultColors() { ! if (!getPreferenceStore().contains(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR)) { ! RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION).getRGB(); ! PreferenceConverter.setDefault(fOverlayStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, rgb); ! PreferenceConverter.setDefault(getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, rgb); ! } ! if (!getPreferenceStore().contains(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR)) { ! RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT).getRGB(); ! PreferenceConverter.setDefault(fOverlayStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, rgb); ! PreferenceConverter.setDefault(getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, rgb); ! } ! } ! ! /* ! * @see PreferencePage#performOk() ! */ ! public boolean performOk() { ! fOverlayStore.propagate(); ! PydevPlugin.getDefault().savePluginPreferences(); ! return true; ! } ! ! /* ! * @see PreferencePage#performDefaults() ! */ ! protected void performDefaults() { ! fOverlayStore.loadDefaults(); ! ! initializeFields(); ! ! handleAppearanceColorListSelection(); ! ! super.performDefaults(); } ! /* ! * @see DialogPage#dispose() ! */ ! public void dispose() { ! ! if (fOverlayStore != null) { ! fOverlayStore.stop(); ! fOverlayStore= null; ! } ! ! super.dispose(); } ! private Button addCheckBox(Composite parent, String label, String key, int indentation) { ! Button checkBox= new Button(parent, SWT.CHECK); ! checkBox.setText(label); ! ! GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); ! gd.horizontalIndent= indentation; ! gd.horizontalSpan= 2; ! checkBox.setLayoutData(gd); ! checkBox.addSelectionListener(fCheckBoxListener); ! ! fCheckBoxes.put(checkBox, key); ! ! return checkBox; ! } ! ! private Control addTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) { ! ! Label labelControl= new Label(composite, SWT.NONE); ! labelControl.setText(label); ! GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); ! gd.horizontalIndent= indentation; ! labelControl.setLayoutData(gd); ! ! Text textControl= new Text(composite, SWT.BORDER | SWT.SINGLE); ! gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); ! gd.widthHint= convertWidthInCharsToPixels(textLimit + 1); ! textControl.setLayoutData(gd); ! textControl.setTextLimit(textLimit); ! fTextFields.put(textControl, key); ! if (isNumber) { ! fNumberFields.add(textControl); ! textControl.addModifyListener(fNumberFieldListener); ! } else { ! textControl.addModifyListener(fTextFieldListener); } + + return textControl; } ! private void createDependency(final Button master, String masterKey, final Control slave) { ! indent(slave); ! boolean masterState= fOverlayStore.getBoolean(masterKey); ! slave.setEnabled(masterState); ! ! SelectionListener listener= new SelectionListener() { ! public void widgetSelected(SelectionEvent e) { ! slave.setEnabled(master.getSelection()); ! } ! ! public void widgetDefaultSelected(SelectionEvent e) {} ! }; ! master.addSelectionListener(listener); ! fMasterSlaveListeners.add(listener); ! } ! ! private static void indent(Control control) { ! GridData gridData= new GridData(); ! gridData.horizontalIndent= 20; ! control.setLayoutData(gridData); } + + private void numberFieldChanged(Text textControl) { + String number= textControl.getText(); + IStatus status= validatePositiveNumber(number); + if (!status.matches(IStatus.ERROR)) + fOverlayStore.setValue((String) fTextFields.get(textControl), number); + updateStatus(status); + } + + private IStatus validatePositiveNumber(String number) { + StatusInfo status= new StatusInfo(); + if (number.length() == 0) { + status.setError("empty_input??"); + } else { + try { + int value= Integer.parseInt(number); + if (value < 0) + status.setError("invalid_input??"); + } catch (NumberFormatException e) { + status.setError("invalid_input??"); + } + } + return status; + } + + void updateStatus(IStatus status) { + if (!fFieldsInitialized) + return; + if (!status.matches(IStatus.ERROR)) { + for (int i= 0; i < fNumberFields.size(); i++) { + Text text= (Text) fNumberFields.get(i); + IStatus s= validatePositiveNumber(text.getText()); + status= s.getSeverity() > status.getSeverity() ? s : status; + } + } + setValid(!status.matches(IStatus.ERROR)); + applyToStatusLine(this, status); + } + + /** + * Applies the status to the status line of a dialog page. + * + * @param page the dialog page + * @param status the status + */ + public void applyToStatusLine(DialogPage page, IStatus status) { + String message= status.getMessage(); + switch (status.getSeverity()) { + case IStatus.OK: + page.setMessage(message, IMessageProvider.NONE); + page.setErrorMessage(null); + break; + case IStatus.WARNING: + page.setMessage(message, IMessageProvider.WARNING); + page.setErrorMessage(null); + break; + case IStatus.INFO: + page.setMessage(message, IMessageProvider.INFORMATION); + page.setErrorMessage(null); + break; + default: + if (message.length() == 0) { + message= null; + } + page.setMessage(null); + page.setErrorMessage(message); + break; + } + } + /** * Sets default preference values */ protected static void initializeDefaultPreferences(Preferences prefs) { + //text + prefs.setDefault(TAB_WIDTH, DEFAULT_TAB_WIDTH); + prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, DEFAULT_EDITOR_PRINT_MARGIN_COLUMN); + prefs.setDefault(BLOCK_COMMENT, DEFAULT_BLOCK_COMMENT_STRING); + + //checkboxes prefs.setDefault(SUBSTITUTE_TABS, DEFAULT_SUBSTITUTE_TABS); prefs.setDefault(GUESS_TAB_SUBSTITUTION, DEFAULT_GUESS_TAB_SUBSTITUTION); ! prefs.setDefault(USE_CODE_FOLDING, DEFAULT_USE_CODE_FOLDING); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, StringConverter.asString(DEFAULT_EDITOR_OVERVIEW_RULER)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, StringConverter.asString(DEFAULT_EDITOR_LINE_NUMBER_RULER)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, StringConverter.asString(DEFAULT_EDITOR_CURRENT_LINE)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, StringConverter.asString(DEFAULT_EDITOR_PRINT_MARGIN)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_USE_CUSTOM_CARETS, StringConverter.asString(DEFAULT_EDITOR_USE_CUSTOM_CARETS)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WIDE_CARET, StringConverter.asString(DEFAULT_EDITOR_WIDE_CARET)); ! ! //colors prefs.setDefault(CODE_COLOR,StringConverter.asString(DEFAULT_CODE_COLOR)); prefs.setDefault(KEYWORD_COLOR,StringConverter.asString(DEFAULT_KEYWORD_COLOR)); prefs.setDefault(STRING_COLOR,StringConverter.asString(DEFAULT_STRING_COLOR)); prefs.setDefault(COMMENT_COLOR,StringConverter.asString(DEFAULT_COMMENT_COLOR)); ! prefs.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, StringConverter.asString(DEFAULT_PREFERENCE_COLOR_BACKGROUND)); ! prefs.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, StringConverter.asString(DEFAULT_EDITOR_BACKGROUND_COLOR_SYSTEM_DEFAULT)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, StringConverter.asString(DEFAULT_EDITOR_CURRENT_LINE_COLOR)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, StringConverter.asString(DEFAULT_EDITOR_LINE_NUMBER_RULER_COLOR)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, StringConverter.asString(DEFAULT_EDITOR_PRINT_MARGIN_COLOR)); ! //for selection colors see initializeDefaultColors() ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR, StringConverter.asString(DEFAULT_EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR)); ! prefs.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR, StringConverter.asString(DEFAULT_EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR)); ! ! //no UI prefs.setDefault(CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT); prefs.setDefault(RUN_MANY_SCRIPT_LOCATION, DEFAULT_RUN_MANY_SCRIPT_LOCATION); + prefs.setDefault(HYPERLINK_COLOR, StringConverter.asString(DEFAULT_HYPERLINK_COLOR)); + prefs.setDefault(INTERPRETER_PATH, DEFAULT_INTERPRETER_PATH); } ! ! static public Preferences getPreferences() { ! return PydevPlugin.getDefault().getPluginPreferences(); ! } ! ! public static String[] getInterpreters() { ! String interpreters = getPreferences().getString(PydevPrefs.INTERPRETER_PATH); ! return InterpreterEditor.getInterpreterList(interpreters); ! } ! ! public static String getDefaultInterpreter() { ! try { ! return getInterpreters()[0]; ! } catch (Exception e) { ! return "python"; ! } ! ! } ! } \ No newline at end of file |