FAQ How do I enable global actions such as Cut, Paste, and Print in my editor?

From Eclipsepedia

Revision as of 16:47, 14 March 2006 by Claffra (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Your editor's IEditorActionBarContributor, defined in the editor definition in the plugin.xml file, is responsible for enabling global actions. Whenever your editor becomes the active part, the method setActiveEditor is called on the action bar contributor. This is where you can retarget the global actions for your editor. Keep in mind that each editor type has only one editor action bar contributor, so you need to update your actions to reflect the current editor. In this example, the global Print action is being retargeted to the active editor:

   IAction print = ...;
   public void setActiveEditor(IEditorPart part) {
      IActionBars bars= getActionBars();
      if (bars == null)
         return;
      print.setEditor(part);
      bars.setGlobalActionHandler(
         IWorkbenchActionConstants.PRINT, print);
      bars.updateActionBars();
   }


See Also:

[[FAQ_How_do_I_hook_into_global_actions%2C_such_as_%3Cb%3ECopy%3C%2Fb%3E_and_%3Cb%3EDelete%3C%2Fb%3E%3F]]'Copy' and Delete?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.