[Gtk-sharp-list] Context menu

Adam Tauno Williams awilliam at whitemice.org
Wed Aug 25 08:17:49 EDT 2010


On Wed, 2010-08-25 at 13:40 +0200, Rampage wrote:
> Hello everyone :)
> Does anyone have any sort of tutorial/example on how to implement 
> context menus? like: right click on an item of a treeview and i get 
> access to functions that are related to that specific item?
> the simpliest the better, since i'm at the beginning with gtk# and gtk 
> in general, i'm looking for something that even a monkey can understand :D

In your NodeView / TreeView  (this example is from a NodeView)
##########
  [GLib.ConnectBefore]		
  public void OnButonPressEvent(object _sender, 
                                ButtonPressEventArgs _args)

    ITreeNode		node;
    Enterprise		enterprise;

    if (PopupEnabled)
    {
      /* Get the selected list node from the nodeview
	 and bail out if result is not a EnterpriseListNode */
      node = (_sender as NodeView).NodeSelection.SelectedNode;
      if (node is EnterpriseListNode)
        enterprise = ((EnterpriseListNode)node).Enterprise;
      else return;
      /* Is the click a right-button */
     if (_args.Event.Button == 3) 
     {
       PopupMenuBuilder  menu;
       menu.Append("Edit", enterprise, 
                   newEventHandler (EnterpriseEdit), 
	      	   (OnEnterpriseEdit != null));
   ....
      menu.Run();
  }

##########
I cheat a little bit by having my own PopupMenuBuilder class; mostly
because the delegate needs the item represented by the node/row that was
selected in the view.

-- 
Adam Tauno Williams <awilliam at whitemice.org> LPIC-1, Novell CLA
<http://www.whitemiceconsulting.com>
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PopupMenuBuilder.cs
Type: text/x-csharp
Size: 2217 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20100825/3f803a4d/attachment-0001.bin 


More information about the Gtk-sharp-list mailing list