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