Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
diff FrmMainWindow.cs @ 30:5fafbb1b4592
Re #145: Add UI to remove units from army
* Add initial right-click "remove unit" for GTK app
Existing problems:
* Right-click occurs before selection changes, so it can be a click out of synch
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 04 Sep 2009 20:11:02 +0000 |
parents | 2e5448a662b6 |
children | eab45344cd56 |
line wrap: on
line diff
--- a/FrmMainWindow.cs Tue Sep 01 19:42:53 2009 +0000 +++ b/FrmMainWindow.cs Fri Sep 04 20:11:02 2009 +0000 @@ -923,10 +923,7 @@ protected virtual void ArmyRowActivated (object o, Gtk.RowActivatedArgs args) { - TreeModel model = treeUnits.Model; - TreeIter iter; - model.GetIter(out iter, args.Path); - object obj = model.GetValue(iter, 0); + object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); if (obj is IBBoard.WarFoundry.API.Objects.Unit) { @@ -987,5 +984,37 @@ WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); } } + + protected virtual void OnTreeUnitsPopupMenu (object o, Gtk.PopupMenuArgs args) + { + object selectedItem = TreeUtils.GetSelectedItem(treeUnits); + + if (selectedItem is IBBoard.WarFoundry.API.Objects.Unit) + { + Menu menu = new Menu(); + ImageMenuItem delete = new ImageMenuItem("Remove unit"); + delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu); + delete.Activated+= new EventHandler(OnUnitDelete); + delete.Data["unit"] = selectedItem; + menu.Append(delete); + menu.ShowAll(); + menu.Popup(); + } + } + + private void OnUnitDelete(object o, EventArgs args) + { + RemoveUnitCommand command = new RemoveUnitCommand((IBBoard.WarFoundry.API.Objects.Unit)((ImageMenuItem)o).Data["unit"]); + commandStack.Execute(command); + } + + [GLib.ConnectBefore] + protected virtual void UnitTreeButtonPressed (object o, Gtk.ButtonPressEventArgs args) + { + if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3) + { + OnTreeUnitsPopupMenu(o, null); + } + } } }