*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
index 71f26dc..f5f9edf 100644 (file)
@@ -11,15 +11,16 @@ Contributors:
     IBM Corporation - Initial implementation
     Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
+import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
+import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
 import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.help.IHelp;
-import org.eclipse.help.IHelpResource;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.MenuManager;
@@ -28,7 +29,6 @@ import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextOperationTarget;
-import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.text.source.AnnotationRulerColumn;
 import org.eclipse.jface.text.source.CompositeRuler;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -40,8 +40,9 @@ import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionGroup;
 import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.help.WorkbenchHelp;
 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.ui.texteditor.TextOperationAction;
@@ -51,7 +52,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
  */
 public class PHPEditor extends TextEditor {
 
-  protected PHPActionGroup actionGroup;
+  // protected PHPActionGroup fActionGroups;
   /** The outline page */
   private PHPContentOutlinePage fOutlinePage;
   private IPreferenceStore phpPrefStore;
@@ -59,13 +60,25 @@ public class PHPEditor extends TextEditor {
   /** The line number ruler column */
   private LineNumberRulerColumn fLineNumberRulerColumn;
 
+  protected CompositeActionGroup fActionGroups;
+  /** The standard action groups added to the menu */
+  private GenerateActionGroup fGenerateActionGroup;
+  private CompositeActionGroup fContextMenuGroup;
   /**
    * Default constructor.
    */
   public PHPEditor() {
     super();
+    setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
   }
 
+  /**
+   *  Returns the standard action group of this editor.
+   */
+  protected ActionGroup getActionGroup() {
+    return fActionGroups;
+  } 
+  
   public PHPContentOutlinePage getfOutlinePage() {
     return fOutlinePage;
   }
@@ -99,20 +112,37 @@ public class PHPEditor extends TextEditor {
     action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
     setAction("Uncomment", action);
 
-    actionGroup = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
+  //  fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
 
     markAsStateDependentAction("Comment", true); //$NON-NLS-1$
     markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
+
+    fGenerateActionGroup= new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
+
+    fActionGroups= new CompositeActionGroup(
+      new ActionGroup[] { fGenerateActionGroup }
+      );
+  
+    
+    // We have to keep the context menu group separate to have better control over positioning
+    fContextMenuGroup= new CompositeActionGroup(new ActionGroup[] {
+      fGenerateActionGroup });
+//      rg, 
+//      new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method performs any extra 
-   * disposal actions required by the java editor.
+   * disposal actions required by the php editor.
    */
   public void dispose() {
     PHPEditorEnvironment.disconnect(this);
     if (fOutlinePage != null)
       fOutlinePage.setInput(null);
+      
+    if (fActionGroups != null)
+      fActionGroups.dispose();  
+      
     super.dispose();
   }
 
@@ -163,18 +193,29 @@ public class PHPEditor extends TextEditor {
       fOutlinePage.setInput(input);
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method adds any 
-   * JavaEditor specific entries.
+   * PHPEditor specific entries.
    */
   public void editorContextMenuAboutToShow(MenuManager menu) {
     super.editorContextMenuAboutToShow(menu);
     //  addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
     //  addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
-    actionGroup.fillContextMenu(menu);
+    
+    // fActionGroups.fillContextMenu(menu);
+    
+    ActionContext context= new ActionContext(getSelectionProvider().getSelection());
+    fContextMenuGroup.setContext(context);
+    fContextMenuGroup.fillContextMenu(menu);
+    fContextMenuGroup.setContext(null);
   }
 
-  /** The <code>JavaEditor</code> implementation of this 
+  protected void updateStateDependentActions() {
+    super.updateStateDependentActions();
+    fGenerateActionGroup.editorStateChanged();
+  }
+  
+  /** The <code>PHPEditor</code> implementation of this 
    * <code>AbstractTextEditor</code> method performs gets
    * the java content outline page if request is for a an 
    * outline page.
@@ -191,27 +232,27 @@ public class PHPEditor extends TextEditor {
     return super.getAdapter(required);
   }
 
-//  public void openContextHelp() {
-//    IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
-//    ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
-//    int pos = selection.getOffset();
-//    String word = getFunctionName(doc, pos);
-//    openContextHelp(word);
-//  }
-//
-//  private void openContextHelp(String word) {
-//    open(word);
-//  }
-//
-//  public static void open(String word) {
-//    IHelp help = WorkbenchHelp.getHelpSupport();
-//    if (help != null) {
-//      IHelpResource helpResource = new PHPFunctionHelpResource(word);
-//      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
-//    } else {
-//      //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
-//    }
-//  }
+  //  public void openContextHelp() {
+  //    IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
+  //    ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
+  //    int pos = selection.getOffset();
+  //    String word = getFunctionName(doc, pos);
+  //    openContextHelp(word);
+  //  }
+  //
+  //  private void openContextHelp(String word) {
+  //    open(word);
+  //  }
+  //
+  //  public static void open(String word) {
+  //    IHelp help = WorkbenchHelp.getHelpSupport();
+  //    if (help != null) {
+  //      IHelpResource helpResource = new PHPFunctionHelpResource(word);
+  //      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+  //    } else {
+  //      //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+  //    }
+  //  }
 
   private String getFunctionName(IDocument doc, int pos) {
     Point word = PHPWordExtractor.findWord(doc, pos);
@@ -294,7 +335,10 @@ public class PHPEditor extends TextEditor {
     IVerticalRuler v = getVerticalRuler();
     if (v instanceof CompositeRuler) {
       CompositeRuler c = (CompositeRuler) v;
-      c.removeDecorator(1);
+      try {
+        c.removeDecorator(1);
+      } catch (Throwable e) {
+      }
     }
   }