Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmMainWindow.cs @ 122:2479414b16f6
Re #361: Add XML output to GTK GUI
* Add initial form and load XSLT file list
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 27 Sep 2011 21:01:49 +0100 |
parents | 76b73f15d07e |
children | f58f69ea2435 |
rev | line source |
---|---|
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
1 // This file (FrmMainWindow.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 |
5 using System; | |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
6 using System.Collections; |
0 | 7 using System.Collections.Generic; |
8 using System.Configuration; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
9 using System.IO; |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
10 using GLib; |
13 | 11 using Gtk; |
12 using IBBoard; | |
0 | 13 using IBBoard.Commands; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
14 using IBBoard.CustomMath; |
12
685532d43a96
Re #88: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
10
diff
changeset
|
15 using IBBoard.GtkSharp; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
16 using IBBoard.GtkSharp.Translatable; |
0 | 17 using IBBoard.IO; |
13 | 18 using IBBoard.Lang; |
19 using IBBoard.Logging; | |
0 | 20 using IBBoard.WarFoundry.API; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
21 using IBBoard.WarFoundry.API.Commands; |
28 | 22 using IBBoard.WarFoundry.API.Exporters; |
0 | 23 using IBBoard.WarFoundry.API.Factories; |
13 | 24 using IBBoard.WarFoundry.API.Factories.Xml; |
25 using IBBoard.WarFoundry.API.Objects; | |
0 | 26 using IBBoard.WarFoundry.API.Savers; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
27 using IBBoard.WarFoundry.GUI.GTK.Widgets; |
0 | 28 using IBBoard.Xml; |
29 using log4net; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
30 using WFObjects = IBBoard.WarFoundry.API.Objects; |
108 | 31 using IBBoard.WarFoundry.API.Savers.Xml; |
0 | 32 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
33 namespace IBBoard.WarFoundry.GUI.GTK |
21 | 34 { |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
35 public partial class FrmMainWindow: TranslatableWindowWithActions |
0 | 36 { |
37 private static readonly string AppTitle = "WarFoundry"; | |
13 | 38 private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; |
39 private Preferences preferences; | |
40 private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); | |
0 | 41 private CommandStack commandStack; |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
42 private Dictionary<WFObjects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<WFObjects.Unit,UnitDisplayWidget>(); |
13 | 43 private ObjectAddDelegate UnitAddedMethod; |
44 private ObjectRemoveDelegate UnitRemovedMethod; | |
45 private DoubleValChangedDelegate PointsValueChangedMethod; | |
0 | 46 private StringValChangedDelegate UnitNameChangedMethod; |
47 private GameSystem system; | |
48 private string loadedArmyPath; | |
49 private MenuToolButton undoMenuButton, redoMenuButton; | |
21 | 50 |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
51 public static void Main(string[] args) |
21 | 52 { |
13 | 53 try |
0 | 54 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
55 ExceptionManager.UnhandledException += HandleUnhandledException; |
0 | 56 Application.Init(); |
57 FrmMainWindow win = new FrmMainWindow(args); | |
58 win.Show(); | |
59 Application.Run(); | |
13 | 60 LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); |
61 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
62 catch (Exception ex) |
13 | 63 { |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
64 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
65 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
66 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
67 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
68 private static void HandleUnhandledException(UnhandledExceptionArgs args) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
69 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
70 object obj = args.ExceptionObject; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
71 Exception ex = null; |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
72 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
73 if (obj is Exception) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
74 { |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
75 ex = (Exception)obj; |
0 | 76 } |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
77 else |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
78 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
79 ex = new Exception("GLib returned unexpected exception object type " + obj.GetType()); |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
80 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
81 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
82 HandleUnhandledException(ex); |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
83 } |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
84 |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
85 private static void HandleUnhandledException(Exception ex) |
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
86 { |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
87 string msg = String.Format("({0}) {1}", ex.GetType().FullName, ex.Message); |
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
88 LogManager.GetLogger(typeof(FrmMainWindow)).Fatal(msg, ex); |
47
07fd9f7b0dd1
Re #79: Make use of GTK# callback for exceptions
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
89 MessageDialog dialog = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "An unhandled exception occurred. Please check the log for more details."); |
57
293d204e40db
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
90 dialog.Run(); |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
91 dialog.Hide(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
57
diff
changeset
|
92 dialog.Dispose(); |
0 | 93 } |
21 | 94 |
0 | 95 public FrmMainWindow() : this(new string[0]) |
96 { | |
97 //Do nothing extra | |
98 } | |
21 | 99 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
100 public FrmMainWindow(string[] args) : base(Gtk.WindowType.Toplevel) |
0 | 101 { |
102 logger.Info("Opening FrmMainWindow"); | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
103 Build(); |
0 | 104 //Replace the undo/redo buttons with menu versions, which Monodevelop's GUI editor doesn't currently support |
105 redoMenuButton = new MenuToolButton("gtk-redo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
106 redoMenuButton.Name = "bttnRedo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
107 redoMenuButton.Clicked += redoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
108 redoMenuButton.Sensitive = false; |
0 | 109 toolbar.Insert(redoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
110 undoMenuButton = new MenuToolButton("gtk-undo"); | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
111 undoMenuButton.Name = "bttnUndo"; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
112 undoMenuButton.Clicked += undoTBButtonActivated; |
78
e63209ab2cfa
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
113 undoMenuButton.Sensitive = false; |
0 | 114 toolbar.Insert(undoMenuButton, CATEGORY_BUTTON_SEPARATOR_INDEX); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
115 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 1]); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
116 toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX - 2]); |
0 | 117 toolbar.ShowAll(); |
21 | 118 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
119 TreeViewColumn mainColumn = new TreeViewColumn(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
120 CellRendererText mainCell = new CellRendererText(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
121 mainColumn.PackStart(mainCell, true); |
0 | 122 treeUnits.AppendColumn(mainColumn); |
123 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderCategoryTreeObjectName)); | |
124 treeUnits.Model = new TreeStore(typeof(WarFoundryObject)); | |
125 logger.Debug("Loading preferences"); | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
126 Preferences = new Preferences("WarFoundry-GTK"); |
0 | 127 logger.Debug("Loading translations"); |
21 | 128 |
8
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
129 try |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
130 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
131 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
132 } |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
133 catch (TranslationLoadException ex) |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
134 { |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
135 logger.Error(ex); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
136 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, ex.Message); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
137 dialog.Title = "Translation loading failed"; |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
138 dialog.Run(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
139 dialog.Destroy(); |
20c5fd0bb79d
Fixes #5 - Stop missing translations being fatal
IBBoard <dev@ibboard.co.uk>
parents:
6
diff
changeset
|
140 } |
21 | 141 |
13 | 142 logger.Debug("Initialising"); |
143 commandStack = new CommandStack(); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
144 commandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
145 WarFoundryCore.GameSystemChanged += new GameSystemChangedDelegate(OnGameSystemChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
146 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(OnArmyChanged); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
147 Destroyed += new EventHandler(OnWindowDestroyed); |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
148 Translation.TranslationChanged += Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
149 Translate(); |
13 | 150 UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); |
151 UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); | |
152 PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); | |
0 | 153 UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged); |
21 | 154 |
18
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
155 //FIXME: Temporary hack to add paths and factories before we get preferences and plugins |
0 | 156 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + "data")); |
18
c4d9b1ec75ed
Re #124: Remove "factory factory"
IBBoard <dev@ibboard.co.uk>
parents:
17
diff
changeset
|
157 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
158 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; |
108 | 159 WarFoundrySaver.SetFileSaver(new WarFoundryXmlFileSaver()); |
21 | 160 |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
161 logger.Debug("Initialising complete - seeing if we can load default army or system"); |
21 | 162 |
0 | 163 if (args.Length == 1) |
164 { | |
21 | 165 logger.Debug("Attempting to load from file"); |
0 | 166 FileInfo file = new FileInfo(args[0]); |
21 | 167 |
0 | 168 try |
169 { | |
5 | 170 ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file); |
171 | |
172 if (objects.Count == 1) | |
0 | 173 { |
5 | 174 List<IWarFoundryObject> objectList = new List<IWarFoundryObject>(); |
175 objectList.AddRange(objects); | |
176 IWarFoundryObject loadedObject = objectList[0]; | |
21 | 177 |
5 | 178 if (loadedObject is Army) |
179 { | |
180 WarFoundryCore.CurrentArmy = (Army)loadedObject; | |
181 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
182 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
183 else |
5 | 184 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
185 if (loadedObject is GameSystem) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
186 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
187 WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
188 logger.InfoFormat("Loaded game system from {0}", file.FullName); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
189 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
190 |
5 | 191 } |
0 | 192 } |
193 } | |
194 catch (InvalidFileException ex) | |
195 { | |
196 //TODO: show error dialog | |
197 logger.Error(ex); | |
198 } | |
199 } | |
200 else | |
201 { | |
202 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
203 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
204 if (gameSystemID != null && !"".Equals(gameSystemID)) |
0 | 205 { |
206 logger.Debug("Attempting to load current game system from properties"); | |
207 GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); | |
21 | 208 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
209 if (sys != null) |
0 | 210 { |
211 WarFoundryCore.CurrentGameSystem = sys; | |
212 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
213 } | |
214 } | |
215 } | |
216 } | |
21 | 217 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
218 protected override void Translate() |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
219 { |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
220 base.Translate(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
221 SetAppTitle(); |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
222 treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
223 RebuildUndoRedoMenus(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
224 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
225 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
226 private void Retranslate() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
227 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
228 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
229 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
230 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
231 public override void Dispose() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
232 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
233 Translation.TranslationChanged -= Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
234 base.Dispose(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
235 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
95
diff
changeset
|
236 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
237 private void FileLoadingFinished(List<FileLoadFailure> failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
238 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
239 foreach (FileLoadFailure failure in failures) |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
240 { |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
241 logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
242 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
243 } |
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
244 |
0 | 245 private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
246 { | |
247 object o = model.GetValue(iter, 0); | |
21 | 248 |
0 | 249 if (o is ArmyCategory) |
250 { | |
251 ArmyCategory c = (ArmyCategory)o; | |
252 string name = ""; | |
21 | 253 |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
254 if (!Preferences.GetBooleanProperty("ShowCatPercentage")) |
0 | 255 { |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
256 name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.Points); |
0 | 257 } |
258 else | |
259 { | |
32
eab45344cd56
Re #172: Add GTK# UI for showing debugging messages
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
260 name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}pts ({2}%)", c.Name, c.Points, (c.ParentArmy.Points > 0 ? Math.Round((c.Points / c.ParentArmy.Points) * 100) : 0)); |
0 | 261 } |
21 | 262 |
0 | 263 (cell as CellRendererText).Text = name; |
264 } | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
265 else |
0 | 266 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
267 if (o is WFObjects.Unit) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
268 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
269 WFObjects.Unit u = (WFObjects.Unit)o; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
270 string name = Translation.GetTranslation("unitTreeCatName", "{0} - {1}pts", u.Name, u.Points); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
271 (cell as CellRendererText).Text = name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
272 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
273 |
0 | 274 } |
275 } | |
21 | 276 |
0 | 277 private void OnWindowDestroyed(object source, EventArgs args) |
278 { | |
279 logger.Info("Exiting"); | |
280 Application.Quit(); | |
281 } | |
21 | 282 |
0 | 283 private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue) |
284 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
285 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
286 logger.DebugFormat("Unit name changed for {0} - now called {1}", unit.ID, unit.Name); |
0 | 287 UnitDisplayWidget widget; |
288 unitToWidgetMap.TryGetValue(unit, out widget); | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
289 |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
290 if (widget != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
291 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
292 unitsNotebook.SetTabLabel(widget, NotebookUtil.CreateNotebookTabLabelWithClose(unitsNotebook, widget, unit.Name)); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
293 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
294 |
41
a32b6bb7f1eb
Fixes #129: Change notifications are slow in GTK app
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
295 treeUnits.QueueDraw(); |
0 | 296 } |
21 | 297 |
0 | 298 private void OnUnitAdded(WarFoundryObject val) |
299 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
300 WFObjects.Unit unit = (WFObjects.Unit)val; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
301 unit.NameChanged += UnitNameChangedMethod; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
302 unit.PointsValueChanged += HandleUnitPointsValueChanged; |
0 | 303 AddUnitToTree(unit); |
304 } | |
21 | 305 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
306 private void HandleUnitPointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
307 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
308 treeUnits.QueueDraw(); |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
309 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
310 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
311 private void AddUnitToTree(WFObjects.Unit unit) |
0 | 312 { |
313 TreeStore model = (TreeStore)treeUnits.Model; | |
314 TreeIter iter; | |
315 model.GetIterFirst(out iter); | |
21 | 316 |
0 | 317 do |
318 { | |
319 object obj = model.GetValue(iter, 0); | |
21 | 320 |
0 | 321 if (obj is ArmyCategory) |
322 { | |
323 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 324 |
0 | 325 if (cat.Equals(unit.Category)) |
326 { | |
327 model.AppendValues(iter, unit); | |
328 TreePath path = model.GetPath(iter); | |
329 treeUnits.ExpandToPath(path); | |
330 } | |
331 } | |
332 } | |
333 while (model.IterNext(ref iter)); | |
334 } | |
21 | 335 |
0 | 336 private void OnUnitRemoved(WarFoundryObject obj) |
337 { | |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
338 WFObjects.Unit unit = (WFObjects.Unit)obj; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
339 unit.NameChanged -= UnitNameChangedMethod; |
0 | 340 RemoveUnitFromTree(unit); |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
341 RemoveUnitTab(unit); |
0 | 342 } |
21 | 343 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
344 private void RemoveUnitFromTree(WFObjects.Unit unit) |
0 | 345 { |
346 TreeStore model = (TreeStore)treeUnits.Model; | |
347 TreeIter iter; | |
348 model.GetIterFirst(out iter); | |
349 bool removed = false; | |
21 | 350 |
0 | 351 do |
352 { | |
353 object obj = model.GetValue(iter, 0); | |
21 | 354 |
0 | 355 if (obj is ArmyCategory) |
356 { | |
357 ArmyCategory cat = (ArmyCategory)obj; | |
21 | 358 |
0 | 359 if (unit.Category == null || cat.Equals(unit.Category)) |
360 { | |
361 TreeIter innerIter; | |
362 model.IterChildren(out innerIter, iter); | |
21 | 363 |
0 | 364 do |
365 { | |
366 object innerObj = model.GetValue(innerIter, 0); | |
21 | 367 |
0 | 368 if (unit.Equals(innerObj)) |
369 { | |
370 model.Remove(ref innerIter); | |
371 removed = true; | |
372 break; | |
373 } | |
374 } | |
375 while (model.IterNext(ref innerIter)); | |
21 | 376 |
0 | 377 if (removed) |
378 { | |
379 break; | |
380 } | |
381 } | |
382 } | |
383 } | |
384 while (model.IterNext(ref iter)); | |
385 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
386 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
387 private void RemoveUnitTab(WFObjects.Unit unit) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
388 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
389 UnitDisplayWidget widget = DictionaryUtils.GetValue(unitToWidgetMap, unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
390 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
391 if (widget != null) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
392 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
393 unitsNotebook.Remove(widget); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
394 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
395 } |
21 | 396 |
0 | 397 private void OnPointsValueChanged(WarFoundryObject obj, double before, double after) |
398 { | |
99
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
399 SetPointsPanelText(); |
0 | 400 } |
21 | 401 |
0 | 402 public Preferences Preferences |
403 { | |
404 get { return preferences; } | |
21 | 405 set { preferences = value; } |
0 | 406 } |
21 | 407 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
408 protected void OnDeleteEvent(object sender, DeleteEventArgs a) |
0 | 409 { |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
410 Application.Quit(); |
0 | 411 a.RetVal = true; |
412 } | |
413 | |
414 protected virtual void OnExitActivated(object sender, System.EventArgs e) | |
415 { | |
416 Application.Quit(); | |
417 } | |
418 | |
419 protected virtual void OnCreateArmyActivated(object sender, System.EventArgs e) | |
420 { | |
421 CreateNewArmy(); | |
422 } | |
423 | |
424 protected virtual void OnReloadFilesActivated(object sender, System.EventArgs e) | |
425 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
426 WarFoundryLoader.GetDefault().LoadFiles(); |
0 | 427 } |
428 | |
429 protected virtual void OnSaveArmyAsActivated(object sender, System.EventArgs e) | |
430 { | |
431 SaveCurrentArmyAs(); | |
432 } | |
433 | |
434 protected virtual void OnCloseArmyActivated(object sender, System.EventArgs e) | |
435 { | |
436 CloseCurrentArmy(); | |
437 } | |
438 | |
439 protected virtual void OnOpenArmyActivated(object sender, System.EventArgs e) | |
440 { | |
441 OpenArmy(); | |
442 } | |
443 | |
444 protected virtual void OnSaveArmyActivated(object sender, System.EventArgs e) | |
445 { | |
33 | 446 SaveCurrentArmyOrSaveAs(); |
0 | 447 } |
21 | 448 |
0 | 449 protected virtual void OnAddUnitActivated(object sender, System.EventArgs e) |
450 { | |
451 if (sender is ToolButton) | |
452 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
453 ToolButton toolButton = (ToolButton)sender; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
454 Category cat = (Category)toolButton.Data["Category"]; |
21 | 455 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
456 if (cat != null) |
0 | 457 { |
458 logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name); | |
459 FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy); | |
460 ResponseType response = (ResponseType)newUnit.Run(); | |
461 newUnit.Hide(); | |
21 | 462 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
463 if (response == ResponseType.Ok) |
0 | 464 { |
14
abbf8a3ac431
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
465 CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat)); |
0 | 466 commandStack.Execute(cmd); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
467 ShowUnitWidget(cmd.Unit); |
0 | 468 } |
21 | 469 |
0 | 470 newUnit.Dispose(); |
471 } | |
472 } | |
473 } | |
21 | 474 |
13 | 475 public CommandStack CommandStack |
476 { | |
477 get { return commandStack; } | |
0 | 478 } |
21 | 479 |
0 | 480 private void SetAppTitle() |
481 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
482 if (WarFoundryCore.CurrentArmy != null) |
0 | 483 { |
484 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name + " - " + WarFoundryCore.CurrentArmy.Name; | |
485 } | |
486 else | |
487 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
488 if (WarFoundryCore.CurrentGameSystem != null) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
489 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
490 Title = AppTitle + " - " + WarFoundryCore.CurrentGameSystem.Name; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
491 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
492 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
493 { |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
494 Title = AppTitle; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
495 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
496 |
0 | 497 } |
498 } | |
21 | 499 |
0 | 500 private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys) |
501 { | |
502 system = newSys; | |
503 SetAppTitle(); | |
504 RemoveCategoryButtons(); | |
21 | 505 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
506 if (system != null) |
0 | 507 { |
508 AddCategoryButtons(system.Categories); | |
509 } | |
510 } | |
21 | 511 |
0 | 512 private void OnArmyChanged(Army oldArmy, Army newArmy) |
513 { | |
514 loadedArmyPath = null; | |
515 SetAppTitle(); | |
516 SetArmyTree(newArmy); | |
21 | 517 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
518 if (oldArmy != null) |
13 | 519 { |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
520 oldArmy.UnitAdded -= UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
521 oldArmy.UnitRemoved -= UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
522 oldArmy.PointsValueChanged -= PointsValueChangedMethod; |
0 | 523 } |
21 | 524 |
0 | 525 unitToWidgetMap.Clear(); |
21 | 526 |
0 | 527 while (unitsNotebook.NPages > 0) |
528 { | |
529 unitsNotebook.RemovePage(0); | |
530 } | |
21 | 531 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
532 if (newArmy == null) |
13 | 533 { |
534 DisableCategoryButtons(); | |
535 } | |
536 else | |
537 { | |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
538 newArmy.UnitAdded += UnitAddedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
539 newArmy.UnitRemoved += UnitRemovedMethod; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
540 newArmy.PointsValueChanged += PointsValueChangedMethod; |
13 | 541 //TODO: Clear all buttons |
542 EnableCategoryButtons(); | |
543 | |
544 if (newArmy.Race.HasCategoryOverrides()) | |
545 { | |
546 RemoveCategoryButtons(); | |
547 AddCategoryButtons(newArmy.Race.Categories); | |
548 } | |
0 | 549 } |
21 | 550 |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
551 bool nonNullNewArmy = (newArmy != null); |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
552 miCloseArmy.Sensitive = nonNullNewArmy; |
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
553 miSaveArmyAs.Sensitive = nonNullNewArmy; |
81
3ff8e10de45a
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
79
diff
changeset
|
554 miExportArmyAs.Sensitive = nonNullNewArmy; |
43
4e127ce8682f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
555 hpaned2.Visible = nonNullNewArmy; |
33 | 556 loadedArmyPath = null; |
0 | 557 //New army has no changes, so we can't save it |
558 miSaveArmy.Sensitive = false; | |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
559 bttnSaveArmy.Sensitive = false; |
13 | 560 |
561 CommandStack.Reset(); | |
0 | 562 SetPointsPanelText(); |
563 } | |
21 | 564 |
0 | 565 private void SetArmyTree(Army army) |
566 { | |
567 logger.Debug("Resetting tree"); | |
568 TreeStore store = (TreeStore)treeUnits.Model; | |
569 store.Clear(); | |
570 TreeIter iter; | |
21 | 571 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
572 if (army != null) |
0 | 573 { |
574 logger.Debug("Loading in categories to tree"); | |
21 | 575 |
0 | 576 foreach (ArmyCategory cat in army.Categories) |
577 { | |
578 logger.DebugFormat("Append category {0}", cat.Name); | |
579 iter = store.AppendValues(cat); | |
21 | 580 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
581 foreach (WFObjects.Unit unit in cat.GetUnits()) |
0 | 582 { |
583 store.AppendValues(iter, unit); | |
21 | 584 } |
0 | 585 } |
21 | 586 |
0 | 587 logger.Debug("Finished loading tree categories"); |
588 } | |
589 } | |
21 | 590 |
0 | 591 private void DisableCategoryButtons() |
592 { | |
593 SetCategoryButtonsSensitive(false); | |
594 } | |
21 | 595 |
0 | 596 private void EnableCategoryButtons() |
597 { | |
598 SetCategoryButtonsSensitive(true); | |
599 } | |
21 | 600 |
0 | 601 private void SetCategoryButtonsSensitive(bool state) |
602 { | |
603 int toolbarButtonCount = toolbar.Children.Length - 1; | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
604 logger.Debug("Last button index: " + toolbarButtonCount); |
21 | 605 |
0 | 606 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
607 { | |
608 logger.DebugFormat("Setting button {0} state to {1}", i, state); | |
609 toolbar.Children[i].Sensitive = state; | |
610 } | |
611 } | |
21 | 612 |
0 | 613 private void RemoveCategoryButtons() |
614 { | |
615 int toolbarButtonCount = toolbar.Children.Length - 1; | |
21 | 616 |
0 | 617 for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--) |
618 { | |
619 toolbar.Remove(toolbar.Children[i]); | |
620 } | |
621 } | |
21 | 622 |
0 | 623 private void AddCategoryButtons(Category[] cats) |
624 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
625 if (cats != null && cats.Length > 0) |
0 | 626 { |
627 logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length); | |
21 | 628 |
0 | 629 foreach (Category cat in cats) |
630 { | |
631 ToolButton button = new ToolButton("gtk-add"); | |
632 button.Label = cat.Name; | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
633 button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
634 button.Data["Category"] = cat; |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
635 button.Clicked += new System.EventHandler(OnAddUnitActivated); |
0 | 636 toolbar.Insert(button, -1); |
637 } | |
638 } | |
21 | 639 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
640 toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats != null && cats.Length > 0; |
21 | 641 |
0 | 642 toolbar.ShowAll(); |
643 } | |
21 | 644 |
0 | 645 private void SetPointsPanelText() |
646 { | |
99
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
647 if (WarFoundryCore.CurrentArmy != null) |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
648 { |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
649 lblTotalPoints.Text = Translation.GetTranslation("statusPanelPoints", "{0}pts of {1} pts", WarFoundryCore.CurrentArmy.Points, WarFoundryCore.CurrentArmy.MaxPoints); |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
650 } |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
651 else |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
652 { |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
653 lblTotalPoints.Text = ""; |
8777e4f64d8e
Fixes #335: Show current points total in status bar
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
654 } |
0 | 655 } |
21 | 656 |
13 | 657 private void commandStack_CommandStackUpdated() |
658 { | |
659 undoMenuButton.Sensitive = commandStack.CanUndo(); | |
660 miUndo.Sensitive = undoMenuButton.Sensitive; | |
661 redoMenuButton.Sensitive = commandStack.CanRedo(); | |
662 miRedo.Sensitive = redoMenuButton.Sensitive; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
663 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
664 RebuildUndoRedoMenus(); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
665 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
666 bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
667 miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
668 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
669 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
670 private void RebuildUndoRedoMenus() |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
671 { |
0 | 672 int redoLength = commandStack.RedoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
673 int maxRedo = Math.Min(10, redoLength); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
674 |
13 | 675 if (redoLength > 0) |
676 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
677 Menu menu = new Menu(); |
13 | 678 Command com; |
679 MenuItem mi; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
680 |
13 | 681 for (int i = 0; i < maxRedo; i++) |
682 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
683 com = commandStack.PeekRedoCommand(i + 1); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
684 |
13 | 685 if (com == null) |
686 { | |
21 | 687 break; |
13 | 688 } |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
689 |
13 | 690 mi = new MenuItem(com.Description); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
691 mi.Activated += new EventHandler(RedoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
692 menu.Append(mi); |
13 | 693 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
694 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
695 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
696 redoMenuButton.Menu = menu; |
13 | 697 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
698 else |
13 | 699 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
700 redoMenuButton.Menu = null; |
13 | 701 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
702 |
13 | 703 int undoLength = commandStack.UndoLength; |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
704 int maxUndo = Math.Min(10, undoLength); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
705 |
13 | 706 if (undoLength > 0) |
707 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
708 Menu menu = new Menu(); |
13 | 709 Command com; |
710 MenuItem mi; | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
711 |
13 | 712 for (int i = 0; i < maxUndo; i++) |
713 { | |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
714 com = commandStack.PeekUndoCommand(i + 1); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
715 |
13 | 716 if (com == null) |
717 { | |
21 | 718 break; |
13 | 719 } |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
720 |
13 | 721 mi = new MenuItem(com.UndoDescription); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
722 mi.Activated += new EventHandler(UndoMenuActivated); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
723 menu.Add(mi); |
13 | 724 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
725 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
726 menu.ShowAll(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
727 undoMenuButton.Menu = menu; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
728 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
729 else |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
730 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
731 undoMenuButton.Menu = null; |
13 | 732 } |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
733 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
734 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
735 private void RedoMenuActivated(object sender, EventArgs e) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
736 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
737 if (sender is MenuItem) |
13 | 738 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
739 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
740 //we know it's an redo menu item so find it's index and redo everything |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
741 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
742 int max = Arrays.IndexOf(((Menu)redoMenuButton.Menu).Children, item); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
743 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
744 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
745 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
746 for (int i = 0; i <= max; i++) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
747 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
748 commandStack.Redo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
749 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
750 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
751 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
752 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
753 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
754 private void UndoMenuActivated(object sender, EventArgs e) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
755 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
756 if (sender is MenuItem) |
0 | 757 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
758 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
759 MenuItem item = (MenuItem)sender; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
760 //we know it's an undo menu item so find it's index and undo everything |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
761 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
762 int max = Arrays.IndexOf(((Menu)undoMenuButton.Menu).Children, item); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
763 |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
764 if (max >= 0) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
765 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
766 for (int i = 0; i <= max; i++) |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
767 { |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
768 commandStack.Undo(); |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
769 } |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
770 } |
0 | 771 } |
13 | 772 } |
773 | |
774 private bool SaveCurrentArmyOrSaveAs() | |
775 { | |
33 | 776 if (loadedArmyPath != null) |
13 | 777 { |
778 return SaveCurrentArmy(); | |
779 } | |
21 | 780 else |
13 | 781 { |
782 return SaveCurrentArmyAs(); | |
783 } | |
0 | 784 } |
21 | 785 |
0 | 786 private bool OpenArmy() |
787 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
788 string title = Translation.GetTranslation("openArmyDialog", "open army"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
789 string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
790 string openText = Translation.GetTranslation("bttnOpen", "open"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
791 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
792 FileFilter filter = new FileFilter(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
793 filter.AddPattern("*.army"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
794 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
795 fileDialog.AddFilter(filter); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
796 int response = fileDialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
797 string filePath = null; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
798 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
799 if (response == (int)ResponseType.Accept) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
800 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
801 filePath = fileDialog.Filename; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
802 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
803 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
804 fileDialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
805 fileDialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
806 |
0 | 807 bool success = false; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
808 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
809 if (filePath != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
810 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
811 FileInfo file = new FileInfo(filePath); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
812 Army army = null; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
813 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
814 try |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
815 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
816 army = WarFoundryLoader.GetDefault().LoadArmy(file); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
817 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
818 catch (Exception ex) |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
819 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
820 logger.Error("Error while loading army file " + filePath, ex); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
821 } |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
822 |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
823 if (army != null) |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
824 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
825 logger.Debug("Loaded army " + army.ID); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
826 success = true; |
33 | 827 WarFoundryCore.CurrentArmy = army; |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
828 loadedArmyPath = filePath; |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
829 logger.Debug("Army loading complete"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
830 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
831 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
832 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
833 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("OpenFailed", "File open failed. Please check log file")); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
834 dialog.Title = Translation.GetTranslation("OpenFailedTitle", "File open failed"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
835 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
836 dialog.Hide(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
837 dialog.Dispose(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
838 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
839 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
840 else |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
841 { |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
842 logger.Debug("Army open requested but cancelled"); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
843 } |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
844 |
0 | 845 return success; |
13 | 846 } |
847 | |
848 private bool SaveCurrentArmy() | |
0 | 849 { |
850 bool success = false; | |
21 | 851 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
852 if (loadedArmyPath != null) |
0 | 853 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
854 success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); |
0 | 855 } |
21 | 856 |
13 | 857 return success; |
858 } | |
859 | |
860 private bool SaveCurrentArmyAs() | |
861 { | |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
862 string title = Translation.GetTranslation("saveArmyDialog", "save army"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
863 string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
864 string saveText = Translation.GetTranslation("bttnSave", "save"); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
865 FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, saveText, ResponseType.Accept); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
866 FileFilter filter = new FileFilter(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
867 filter.AddPattern("*.army"); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
868 filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
869 fileDialog.AddFilter(filter); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
870 int response = fileDialog.Run(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
871 string filePath = null; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
872 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
873 if (response == (int)ResponseType.Accept) |
13 | 874 { |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
875 filePath = fileDialog.Filename; |
13 | 876 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
877 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
878 fileDialog.Hide(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
879 fileDialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
880 |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
881 return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
882 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
883 |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
884 private bool SaveArmyToPath(Army army, string filePath) |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
885 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
886 bool success = false; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
887 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
888 if (filePath != null) |
13 | 889 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
890 bool saveSuccess = false; |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
891 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
892 try |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
893 { |
106
41e82ba675dc
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
894 saveSuccess = WarFoundrySaver.GetSaver().Save(filePath, WarFoundryCore.CurrentArmy); |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
895 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
896 catch (Exception ex) |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
897 { |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
898 logger.Error("Error while saving army file to " + filePath, ex); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
899 } |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
900 |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
901 if (saveSuccess) |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
902 { |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
903 miSaveArmy.Sensitive = false; |
82
fb16ca1cb52b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
81
diff
changeset
|
904 bttnSaveArmy.Sensitive = false; |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
905 CommandStack.setCleanMark(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
906 loadedArmyPath = filePath; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
907 success = true; |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
908 } |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
909 else |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
910 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
911 MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("SaveFailed", "File save failed. Please check log file")); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
912 dialog.Title = Translation.GetTranslation("SaveFailedTitle", "File save failed"); |
25
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
913 dialog.Run(); |
01ddadfa9653
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
23
diff
changeset
|
914 dialog.Hide(); |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
915 dialog.Dispose(); |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
916 } |
21 | 917 } |
23
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
918 //else user cancelled |
d661cb257511
Re #86: Initial GTK# GUI (because of Re #53)
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
919 |
21 | 920 return success; |
0 | 921 } |
21 | 922 |
13 | 923 private bool CloseCurrentArmy() |
924 { | |
42
35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
41
diff
changeset
|
925 if (WarFoundryCore.CurrentArmy != null) |
13 | 926 { |
927 bool canClose = false; | |
928 | |
929 if (CommandStack.IsDirty()) | |
0 | 930 { |
98
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
931 string message = Translation.GetTranslation("SaveChangesQuestion", "Save changes to army before closing?", WarFoundryCore.CurrentArmy.Name); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
932 MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.None, message); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
933 dia.AddButton(Translation.GetTranslation("bttnDiscard", "lose changes"), ResponseType.No); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
934 Button button = (Button)dia.AddButton(Translation.GetTranslation("bttnCancel", "cancel"), ResponseType.Cancel); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
935 button.Image = new Image("gtk-cancel", IconSize.Button); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
936 button = (Button)dia.AddButton(Translation.GetTranslation("bttnSave", "save"), ResponseType.Yes); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
937 button.Image = new Image("gtk-save", IconSize.Button); |
fac0636ae13b
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
938 dia.Title = Translation.GetTranslation("SaveChangesTitle", "Save changes?"); |
0 | 939 ResponseType dr = (ResponseType)dia.Run(); |
27
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
940 dia.Hide(); |
83c8945edac2
Re #143: GTK "Army has been modified" dialog has no buttons
IBBoard <dev@ibboard.co.uk>
parents:
26
diff
changeset
|
941 dia.Dispose(); |
0 | 942 |
13 | 943 if (dr == ResponseType.Yes) |
0 | 944 { |
945 //They want to save so try to save it or prompt for save as | |
13 | 946 //If they cancel the save as then assume they don't want to close |
947 canClose = SaveCurrentArmyOrSaveAs(); | |
948 } | |
0 | 949 else |
950 { | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
951 if (dr == ResponseType.No) |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
952 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
953 //They don't care about their changes |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
954 canClose = true; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
955 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
956 else |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
957 { |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
958 //Assume cancel or close with the X button |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
959 canClose = false; |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
960 } |
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
961 |
0 | 962 } |
13 | 963 } |
964 else | |
965 { | |
966 //Nothing has changed so we can safely close | |
967 canClose = true; | |
968 } | |
969 | |
970 if (canClose) | |
0 | 971 { |
13 | 972 //do close |
973 WarFoundryCore.CurrentArmy = null; | |
974 return true; | |
975 } | |
976 else | |
977 { | |
978 return false; | |
979 } | |
980 } | |
981 else | |
982 { | |
983 //pretend we succeeded | |
984 return true; | |
985 } | |
986 } | |
987 | |
988 private void CreateNewArmy() | |
0 | 989 { |
990 logger.Debug("Create new army"); | |
991 FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); | |
992 ResponseType type = (ResponseType)newArmy.Run(); | |
993 newArmy.Hide(); | |
21 | 994 |
0 | 995 if (type == ResponseType.Ok) |
13 | 996 { |
997 if (CloseCurrentArmy()) | |
0 | 998 { |
999 WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | |
1000 } | |
1001 } | |
1002 else | |
1003 { | |
1004 logger.Debug("Create new army cancelled"); | |
1005 } | |
21 | 1006 |
13 | 1007 newArmy.Destroy(); |
0 | 1008 } |
21 | 1009 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1010 protected virtual void undoTBButtonActivated(object sender, System.EventArgs e) |
0 | 1011 { |
1012 CommandStack.Undo(); | |
1013 } | |
1014 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1015 protected virtual void redoTBButtonActivated(object sender, System.EventArgs e) |
0 | 1016 { |
1017 CommandStack.Redo(); | |
1018 } | |
1019 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1020 protected virtual void saveTBButtonActivated(object sender, System.EventArgs e) |
0 | 1021 { |
33 | 1022 SaveCurrentArmyOrSaveAs(); |
0 | 1023 } |
1024 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1025 protected virtual void openTBButtonActivated(object sender, System.EventArgs e) |
0 | 1026 { |
1027 OpenArmy(); | |
1028 } | |
1029 | |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1030 protected virtual void newTBButtonActivated(object sender, System.EventArgs e) |
0 | 1031 { |
1032 CreateNewArmy(); | |
1033 } | |
1034 | |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1035 protected virtual void ArmyRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 1036 { |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1037 object obj = TreeUtils.GetItemAtPath(treeUnits, args.Path); |
21 | 1038 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1039 if (obj is WFObjects.Unit) |
0 | 1040 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1041 WFObjects.Unit unit = (WFObjects.Unit)obj; |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1042 ShowUnitWidget(unit); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1043 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1044 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1045 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1046 private void ShowUnitWidget(WFObjects.Unit unit) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1047 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1048 UnitDisplayWidget widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1049 unitToWidgetMap.TryGetValue(unit, out widget); |
21 | 1050 |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1051 if (widget != null) |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1052 { |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1053 logger.DebugFormat("Selecting existing page for " + unit.Name); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1054 unitsNotebook.Page = unitsNotebook.PageNum(widget); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1055 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1056 else |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1057 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1058 widget = new UnitDisplayWidget(unit, CommandStack); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1059 logger.Debug("Adding page for " + unit.Name); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1060 unitToWidgetMap[unit] = widget; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1061 int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1062 logger.Debug("Page added at index " + pageNum); |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1063 unitsNotebook.ShowAll(); |
46
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1064 unitsNotebook.CurrentPage = pageNum; |
3314f6a46661
Fixes #138: Re-implement menu for undo/redo
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
1065 unitsNotebook.SetTabReorderable(widget, true); |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1066 } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
14
diff
changeset
|
1067 } |
28 | 1068 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1069 protected virtual void OnMiExportAsBasicHtmlActivated(object sender, System.EventArgs e) |
28 | 1070 { |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1071 string exportArmyTitle = Translation.GetTranslation("exportBasicHtmlDialogTitle", "export army"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1072 string cancelText = Translation.GetTranslation("exportBasicHtmlCancel", "cancel"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1073 string exportText = Translation.GetTranslation("exportBasicHtmlExport", "export"); |
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1074 FileChooserDialog fileDialog = new FileChooserDialog(exportArmyTitle, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, exportText, ResponseType.Accept); |
28 | 1075 FileFilter filter = new FileFilter(); |
1076 filter.AddPattern("*.html"); | |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1077 filter.Name = Translation.GetTranslation("exportBasicHtmlHtmlFilter", "HTML pages (*.html)"); |
28 | 1078 fileDialog.AddFilter(filter); |
1079 int response = fileDialog.Run(); | |
1080 string filePath = null; | |
1081 | |
1082 if (response == (int)ResponseType.Accept) | |
1083 { | |
1084 filePath = fileDialog.Filename; | |
1085 } | |
1086 | |
1087 fileDialog.Hide(); | |
1088 fileDialog.Dispose(); | |
1089 | |
1090 if (filePath != null) | |
1091 { | |
1092 Army army = WarFoundryCore.CurrentArmy; | |
1093 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1094 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1095 } | |
1096 } | |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1097 |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1098 protected virtual void OnTreeUnitsPopupMenu(object o, Gtk.PopupMenuArgs args) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1099 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1100 object selectedItem = TreeUtils.GetSelectedItem(treeUnits); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1101 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1102 if (selectedItem is WFObjects.Unit) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1103 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1104 Menu menu = new Menu(); |
83
678e9a0392fc
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1105 ImageMenuItem delete = new ImageMenuItem(Translation.GetTranslation("menuRemoveUnit", "remove unit")); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1106 delete.Image = new Gtk.Image(Stock.Delete, IconSize.Menu); |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1107 delete.Activated += new EventHandler(OnUnitDelete); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1108 delete.Data["unit"] = selectedItem; |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1109 menu.Append(delete); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1110 menu.ShowAll(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1111 menu.Popup(); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1112 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1113 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1114 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1115 private void OnUnitDelete(object o, EventArgs args) |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1116 { |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1117 RemoveUnitCommand command = new RemoveUnitCommand((WFObjects.Unit)((ImageMenuItem)o).Data["unit"]); |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1118 commandStack.Execute(command); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1119 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1120 |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1121 [GLib.ConnectBefore] |
69
3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
1122 |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1123 protected virtual void UnitTreeButtonPressed(object o, Gtk.ButtonPressEventArgs args) |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1124 { |
44
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1125 TreePath path; |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1126 treeUnits.GetPathAtPos((int)args.Event.X, (int)args.Event.Y, out path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1127 |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1128 if (!treeUnits.Selection.PathIsSelected(path)) |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1129 { |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1130 treeUnits.Selection.SelectPath(path); |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1131 } |
44e6833bb41a
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
1132 |
30
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1133 if (args.Event.Type == Gdk.EventType.ButtonPress && args.Event.Button == 3) |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1134 { |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1135 OnTreeUnitsPopupMenu(o, null); |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1136 } |
5fafbb1b4592
Re #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
29
diff
changeset
|
1137 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1138 |
45
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1139 protected virtual void NotebookPageRemoved(object o, Gtk.RemovedArgs args) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1140 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1141 Widget widget = args.Widget; |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1142 |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1143 if (widget is UnitDisplayWidget) |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1144 { |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1145 unitToWidgetMap.Remove(((UnitDisplayWidget)widget).Unit); |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1146 } |
5584860fb44b
Fixes #145: Add UI to remove units from army
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
1147 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1148 |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1149 protected virtual void HelpAboutActivated(object sender, System.EventArgs e) |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1150 { |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1151 FrmAbout form = FrmAbout.GetForm(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1152 form.Run(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1153 form.Hide(); |
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
74
diff
changeset
|
1154 } |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1155 |
95
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1156 protected virtual void miPreferencesClicked(object sender, System.EventArgs e) |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1157 { |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1158 FrmPreferences form = new FrmPreferences(Preferences); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1159 form.Run(); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1160 form.Hide(); |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1161 } |
ea4069bbe6e9
Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
83
diff
changeset
|
1162 |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
1163 public override ICollection<Gtk.Action> Actions |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1164 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1165 get |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1166 { |
103
1bd748721040
* Resolve conflict of System.Action vs Gtk.Action
IBBoard <dev@ibboard.co.uk>
parents:
99
diff
changeset
|
1167 List<Gtk.Action> actions = new List<Gtk.Action>(); |
79
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1168 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1169 foreach (ActionGroup actionGroup in this.UIManager.ActionGroups) |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1170 { |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1171 actions.AddRange(actionGroup.ListActions()); |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1172 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1173 |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1174 return actions; |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1175 } |
592930d28da4
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
78
diff
changeset
|
1176 } |
0 | 1177 } |
1178 } |