Adding new code for feature save on unfocus. This is from ticket #542. It also adds...
authorEdward Mann <phpeclipse.dev@edmann.com>
Tue, 22 Jan 2008 16:41:28 +0000 (16:41 +0000)
committerEdward Mann <phpeclipse.dev@edmann.com>
Tue, 22 Jan 2008 16:41:28 +0000 (16:41 +0000)
net.sourceforge.phpeclipse/plugin.properties
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorConfigurationBlock.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorPreferencePage.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PreferencesMessages.properties
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java

index 4d7c321..6e8cb8c 100644 (file)
@@ -40,6 +40,7 @@ todoTaskPrefName= Task Tags
 templatePageName= Templates
 spellingPrefName= Spelling
 codeAssistPageName= Code Assist
+editorPageName= Editor
 editorMarkOccurrencesPage= Mark Occurrences
 
 #
index 1a3aee8..a433151 100644 (file)
                        class="net.sourceforge.phpdt.internal.ui.preferences.CodeAssistPreferencePage"
                        id="net.sourceforge.phpdt.internal.ui.preferences.CodeAssistPreferencePage">
          </page>
-                       <page
+      <page name="%editorPageName"
+            category="net.sourceforge.phpeclipse.preferences.PHPPreferencePage"
+            class="net.sourceforge.phpdt.internal.ui.preferences.EditorPreferencePage"
+            id="net.sourceforge.phpdt.internal.ui.preferences.EditorPreferencePage">
+      </page>
+      <page
                        name="%templatePageName"
                        category="net.sourceforge.phpeclipse.preferences.PHPPreferencePage"
                        class="net.sourceforge.phpdt.internal.ui.preferences.JavaTemplatePreferencePage"
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorConfigurationBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorConfigurationBlock.java
new file mode 100644 (file)
index 0000000..53482fd
--- /dev/null
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 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
+ *******************************************************************************/
+
+package net.sourceforge.phpdt.internal.ui.preferences;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sourceforge.phpdt.core.IJavaProject;
+import net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener;
+import net.sourceforge.phpdt.ui.PreferenceConstants;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+
+/**
+ * Options configuration block for editor related settings.
+ * 
+ * @since 3.0
+ */
+public class EditorConfigurationBlock extends OptionsConfigurationBlock {
+
+       /** Preference keys for the preferences in this block */
+       private static final String PREF_EDITOR_SAVE_ON_BLUR = PreferenceConstants.EDITOR_SAVE_ON_BLUR;
+
+       private static final String PREF_EDITOR_P_RTRIM_ON_SAVE = PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE;
+       
+       /**
+        * Creates a new editor configuration block.
+        * 
+        * @param context
+        *            The status change listener
+        * @param project
+        *            The Java project
+        */
+       public EditorConfigurationBlock(final IStatusChangeListener context,
+                       final IJavaProject project) {
+               super(context, project, getAllKeys());
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
+        */
+       protected Control createContents(final Composite parent) {
+
+               Composite composite = new Composite(parent, SWT.NONE);
+               GridLayout layout = new GridLayout();
+               layout.numColumns = 1;
+               composite.setLayout(layout);
+
+               final String[] trueFalse = new String[] { IPreferenceStore.TRUE,
+                               IPreferenceStore.FALSE };
+
+               Group user = new Group(composite, SWT.NONE);
+               user.setText(PreferencesMessages
+                               .getString("EditorPreferencePage.file.title")); //$NON-NLS-1$
+               user.setLayout(new GridLayout());
+               user.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+               String label = PreferencesMessages
+                               .getString("EditorPreferencePage.save_on_blur"); //$NON-NLS-1$
+               addCheckBox(user, label, PREF_EDITOR_SAVE_ON_BLUR, trueFalse, 0);
+
+               label = PreferencesMessages
+                               .getString("EditorPreferencePage.p_rtrim_on_save"); //$NON-NLS-1$
+               addCheckBox(user, label, PREF_EDITOR_P_RTRIM_ON_SAVE, trueFalse, 0);
+
+               return composite;
+       }
+
+       private static String[] getAllKeys() {
+               return new String[] { PREF_EDITOR_SAVE_ON_BLUR,
+                               PREF_EDITOR_P_RTRIM_ON_SAVE };
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getDefaultOptions()
+        */
+       protected Map getDefaultOptions() {
+
+               final String[] keys = fAllKeys;
+               final Map options = new HashMap();
+               final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
+
+               for (int index = 0; index < keys.length; index++)
+                       options.put(keys[index], store.getDefaultString(keys[index]));
+
+               return options;
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
+        */
+       protected final String[] getFullBuildDialogStrings(final boolean workspace) {
+               return null;
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getOptions(boolean)
+        */
+       protected Map getOptions(final boolean inherit) {
+
+               final String[] keys = fAllKeys;
+               final Map options = new HashMap();
+               final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
+
+               for (int index = 0; index < keys.length; index++)
+                       options.put(keys[index], store.getString(keys[index]));
+
+               return options;
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#setOptions(java.util.Map)
+        */
+       protected void setOptions(final Map options) {
+
+               final String[] keys = fAllKeys;
+               final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
+
+               for (int index = 0; index < keys.length; index++)
+                       store.setValue(keys[index], (String) fWorkingValues
+                                       .get(keys[index]));
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String,java.lang.String)
+        */
+       protected void validateSettings(final String key, final String value) {
+       }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorPreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditorPreferencePage.java
new file mode 100644 (file)
index 0000000..c93b9cc
--- /dev/null
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package net.sourceforge.phpdt.internal.ui.preferences;
+
+import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
+import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
+import net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.runtime.IStatus;
+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;
+
+/**
+ * Preference page for spell checking preferences.
+ * 
+ * @since 3.0
+ */
+public class EditorPreferencePage extends PreferencePage implements
+               IWorkbenchPreferencePage, IStatusChangeListener {
+
+       /** The spelling configuration block */
+       private final EditorConfigurationBlock fBlock = new EditorConfigurationBlock(
+                       this, null);
+
+       /**
+        * Creates a new spelling preference page.
+        */
+       public EditorPreferencePage() {
+
+               setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
+               setDescription(PreferencesMessages
+                               .getString("EditorPreferencePage.description")); //$NON-NLS-1$
+               setTitle(PreferencesMessages.getString("EditorPreferencePage.title")); //$NON-NLS-1$
+       }
+
+       /*
+        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+        */
+       protected Control createContents(final Composite parent) {
+
+               final Control control = fBlock.createContents(parent);
+               Dialog.applyDialogFont(control);
+
+               return control;
+       }
+
+       /*
+        * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+        */
+       public void createControl(final Composite parent) {
+               super.createControl(parent);
+               PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
+                               IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE);
+       }
+
+       /*
+        * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+        */
+       public void init(final IWorkbench workbench) {
+               // Do nothing
+       }
+
+       /*
+        * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+        */
+       protected void performDefaults() {
+               fBlock.performDefaults();
+
+               super.performDefaults();
+       }
+
+       /*
+        * @see org.eclipse.jface.preference.IPreferencePage#performOk()
+        */
+       public boolean performOk() {
+
+               if (!fBlock.performOk(true))
+                       return false;
+
+               return super.performOk();
+       }
+
+       /*
+        * @see net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
+        */
+       public void statusChanged(final IStatus status) {
+               setValid(!status.matches(IStatus.ERROR));
+
+               StatusUtil.applyToStatusLine(this, status);
+       }
+}
index c088d4e..e1700c5 100644 (file)
@@ -665,9 +665,6 @@ public class JavaEditorPreferencePage extends PreferencePage implements
                overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
                                OverlayPreferenceStore.BOOLEAN,
                                PreferenceConstants.EDITOR_FORMAT_JAVADOCS));
-               overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
-                               OverlayPreferenceStore.BOOLEAN,
-                               PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE));
 
                overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
                                OverlayPreferenceStore.BOOLEAN,
@@ -1435,9 +1432,6 @@ public class JavaEditorPreferencePage extends PreferencePage implements
                button = addCheckBox(group, label,
                                PreferenceConstants.EDITOR_FORMAT_JAVADOCS, 1);
 
-               label = PreferencesMessages
-                               .getString("JavaEditorPreferencePage.p_rtrim_on_save");
-               addCheckBox(group, label, PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE, 1);
                //
                // label = PreferencesMessages
                // .getString("JavaEditorPreferencePage.addJavaDocTags");
index 0756df8..4884b64 100644 (file)
@@ -189,7 +189,6 @@ JavaEditorPreferencePage.wrapStringsSQ= Wra&p single quoted PHP strings
 JavaEditorPreferencePage.escapeStringsSQ= &Escape text when pasting into a single quoted PHP string
 JavaEditorPreferencePage.addJavaDocTags= Add PHPdoc &tags
 JavaEditorPreferencePage.smartPaste= Pasting fo&r correct indentation
-JavaEditorPreferencePage.p_rtrim_on_save= Remove trailing spaces on editor save
 
 JavaEditorPreferencePage.smartHomeEnd= S&mart cursor positioning at line start and end
 JavaEditorPreferencePage.subWordNavigation= Smart cursor positioning in &PHP names
@@ -691,6 +690,12 @@ SpellingPreferencePage.preferences.user=&Comments
 SpellingPreferencePage.preferences.engine=&Language
 SpellingPreferencePage.preferences.advanced=&Advanced
 
+EditorPreferencePage.description=General Editor Preferences:
+EditorPreferencePage.title=Editor
+EditorPreferencePage.file.title=File Saving
+EditorPreferencePage.save_on_blur=&Save files when focus is lost
+EditorPreferencePage.p_rtrim_on_save=&Remove trailing spaces on save
+
 
 JavaEditorPreferencePage.AnnotationDecoration.NONE=None
 JavaEditorPreferencePage.AnnotationDecoration.SQUIGGLIES=Squiggles
index 16ea7d9..d3414ec 100644 (file)
@@ -1904,6 +1904,16 @@ public class PreferenceConstants {
        public static final String EDITOR_DISABLE_OVERWRITE_MODE = "disable_overwrite_mode"; //$NON-NLS-1$
 
        /**
+        * A named preference that controls saving of a file on loss of editor focus.
+        * <p>
+        * Value is of type <code>Boolean</code>.
+        * </p>
+        * 
+        * @since 3.0
+        */
+       public static final String EDITOR_SAVE_ON_BLUR = "save_on_blur"; //$NON-NLS-1$
+
+       /**
         * A named preference that controls the "smart semicolon" smart typing
         * handler
         * <p>
index 4eb14da..a3605cb 100644 (file)
@@ -61,7 +61,9 @@ import net.sourceforge.phpdt.ui.text.JavaTextTools;
 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingStructureProvider;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
+import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil;
 import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
 
 import org.eclipse.core.resources.IMarker;
@@ -2370,7 +2372,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
                        }
 
                }
-
+               
                /**
                 * Finds the next position after the given position.
                 * 
@@ -3198,7 +3200,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
         * Default constructor.
         */
        public PHPEditor() {
-               super();
+               super();                
        }
 
        /*
@@ -3226,7 +3228,7 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
                setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools
                                .getColorManager(), store, this,
                                IPHPPartitions.PHP_PARTITIONING));
-
+               
                // TODO changed in 3.x ?
                // setRangeIndicator(new DefaultRangeIndicator());
                // if
@@ -3373,7 +3375,6 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
                Preferences preferences = PHPeclipsePlugin.getDefault()
                                .getPluginPreferences();
                preferences.addPropertyChangeListener(fPropertyChangeListener);
-
                IInformationControlCreator informationControlCreator = new IInformationControlCreator() {
                        public IInformationControl createInformationControl(Shell parent) {
                                boolean cutDown = false;
@@ -3402,7 +3403,32 @@ public abstract class PHPEditor extends AbstractDecoratedTextEditor implements
                        installOccurrencesFinder();
 
                PlatformUI.getWorkbench().addWindowListener(fActivationListener);
-
+               
+               /*
+                * start of EDITOR_SAVE_ON_BLUR
+                * ed_mann
+                */
+               final PHPEditor editor = this;
+               FocusListener focusListener = new FocusListener() {
+                       
+                     public void focusGained(FocusEvent e) {
+                         return;
+                       }
+
+                       public void focusLost(FocusEvent e) {
+                               //viewer.get
+                               if(editor.isDirty() && PHPeclipsePlugin.getDefault().getPreferenceStore()
+                                                       .getBoolean(PreferenceConstants.EDITOR_SAVE_ON_BLUR)){
+                                       editor.doSave(null);
+                               }
+                       }
+                     };
+                 projectionViewer.getTextWidget().addFocusListener(focusListener);
+                       /*
+                        * end of EDITOR_SAVE_ON_BLUR
+                        * ed_mann
+                        */
+                 
                setWordWrap();
        }