Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 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 | ca863c693550 |
files | FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs gtk-gui/gui.stetic |
diffstat | 3 files changed, 37 insertions(+), 4 deletions(-) [+] |
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); + } + } } }
--- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Tue Sep 01 19:42:53 2009 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Fri Sep 04 20:11:02 2009 +0000 @@ -240,6 +240,8 @@ this.redoActionButton.Activated += new System.EventHandler(this.redoTBButtonActivated); this.miExportAsBasicHtml.Activated += new System.EventHandler(this.OnMiExportAsBasicHtmlActivated); this.treeUnits.RowActivated += new Gtk.RowActivatedHandler(this.ArmyRowActivated); + this.treeUnits.PopupMenu += new Gtk.PopupMenuHandler(this.OnTreeUnitsPopupMenu); + this.treeUnits.ButtonPressEvent += new Gtk.ButtonPressEventHandler(this.UnitTreeButtonPressed); } } }
--- a/gtk-gui/gui.stetic Tue Sep 01 19:42:53 2009 +0000 +++ b/gtk-gui/gui.stetic Fri Sep 04 20:11:02 2009 +0000 @@ -243,6 +243,8 @@ <property name="MemberName" /> <property name="CanFocus">True</property> <signal name="RowActivated" handler="ArmyRowActivated" /> + <signal name="PopupMenu" handler="OnTreeUnitsPopupMenu" /> + <signal name="ButtonPressEvent" handler="UnitTreeButtonPressed" /> </widget> <packing> <property name="Resize">False</property>