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