Goto line/Goto Matching Bracket Shortcuts should work
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / CompilationUnitEditorActionContributor.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  * 
7  * Contributors: IBM Corporation - initial API and implementation
8  ******************************************************************************/
9 package net.sourceforge.phpeclipse.phpeditor;
10
11 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
12 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.ui.IActionBars;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IFileEditorInput;
21 import org.eclipse.ui.texteditor.ITextEditor;
22
23 public class CompilationUnitEditorActionContributor
24                 extends
25                         BasicEditorActionContributor {
26         protected ShowExternalPreviewAction fShowExternalPreviewAction;
27         public CompilationUnitEditorActionContributor() {
28                 super();
29                 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
30         }
31
32         /*
33          * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
34          */
35         public void setActiveEditor(IEditorPart part) {
36                 super.setActiveEditor(part);
37
38                 ITextEditor textEditor = null;
39                 if (part instanceof ITextEditor)
40                         textEditor = (ITextEditor) part;
41
42                 // Source menu.
43                 IActionBars bars = getActionBars();
44                 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(
45                                 textEditor, "Comment")); //$NON-NLS-1$
46                 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(
47                                 textEditor, "Uncomment")); //$NON-NLS-1$
48                 bars.setGlobalActionHandler(PHPdtActionConstants.TOGGLE_COMMENT,
49                                 getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
50                 bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(
51                                 textEditor, "Format")); //$NON-NLS-1$
52 //              bars.setGlobalActionHandler(PHPdtActionConstants.ADD_BLOCK_COMMENT,
53 //                              getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
54 //              bars.setGlobalActionHandler(PHPdtActionConstants.REMOVE_BLOCK_COMMENT,
55 //                              getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
56 //              bars.setGlobalActionHandler(PHPdtActionConstants.INDENT, getAction(
57 //                              textEditor, "Indent")); //$NON-NLS-1$ //$NON-NLS-2$
58
59                 if (textEditor != null) {
60                         IFile file = null;
61                         IEditorInput editorInput = textEditor.getEditorInput();
62
63                         if (editorInput instanceof IFileEditorInput) {
64                                 file = ((IFileEditorInput) editorInput).getFile();
65                         }
66
67                         PHPeclipsePlugin.getDefault().setLastEditorFile(file);
68
69                         fShowExternalPreviewAction.setEditor(textEditor);
70                         fShowExternalPreviewAction.update();
71                         IPreferenceStore store = PHPeclipsePlugin.getDefault()
72                                         .getPreferenceStore();
73                         IAction a = ShowExternalPreviewAction.getInstance();
74                         if (a != null)
75                                 a.run();
76                 }
77         }
78 }