misc changes
[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. 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.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 extends BasicEditorActionContributor {
24   public CompilationUnitEditorActionContributor() {
25     super();
26   }
27
28   /*
29    * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
30    */
31   public void setActiveEditor(IEditorPart part) {
32     super.setActiveEditor(part);
33
34     ITextEditor textEditor = null;
35     if (part instanceof ITextEditor)
36       textEditor = (ITextEditor) part;
37
38     // Source menu.
39     IActionBars bars = getActionBars();
40     bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment")); //$NON-NLS-1$
41     bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); //$NON-NLS-1$
42     bars.setGlobalActionHandler(PHPdtActionConstants.TOGGLE_COMMENT, getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
43     bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format")); //$NON-NLS-1$
44     //          bars.setGlobalActionHandler(PHPdtActionConstants.ADD_BLOCK_COMMENT,
45     //                          getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
46     //          bars.setGlobalActionHandler(PHPdtActionConstants.REMOVE_BLOCK_COMMENT,
47     //                          getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
48     //          bars.setGlobalActionHandler(PHPdtActionConstants.INDENT, getAction(
49     //                          textEditor, "Indent")); //$NON-NLS-1$ //$NON-NLS-2$
50
51     if (textEditor != null) {
52       IFile file = null;
53       IEditorInput editorInput = textEditor.getEditorInput();
54
55       if (editorInput instanceof IFileEditorInput) {
56         file = ((IFileEditorInput) editorInput).getFile();
57       }
58
59       PHPeclipsePlugin.getDefault().setLastEditorFile(file);
60
61       ShowExternalPreviewAction fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
62       fShowExternalPreviewAction.setEditor(textEditor);
63       fShowExternalPreviewAction.update();
64       if (fShowExternalPreviewAction != null)
65         fShowExternalPreviewAction.doRun(ShowExternalPreviewAction.PHP_TYPE);
66     }
67   }
68 }