|
From: Christopher W. <caw...@us...> - 2006-04-12 21:26:29
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25379/src/org/rubypeople/rdt/internal/ui/preferences Modified Files: TextEditorPreferencePage2.java PreferencesMessages.java PreferencesMessages.properties Added Files: AbstractConfigurationBlock.java RubyEditorColoringPreferencePage.java ColorSettingPreviewCode.txt IPreferenceConfigurationBlock.java RubyEditorColoringConfigurationBlock.java AbstractConfigurationBlockPreferencePage.java Log Message: a number of changes: - Re-arrange the preferences - add ability to edit ruby editor font - whole new syntax coloring page - new underline/strikethrough options for syntax coloring - fix bug delaying preference changes from applying on syntax coloring to open editors. - Add hyperlink between syntax coloring and general text editor prefs (which apply to coloring/fonts/appearance) - Remove some deprecated code Index: PreferencesMessages.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PreferencesMessages.java 30 Mar 2006 02:56:45 -0000 1.4 --- PreferencesMessages.java 12 Apr 2006 21:26:25 -0000 1.5 *************** *** 75,78 **** --- 75,104 ---- public static String AppearancePreferencePage_stackViewsVerticallyInTheRubyBrowsingPerspective; public static String AppearancePreferencePage_description; + public static String RubyEditorColoringConfigurationBlock_link; + public static String RubyEditorPreferencePage_coloring_element; + public static String RubyEditorPreferencePage_enable; + public static String RubyEditorPreferencePage_color; + public static String RubyEditorPreferencePage_bold; + public static String RubyEditorPreferencePage_italic; + public static String RubyEditorPreferencePage_strikethrough; + public static String RubyEditorPreferencePage_underline; + public static String RubyEditorPreferencePage_preview; + public static String RubyEditorPreferencePage_multiLineComment; + public static String RubyEditorPreferencePage_coloring_category_ruby; + public static String RubyEditorPreferencePage_singleLineComment; + public static String RubyEditorPreferencePage_rubyCommentTaskTags; + public static String RubyEditorPreferencePage_keywords; + public static String RubyEditorPreferencePage_strings; + public static String RubyEditorPreferencePage_characters; + public static String RubyEditorPreferencePage_commands; + public static String RubyEditorPreferencePage_fixnums; + public static String RubyEditorPreferencePage_globals; + public static String RubyEditorPreferencePage_regular_expressions; + public static String RubyEditorPreferencePage_symbols; + public static String RubyEditorPreferencePage_variables; + public static String RubyEditorPreferencePage_others; + public static String RubyEditorPreferencePage_colors; + public static String RubyEditorPreferencePage_empty_input; + public static String RubyEditorPreferencePage_invalid_input; static { Index: PreferencesMessages.properties =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PreferencesMessages.properties 30 Mar 2006 02:56:45 -0000 1.7 --- PreferencesMessages.properties 12 Apr 2006 21:26:25 -0000 1.8 *************** *** 80,81 **** --- 80,110 ---- AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives=This preference will only take effect on new perspectives + RubyEditorPreferencePage_colors=Synta&x + RubyEditorPreferencePage_empty_input=Empty input + RubyEditorPreferencePage_invalid_input=''{0}'' is not a valid input. + RubyEditorPreferencePage_enable= Enab&le + + # coloring + RubyEditorPreferencePage_coloring_category_ruby=Ruby + RubyEditorColoringConfigurationBlock_link= Default colors and font can be configured on the <a href=\"org.eclipse.ui.preferencePages.GeneralTextEditor\">Text Editors</a> and on the <a href=\"org.eclipse.ui.preferencePages.ColorsAndFonts\">Colors and Fonts</a> preference page. + RubyEditorPreferencePage_coloring_element=&Element: + RubyEditorPreferencePage_color= C&olor: + RubyEditorPreferencePage_bold= &Bold + RubyEditorPreferencePage_italic= &Italic + RubyEditorPreferencePage_strikethrough=&Strikethrough + RubyEditorPreferencePage_underline=&Underline + RubyEditorPreferencePage_preview= Previe&w: + + RubyEditorPreferencePage_multiLineComment= Multi-line comment + RubyEditorPreferencePage_singleLineComment= Single-line comment + RubyEditorPreferencePage_rubyCommentTaskTags= Task Tags + RubyEditorPreferencePage_keywords= Keywords + RubyEditorPreferencePage_strings= Strings + RubyEditorPreferencePage_others= Others + RubyEditorPreferencePage_characters= Characters + RubyEditorPreferencePage_commands= Commands + RubyEditorPreferencePage_fixnums= Fixnums + RubyEditorPreferencePage_globals= Globals + RubyEditorPreferencePage_regular_expressions= Regular Expressions + RubyEditorPreferencePage_symbols= Symbols + RubyEditorPreferencePage_variables= Variables \ No newline at end of file --- NEW FILE: ColorSettingPreviewCode.txt --- =begin This is about ClassName. =end class ClassName < SuperClass CLASS_CONSTANT = 123 $global = 'around the world' # This comment may span only this line @@class_variable = "some string" def initialize(value) @field = value end # TASK: refactor def foo(parameter) abstract_method() string = 'Blah blah blah' string.gsub!(/ah/, 'eet') local = 42 * hash_code() static_method() return bar(local) + parameter end end Index: TextEditorPreferencePage2.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/TextEditorPreferencePage2.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** TextEditorPreferencePage2.java 10 Feb 2006 19:52:26 -0000 1.23 --- TextEditorPreferencePage2.java 12 Apr 2006 21:26:25 -0000 1.24 *************** *** 15,19 **** import org.eclipse.core.runtime.IStatus; - import org.eclipse.debug.internal.ui.actions.StatusInfo; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.DialogPage; --- 15,18 ---- *************** *** 45,48 **** --- 44,48 ---- import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.RubyUIMessages; + import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo; import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants; import org.rubypeople.rdt.ui.PreferenceConstants; *************** *** 58,75 **** public class TextEditorPreferencePage2 extends RubyAbstractPreferencePage implements IWorkbenchPreferencePage { - protected TextPropertyWidget[] textPropertyWidgets; protected Text indentationWidget; ! protected final String[] colorProperties = { ! IRubyColorConstants.RUBY_KEYWORD, ! IRubyColorConstants.RUBY_MULTI_LINE_COMMENT, ! IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT, ! IRubyColorConstants.RUBY_STRING, IRubyColorConstants.TASK_TAG, ! IRubyColorConstants.RUBY_REGEXP, IRubyColorConstants.RUBY_COMMAND, ! IRubyColorConstants.RUBY_FIXNUM, ! IRubyColorConstants.RUBY_CHARACTER, ! IRubyColorConstants.RUBY_SYMBOL, ! IRubyColorConstants.RUBY_INSTANCE_VARIABLE, ! IRubyColorConstants.RUBY_GLOBAL, ! IRubyColorConstants.RUBY_DEFAULT }; private ModifyListener fTextFieldListener = new ModifyListener() { --- 58,63 ---- public class TextEditorPreferencePage2 extends RubyAbstractPreferencePage implements IWorkbenchPreferencePage { protected Text indentationWidget; ! private ModifyListener fTextFieldListener = new ModifyListener() { *************** *** 197,204 **** item.setText(RubyUIMessages.getString("RubyEditorPropertyPage.codeFormatterTabTitle")); item.setControl(createCodeFormatterPage(folder)); - - item = new TabItem(folder, SWT.NONE); - item.setText("Syntax"); - item.setControl(createSyntaxPage(folder)); item= new TabItem(folder, SWT.NONE); --- 185,188 ---- *************** *** 211,264 **** } - /** - * @param folder - * @return - */ - private Control createSyntaxPage(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginWidth = 0; - layout.marginHeight = 0; - layout.verticalSpacing = 10; - - composite.setLayout(layout); - - Group colorComposite = new Group(composite, SWT.NONE); - layout = new GridLayout(); - layout.numColumns = 4; - layout.horizontalSpacing = 10; - layout.verticalSpacing = 8; - layout.marginWidth = 10; - layout.marginHeight = 10; - - colorComposite.setLayout(layout); - colorComposite.setText(RubyUIMessages.getString("RubyEditorPropertyPage.highlighting.group")); //$NON-NLS-1$ - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - colorComposite.setLayoutData(data); - - Label header = new Label(colorComposite, SWT.BOLD); - header.setText(RubyUIMessages.getString("RubyEditorPropertyPage.property")); - header = new Label(colorComposite, SWT.BOLD); - header.setText(RubyUIMessages.getString("RubyEditorPropertyPage.color")); - header.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); - header = new Label(colorComposite, SWT.BOLD); - header.setText(RubyUIMessages.getString("RubyEditorPropertyPage.bold")); - header.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); - header = new Label(colorComposite, SWT.BOLD); - header.setText(RubyUIMessages.getString("RubyEditorPropertyPage.italic")); - header.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - - textPropertyWidgets = new TextPropertyWidget[colorProperties.length]; - for (int i = 0; i < colorProperties.length; i++) { - textPropertyWidgets[i] = new TextPropertyWidget(colorComposite, colorProperties[i]); - } - - return composite; - } - private void initialize() { --- 195,198 ---- *************** *** 272,281 **** */ public boolean performOk() { - for (int i = 0; i < textPropertyWidgets.length; i++) { - TextPropertyWidget widget = textPropertyWidgets[i]; - widget.stringColorEditor.store(); - RubyPlugin.getDefault().getPreferenceStore().setValue(widget.property + PreferenceConstants.EDITOR_BOLD_SUFFIX, widget.boldCheckBox.getSelection()); - RubyPlugin.getDefault().getPreferenceStore().setValue(widget.property + PreferenceConstants.EDITOR_ITALIC_SUFFIX, widget.italicCheckBox.getSelection()); - } fFoldingConfigurationBlock.performOk(); fOverlayStore.propagate(); --- 206,209 ---- *************** *** 293,300 **** initializeFields(); - for (int i = 0; i < textPropertyWidgets.length; i++) { - textPropertyWidgets[i].loadDefault(); - } - fFoldingConfigurationBlock.performDefaults(); --- 221,224 ---- *************** *** 401,437 **** } } - - class TextPropertyWidget { - - protected ColorFieldEditor stringColorEditor; - protected Button boldCheckBox; - protected Button italicCheckBox; - protected String property; - - TextPropertyWidget(Composite parent, String property) { - this.property = property; - Label label = new Label(parent, SWT.NORMAL); - label.setText(RubyUIMessages.getString("RubyEditorPropertyPage." + property)); - - Composite dummyComposite = new Composite(parent, SWT.NONE); - // ColorFieldEditor sets its parent composite to 2 columns, - // therefore a dummyComposite is used here - stringColorEditor = new ColorFieldEditor(property, "", dummyComposite); - stringColorEditor.setPreferenceStore(getPreferenceStore()); - stringColorEditor.load(); - - boldCheckBox = new Button(parent, SWT.CHECK); - boldCheckBox.setSelection(getPreferenceStore().getBoolean(property + PreferenceConstants.EDITOR_BOLD_SUFFIX)); - boldCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); - - italicCheckBox = new Button(parent, SWT.CHECK); - italicCheckBox.setSelection(getPreferenceStore().getBoolean(property + PreferenceConstants.EDITOR_ITALIC_SUFFIX)); - italicCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - } - - public void loadDefault() { - stringColorEditor.loadDefault(); - boldCheckBox.setSelection(getPreferenceStore().getBoolean(property + PreferenceConstants.EDITOR_BOLD_SUFFIX)); - } - } } \ No newline at end of file --- 325,327 ---- --- NEW FILE: AbstractConfigurationBlockPreferencePage.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.preferences; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; import org.rubypeople.rdt.internal.ui.RubyPlugin; /** * Abstract preference page which is used to wrap a * {@link org.rubypeople.rdt.internal.ui.preferences.IPreferenceConfigurationBlock}. * * @since 0.9.0 */ public abstract class AbstractConfigurationBlockPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { private IPreferenceConfigurationBlock fConfigurationBlock; private OverlayPreferenceStore fOverlayStore; /** * Creates a new preference page. */ public AbstractConfigurationBlockPreferencePage() { setDescription(); setPreferenceStore(); fOverlayStore= new OverlayPreferenceStore(getPreferenceStore(), new OverlayPreferenceStore.OverlayKey[] {}); fConfigurationBlock= createConfigurationBlock(fOverlayStore); } protected abstract IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore); protected abstract String getHelpId(); protected abstract void setDescription(); protected abstract void setPreferenceStore(); /* * @see IWorkbenchPreferencePage#init() */ public void init(IWorkbench workbench) { } /* * @see PreferencePage#createControl(Composite) */ public void createControl(Composite parent) { super.createControl(parent); PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpId()); } /* * @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite parent) { fOverlayStore.load(); fOverlayStore.start(); Control content= fConfigurationBlock.createControl(parent); initialize(); Dialog.applyDialogFont(content); return content; } private void initialize() { fConfigurationBlock.initialize(); } /* * @see PreferencePage#performOk() */ public boolean performOk() { fConfigurationBlock.performOk(); fOverlayStore.propagate(); RubyPlugin.getDefault().savePluginPreferences(); return true; } /* * @see PreferencePage#performDefaults() */ public void performDefaults() { fOverlayStore.loadDefaults(); fConfigurationBlock.performDefaults(); super.performDefaults(); } /* * @see DialogPage#dispose() */ public void dispose() { fConfigurationBlock.dispose(); if (fOverlayStore != null) { fOverlayStore.stop(); fOverlayStore= null; } super.dispose(); } } --- NEW FILE: AbstractConfigurationBlock.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.preferences; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Assert; 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.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.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.events.ExpansionAdapter; import org.eclipse.ui.forms.events.ExpansionEvent; import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.rubypeople.rdt.internal.corext.util.Messages; import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo; import org.rubypeople.rdt.internal.ui.dialogs.StatusUtil; import org.rubypeople.rdt.internal.ui.util.PixelConverter; /** * Configures Java Editor typing preferences. * * @since 3.1 */ abstract class AbstractConfigurationBlock implements IPreferenceConfigurationBlock { /** * Use as follows: * * <pre> * SectionManager manager= new SectionManager(); * Composite composite= manager.createSectionComposite(parent); * * Composite xSection= manager.createSection("section X")); * xSection.setLayout(new FillLayout()); * new Button(xSection, SWT.PUSH); // add controls to section.. * * [...] * * return composite; // return main composite * </pre> */ protected final class SectionManager { /** The preference setting for keeping no section open. */ private static final String __NONE= "__none"; //$NON-NLS-1$ private Set fSections= new HashSet(); private boolean fIsBeingManaged= false; private ExpansionAdapter fListener= new ExpansionAdapter() { public void expansionStateChanged(ExpansionEvent e) { ExpandableComposite source= (ExpandableComposite) e.getSource(); updateSectionStyle(source); if (fIsBeingManaged) return; if (e.getState()) { try { fIsBeingManaged= true; for (Iterator iter= fSections.iterator(); iter.hasNext();) { ExpandableComposite composite= (ExpandableComposite) iter.next(); if (composite != source) composite.setExpanded(false); } } finally { fIsBeingManaged= false; } if (fLastOpenKey != null && fDialogSettingsStore != null) fDialogSettingsStore.setValue(fLastOpenKey, source.getText()); } else { if (!fIsBeingManaged && fLastOpenKey != null && fDialogSettingsStore != null) fDialogSettingsStore.setValue(fLastOpenKey, __NONE); } ExpandableComposite exComp= getParentExpandableComposite(source); if (exComp != null) exComp.layout(true, true); ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(source); if (parentScrolledComposite != null) { parentScrolledComposite.reflow(true); } } }; private Composite fBody; private final String fLastOpenKey; private final IPreferenceStore fDialogSettingsStore; private ExpandableComposite fFirstChild= null; /** * Creates a new section manager. */ public SectionManager() { this(null, null); } /** * Creates a new section manager. */ public SectionManager(IPreferenceStore dialogSettingsStore, String lastOpenKey) { fDialogSettingsStore= dialogSettingsStore; fLastOpenKey= lastOpenKey; } private void manage(ExpandableComposite section) { if (section == null) throw new NullPointerException(); if (fSections.add(section)) section.addExpansionListener(fListener); makeScrollableCompositeAware(section); } /** * Creates a new composite that can contain a set of expandable * sections. A <code>ScrolledPageComposite</code> is created and a new * composite within that, to ensure that expanding the sections will * always have enough space, unless there already is a * <code>ScrolledComposite</code> along the parent chain of * <code>parent</code>, in which case a normal <code>Composite</code> * is created. * <p> * The receiver keeps a reference to the inner body composite, so that * new sections can be added via <code>createSection</code>. * </p> * * @param parent the parent composite * @return the newly created composite */ public Composite createSectionComposite(Composite parent) { Assert.isTrue(fBody == null); boolean isNested= isNestedInScrolledComposite(parent); Composite composite; if (isNested) { composite= new Composite(parent, SWT.NONE); fBody= composite; } else { composite= new ScrolledPageContent(parent); fBody= ((ScrolledPageContent) composite).getBody(); } fBody.setLayout(new GridLayout()); return composite; } /** * Creates an expandable section within the parent created previously by * calling <code>createSectionComposite</code>. Controls can be added * directly to the returned composite, which has no layout initially. * * @param label the display name of the section * @return a composite within the expandable section */ public Composite createSection(String label) { Assert.isNotNull(fBody); final ExpandableComposite excomposite= new ExpandableComposite(fBody, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT | ExpandableComposite.COMPACT); if (fFirstChild == null) fFirstChild= excomposite; excomposite.setText(label); String last= null; if (fLastOpenKey != null && fDialogSettingsStore != null) last= fDialogSettingsStore.getString(fLastOpenKey); if (fFirstChild == excomposite && !__NONE.equals(last) || label.equals(last)) { excomposite.setExpanded(true); if (fFirstChild != excomposite) fFirstChild.setExpanded(false); } else { excomposite.setExpanded(false); } excomposite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false)); updateSectionStyle(excomposite); manage(excomposite); Composite contents= new Composite(excomposite, SWT.NONE); excomposite.setClient(contents); return contents; } } protected static final int INDENT= 20; private OverlayPreferenceStore fStore; 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; fStore.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; fStore.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); } }; /** * List of master/slave listeners when there's a dependency. * * @see #createDependency(Button, Control) * @since 3.0 */ private ArrayList fMasterSlaveListeners= new ArrayList(); private StatusInfo fStatus; private final PreferencePage fMainPage; public AbstractConfigurationBlock(OverlayPreferenceStore store) { Assert.isNotNull(store); fStore= store; fMainPage= null; } public AbstractConfigurationBlock(OverlayPreferenceStore store, PreferencePage mainPreferencePage) { Assert.isNotNull(store); Assert.isNotNull(mainPreferencePage); fStore= store; fMainPage= mainPreferencePage; } protected final ScrolledPageContent getParentScrolledComposite(Control control) { Control parent= control.getParent(); while (!(parent instanceof ScrolledPageContent) && parent != null) { parent= parent.getParent(); } if (parent instanceof ScrolledPageContent) { return (ScrolledPageContent) parent; } return null; } private final ExpandableComposite getParentExpandableComposite(Control control) { Control parent= control.getParent(); while (!(parent instanceof ExpandableComposite) && parent != null) { parent= parent.getParent(); } if (parent instanceof ExpandableComposite) { return (ExpandableComposite) parent; } return null; } protected void updateSectionStyle(ExpandableComposite excomposite) { excomposite.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); } private void makeScrollableCompositeAware(Control control) { ScrolledPageContent parentScrolledComposite= getParentScrolledComposite(control); if (parentScrolledComposite != null) { parentScrolledComposite.adaptChild(control); } } private boolean isNestedInScrolledComposite(Composite parent) { return getParentScrolledComposite(parent) != null; } protected 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); makeScrollableCompositeAware(checkBox); fCheckBoxes.put(checkBox, key); return checkBox; } /** * Returns an array of size 2: * - first element is of type <code>Label</code> * - second element is of type <code>Text</code> * Use <code>getLabelControl</code> and <code>getTextControl</code> to get the 2 controls. * * @param composite the parent composite * @param label the text field's label * @param key the preference key * @param textLimit the text limit * @param indentation the field's indentation * @param isNumber <code>true</code> iff this text field is used to e4dit a number * @return the controls added */ protected Control[] addLabelledTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) { PixelConverter pixelConverter= new PixelConverter(composite); 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= pixelConverter.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 new Control[]{labelControl, textControl}; } protected void createDependency(final Button master, final Control slave) { createDependency(master, new Control[] {slave}); } protected void createDependency(final Button master, final Control[] slaves) { Assert.isTrue(slaves.length > 0); indent(slaves[0]); SelectionListener listener= new SelectionListener() { public void widgetSelected(SelectionEvent e) { boolean state= master.getSelection(); for (int i= 0; i < slaves.length; i++) { slaves[i].setEnabled(state); } } public void widgetDefaultSelected(SelectionEvent e) {} }; master.addSelectionListener(listener); fMasterSlaveListeners.add(listener); } protected static void indent(Control control) { ((GridData) control.getLayoutData()).horizontalIndent+= INDENT; } public void initialize() { initializeFields(); } private void initializeFields() { Iterator iter= fCheckBoxes.keySet().iterator(); while (iter.hasNext()) { Button b= (Button) iter.next(); String key= (String) fCheckBoxes.get(b); b.setSelection(fStore.getBoolean(key)); } iter= fTextFields.keySet().iterator(); while (iter.hasNext()) { Text t= (Text) iter.next(); String key= (String) fTextFields.get(t); t.setText(fStore.getString(key)); } // Update slaves iter= fMasterSlaveListeners.iterator(); while (iter.hasNext()) { SelectionListener listener= (SelectionListener)iter.next(); listener.widgetSelected(null); } updateStatus(new StatusInfo()); } public void performOk() { } public void performDefaults() { initializeFields(); } IStatus getStatus() { if (fStatus == null) fStatus= new StatusInfo(); return fStatus; } /* * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose() * @since 3.0 */ public void dispose() { } private void numberFieldChanged(Text textControl) { String number= textControl.getText(); IStatus status= validatePositiveNumber(number); if (!status.matches(IStatus.ERROR)) fStore.setValue((String) fTextFields.get(textControl), number); updateStatus(status); } private IStatus validatePositiveNumber(String number) { StatusInfo status= new StatusInfo(); if (number.length() == 0) { status.setError(PreferencesMessages.RubyEditorPreferencePage_empty_input); } else { try { int value= Integer.parseInt(number); if (value < 0) status.setError(Messages.format(PreferencesMessages.RubyEditorPreferencePage_invalid_input, number)); } catch (NumberFormatException e) { status.setError(Messages.format(PreferencesMessages.RubyEditorPreferencePage_invalid_input, number)); } } return status; } protected void updateStatus(IStatus status) { if (fMainPage == null) return; fMainPage.setValid(status.isOK()); StatusUtil.applyToStatusLine(fMainPage, status); } protected final OverlayPreferenceStore getPreferenceStore() { return fStore; } protected Composite createSubsection(Composite parent, SectionManager manager, String label) { if (manager != null) { return manager.createSection(label); } else { Group group= new Group(parent, SWT.SHADOW_NONE); group.setText(label); GridData data= new GridData(SWT.FILL, SWT.CENTER, true, false); group.setLayoutData(data); return group; } } } --- NEW FILE: RubyEditorColoringPreferencePage.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.preferences; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.rubypeople.rdt.internal.ui.RubyPlugin; /** * Quick Diff preference page. * <p> * Note: Must be public since it is referenced from plugin.xml * </p> * * @since 0.9.0 */ public class RubyEditorColoringPreferencePage extends AbstractConfigurationBlockPreferencePage { /* * @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#getHelpId() */ protected String getHelpId() { return null; // TODO Fix when we have IRubyHelpContextIds //return IRubyHelpContextIds.RUBY_EDITOR_PREFERENCE_PAGE; } /* * @see org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setDescription() */ protected void setDescription() { String description= PreferencesMessages.RubyEditorPreferencePage_colors; setDescription(description); } protected Label createDescriptionLabel(Composite parent) { return null; } /* * @see org.org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setPreferenceStore() */ protected void setPreferenceStore() { setPreferenceStore(RubyPlugin.getDefault().getPreferenceStore()); } /* * @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#createConfigurationBlock(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore) */ protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { return new RubyEditorColoringConfigurationBlock(overlayPreferenceStore); } } --- NEW FILE: IPreferenceConfigurationBlock.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.preferences; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; /** * Interface for preference configuration blocks which can either be * wrapped by a {@link org.rubypeople.rdt.internal.ui.preferences.AbstractConfigurationBlockPreferencePage} * or be included some preference page. * <p> * Clients may implement this interface. * </p> * * @since 0.9.0 */ public interface IPreferenceConfigurationBlock { /** * Creates the preference control. * * @param parent the parent composite to which to add the preferences control * @return the control that was added to <code>parent</code> */ Control createControl(Composite parent); /** * Called after creating the control. Implementations should load the * preferences values and update the controls accordingly. */ void initialize(); /** * Called when the <code>OK</code> button is pressed on the preference * page. Implementations should commit the configured preference settings * into their form of preference storage. */ void performOk(); /** * Called when the <code>Defaults</code> button is pressed on the * preference page. Implementation should reset any preference settings to * their default values and adjust the controls accordingly. */ void performDefaults(); /** * Called when the preference page is being disposed. Implementations should * free any resources they are holding on to. */ void dispose(); } --- NEW FILE: RubyEditorColoringConfigurationBlock.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.preferences; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.ColorSelector; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; 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.Link; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Scrollable; import org.eclipse.ui.dialogs.PreferencesUtil; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.rubypeople.rdt.core.RubyCore; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.rubyeditor.RubySourceViewer; import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants; import org.rubypeople.rdt.internal.ui.text.IRubyPartitions; import org.rubypeople.rdt.internal.ui.text.PreferencesAdapter; import org.rubypeople.rdt.internal.ui.text.RubyColorManager; import org.rubypeople.rdt.internal.ui.text.SimpleRubySourceViewerConfiguration; import org.rubypeople.rdt.internal.ui.util.PixelConverter; import org.rubypeople.rdt.ui.PreferenceConstants; import org.rubypeople.rdt.ui.text.IColorManager; /** * Configures Ruby Editor hover preferences. * * @since 0.9.0 */ class RubyEditorColoringConfigurationBlock extends AbstractConfigurationBlock { /** * Item in the highlighting color list. * * @since 0.9.0 */ private static class HighlightingColorListItem { /** Display name */ private String fDisplayName; /** Color preference key */ private String fColorKey; /** Bold preference key */ private String fBoldKey; /** Italic preference key */ private String fItalicKey; /** * Strikethrough preference key. * @since 3.1 */ private String fStrikethroughKey; /** Underline preference key. * @since 3.1 */ private String fUnderlineKey; /** * Initialize the item with the given values. * @param displayName the display name * @param colorKey the color preference key * @param boldKey the bold preference key * @param italicKey the italic preference key * @param strikethroughKey the strikethrough preference key * @param underlineKey the underline preference key */ public HighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { fDisplayName= displayName; fColorKey= colorKey; fBoldKey= boldKey; fItalicKey= italicKey; fStrikethroughKey= strikethroughKey; fUnderlineKey= underlineKey; } /** * @return the bold preference key */ public String getBoldKey() { return fBoldKey; } /** * @return the bold preference key */ public String getItalicKey() { return fItalicKey; } /** * @return the strikethrough preference key * @since 3.1 */ public String getStrikethroughKey() { return fStrikethroughKey; } /** * @return the underline preference key * @since 3.1 */ public String getUnderlineKey() { return fUnderlineKey; } /** * @return the color preference key */ public String getColorKey() { return fColorKey; } /** * @return the display name */ public String getDisplayName() { return fDisplayName; } } private static class SemanticHighlightingColorListItem extends HighlightingColorListItem { /** Enablement preference key */ private final String fEnableKey; /** * Initialize the item with the given values. * @param displayName the display name * @param colorKey the color preference key * @param boldKey the bold preference key * @param italicKey the italic preference key * @param strikethroughKey the strikethroughKey preference key * @param underlineKey the underlineKey preference key * @param enableKey the enable preference key */ public SemanticHighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey, String enableKey) { super(displayName, colorKey, boldKey, italicKey, strikethroughKey, underlineKey); fEnableKey= enableKey; } /** * @return the enablement preference key */ public String getEnableKey() { return fEnableKey; } } /** * Color list label provider. * * @since 3.0 */ private class ColorListLabelProvider extends LabelProvider { /* * @see org.eclipse.jface.viewers.ILabelProvider#getText(ruby.lang.Object) */ public String getText(Object element) { if (element instanceof String) return (String) element; return ((HighlightingColorListItem)element).getDisplayName(); } } /** * Color list content provider. * * @since 3.0 */ private class ColorListContentProvider implements ITreeContentProvider { /* * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(ruby.lang.Object) */ public Object[] getElements(Object inputElement) { return new String[] {fRubyCategory}; } /* * @see org.eclipse.jface.viewers.IContentProvider#dispose() */ public void dispose() { } /* * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, ruby.lang.Object, ruby.lang.Object) */ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getChildren(Object parentElement) { if (parentElement instanceof String) { String entry= (String) parentElement; if (fRubyCategory.equals(entry)) return fListModel.toArray(); } return new Object[0]; } public Object getParent(Object element) { if (element instanceof String) return null; return fRubyCategory; } public boolean hasChildren(Object element) { return element instanceof String; } } private static final String BOLD= PreferenceConstants.EDITOR_BOLD_SUFFIX; /** * Preference key suffix for italic preferences. * @since 0.9.0 */ private static final String ITALIC= PreferenceConstants.EDITOR_ITALIC_SUFFIX; /** * Preference key suffix for strikethrough preferences. * @since 0.9.0 */ private static final String STRIKETHROUGH= PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX; /** * Preference key suffix for underline preferences. * @since 0.9.0 */ private static final String UNDERLINE= PreferenceConstants.EDITOR_UNDERLINE_SUFFIX; private static final String COMPILER_TASK_TAGS= RubyCore.COMPILER_TASK_TAGS; /** * The keys of the overlay store. */ private final String[][] fSyntaxColorListModel= new String[][] { { PreferencesMessages.RubyEditorPreferencePage_multiLineComment, IRubyColorConstants.RUBY_MULTI_LINE_COMMENT }, { PreferencesMessages.RubyEditorPreferencePage_singleLineComment, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT }, { PreferencesMessages.RubyEditorPreferencePage_rubyCommentTaskTags, IRubyColorConstants.TASK_TAG }, { PreferencesMessages.RubyEditorPreferencePage_keywords, IRubyColorConstants.RUBY_KEYWORD }, { PreferencesMessages.RubyEditorPreferencePage_strings, IRubyColorConstants.RUBY_STRING }, { PreferencesMessages.RubyEditorPreferencePage_characters, IRubyColorConstants.RUBY_CHARACTER }, { PreferencesMessages.RubyEditorPreferencePage_commands, IRubyColorConstants.RUBY_COMMAND }, { PreferencesMessages.RubyEditorPreferencePage_fixnums, IRubyColorConstants.RUBY_FIXNUM }, { PreferencesMessages.RubyEditorPreferencePage_globals, IRubyColorConstants.RUBY_GLOBAL }, { PreferencesMessages.RubyEditorPreferencePage_regular_expressions, IRubyColorConstants.RUBY_REGEXP }, { PreferencesMessages.RubyEditorPreferencePage_symbols, IRubyColorConstants.RUBY_SYMBOL }, { PreferencesMessages.RubyEditorPreferencePage_variables, IRubyColorConstants.RUBY_INSTANCE_VARIABLE }, { PreferencesMessages.RubyEditorPreferencePage_others, IRubyColorConstants.RUBY_DEFAULT } }; private final String fRubyCategory= PreferencesMessages.RubyEditorPreferencePage_coloring_category_ruby; private ColorSelector fSyntaxForegroundColorEditor; private Label fColorEditorLabel; private Button fBoldCheckBox; private Button fEnableCheckbox; /** * Check box for italic preference. * @since 3.0 */ private Button fItalicCheckBox; /** * Check box for strikethrough preference. * @since 3.1 */ private Button fStrikethroughCheckBox; /** * Check box for underline preference. * @since 3.1 */ private Button fUnderlineCheckBox; /** * Highlighting color list * @since 3.0 */ private final java.util.List fListModel= new ArrayList(); /** * Highlighting color list viewer * @since 3.0 */ private StructuredViewer fListViewer; /** * The previewer. * @since 3.0 */ private RubySourceViewer fPreviewViewer; /** * The color manager. * @since 3.1 */ private IColorManager fColorManager; /** * The font metrics. * @since 3.1 */ private FontMetrics fFontMetrics; public RubyEditorColoringConfigurationBlock(OverlayPreferenceStore store) { super(store); fColorManager= new RubyColorManager(false); for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) fListModel.add(new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1], fSyntaxColorListModel[i][1] + BOLD, fSyntaxColorListModel[i][1] + ITALIC, fSyntaxColorListModel[i][1] + STRIKETHROUGH, fSyntaxColorListModel[i][1] + UNDERLINE)); store.addKeys(createOverlayStoreKeys()); } private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() { ArrayList overlayKeys= new ArrayList(); for (int i= 0, n= fListModel.size(); i < n; i++) { HighlightingColorListItem item= (HighlightingColorListItem) fListModel.get(i); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, item.getColorKey())); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getBoldKey())); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getItalicKey())); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getStrikethroughKey())); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, item.getUnderlineKey())); if (item instanceof SemanticHighlightingColorListItem) overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ((SemanticHighlightingColorListItem) item).getEnableKey())); } OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; overlayKeys.toArray(keys); return keys; } /** * Creates page for hover preferences. * * @param parent the parent composite * @return the control for the preference page */ public Control createControl(Composite parent) { initializeDialogUnits(parent); return createSyntaxPage(parent); } /** * Returns the number of pixels corresponding to the width of the given * number of characters. * <p> * This method may only be called after <code>initializeDialogUnits</code> * has been called. * </p> * <p> * Clients may call this framework method, but should not override it. * </p> * * @param chars * the number of characters * @return the number of pixels */ private int convertWidthInCharsToPixels(int chars) { // test for failure to initialize for backward compatibility if (fFontMetrics == null) return 0; return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); } /** * Returns the number of pixels corresponding to the height of the given * number of characters. * <p> * This method may only be called after <code>initializeDialogUnits</code> * has been called. * </p> * <p> * Clients may call this framework method, but should not override it. * </p> * * @param chars * the number of characters * @return the number of pixels */ private int convertHeightInCharsToPixels(int chars) { // test for failure to initialize for backward compatibility if (fFontMetrics == null) return 0; return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars); } public void initialize() { super.initialize(); fListViewer.setInput(fListModel); fListViewer.setSelection(new StructuredSelection(fRubyCategory)); } public void performDefaults() { super.performDefaults(); handleSyntaxColorListSelection(); fPreviewViewer.invalidateTextPresentation(); } /* * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose() */ public void dispose() { fColorManager.dispose(); super.dispose(); } private void handleSyntaxColorListSelection() { HighlightingColorListItem item= getHighlightingColorListItem(); if (item == null) { fEnableCheckbox.setEnabled(false); fSyntaxForegroundColorEditor.getButton().setEnabled(false); fColorEditorLabel.setEnabled(false); fBoldCheckBox.setEnabled(false); fItalicCheckBox.setEnabled(false); fStrikethroughCheckBox.setEnabled(false); fUnderlineCheckBox.setEnabled(false); return; } RGB rgb= PreferenceConverter.getColor(getPreferenceStore(), item.getColorKey()); fSyntaxForegroundColorEditor.setColorValue(rgb); fBoldCheckBox.setSelection(getPreferenceStore().getBoolean(item.getBoldKey())); fItalicCheckBox.setSelection(getPreferenceStore().getBoolean(item.getItalicKey())); fStrikethroughCheckBox.setSelection(getPreferenceStore().getBoolean(item.getStrikethroughKey())); fUnderlineCheckBox.setSelection(getPreferenceStore().getBoolean(item.getUnderlineKey())); if (item instanceof SemanticHighlightingColorListItem) { fEnableCheckbox.setEnabled(true); boolean enable= getPreferenceStore().getBoolean(((SemanticHighlightingColorListItem) item).getEnableKey()); fEnableCheckbox.setSelection(enable); fSyntaxForegroundColorEditor.getButton().setEnabled(enable); fColorEditorLabel.setEnabled(enable); fBoldCheckBox.setEnabled(enable); fItalicCheckBox.setEnabled(enable); fStrikethroughCheckBox.setEnabled(enable); fUnderlineCheckBox.setEnabled(enable); } else { fSyntaxForegroundColorEditor.getButton().setEnabled(true); fColorEditorLabel.setEnabled(true); fBoldCheckBox.setEnabled(true); fItalicCheckBox.setEnabled(true); fStrikethroughCheckBox.setEnabled(true); fUnderlineCheckBox.setEnabled(true); fEnableCheckbox.setEnabled(false); fEnableCheckbox.setSelection(true); } } private Control createSyntaxPage(final Composite parent) { Composite colorComposite= new Composite(parent, SWT.NONE); GridLayout layout= new GridLayout(); layout.marginHeight= 0; layout.marginWidth= 0; colorComposite.setLayout(layout); Link link= new Link(colorComposite, SWT.NONE); link.setText(PreferencesMessages.RubyEditorColoringConfigurationBlock_link); link.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); } }); // TODO replace by link-specific tooltips when // bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed // link.setToolTipText(PreferencesMessages.RubyEditorColoringConfigurationBlock_link_tooltip); GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint= 150; // only expand further if anyone else requires it gridData.horizontalSpan= 2; link.setLayoutData(gridData); addFiller(colorComposite, 1); Label label; label= new Label(colorComposite, SWT.LEFT); label.setText(PreferencesMessages.RubyEditorPreferencePage_coloring_element); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite editorComposite= new Composite(colorComposite, SWT.NONE); layout= new GridLayout(); layout.numColumns= 2; layout.marginHeight= 0; layout.marginWidth= 0; editorComposite.setLayout(layout); GridData gd= new GridData(SWT.FILL, SWT.BEGINNING, true, false); editorComposite.setLayoutData(gd); fListViewer= new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER); fListViewer.setLabelProvider(new ColorListLabelProvider()); fListViewer.setContentProvider(new ColorListContentProvider()); fListViewer.setSorter(new ViewerSorter() { public int category(Object element) { // don't sort the top level categories if (fRubyCategory.equals(element)) return 0; // to sort semantic settings after partition based ones: // if (element instanceof SemanticHighlightingColorListItem) // return 1; return 0; } }); gd= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true); gd.heightHint= convertHeightInCharsToPixels(9); int maxWidth= 0; for (Iterator it= fListModel.iterator(); it.hasNext();) { HighlightingColorListItem item= (HighlightingColorListItem) it.next(); maxWidth= Math.max(maxWidth, convertWidthInCharsToPixels(item.getDisplayName().length())); } ScrollBar vBar= ((Scrollable) fListViewer.getControl()).getVerticalBar(); if (vBar != null) maxWidth += vBar.getSize().x * 3; // scrollbars and tree indentation guess gd.widthHint= maxWidth; fListViewer.getControl().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)); fEnableCheckbox= new Button(stylesComposite, SWT.CHECK); fEnableCheckbox.setText(PreferencesMessages.RubyEditorPreferencePage_enable); gd= new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment= GridData.BEGINNING; gd.horizontalSpan= 2; fEnableCheckbox.setLayoutData(gd); fColorEditorLabel= new Label(stylesComposite, SWT.LEFT); fColorEditorLabel.setText(PreferencesMessages.RubyEditorPreferencePage_color); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= 20; fColorEditorLabel.setLayoutData(gd); fSyntaxForegroundColorEditor= new ColorSelector(stylesComposite); Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton(); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); foregroundColorButton.setLayoutData(gd); fBoldCheckBox= new Button(stylesComposite, SWT.CHECK); fBoldCheckBox.setText(PreferencesMessages.RubyEditorPreferencePage_bold); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= 20; gd.horizontalSpan= 2; fBoldCheckBox.setLayoutData(gd); fItalicCheckBox= new Button(stylesComposite, SWT.CHECK); fItalicCheckBox.setText(PreferencesMessages.RubyEditorPreferencePage_italic); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= 20; gd.horizontalSpan= 2; fItalicCheckBox.setLayoutData(gd); fStrikethroughCheckBox= new Button(stylesComposite, SWT.CHECK); fStrikethroughCheckBox.setText(PreferencesMessages.RubyEditorPreferencePage_strikethrough); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= 20; gd.horizontalSpan= 2; fStrikethroughCheckBox.setLayoutData(gd); fUnderlineCheckBox= new Button(stylesComposite, SWT.CHECK); fUnderlineCheckBox.setText(PreferencesMessages.RubyEditorPreferencePage_underline); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= 20; gd.horizontalSpan= 2; fUnderlineCheckBox.setLayoutData(gd); label= new Label(colorComposite, SWT.LEFT); label.setText(PreferencesMessages.RubyEditorPreferencePage_preview); label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Control previewer= createPreviewer(colorComposite); gd= new GridData(GridData.FILL_BOTH); gd.widthHint= convertWidthInCharsToPixels(20); gd.heightHint= convertHeightInCharsToPixels(5); previewer.setLayoutData(gd); fListViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { handleSyntaxColorListSelection(); } }); foregroundColorButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); PreferenceConverter.setValue(getPreferenceStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue()); } }); fBoldCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); getPreferenceStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection()); } }); fItalicCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); getPreferenceStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection()); } }); fStrikethroughCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); getPreferenceStore().setValue(item.getStrikethroughKey(), fStrikethroughCheckBox.getSelection()); } }); fUnderlineCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); getPreferenceStore().setValue(item.getUnderlineKey(), fUnderlineCheckBox.getSelection()); } }); fEnableCheckbox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { HighlightingColorListItem item= getHighlightingColorListItem(); if (item instanceof SemanticHighlightingColorListItem) { boolean enable= fEnableCheckbox.getSelection(); getPreferenceStore().setValue(((SemanticHighlightingColorListItem) item).getEnableKey(), enable); ... [truncated message content] |