8e3bc43200f3ed6c9376dbb39fadae9cac99019d
[phpeclipse.git] /
1 package net.sourceforge.phpeclipse.phpeditor;
2 /*******************************************************************************
3  * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This
4  * program and the accompanying materials are made available under the terms of
5  * the Common Public License v1.0 which accompanies this distribution, and is
6  * available at http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors: IBM Corporation - Initial implementation Klaus Hartlage -
9  * www.eclipseproject.de
10  ******************************************************************************/
11 import java.util.ArrayList;
12 import java.util.Iterator;
13 import java.util.List;
14 import java.util.ResourceBundle;
15
16 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
17 import net.sourceforge.phpdt.ui.IContextMenuConstants;
18 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20
21 import org.eclipse.core.resources.IFile;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IStatusLineManager;
25 import org.eclipse.jface.action.IToolBarManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.ui.IActionBars;
28 import org.eclipse.ui.IEditorInput;
29 import org.eclipse.ui.IEditorPart;
30 import org.eclipse.ui.IFileEditorInput;
31 import org.eclipse.ui.IWorkbenchActionConstants;
32 import org.eclipse.ui.IWorkbenchPage;
33 import org.eclipse.ui.actions.RetargetAction;
34 import org.eclipse.ui.editors.text.EncodingActionGroup;
35 import org.eclipse.ui.ide.IDEActionFactory;
36 import org.eclipse.ui.texteditor.AbstractTextEditor;
37 import org.eclipse.ui.texteditor.ITextEditor;
38 import org.eclipse.ui.texteditor.RetargetTextEditorAction;
39 /**
40  * Contributes interesting PHP actions to the desktop's Edit menu and the
41  * toolbar.
42  */
43 public class PHPActionContributor_DeleteIt extends BasicJavaEditorActionContributor {
44 //  protected RetargetTextEditorAction fContentAssistTip;
45   // protected TextEditorAction fTogglePresentation;
46   protected RetargetAction fRetargetContentAssist;
47   protected RetargetTextEditorAction fContentAssist;
48   protected RetargetTextEditorAction fContextInformation;
49   private RetargetTextEditorAction fGotoMatchingBracket;
50   private List fRetargetToolbarActions = new ArrayList();
51 //  private List fPartListeners = new ArrayList();
52   protected PHPParserAction fParserAction;
53   protected ShowExternalPreviewAction fShowExternalPreviewAction;
54   private EncodingActionGroup fEncodingActionGroup;
55   /**
56    * Default constructor.
57    */
58   public PHPActionContributor_DeleteIt() {
59     super();
60     ResourceBundle b = PHPEditorMessages.getResourceBundle();
61     
62 //    fRetargetContentAssist = new RetargetAction(
63 //        PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages
64 //            .getString("ContentAssistProposal.label")); //$NON-NLS-1$
65 //    fRetargetContentAssist
66 //        .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
67 //    markAsPartListener(fRetargetContentAssist);
68 //    
69 //    fContentAssist = new RetargetTextEditorAction(b, "ContentAssistProposal."); //$NON-NLS-1$
70 //    fContentAssist
71 //        .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
72     
73     fRetargetContentAssist= new RetargetAction(PHPdtActionConstants.CONTENT_ASSIST, PHPEditorMessages.getString("ContentAssistProposal.label")); //$NON-NLS-1$
74         fRetargetContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
75         markAsPartListener(fRetargetContentAssist);
76         
77         fContentAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
78         fContentAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); 
79         fContentAssist.setImageDescriptor(PHPUiImages.DESC_CLCL_CODE_ASSIST);
80         fContentAssist.setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_CODE_ASSIST);
81         
82         fContextInformation= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistContextInformation."); //$NON-NLS-1$
83         fContextInformation.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
84         
85 //      fCorrectionAssist= new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "CorrectionAssistProposal."); //$NON-NLS-1$
86 //      fCorrectionAssist.setActionDefinitionId(PHPEditorActionDefinitionIds.CORRECTION_ASSIST_PROPOSALS);
87         
88         // character encoding
89         fEncodingActionGroup= new EncodingActionGroup();
90
91     fParserAction = PHPParserAction.getInstance();
92     fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
93   }
94   
95   /*
96    * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
97    */
98   //  public void contributeToMenu(IMenuManager menu) {
99   //    super.contributeToMenu(menu);
100   //    IMenuManager editMenu=
101   // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
102   //    if (editMenu != null) {
103   //      MenuManager structureSelection= new
104   // MenuManager(JavaEditorMessages.getString("ExpandSelectionMenu.label"));
105   // //$NON-NLS-1$
106   //      structureSelection.add(fStructureSelectEnclosingAction);
107   //      structureSelection.add(fStructureSelectNextAction);
108   //      structureSelection.add(fStructureSelectPreviousAction);
109   //      structureSelection.add(fStructureSelectHistoryAction);
110   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
111   // structureSelection);
112   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
113   // fGotoPreviousMemberAction);
114   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
115   // fGotoNextMemberAction);
116   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_OPEN,
117   // fGotoMatchingBracket);
118   //      editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
119   // fShowOutline);
120   //    }
121   //  }
122   /*
123    * @see EditorActionBarContributor#contributeToMenu(IMenuManager)
124    */
125   //  public void contributeToMenu(IMenuManager menu) {
126   //            
127   //      super.contributeToMenu(menu);
128   //            
129   //      IMenuManager editMenu=
130   // menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
131   //      if (editMenu != null) {
132   //              editMenu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
133   //              editMenu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
134   //                    
135   //              editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE,
136   // fRetargetContentAssist);
137   //      }
138   //  }
139   /*
140    * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
141    */
142   public void contributeToMenu(IMenuManager menu) {
143     super.contributeToMenu(menu);
144         
145         IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
146         if (editMenu != null) {
147                 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fRetargetContentAssist);
148 //              editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fCorrectionAssist);                        
149                 editMenu.appendToGroup(IContextMenuConstants.GROUP_GENERATE, fContextInformation);
150         }       
151   }
152 //  /*
153 //   * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager)
154 //   */
155 //  public void contributeToToolBar(IToolBarManager tbm) {
156 //    tbm.add(new Separator());
157 //    Iterator e = fRetargetToolbarActions.iterator();
158 //    while (e.hasNext())
159 //      tbm.add((IAction) e.next());
160 //  }
161   /*
162    * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
163    */
164 //  public void init(IActionBars bars, IWorkbenchPage page) {
165 //    Iterator e = fPartListeners.iterator();
166 //    while (e.hasNext())
167 //      page.addPartListener((RetargetAction) e.next());
168 //    // character encoding
169 //    fEncodingActionGroup.fillActionBars(bars);
170 //    super.init(bars, page);
171 //  }
172
173         /*
174          * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage)
175          */
176         public void init(IActionBars bars, IWorkbenchPage page) {
177                 super.init(bars, page);
178                 
179                 // register actions that have a dynamic editor. 
180                 bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST, fContentAssist);
181                 // character encoding
182                 fEncodingActionGroup.fillActionBars(bars);
183         }       
184   //  /*
185 //   * @see IEditorActionBarContributor#init(IActionBars)
186 //   */
187 //  public void init(IActionBars bars) {
188 //    super.init(bars);
189 //    IMenuManager menuManager = bars.getMenuManager();
190 //    IMenuManager editMenu = menuManager
191 //        .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
192 //    if (editMenu != null) {
193 //      editMenu.add(new Separator());
194 //      editMenu.add(fContentAssist);
195 //      // editMenu.add(fGotoMatchingBracket);
196 //      //   editMenu.add(fContentAssistTip);
197 //    }
198 //    bars.setGlobalActionHandler(PHPdtActionConstants.CONTENT_ASSIST,
199 //        fContentAssist);
200 //    //    IToolBarManager toolBarManager = bars.getToolBarManager();
201 //    //    if (toolBarManager != null) {
202 //    //      toolBarManager.add(new Separator());
203 //    //      toolBarManager.add(fTogglePresentation);
204 //    //    }
205 //  }
206   
207
208   /*
209    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
210    */
211   public void setActiveEditor(IEditorPart part) {
212     super.setActiveEditor(part);
213     IActionBars bars = getActionBars();
214     IStatusLineManager manager = bars.getStatusLineManager();
215     manager.setMessage(null);
216     manager.setErrorMessage(null);
217     
218     ITextEditor textEditor = null;    
219     if (part instanceof ITextEditor)
220       textEditor = (ITextEditor) part;
221         
222         fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
223         fContextInformation.setAction(getAction(textEditor, "ContentAssistContextInformation")); //$NON-NLS-1$
224 //      fCorrectionAssist.setAction(getAction(textEditor, "CorrectionAssistProposal")); //$NON-NLS-1$
225         
226         IActionBars actionBars= getActionBars();
227         actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_RIGHT, getAction(textEditor, "ShiftRight")); //$NON-NLS-1$
228         actionBars.setGlobalActionHandler(PHPdtActionConstants.SHIFT_LEFT, getAction(textEditor, "ShiftLeft")); //$NON-NLS-1$
229
230         actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId())); //$NON-NLS-1$
231         actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId())); //$NON-NLS-1$
232         
233         // character encoding
234         fEncodingActionGroup.retarget(textEditor);
235     
236     if (textEditor != null) {
237       IFile file = null;
238       IEditorInput editorInput = textEditor.getEditorInput();
239       if (editorInput instanceof IFileEditorInput) {
240         file = ((IFileEditorInput) editorInput).getFile();
241       }
242       PHPeclipsePlugin.getDefault().setLastEditorFile(file);
243       fParserAction.setEditor(textEditor);
244       fParserAction.update();
245       if (textEditor instanceof AbstractTextEditor) {
246         fShowExternalPreviewAction.setEditor(textEditor);
247         fShowExternalPreviewAction.update();
248         IAction a = ShowExternalPreviewAction.getInstance();
249         if (a != null)
250           a.run();
251       }
252     }
253   }
254   
255 }