Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » "Paste" action redefinition not complete.
"Paste" action redefinition not complete. [message #484361] Mon, 07 September 2009 08:24 Go to next message
Jean-Marie Damas is currently offline Jean-Marie DamasFriend
Messages: 29
Registered: July 2009
Junior Member
Hello.

I'm using Eclipse Platform 3.4.2 and I'm trying to redefine the "paste"
action in the Project Explorer view.

I used this extension point to redefine the handler of the "paste" action
(it must only be active when the "resource" selected in the Project
Explorer view is managed in VCS) :

<extension point="org.eclipse.ui.handlers">
<handler
class="com.airbus.forges.client.ui.handlers.ForgesPasteHandler "
commandId="org.eclipse.ui.edit.paste">
<activeWhen>
<and>
<with
variable="activePartId">
<equals
value="org.eclipse.ui.navigator.ProjectExplorer">
</equals>
</with>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<test
property="org.eclipse.core.resources.projectPersistentProperty "
args="org.eclipse.team.core.repository"/>
</adapt>
</iterate>
</and>
</activeWhen>
</handler>
</extension>

and it works quite fine :
- the keybiding (Ctrl+V) triggers my handler
- the [Edit+Paste] menu action triggers my handler
but :
- the Project Explorer pop-up menu "Paste" action does NOT :-(

Can somebody explain me why ? Isn't this action mapped with the
"org.eclipse.ui.edit.paste" command ?
And how can I do to trigger my handler when using this action ?

Thank you for your help.
JM.D
Re: "Paste" action redefinition not complete. [message #484682 is a reply to message #484361] Tue, 08 September 2009 17:54 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You guessed it. The paste item in the popup-menu is an action, not a command.

You can't re-define it AFAIK, as the project explorer uses action groups to contribute those menus

PW


Re: "Paste" action redefinition not complete. [message #485155 is a reply to message #484682] Thu, 10 September 2009 16:15 Go to previous messageGo to next message
Jean-Marie Damas is currently offline Jean-Marie DamasFriend
Messages: 29
Registered: July 2009
Junior Member
Paul Webster wrote:

> You guessed it. The paste item in the popup-menu is an action, not a
command.
> You can't re-define it AFAIK, as the project explorer uses action groups to
contribute those menus

I've found the "paste action" definition in
"org.eclipse.ui.navigator.resources" plugin and I can see in
EditActionGroup.makeActions() :

pasteAction = new PasteAction(shell, clipboard);
...
pasteAction.setActionDefinitionId(IWorkbenchActionDefinition Ids.PASTE);

with IWorkbenchActionDefinitionIds.PASTE = "org.eclipse.ui.edit.paste" !!

And this Eclipse help page :
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/wrkAdv_keyBindings_actionDef.htm
explains that this should be an association between the action and the
command !!

So, why is this action not handled by my "edit.paste" handler ??
Thanks. JM.D
Re: "Paste" action redefinition not complete. [message #485159 is a reply to message #485155] Thu, 10 September 2009 16:37 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The definition id on an action tells the framework that the action is a handler for a command, not that the action should call out to a command. When an action is placed directly in a MenuManager, the SWT menu will only ever call that action (no commands involved at all).

As an aside, context menus don't support any keybindings for their contributed actions. Putting an action into a context menu will not make it available to the keybinding framework.

You can open an enhancement request at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=UI for the edit actions to support some sort of bridge with the command framework.

PW


Re: "Paste" action redefinition not complete. [message #485284 is a reply to message #485159] Fri, 11 September 2009 08:08 Go to previous messageGo to next message
Jean-Marie Damas is currently offline Jean-Marie DamasFriend
Messages: 29
Registered: July 2009
Junior Member
Paul Webster wrote:

> The definition id on an action tells the framework that the action is a
handler for a command, not that the action should call out to a command. When
an action is placed directly in a MenuManager, the SWT menu will only ever
call that action (no commands involved at all).

Ok, understood...
My objective is (trying) to disable the "paste" action in some conditions,
which conditions I've defined in the <activeWhen> clause of my
"org.eclipse.ui.handlers" extension point. My handler only pop ups a
dialog box saying "you can't paste".

So, my question now is about finding a way to remove completely the
"paste" action added in the pop-up menu by the ProjectExplorer plugin. Can
I do that with an API ? A workbench "Menu service" ?

Thanks.
JM.D
Re: "Paste" action redefinition not complete. [message #485373 is a reply to message #485284] Fri, 11 September 2009 14:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You can do it by creating your own common navigator view (content providers, action providers, etc).

You might be able to use the extension points to override an action provider and provide your own ... or you might have to create your own view that has similar extension definitions as the Project Explorer and simply replace the one you don't like with your own, more friendly, action provider (although you'll then possibly have to add the appropriate paste action as an ActionHandler for the command so that it works for the other cases).

If Paste in that menu was a CommandContributionItem, then it would do the correct thing.

PW


Re: "Paste" action redefinition not complete. [message #485825 is a reply to message #485373] Tue, 15 September 2009 08:38 Go to previous messageGo to next message
Jean-Marie Damas is currently offline Jean-Marie DamasFriend
Messages: 29
Registered: July 2009
Junior Member
Paul Webster wrote:

> You might be able to use the extension points to override an action provider
> and provide your own

I succeeded in removing the "group.edit" actions (Cut/Copy/Paste) and I've
done it that way, using the Common Navigator extension points :

<extension
point="org.eclipse.ui.navigator.viewer">
<viewerActionBinding
viewerId="org.eclipse.ui.navigator.ProjectExplorer">
<includes>
<actionExtension
pattern="my.app.client.actions.MyAppEditActionExtension">
</actionExtension>
</includes>
</viewerActionBinding>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
<actionProvider
class="my.app.client.workshop.MyPasteActionProvider"
id="my.app.client.actions.MyAppEditActionExtension"

overrides="org.eclipse.ui.navigator.resources.actions.EditActions "
priority="highest">
<enablement>
<!-- A hack to allways be enabled -->
<not>
<systemTest
property="MyApp"
value="WONT-EVER-BE-SET">
</systemTest>
</not>
</enablement>
</actionProvider>
</extension>

And implemented "MyPasteActionProvider" which does nothing.

I wanted to use the "activePartId" in the "enablement" clause of the
action provider but I've got a message "The variable activePartId is not
defined" so I used a hack to always be enabled ...
JM.D
Re: "Paste" action redefinition not complete. [message #486102 is a reply to message #485825] Wed, 16 September 2009 10:55 Go to previous messageGo to next message
Jean-Marie Damas is currently offline Jean-Marie DamasFriend
Messages: 29
Registered: July 2009
Junior Member
Jean-Marie Damas wrote:

> And implemented "MyPasteActionProvider" which does nothing.

Hum ... that's was to much rude ... and completely de-activated the "copy"
and "paste" actions, because they were no more registered in the workbench
!

So, I implemented "MyPasteActionProvider" like this :

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import
org.eclipse.ui.internal.navigator.resources.actions.EditActi onProvider;

/**
* Create the Edit actions (Cut/Copy/Paste) and register then globally in
the workbench using EditActionProvider.
* <p/>
* Then, removes the Copy/Paste contributions in the pop-up menu.
*/
public class MyPasteActionProvider extends EditActionProvider {

public void fillContextMenu(IMenuManager menu) {
super.fillContextMenu(menu);
// remove Copy/Paste contributions
IContributionItem copyItemRemoved =
menu.remove("org.eclipse.ui.CopyAction");
IContributionItem pasteItemRemoved =
menu.remove("org.eclipse.ui.PasteAction");
}
}

Well, that's a "discouraged access" but I was getting myself discouraged
;-)
JM.D
Re: "Paste" action redefinition not complete. [message #504112 is a reply to message #485159] Thu, 17 December 2009 10:25 Go to previous message
Krzysztof Kazmierczyk is currently offline Krzysztof KazmierczykFriend
Messages: 2
Registered: December 2009
Junior Member
Such enhancement has been opened: see bug 298052

Paul Webster wrote on Thu, 10 September 2009 12:37

You can open an enhancement request at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=UI for the edit actions to support some sort of bridge with the command framework.
PW


[Updated on: Thu, 17 December 2009 05:26]

Report message to a moderator

Previous Topic:SWT_AWT: OK under Java5, flakey under java 6
Next Topic:Software Updates in eclipse 3.4
Goto Forum:
  


Current Time: Thu Apr 25 17:06:59 GMT 2024

Powered by FUDForum. Page generated in 0.04340 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top