[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: Limit Copy, Paste, Cut keyboard shortcuts to EMF tree only (not the entire editor)

Hi Paul an Tom,

With some extra inspiration, I found the solution to my problem. Here it is:

        textName.addFocusListener(new FocusListener()
        {
            IAction emfcutaction = detailsPage.getActionBars().getGlobalActionHandler(ActionFactory.CUT.getId());
            IAction emfcopyaction = detailsPage.getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId());
            IAction emfpasteaction = detailsPage.getActionBars().getGlobalActionHandler(ActionFactory.PASTE.getId());
           
            IAction standardCut = new Action()
            {
                public void run()
                {
                    textName.cut();
                }
            };

            IAction standardCopy = new Action()
            {
                public void run()
                {
                    textName.copy();
                }
            };

            IAction standardPaste = new Action()
            {
                public void run()
                {
                    textName.paste();
                }
            };
           
            public void focusLost(FocusEvent e)
            {

                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.CUT.getId(), emfcutaction);
                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), emfcopyaction);
                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), emfpasteaction);
                detailsPage.getActionBars().updateActionBars();
            }


            public void focusGained(FocusEvent e)
            {
                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.CUT.getId(), standardCut);
                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), standardCopy);
                detailsPage.getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), standardPaste);
                detailsPage.getActionBars().updateActionBars();
            }

        });

Thanks for your help.

Mircea


Paul Webster wrote:
Mircea Luchian wrote:

Would it be possible that I pass the wrong workbench window to these three actions? Here is how I initialized them below:

    IAction standardCut = ActionFactory.CUT.create(editor.getEditorSite().getWorkbenchWindow());
    IAction standardCopy = ActionFactory.COPY.create(editor.getEditorSite().getWorkbenchWindow());
    IAction standardPaste = ActionFactory.PASTE.create(editor.getEditorSite().getWorkbenchWindow());

As Tom mentioned, the ActionFactory actions are retargetable (and not even that in 3.4).  They don't do anything, they just delegate execution to something else.

If you need to have "copy" work as *either* normal copy in the current text control *or* run your copy action to deal with something in the part (a graphical object, for example) you can use org.eclipse.ui.actions.TextActionHandler

PW