#1365431 (toshihiro) - PHP Editor crashes Windows with JavaScript 'windows.close()'
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / TogglePresentationAction.java
index 1a59a91..71b3da6 100644 (file)
@@ -10,7 +10,6 @@
  *******************************************************************************/
 package net.sourceforge.phpeclipse.phpeditor;
 
-
 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.actions.PHPEditorActionDefinitionIds;
@@ -23,102 +22,109 @@ import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.ui.texteditor.ITextEditor;
 import org.eclipse.ui.texteditor.TextEditorAction;
 
-
 /**
- * A toolbar action which toggles the presentation model of the
- * connected text editor. The editor shows either the highlight range
- * only or always the whole document.
+ * A toolbar action which toggles the presentation model of the connected text
+ * editor. The editor shows either the highlight range only or always the whole
+ * document.
  */
-public class TogglePresentationAction extends TextEditorAction implements IPropertyChangeListener {
-               
+public class TogglePresentationAction extends TextEditorAction implements
+               IPropertyChangeListener {
+
        private IPreferenceStore fStore;
 
        /**
         * Constructs and updates the action.
         */
        public TogglePresentationAction() {
-               super(PHPEditorMessages.getResourceBundle(), "TogglePresentation.", null); //$NON-NLS-1$
+               super(PHPEditorMessages.getResourceBundle(),
+                               "TogglePresentation.", null); //$NON-NLS-1$
                PHPUiImages.setToolImageDescriptors(this, "segment_edit.gif"); //$NON-NLS-1$
-               setToolTipText(PHPEditorMessages.getString("TogglePresentation.tooltip")); //$NON-NLS-1$
+               setToolTipText(PHPEditorMessages
+                               .getString("TogglePresentation.tooltip")); //$NON-NLS-1$
                setActionDefinitionId(PHPEditorActionDefinitionIds.TOGGLE_PRESENTATION);
-//             WorkbenchHelp.setHelp(this,     IJavaHelpContextIds.TOGGLE_PRESENTATION_ACTION);                
+               // WorkbenchHelp.setHelp(this,
+               // IJavaHelpContextIds.TOGGLE_PRESENTATION_ACTION);
                update();
        }
-       
+
        /*
         * @see IAction#actionPerformed
         */
        public void run() {
-               
-               ITextEditor editor= getTextEditor();
+
+               ITextEditor editor = getTextEditor();
                if (editor == null)
                        return;
-               
-               IRegion remembered= editor.getHighlightRange();
+
+               IRegion remembered = editor.getHighlightRange();
                editor.resetHighlightRange();
-               
-               boolean showAll= !editor.showsHighlightRangeOnly();
+
+               boolean showAll = !editor.showsHighlightRangeOnly();
                setChecked(showAll);
-               
+
                editor.showHighlightRangeOnly(showAll);
                if (remembered != null)
-                       editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);
-               
+                       editor.setHighlightRange(remembered.getOffset(), remembered
+                                       .getLength(), true);
+
                fStore.removePropertyChangeListener(this);
                fStore.setValue(PreferenceConstants.EDITOR_SHOW_SEGMENTS, showAll);
                fStore.addPropertyChangeListener(this);
        }
-       
+
        /*
         * @see TextEditorAction#update
         */
        public void update() {
-               ITextEditor editor= getTextEditor();
-               boolean checked= (editor != null && editor.showsHighlightRangeOnly());
+               ITextEditor editor = getTextEditor();
+               boolean checked = (editor != null && editor.showsHighlightRangeOnly());
                setChecked(checked);
                setEnabled(editor != null);
        }
-       
+
        /*
         * @see TextEditorAction#setEditor(ITextEditor)
         */
        public void setEditor(ITextEditor editor) {
-               
+
                super.setEditor(editor);
-               
+
                if (editor != null) {
-                       
+
                        if (fStore == null) {
-                               fStore= PHPeclipsePlugin.getDefault().getPreferenceStore();
+                               fStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
                                fStore.addPropertyChangeListener(this);
                        }
                        synchronizeWithPreference(editor);
-                       
+
                } else if (fStore != null) {
                        fStore.removePropertyChangeListener(this);
-                       fStore= null;
+                       fStore = null;
                }
-               
+
                update();
        }
-       
+
        /**
-        * Synchronizes the appearance of the editor with what the preference store tells him.
+        * Synchronizes the appearance of the editor with what the preference store
+        * tells him.
         */
        private void synchronizeWithPreference(ITextEditor editor) {
-               
+
                if (editor == null)
                        return;
-               
-               boolean showSegments= fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);                      
+
+               boolean showSegments = fStore
+                               .getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);
                setChecked(showSegments);
-               
+
                if (editor.showsHighlightRangeOnly() != showSegments) {
-                       IRegion remembered= editor.getHighlightRange();
+                       IRegion remembered = editor.getHighlightRange();
                        editor.resetHighlightRange();
                        editor.showHighlightRangeOnly(showSegments);
                        if (remembered != null)
-                               editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);
+                               editor.setHighlightRange(remembered.getOffset(), remembered
+                                               .getLength(), true);
                }
        }
 
@@ -126,7 +132,8 @@ public class TogglePresentationAction extends TextEditorAction implements IPrope
         * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
-               if (event.getProperty().equals(PreferenceConstants.EDITOR_SHOW_SEGMENTS))
+               if (event.getProperty()
+                               .equals(PreferenceConstants.EDITOR_SHOW_SEGMENTS))
                        synchronizeWithPreference(getTextEditor());
        }
 }