changeset 44:44e6833bb41a

Re #145: Add UI to remove units from army * Fix the delay in right-click menu caused by out of sync selection Re #86: Complete initial GTK# UI * Make unit creation create a tab
author IBBoard <dev@ibboard.co.uk>
date Wed, 11 Aug 2010 19:43:20 +0000
parents 4e127ce8682f
children 5584860fb44b
files FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs
diffstat 2 files changed, 44 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMainWindow.cs	Wed Aug 11 19:23:43 2010 +0000
+++ b/FrmMainWindow.cs	Wed Aug 11 19:43:20 2010 +0000
@@ -73,10 +73,10 @@
 			//Do nothing extra
 		}
 
-		public FrmMainWindow (string[] args): base (Gtk.WindowType.Toplevel)
+		public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel)
 		{
 			logger.Info("Opening FrmMainWindow");
-			Build ();
+			Build();
 			//Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support
 			redoMenuButton = new MenuToolButton("gtk-redo");
 			redoMenuButton.Label = "Redo";
@@ -399,17 +399,18 @@
 				Category cat = null;
 				categoryMap.TryGetValue((ToolButton)sender, out cat);
 
-				if (cat!=null)
+				if (cat != null)
 				{
 					logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name);
 					FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy);
 					ResponseType response = (ResponseType)newUnit.Run();
 					newUnit.Hide();
 
-					if (response==ResponseType.Ok)
+					if (response == ResponseType.Ok)
 					{
 						CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat));
 						commandStack.Execute(cmd);
+						ShowUnitWidget(cmd.Unit);
 					}
 
 					newUnit.Dispose();
@@ -906,33 +907,37 @@
 			CreateNewArmy();
 		}
 
-		protected virtual void ArmyRowActivated (object o, Gtk.RowActivatedArgs args)
+		protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args)
 		{
 			object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path);
 
 			if (obj is IBBoard.WarFoundry.API.Objects.Unit)
 			{
 				IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj;
-
-				UnitDisplayWidget widget;
-				unitToWidgetMap.TryGetValue(unit, out widget);
+				ShowUnitWidget(unit);
+			}
+		}
+		
+		private void ShowUnitWidget(IBBoard.WarFoundry.API.Objects.Unit unit)
+		{
+			UnitDisplayWidget widget;
+			unitToWidgetMap.TryGetValue(unit, out widget);
 
-				if (widget!=null)
-				{
-					logger.DebugFormat("Selecting existing page for "+unit.Name);
-					unitsNotebook.Page = unitsNotebook.PageNum(widget);
-				}
-				else
-				{
-					widget = new UnitDisplayWidget(unit, CommandStack);
-					logger.Debug("Adding page for "+unit.Name);
-					unitToWidgetMap[unit] = widget;
-					widget.Destroyed+= new EventHandler(UnitWidgetDestroyed);
-					int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name);
-					logger.Debug("Page added at index "+pageNum);
-					unitsNotebook.ShowAll();
-					unitsNotebook.Page = pageNum;
-				}
+			if (widget!=null)
+			{
+				logger.DebugFormat("Selecting existing page for "+unit.Name);
+				unitsNotebook.Page = unitsNotebook.PageNum(widget);
+			}
+			else
+			{
+				widget = new UnitDisplayWidget(unit, CommandStack);
+				logger.Debug("Adding page for "+unit.Name);
+				unitToWidgetMap[unit] = widget;
+				widget.Destroyed+= new EventHandler(UnitWidgetDestroyed);
+				int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name);
+				logger.Debug("Page added at index "+pageNum);
+				unitsNotebook.ShowAll();
+				unitsNotebook.Page = pageNum;
 			}
 		}
 
@@ -994,8 +999,16 @@
 		}
 
 		[GLib.ConnectBefore]
-		protected virtual void UnitTreeButtonPressed (object o, Gtk.ButtonPressEventArgs args)
+		protected virtual void UnitTreeButtonPressed(object o, Gtk.ButtonPressEventArgs args)
 		{
+			TreePath path;
+			treeUnits.GetPathAtPos((int)args.Event.X, (int)args.Event.Y, out path);
+			
+			if (!treeUnits.Selection.PathIsSelected(path))
+			{
+				treeUnits.Selection.SelectPath(path);
+			}
+			
 			if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3)
 			{
 				OnTreeUnitsPopupMenu(o, null);
--- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Wed Aug 11 19:23:43 2010 +0000
+++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Wed Aug 11 19:43:20 2010 +0000
@@ -18,7 +18,7 @@
 
 		private global::Gtk.Action miCloseArmy;
 
-		private global::Gtk.Action miReloadFiles;
+		private global::Gtk.Action refreshAction;
 
 		private global::Gtk.Action miExit;
 
@@ -93,10 +93,9 @@
 			this.miCloseArmy.Sensitive = false;
 			this.miCloseArmy.ShortLabel = global::Mono.Unix.Catalog.GetString("Close army");
 			w1.Add(this.miCloseArmy, null);
-			this.miReloadFiles = new global::Gtk.Action("miReloadFiles", global::Mono.Unix.Catalog.GetString("Reload files"), null, "gtk-refresh");
-			this.miReloadFiles.Sensitive = false;
-			this.miReloadFiles.ShortLabel = global::Mono.Unix.Catalog.GetString("Reload files");
-			w1.Add(this.miReloadFiles, null);
+			this.refreshAction = new global::Gtk.Action("refreshAction", global::Mono.Unix.Catalog.GetString("Reload files"), null, "gtk-refresh");
+			this.refreshAction.ShortLabel = global::Mono.Unix.Catalog.GetString("Reload files");
+			w1.Add(this.refreshAction, null);
 			this.miExit = new global::Gtk.Action("miExit", global::Mono.Unix.Catalog.GetString("Exit"), null, "gtk-quit");
 			this.miExit.ShortLabel = global::Mono.Unix.Catalog.GetString("Exit");
 			w1.Add(this.miExit, null);
@@ -153,7 +152,7 @@
 			this.vbox1 = new global::Gtk.VBox();
 			this.vbox1.Name = "vbox1";
 			// Container child vbox1.Gtk.Box+BoxChild
-			this.UIManager.AddUiFromString("<ui><menubar name='menubar1'><menu name='menuFile' action='menuFile'><menuitem name='miCreateArmy' action='miCreateArmy'/><menuitem name='miOpenArmy' action='miOpenArmy'/><menuitem name='miSaveArmy' action='miSaveArmy'/><menuitem name='miSaveArmyAs' action='miSaveArmyAs'/><menu name='miExportArmy' action='miExportArmy'><menuitem name='miExportAsBasicHtml' action='miExportAsBasicHtml'/></menu><menuitem name='miCloseArmy' action='miCloseArmy'/><separator/><menuitem name='miReloadFiles' action='miReloadFiles'/><separator/><menuitem name='miExit' action='miExit'/></menu><menu name='menuEdit' action='menuEdit'><menuitem name='miUndo' action='miUndo'/><menuitem name='miRedo' action='miRedo'/></menu><menu name='menuHelp' action='menuHelp'><menuitem name='miAbout' action='miAbout'/><menuitem name='miDebugInformation' action='miDebugInformation'/></menu></menubar></ui>");
+			this.UIManager.AddUiFromString("<ui><menubar name='menubar1'><menu name='menuFile' action='menuFile'><menuitem name='miCreateArmy' action='miCreateArmy'/><menuitem name='miOpenArmy' action='miOpenArmy'/><menuitem name='miSaveArmy' action='miSaveArmy'/><menuitem name='miSaveArmyAs' action='miSaveArmyAs'/><menu name='miExportArmy' action='miExportArmy'><menuitem name='miExportAsBasicHtml' action='miExportAsBasicHtml'/></menu><menuitem name='miCloseArmy' action='miCloseArmy'/><separator/><menuitem name='refreshAction' action='refreshAction'/><separator/><menuitem name='miExit' action='miExit'/></menu><menu name='menuEdit' action='menuEdit'><menuitem name='miUndo' action='miUndo'/><menuitem name='miRedo' action='miRedo'/></menu><menu name='menuHelp' action='menuHelp'><menuitem name='miAbout' action='miAbout'/><menuitem name='miDebugInformation' action='miDebugInformation'/></menu></menubar></ui>");
 			this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget("/menubar1")));
 			this.menubar1.Name = "menubar1";
 			this.vbox1.Add(this.menubar1);
@@ -218,7 +217,7 @@
 			this.miSaveArmy.Activated += new global::System.EventHandler(this.OnSaveArmyActivated);
 			this.miSaveArmyAs.Activated += new global::System.EventHandler(this.OnSaveArmyAsActivated);
 			this.miCloseArmy.Activated += new global::System.EventHandler(this.OnCloseArmyActivated);
-			this.miReloadFiles.Activated += new global::System.EventHandler(this.OnReloadFilesActivated);
+			this.refreshAction.Activated += new global::System.EventHandler(this.OnReloadFilesActivated);
 			this.miExit.Activated += new global::System.EventHandler(this.OnExitActivated);
 			this.newArmyButton.Activated += new global::System.EventHandler(this.newTBButtonActivated);
 			this.openArmyButton.Activated += new global::System.EventHandler(this.openTBButtonActivated);