Initial version from the webtools project; sligthly modified for phpeclipse
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / org / eclipse / webbrowser / internal / WebBrowserEditorActionBarContributor.java
diff --git a/net.sourceforge.phpeclipse.webbrowser/src/org/eclipse/webbrowser/internal/WebBrowserEditorActionBarContributor.java b/net.sourceforge.phpeclipse.webbrowser/src/org/eclipse/webbrowser/internal/WebBrowserEditorActionBarContributor.java
new file mode 100644 (file)
index 0000000..fd36893
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved.   This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *    IBM - Initial API and implementation
+ */
+package org.eclipse.webbrowser.internal;
+
+import org.eclipse.ui.*;
+import org.eclipse.ui.actions.ActionFactory;
+/**
+ * ActionBarContributor for the Web browser.
+ * Just adds cut, copy, paste actions.
+ */
+public class WebBrowserEditorActionBarContributor implements IEditorActionBarContributor {
+       protected IActionBars actionBars;
+
+       /**
+        * WebBrowserEditorActionBarContributor constructor comment.
+        */
+       public WebBrowserEditorActionBarContributor() {
+               super();
+       }
+
+       /**
+        * Initializes this contributor, which is expected to add contributions as
+        * required to the given action bars and global action handlers.
+        *
+        * @param bars the action bars
+        */
+       public void init(IActionBars bars, IWorkbenchPage page) {
+               this.actionBars = bars;
+       }
+
+       /**
+        * Sets the active editor for the contributor.  
+        * Implementors should disconnect from the old editor, connect to the 
+        * new editor, and update the actions to reflect the new editor.
+        *
+        * @param targetEditor the new editor target
+        */
+       public void setActiveEditor(IEditorPart targetEditor) {
+               if (targetEditor instanceof WebBrowserEditor) {
+                       WebBrowserEditor editor = (WebBrowserEditor) targetEditor;
+
+                       actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), editor.getCopyAction());
+                       actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), editor.getCutAction());
+                       actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), editor.getPasteAction());
+
+                       editor.updateActions();
+               }
+       }
+
+       /**
+        * Disposes this contributor. 
+        */
+       public void dispose() { }
+}
\ No newline at end of file