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 diff
     1.1 --- a/FrmMainWindow.cs	Tue Sep 01 19:42:53 2009 +0000
     1.2 +++ b/FrmMainWindow.cs	Fri Sep 04 20:11:02 2009 +0000
     1.3 @@ -923,10 +923,7 @@
     1.4  
     1.5  		protected virtual void ArmyRowActivated (object o, Gtk.RowActivatedArgs args)
     1.6  		{
     1.7 -			TreeModel model = treeUnits.Model;
     1.8 -			TreeIter iter;
     1.9 -			model.GetIter(out iter, args.Path);
    1.10 -			object obj = model.GetValue(iter, 0);
    1.11 +			object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path);
    1.12  
    1.13  			if (obj is IBBoard.WarFoundry.API.Objects.Unit)
    1.14  			{
    1.15 @@ -987,5 +984,37 @@
    1.16  				WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
    1.17  			}
    1.18  		}
    1.19 +
    1.20 +		protected virtual void OnTreeUnitsPopupMenu (object o, Gtk.PopupMenuArgs args)
    1.21 +		{
    1.22 +			object selectedItem = TreeUtils.GetSelectedItem(treeUnits);
    1.23 +
    1.24 +			if (selectedItem is IBBoard.WarFoundry.API.Objects.Unit)
    1.25 +			{
    1.26 +				Menu menu = new Menu();
    1.27 +				ImageMenuItem delete = new ImageMenuItem("Remove unit");
    1.28 +				delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu);
    1.29 +				delete.Activated+= new EventHandler(OnUnitDelete);
    1.30 +				delete.Data["unit"] = selectedItem;
    1.31 +				menu.Append(delete);
    1.32 +				menu.ShowAll();
    1.33 +				menu.Popup();
    1.34 +			}
    1.35 +		}
    1.36 +
    1.37 +		private void OnUnitDelete(object o, EventArgs args)
    1.38 +		{
    1.39 +			RemoveUnitCommand command = new RemoveUnitCommand((IBBoard.WarFoundry.API.Objects.Unit)((ImageMenuItem)o).Data["unit"]);
    1.40 +			commandStack.Execute(command);
    1.41 +		}
    1.42 +
    1.43 +		[GLib.ConnectBefore]
    1.44 +		protected virtual void UnitTreeButtonPressed (object o, Gtk.ButtonPressEventArgs args)
    1.45 +		{
    1.46 +			if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3)
    1.47 +			{
    1.48 +				OnTreeUnitsPopupMenu(o, null);
    1.49 +			}
    1.50 +		}
    1.51  	}
    1.52  }
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Tue Sep 01 19:42:53 2009 +0000
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Fri Sep 04 20:11:02 2009 +0000
     2.3 @@ -240,6 +240,8 @@
     2.4              this.redoActionButton.Activated += new System.EventHandler(this.redoTBButtonActivated);
     2.5              this.miExportAsBasicHtml.Activated += new System.EventHandler(this.OnMiExportAsBasicHtmlActivated);
     2.6              this.treeUnits.RowActivated += new Gtk.RowActivatedHandler(this.ArmyRowActivated);
     2.7 +            this.treeUnits.PopupMenu += new Gtk.PopupMenuHandler(this.OnTreeUnitsPopupMenu);
     2.8 +            this.treeUnits.ButtonPressEvent += new Gtk.ButtonPressEventHandler(this.UnitTreeButtonPressed);
     2.9          }
    2.10      }
    2.11  }
     3.1 --- a/gtk-gui/gui.stetic	Tue Sep 01 19:42:53 2009 +0000
     3.2 +++ b/gtk-gui/gui.stetic	Fri Sep 04 20:11:02 2009 +0000
     3.3 @@ -243,6 +243,8 @@
     3.4                  <property name="MemberName" />
     3.5                  <property name="CanFocus">True</property>
     3.6                  <signal name="RowActivated" handler="ArmyRowActivated" />
     3.7 +                <signal name="PopupMenu" handler="OnTreeUnitsPopupMenu" />
     3.8 +                <signal name="ButtonPressEvent" handler="UnitTreeButtonPressed" />
     3.9                </widget>
    3.10                <packing>
    3.11                  <property name="Resize">False</property>