misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
index acf9d5a..43295c7 100644 (file)
@@ -24,20 +24,19 @@ import net.sourceforge.phpdt.core.IJavaElement;
 import net.sourceforge.phpdt.core.IMember;
 import net.sourceforge.phpdt.core.ISourceRange;
 import net.sourceforge.phpdt.core.ISourceReference;
-import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
+import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
 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.JavaUI;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
-import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
 import net.sourceforge.phpdt.ui.text.JavaTextTools;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
 
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IResource;
@@ -64,7 +63,6 @@ import org.eclipse.jface.text.IInformationControlCreator;
 import org.eclipse.jface.text.IRegion;
 import org.eclipse.jface.text.ITextHover;
 import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextOperationTarget;
 import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.ITextViewerExtension2;
@@ -127,13 +125,11 @@ import org.eclipse.ui.actions.ActionGroup;
 import org.eclipse.ui.editors.text.DefaultEncodingSupport;
 import org.eclipse.ui.editors.text.IEncodingSupport;
 import org.eclipse.ui.part.IShowInTargetList;
-import org.eclipse.ui.texteditor.ContentAssistAction;
 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
 import org.eclipse.ui.texteditor.ExtendedTextEditor;
 import org.eclipse.ui.texteditor.IDocumentProvider;
 import org.eclipse.ui.texteditor.IEditorStatusLine;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
-import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 import org.eclipse.ui.texteditor.MarkerAnnotation;
 import org.eclipse.ui.texteditor.ResourceAction;
 import org.eclipse.ui.texteditor.TextEditorAction;
@@ -1132,6 +1128,12 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
   protected JavaOutlinePage fOutlinePage;
   /** Outliner context menu Id */
   protected String fOutlinerContextMenuId;
+       /**
+        * The editor selection changed listener.
+        * 
+        * @since 3.0
+        */
+//  private EditorSelectionChangedListener fEditorSelectionChangedListener;
   /** Indicates whether this editor should react on outline page selection changes */
   private int fIgnoreOutlinePageSelection;
   
@@ -1155,8 +1157,6 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
   private MouseClickListener fMouseListener;
 
   protected CompositeActionGroup fActionGroups;
-  /** The standard action groups added to the menu */
-  protected GenerateActionGroup fGenerateActionGroup;
   protected CompositeActionGroup fContextMenuGroup;
 
   /** The information presenter. */
@@ -1193,32 +1193,20 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
    */
   public PHPEditor() {
     super();
-    JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
-    setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this));
-    setRangeIndicator(new DefaultRangeIndicator());
-    setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
-
-    // don't activate this scope without synchronizing plugin.xml !!!
-    //    setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" }); //$NON-NLS-1$
-
-        if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
-          fUpdater= new OutlinePageSelectionUpdater();
+       JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
+       setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); //, IJavaPartitions.JAVA_PARTITIONING));
+       setRangeIndicator(new DefaultRangeIndicator());
+       IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
+       setPreferenceStore(store);
+       setKeyBindingScopes(new String[] { "net.sourceforge.phpdt.ui.phpEditorScope" });  //$NON-NLS-1$
+//     fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
+//     fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
+    
+       // TODO changed in 3.x ?
+    if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
+      fUpdater= new OutlinePageSelectionUpdater();
   }
-  //
-  //   /**
-  //    * @see IMember#getCompilationUnit()
-  //    */
-  //   public ICompilationUnit getCompilationUnit() {
-  //           return this; 
-  //   }
-  //   /**
-  //    * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
-  //    */
-  //   public char[] getContents() {
-  //           IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
-  //   
-  //           return doc.get().toCharArray();
-  //   }
   /*
    * @see org.eclipse.ui.texteditor.AbstractTextEditor#updatePropertyDependentActions()
    */
@@ -1334,60 +1322,74 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
    */
   protected void createActions() {
     super.createActions();
+    
+       ResourceAction resAction= new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
+       resAction= new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
+       resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
+       setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
+//     WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
+       
+       Action action= new GotoMatchingBracketAction(this);
+       action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);                               
+       setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
+               
+//     action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"ShowOutline.", this, JavaSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE);
+//     setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE, action);
+////   WorkbenchHelp.setHelp(action, IJavaHelpContextIds.SHOW_OUTLINE_ACTION);
+//
+//     action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenStructure.", this, JavaSourceViewer.OPEN_STRUCTURE, true); //$NON-NLS-1$
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE);
+//     setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_STRUCTURE, action);
+////   WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_STRUCTURE_ACTION);
+//     
+//     action= new TextOperationAction(PHPEditorMessages.getResourceBundle(),"OpenHierarchy.", this, JavaSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY);
+//     setAction(PHPEditorActionDefinitionIds.SHOW_OUTLINE.OPEN_HIERARCHY, action);
+////   WorkbenchHelp.setHelp(action, IJavaHelpContextIds.OPEN_HIERARCHY_ACTION);
+       
+       fEncodingSupport= new DefaultEncodingSupport();
+       fEncodingSupport.initialize(this);
+       
+//     fSelectionHistory= new SelectionHistory(this);
+//
+//     action= new StructureSelectEnclosingAction(this, fSelectionHistory);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_ENCLOSING);                            
+//     setAction(StructureSelectionAction.ENCLOSING, action);
+//
+//     action= new StructureSelectNextAction(this, fSelectionHistory);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_NEXT);
+//     setAction(StructureSelectionAction.NEXT, action);
+//
+//     action= new StructureSelectPreviousAction(this, fSelectionHistory);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_PREVIOUS);
+//     setAction(StructureSelectionAction.PREVIOUS, action);
+//
+//     StructureSelectHistoryAction historyAction= new StructureSelectHistoryAction(this, fSelectionHistory);
+//     historyAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SELECT_LAST);          
+//     setAction(StructureSelectionAction.HISTORY, historyAction);
+//     fSelectionHistory.setHistoryAction(historyAction);
+//                     
+//     action= GoToNextPreviousMemberAction.newGoToNextMemberAction(this);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_NEXT_MEMBER);                            
+//     setAction(GoToNextPreviousMemberAction.NEXT_MEMBER, action);
+//
+//     action= GoToNextPreviousMemberAction.newGoToPreviousMemberAction(this);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);                                
+//     setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
+//     
+//     action= new QuickFormatAction();
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.QUICK_FORMAT);
+//     setAction(IJavaEditorActionDefinitionIds.QUICK_FORMAT, action);
+//
+//     action= new RemoveOccurrenceAnnotations(this);
+//     action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_OCCURRENCE_ANNOTATIONS);
+//     setAction("RemoveOccurrenceAnnotations", action); //$NON-NLS-1$
 
-    ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
-    resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
-    resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC);
-    setAction("ShowJavaDoc", resAction); //$NON-NLS-1$
-    //                                         WorkbenchHelp.setHelp(resAction, IJavaHelpContextIds.SHOW_JAVADOC_ACTION);
-
-    Action action;
-
-    setAction(
-      "ContentAssistTip",
-      new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
-
-    action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
-    action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-    setAction("ContentAssistProposal", action); //$NON-NLS-1$
-    markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
-    // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION);
-
-    fEncodingSupport = new DefaultEncodingSupport();
-    fEncodingSupport.initialize(this);
-
-    action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
-    action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
-    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); //$NON-NLS-1$
-    action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
-    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("Format", true); //$NON-NLS-1$
-    markAsSelectionDependentAction("Format", true); //$NON-NLS-1$              
-    // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
-
-    action = new GotoMatchingBracketAction(this);
-    action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
-    setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
-
-    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)});
-
+       // add annotation actions
+       action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
+       setAction("AnnotationAction", action); //$NON-NLS-1$
+    
        // add annotation actions
        action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$
        setAction("AnnotationAction", action); //$NON-NLS-1$
@@ -1622,10 +1624,6 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
       fOutlinePage.addSelectionChangedListener(fSelectionChangedListener);
     }
   }
-  protected void updateStateDependentActions() {
-    super.updateStateDependentActions();
-    fGenerateActionGroup.editorStateChanged();
-  }
 
   protected void setSelection(ISourceReference reference, boolean moveCursor) {
 
@@ -1943,6 +1941,44 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
         return;
       }
 
+//      if (PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE.equals(property)) {
+//             if ((event.getNewValue() instanceof Boolean) && ((Boolean)event.getNewValue()).booleanValue())
+//                     fEditorSelectionChangedListener.selectionChanged();
+//             return;
+//     }
+       
+       if (PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE.equals(property)) {
+               if (event.getNewValue() instanceof Boolean) {
+                       Boolean disable= (Boolean) event.getNewValue();
+                       configureInsertMode(OVERWRITE, !disable.booleanValue());
+               }
+       }
+       
+//     if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) {
+//             if (event.getNewValue() instanceof Boolean) {
+//                     boolean markOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue();
+//                     if (markOccurrenceAnnotations != fMarkOccurrenceAnnotations) {
+//                             fMarkOccurrenceAnnotations= markOccurrenceAnnotations;
+//                             if (!fMarkOccurrenceAnnotations)
+//                                     uninstallOccurrencesFinder();
+//                             else
+//                                     installOccurrencesFinder();
+//                     }
+//             }
+//     }
+//     if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) {
+//             if (event.getNewValue() instanceof Boolean) {
+//                     boolean stickyOccurrenceAnnotations= ((Boolean)event.getNewValue()).booleanValue();
+//                     if (stickyOccurrenceAnnotations != fStickyOccurrenceAnnotations) {
+//                             fStickyOccurrenceAnnotations= stickyOccurrenceAnnotations;
+////                           if (!fMarkOccurrenceAnnotations)
+////                                   uninstallOccurrencesFinder();
+////                           else
+////                                   installOccurrencesFinder();
+//                     }
+//             }
+//     }
+       
     } finally {
       super.handlePreferenceStoreChanged(event);
     }
@@ -2393,7 +2429,7 @@ public abstract class PHPEditor  extends ExtendedTextEditor implements IViewPart
 
     List segmentation = new ArrayList();
     for (int i = 0; i < linePartitioning.length; i++) {
-      if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType()))
+      if (IPHPPartitions.PHP_STRING.equals(linePartitioning[i].getType()))
         segmentation.add(linePartitioning[i]);
     }