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
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.phpeditor;
10 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
11 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
12 import net.sourceforge.phpeclipse.ui.editor.ShowExternalPreviewAction;
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;
21 public class CompilationUnitEditorActionContributor extends
22 BasicEditorActionContributor {
23 public CompilationUnitEditorActionContributor() {
28 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
30 public void setActiveEditor(IEditorPart part) {
31 super.setActiveEditor(part);
33 ITextEditor textEditor = null;
34 if (part instanceof ITextEditor)
35 textEditor = (ITextEditor) part;
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$
54 if (textEditor != null) {
56 IEditorInput editorInput = textEditor.getEditorInput();
58 if (editorInput instanceof IFileEditorInput) {
59 file = ((IFileEditorInput) editorInput).getFile();
62 PHPeclipsePlugin.getDefault().setLastEditorFile(file);
64 ShowExternalPreviewAction fShowExternalPreviewAction = ShowExternalPreviewAction
66 fShowExternalPreviewAction.setEditor(textEditor);
67 fShowExternalPreviewAction.update();
68 if (fShowExternalPreviewAction != null) {
69 fShowExternalPreviewAction
70 .doRun(ShowExternalPreviewAction.PHP_TYPE);