Added a souce context menu to the editor; moved "Goto Matching Bracket" to "Navigate...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
index e1e0261..712a200 100644 (file)
@@ -18,6 +18,7 @@ import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
+import net.sourceforge.phpdt.ui.IContextMenuConstants;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
@@ -30,8 +31,10 @@ import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.text.BadLocationException;
@@ -94,7 +97,7 @@ public class PHPEditor
 
   // protected PHPActionGroup fActionGroups;
   /** The outline page */
-  private PHPContentOutlinePage fOutlinePage;
+  private AbstractContentOutlinePage fOutlinePage;
 
   //  protected PHPSyntaxParserThread fValidationThread = null;
 
@@ -107,8 +110,8 @@ public class PHPEditor
 
   protected CompositeActionGroup fActionGroups;
   /** The standard action groups added to the menu */
-  private GenerateActionGroup fGenerateActionGroup;
-  private CompositeActionGroup fContextMenuGroup;
+  protected GenerateActionGroup fGenerateActionGroup;
+  protected CompositeActionGroup fContextMenuGroup;
 
   /** The information presenter. */
   private InformationPresenter fInformationPresenter;
@@ -149,32 +152,42 @@ public class PHPEditor
    * Update the hovering behavior depending on the preferences.
    */
   private void updateHoverBehavior() {
-    SourceViewerConfiguration configuration= getSourceViewerConfiguration();
-    String[] types= configuration.getConfiguredContentTypes(getSourceViewer());
+    SourceViewerConfiguration configuration = getSourceViewerConfiguration();
+    String[] types = configuration.getConfiguredContentTypes(getSourceViewer());
 
-    for (int i= 0; i < types.length; i++) {
-                       
-      String t= types[i];
-                               
-      int[] stateMasks= configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
+    for (int i = 0; i < types.length; i++) {
 
-      ISourceViewer sourceViewer= getSourceViewer();
+      String t = types[i];
+
+      int[] stateMasks =
+        configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t);
+
+      ISourceViewer sourceViewer = getSourceViewer();
       if (sourceViewer instanceof ITextViewerExtension2) {
         if (stateMasks != null) {
-          for (int j= 0; j < stateMasks.length; j++)   {
-            int stateMask= stateMasks[j];
-            ITextHover textHover= configuration.getTextHover(sourceViewer, t, stateMask);
-            ((ITextViewerExtension2)sourceViewer).setTextHover(textHover, t, stateMask);
+          for (int j = 0; j < stateMasks.length; j++) {
+            int stateMask = stateMasks[j];
+            ITextHover textHover =
+              configuration.getTextHover(sourceViewer, t, stateMask);
+            ((ITextViewerExtension2) sourceViewer).setTextHover(
+              textHover,
+              t,
+              stateMask);
           }
         } else {
-          ITextHover textHover= configuration.getTextHover(sourceViewer, t);
-          ((ITextViewerExtension2)sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
+          ITextHover textHover = configuration.getTextHover(sourceViewer, t);
+          ((ITextViewerExtension2) sourceViewer).setTextHover(
+            textHover,
+            t,
+            ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
         }
       } else
-        sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t);
+        sourceViewer.setTextHover(
+          configuration.getTextHover(sourceViewer, t),
+          t);
     }
   }
-  
+
   /*
    * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
    */
@@ -225,7 +238,7 @@ public class PHPEditor
     return fActionGroups;
   }
 
-  public PHPContentOutlinePage getfOutlinePage() {
+  public AbstractContentOutlinePage getfOutlinePage() {
     return fOutlinePage;
   }
 
@@ -237,17 +250,6 @@ public class PHPEditor
     super.createActions();
 
     Action action;
-    //    setAction(
-    //      "ContentAssistProposal",
-    //      new TextOperationAction(
-    //        PHPEditorMessages.getResourceBundle(),
-    //        "ContentAssistProposal.",
-    //        this,
-    //        ISourceViewer.CONTENTASSIST_PROPOSALS));
-    action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
-    action.setActionDefinitionId(
-      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-    setAction("ContentAssistProposal", action); //$NON-NLS-1$
 
     setAction(
       "ContentAssistTip",
@@ -257,32 +259,31 @@ public class PHPEditor
         this,
         ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
 
-    action =
-      new TextOperationAction(
-        PHPEditorMessages.getResourceBundle(),
-        "Comment.",
-        this,
-        ITextOperationTarget.PREFIX);
+    action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
+    action.setActionDefinitionId(
+      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+    setAction("ContentAssistProposal", action); //$NON-NLS-1$
+    markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
+    // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
+
+    action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
     action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
-    setAction("Comment", action);
+    setAction("Comment", action); //$NON-NLS-1$
+    markAsStateDependentAction("Comment", true); //$NON-NLS-1$
+    //         WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION);
 
-    action =
-      new TextOperationAction(
-        PHPEditorMessages.getResourceBundle(),
-        "Uncomment.",
-        this,
-        ITextOperationTarget.STRIP_PREFIX);
+    action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
     action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
-    setAction("Uncomment", action);
+    setAction("Uncomment", action); //$NON-NLS-1$
+    markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
+    //         WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION);
 
     action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
     action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
     setAction("Format", action); //$NON-NLS-1$
-
-    markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
-    markAsStateDependentAction("Comment", true); //$NON-NLS-1$
-    markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
     markAsStateDependentAction("Format", true); //$NON-NLS-1$
+    markAsSelectionDependentAction("Format", true); //$NON-NLS-1$              
+    // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
 
     action = new GotoMatchingBracketAction(this);
     action.setActionDefinitionId(
@@ -317,7 +318,7 @@ public class PHPEditor
    * disposal actions required by the php editor.
    */
   public void dispose() {
- //   PHPEditorEnvironment.disconnect(this);
+    //   PHPEditorEnvironment.disconnect(this);
     if (fOutlinePage != null)
       fOutlinePage.setInput(null);
 
@@ -350,6 +351,11 @@ public class PHPEditor
       if (a != null)
         a.run();
     }
+    //    if (SWT.getPlatform().equals("win32")) {
+    //      IAction a = ShowExternalPreviewAction.getInstance();
+    //      if (a != null)
+    //        a.run();
+    //    }
     if (fOutlinePage != null)
       fOutlinePage.update();
   }
@@ -387,14 +393,20 @@ public class PHPEditor
    */
   public void editorContextMenuAboutToShow(MenuManager menu) {
     super.editorContextMenuAboutToShow(menu);
-
-    addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
-
-    ActionContext context =
-      new ActionContext(getSelectionProvider().getSelection());
-    fContextMenuGroup.setContext(context);
-    fContextMenuGroup.fillContextMenu(menu);
-    fContextMenuGroup.setContext(null);
+               menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, new Separator(IContextMenuConstants.GROUP_OPEN));     
+               menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));  
+               
+               ActionContext context= new ActionContext(getSelectionProvider().getSelection());
+               fContextMenuGroup.setContext(context);
+               fContextMenuGroup.fillContextMenu(menu);
+               fContextMenuGroup.setContext(null);
+//    addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
+//
+//    ActionContext context =
+//      new ActionContext(getSelectionProvider().getSelection());
+//    fContextMenuGroup.setContext(context);
+//    fContextMenuGroup.fillContextMenu(menu);
+//    fContextMenuGroup.setContext(null);
   }
 
   protected void updateStateDependentActions() {
@@ -654,7 +666,7 @@ public class PHPEditor
    */
   protected void initializeEditor() {
     IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
- //   PHPEditorEnvironment.connect(this);
+    //   PHPEditorEnvironment.connect(this);
 
     //    store.addPropertyChangeListener(new IPropertyChangeListener() {
     //      public void propertyChange(PropertyChangeEvent event) {
@@ -904,12 +916,12 @@ public class PHPEditor
     int styles) {
     return super.createSourceViewer(parent, ruler, styles);
   }
-  
+
   /*
    * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent)
    */
   protected boolean affectsTextPresentation(PropertyChangeEvent event) {
-    JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+    JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
     return textTools.affectsBehavior(event);
   }
 }