comparison 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
comparison
equal deleted inserted replaced
29:2e5448a662b6 30:5fafbb1b4592
921 CreateNewArmy(); 921 CreateNewArmy();
922 } 922 }
923 923
924 protected virtual void ArmyRowActivated (object o, Gtk.RowActivatedArgs args) 924 protected virtual void ArmyRowActivated (object o, Gtk.RowActivatedArgs args)
925 { 925 {
926 TreeModel model = treeUnits.Model; 926 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path);
927 TreeIter iter;
928 model.GetIter(out iter, args.Path);
929 object obj = model.GetValue(iter, 0);
930 927
931 if (obj is IBBoard.WarFoundry.API.Objects.Unit) 928 if (obj is IBBoard.WarFoundry.API.Objects.Unit)
932 { 929 {
933 IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj; 930 IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj;
934 931
985 Army army = WarFoundryCore.CurrentArmy; 982 Army army = WarFoundryCore.CurrentArmy;
986 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); 983 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
987 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); 984 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
988 } 985 }
989 } 986 }
987
988 protected virtual void OnTreeUnitsPopupMenu (object o, Gtk.PopupMenuArgs args)
989 {
990 object selectedItem = TreeUtils.GetSelectedItem(treeUnits);
991
992 if (selectedItem is IBBoard.WarFoundry.API.Objects.Unit)
993 {
994 Menu menu = new Menu();
995 ImageMenuItem delete = new ImageMenuItem("Remove unit");
996 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu);
997 delete.Activated+= new EventHandler(OnUnitDelete);
998 delete.Data["unit"] = selectedItem;
999 menu.Append(delete);
1000 menu.ShowAll();
1001 menu.Popup();
1002 }
1003 }
1004
1005 private void OnUnitDelete(object o, EventArgs args)
1006 {
1007 RemoveUnitCommand command = new RemoveUnitCommand((IBBoard.WarFoundry.API.Objects.Unit)((ImageMenuItem)o).Data["unit"]);
1008 commandStack.Execute(command);
1009 }
1010
1011 [GLib.ConnectBefore]
1012 protected virtual void UnitTreeButtonPressed (object o, Gtk.ButtonPressEventArgs args)
1013 {
1014 if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3)
1015 {
1016 OnTreeUnitsPopupMenu(o, null);
1017 }
1018 }
990 } 1019 }
991 } 1020 }