void OnButtonPressed(object sender, Gtk.ButtonPressEventArgs args) { switch (args.Event.Button) { case 3: // third mouse button (right-click) clickedTask = null; Gtk.TreeView tv = sender as Gtk.TreeView; if (tv == null) return; Gtk.TreeModel model = tv.Model; Gtk.TreeIter iter; Gtk.TreePath path; Gtk.TreeViewColumn column = null; if (!tv.GetPathAtPos ((int) args.Event.X, (int) args.Event.Y, out path, out column)) return; if (!model.GetIter (out iter, path)) return; clickedTask = model.GetValue (iter, 0) as ITask; if (clickedTask == null) return; Menu popupMenu = new Menu (); ImageMenuItem item; item = new ImageMenuItem (Catalog.GetString ("_Notes...")); item.Image = new Gtk.Image (noteIcon); item.Activated += OnShowTaskNotes; popupMenu.Add (item); popupMenu.Add (new SeparatorMenuItem ()); item = new ImageMenuItem (Catalog.GetString ("_Delete task")); item.Image = new Gtk.Image(Gtk.Stock.Delete, IconSize.Menu); item.Activated += OnDeleteTask; popupMenu.Add (item); item = new ImageMenuItem(Catalog.GetString ("_Edit task")); item.Image = new Gtk.Image(Gtk.Stock.Edit, IconSize.Menu); item.Activated += OnEditTask; popupMenu.Add (item); /* * Depending on the currently selected task's category, we create a context popup * here in order to enable changing categories. The list of available categories * is pre-filtered as to not contain the current category and the AllCategory. */ TreeModelFilter filteredCategories = new TreeModelFilter(Application.Backend.Categories, null); filteredCategories.VisibleFunc = delegate(TreeModel t, TreeIter i) { ICategory category = t.GetValue (i, 0) as ICategory; if (category == null || category is AllCategory || category.Equals(clickedTask.Category)) return false; return true; }; // The categories submenu is only created in case we actually provide at least one category. if (filteredCategories.GetIterFirst(out iter)) { Menu categoryMenu = new Menu(); CategoryMenuItem categoryItem; filteredCategories.Foreach(delegate(TreeModel t, TreePath p, TreeIter i) { categoryItem = new CategoryMenuItem((ICategory)t.GetValue(i, 0)); categoryItem.Activated += OnChangeCategory; categoryMenu.Add(categoryItem); return false; }); // TODO Needs translation. item = new ImageMenuItem(Catalog.GetString("_Change category")); item.Image = new Gtk.Image(Gtk.Stock.Convert, IconSize.Menu); item.Submenu = categoryMenu; popupMenu.Add(item); } popupMenu.ShowAll(); popupMenu.Popup (); // Logger.Debug ("Right clicked on task: " + task.Name); break; } }