Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 45:5584860fb44b
Fixes #145: Add UI to remove units from army
* Remove tab on unit deletion
* Remove tab from widget map on close
Also:
* Alias IBBoard.WarFoundry.API.Objects to make access easier (Unit clashes with a GTK class)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 14 Aug 2010 15:43:30 +0000 |
parents | 44e6833bb41a |
children | 3314f6a46661 |
files | FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs gtk-gui/gui.stetic |
diffstat | 3 files changed, 40 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmMainWindow.cs Wed Aug 11 19:43:20 2010 +0000 +++ b/FrmMainWindow.cs Sat Aug 14 15:43:30 2010 +0000 @@ -19,6 +19,7 @@ using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Factories.Xml; using IBBoard.WarFoundry.API.Objects; +using WFObjects = IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Savers; using IBBoard.WarFoundry.API.Requirements; @@ -39,7 +40,7 @@ private CommandStack commandStack; private Dictionary<ToolButton, Category> categoryMap = new Dictionary<ToolButton, Category>(); - private Dictionary<IBBoard.WarFoundry.API.Objects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<IBBoard.WarFoundry.API.Objects.Unit,UnitDisplayWidget>(); + private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>(); private ObjectAddDelegate UnitAddedMethod; private ObjectRemoveDelegate UnitRemovedMethod; @@ -218,9 +219,9 @@ (cell as CellRendererText).Text = name; } - else if (o is IBBoard.WarFoundry.API.Objects.Unit) + else if (o is WFObjects.Unit) { - IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; + WFObjects.Unit u = (WFObjects.Unit)o; string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}pts", u.Name, u.Points); (cell as CellRendererText).Text = name; } @@ -234,7 +235,7 @@ private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) { - IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)val; + WFObjects.Unit unit = (WFObjects.Unit)val; UnitDisplayWidget widget; unitToWidgetMap.TryGetValue(unit, out widget); logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); @@ -248,12 +249,12 @@ private void OnUnitAdded(WarFoundryObject val) { - IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)val; + WFObjects.Unit unit = (WFObjects.Unit)val; unit.NameChanged+= UnitNameChangedMethod; AddUnitToTree(unit); } - private void AddUnitToTree(IBBoard.WarFoundry.API.Objects.Unit unit) + private void AddUnitToTree(WFObjects.Unit unit) { TreeStore model = (TreeStore)treeUnits.Model; TreeIter iter; @@ -280,14 +281,13 @@ private void OnUnitRemoved(WarFoundryObject obj) { - IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj; + WFObjects.Unit unit = (WFObjects.Unit)obj; unit.NameChanged-= UnitNameChangedMethod; RemoveUnitFromTree(unit); - - //See if unit has a tab open and close it if it does + RemoveUnitTab(unit); } - private void RemoveUnitFromTree(IBBoard.WarFoundry.API.Objects.Unit unit) + private void RemoveUnitFromTree(WFObjects.Unit unit) { TreeStore model = (TreeStore)treeUnits.Model; TreeIter iter; @@ -329,6 +329,16 @@ } while (model.IterNext(ref iter)); } + + private void RemoveUnitTab(WFObjects.Unit unit) + { + UnitDisplayWidget widget = DictionaryUtils.GetValue(unitToWidgetMap, unit); + + if (widget != null) + { + unitsNotebook.Remove(widget); + } + } private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) { @@ -522,7 +532,7 @@ logger.DebugFormat("Append category {0}", cat.Name); iter = store.AppendValues(cat); - foreach (IBBoard.WarFoundry.API.Objects.Unit unit in cat.GetUnits()) + foreach (WFObjects.Unit unit in cat.GetUnits()) { store.AppendValues(iter, unit); } @@ -911,14 +921,14 @@ { object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); - if (obj is IBBoard.WarFoundry.API.Objects.Unit) + if (obj is WFObjects.Unit) { - IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj; + WFObjects.Unit unit = (WFObjects.Unit)obj; ShowUnitWidget(unit); } } - private void ShowUnitWidget(IBBoard.WarFoundry.API.Objects.Unit unit) + private void ShowUnitWidget(WFObjects.Unit unit) { UnitDisplayWidget widget; unitToWidgetMap.TryGetValue(unit, out widget); @@ -979,7 +989,7 @@ { object selectedItem = TreeUtils.GetSelectedItem(treeUnits); - if (selectedItem is IBBoard.WarFoundry.API.Objects.Unit) + if (selectedItem is WFObjects.Unit) { Menu menu = new Menu(); ImageMenuItem delete = new ImageMenuItem("Remove unit"); @@ -994,7 +1004,7 @@ private void OnUnitDelete(object o, EventArgs args) { - RemoveUnitCommand command = new RemoveUnitCommand((IBBoard.WarFoundry.API.Objects.Unit)((ImageMenuItem)o).Data["unit"]); + RemoveUnitCommand command = new RemoveUnitCommand((WFObjects.Unit)((ImageMenuItem)o).Data["unit"]); commandStack.Execute(command); } @@ -1014,5 +1024,17 @@ OnTreeUnitsPopupMenu(o, null); } } + + protected virtual void NotebookPageRemoved(object o, Gtk.RemovedArgs args) + { + Widget widget = args.Widget; + + if (widget is UnitDisplayWidget) + { + unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); + } + } + + } }
--- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Wed Aug 11 19:43:20 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Sat Aug 14 15:43:30 2010 +0000 @@ -228,6 +228,7 @@ this.treeUnits.RowActivated += new global::Gtk.RowActivatedHandler(this.ArmyRowActivated); this.treeUnits.PopupMenu += new global::Gtk.PopupMenuHandler(this.OnTreeUnitsPopupMenu); this.treeUnits.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler(this.UnitTreeButtonPressed); + this.unitsNotebook.Removed += new global::Gtk.RemovedHandler(this.NotebookPageRemoved); } } }
--- a/gtk-gui/gui.stetic Wed Aug 11 19:43:20 2010 +0000 +++ b/gtk-gui/gui.stetic Sat Aug 14 15:43:30 2010 +0000 @@ -246,6 +246,7 @@ <property name="MemberName" /> <property name="CanFocus">True</property> <property name="CurrentPage">-1</property> + <signal name="Removed" handler="NotebookPageRemoved" /> </widget> </child> </widget>