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
7 * Contributors: IBM Corporation - initial API and implementation
8 ******************************************************************************/
9 package net.sourceforge.phpeclipse.phpeditor;
11 import net.sourceforge.phpdt.ui.actions.PHPdtActionConstants;
12 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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.swt.SWT;
18 import org.eclipse.ui.IActionBars;
19 import org.eclipse.ui.IEditorInput;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IFileEditorInput;
22 import org.eclipse.ui.texteditor.AbstractTextEditor;
23 import org.eclipse.ui.texteditor.ITextEditor;
25 public class CompilationUnitEditorActionContributor
27 BasicEditorActionContributor {
28 protected ShowExternalPreviewAction fShowExternalPreviewAction;
29 public CompilationUnitEditorActionContributor() {
31 fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance();
35 * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
37 public void setActiveEditor(IEditorPart part) {
38 super.setActiveEditor(part);
40 ITextEditor textEditor = null;
41 if (part instanceof ITextEditor)
42 textEditor = (ITextEditor) part;
45 IActionBars bars = getActionBars();
46 bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(
47 textEditor, "Comment")); //$NON-NLS-1$
48 bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(
49 textEditor, "Uncomment")); //$NON-NLS-1$
50 bars.setGlobalActionHandler(PHPdtActionConstants.TOGGLE_COMMENT,
51 getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
52 bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(
53 textEditor, "Format")); //$NON-NLS-1$
54 bars.setGlobalActionHandler(PHPdtActionConstants.ADD_BLOCK_COMMENT,
55 getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
56 bars.setGlobalActionHandler(PHPdtActionConstants.REMOVE_BLOCK_COMMENT,
57 getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
58 bars.setGlobalActionHandler(PHPdtActionConstants.INDENT, getAction(
59 textEditor, "Indent")); //$NON-NLS-1$ //$NON-NLS-2$
61 if (textEditor != null) {
63 IEditorInput editorInput = textEditor.getEditorInput();
65 if (editorInput instanceof IFileEditorInput) {
66 file = ((IFileEditorInput) editorInput).getFile();
69 PHPeclipsePlugin.getDefault().setLastEditorFile(file);
71 fShowExternalPreviewAction.setEditor(textEditor);
72 fShowExternalPreviewAction.update();
73 IPreferenceStore store = PHPeclipsePlugin.getDefault()
74 .getPreferenceStore();
75 IAction a = ShowExternalPreviewAction.getInstance();