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