[RFC] Context-Menu Handling in KDevelop4
dukju ahn
dukjuahn at gmail.com
Mon May 7 18:20:19 UTC 2007
2007/4/3, Andreas Pakulat <apaku at gmx.de>:
> On 03.04.07 16:56:57, Matt Rogers wrote:
> > On Apr 3, 2007, at 2:15 PM, Andreas Pakulat wrote:
> > > so I finally came around to ask Adam what he meant with the comment on
> > > KDevelop::MainWindow::fillContextMenu().
> > >
> > > His response was:
> > > ,----
> > > | Well, kdevelop has this notion of global context's such as 'file
> > > context'
> > > |
> > > | If a plugin wished to add an action to the context menu shown
> > > whenever a file
> > > | is selected it would just call:
> > > |
> > > | 'KActionCollection *ICore::actionCollection
> > > (ICore::FileContext)'
> > > |
> > > | or something and retrieve the action collection for that context
> > > as denoted by
> > > | some enum. The plugin could then plug it's actions into it or
> > > something.
> > > |
> > > | Hadn't really thought it out.
> > > `----
> >
> > I prefer the actionCollection way as well. Do you have a proposed
> > patch for how it would work when writing code to use it?
>
> No, I didn't even think about it too long. However having done so now I
> see a problem here:
>
> A plugin can't just add actions for a Context, it needs to know the
> actual url of the file (in case of a FileContext) to add the right
> actions. So we'd end up with a signal again, in which case I don't see
> the benefit from using the actionCollection, except that we don't allow
> plugins to remove from the menu, only add new actions.
Yes. In addition, signal approach allows more dynamic contextmenu fillout.
For example, contextMenu( ProjectFileContext*, KMenu* ) is emitted.
Whenever emitted, each VCS plugins (for example) can test whether
this file is under version control. So if not version controlled, no context
menu will be created.
If using actionCollection, I can't imaging how such dynamic menu creation
is possible.
So I support the KDev3 way.
-# Create a popup menu in context menu event handler:
@code KPopupMenu menu(this); @endcode
-# Create a context:
@code MyContext context(param). @endcode
-# Fill a context menu:
@code core()->fillContextMenu(&menu, &context); @endcode
==> signal is emitted here.
-# Show the popup menu:
@code menu.exec(event->globalPos()); @endcode
Any objection? If no objection, I'll be the one who will implement
this upcomming weekend.
More information about the KDevelop-devel
mailing list