Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
diff FrmMainWindow.cs @ 25:01ddadfa9653
Re #86: Complete initial GTK# UI
* Enable "open" buttons
* Fill out "open" method
* Fix showing of "save failed" dialog
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 22 Aug 2009 19:48:03 +0000 |
parents | d661cb257511 |
children | 3a396783bfed |
line wrap: on
line diff
--- a/FrmMainWindow.cs Sat Aug 22 19:10:45 2009 +0000 +++ b/FrmMainWindow.cs Sat Aug 22 19:48:03 2009 +0000 @@ -689,9 +689,52 @@ private bool OpenArmy() { - //TODO: Open dialog for file selection then open army + FileChooserDialog fileDialog = new FileChooserDialog("Open army", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); + FileFilter filter = new FileFilter(); + filter.AddPattern("*.army"); + filter.Name = "WarFoundry Army files (*.army)"; + fileDialog.AddFilter(filter); + int response = fileDialog.Run(); + string filePath = null; + + if (response == (int)ResponseType.Accept) + { + filePath = fileDialog.Filename; + } + + fileDialog.Hide(); + fileDialog.Dispose(); + bool success = false; - loadedArmyPath = null;//TODO: Set loaded file path + + if (filePath != null) + { + FileInfo file = new FileInfo(filePath); + Army army = WarFoundryLoader.GetDefault().LoadArmy(file); + + if (army != null) + { + logger.Debug("Loaded army " + army.ID); + success = true; + loadedArmyPath = filePath; + WarFoundryCore.CurrentArmy = army; + logger.Debug("Army loading complete"); + } + else + { + logger.ErrorFormat("Failed to load {0} as an army file", filePath); + MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, file.Name + " could not be loaded.\n\nIf the file is an army file then please check your file loaders."); + dialog.Title = "Failed to open army"; + dialog.Run(); + dialog.Hide(); + dialog.Dispose(); + } + } + else + { + logger.Debug("Army open requested but cancelled"); + } + return success; } @@ -709,7 +752,6 @@ private bool SaveCurrentArmyAs() { - FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); FileFilter filter = new FileFilter(); filter.AddPattern("*.army"); @@ -746,7 +788,9 @@ else { MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath); - dialog.Show(); + dialog.Title = "Army save failed"; + dialog.Run(); + dialog.Hide(); dialog.Dispose(); } }