diff --git a/NEWS b/NEWS index 8a70ef1..7ff97e4 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +Version 1.5 +============================ +* New settings dialog +* Further refinement of redesigned UI + +Version 1.4 +============================ +* Redo GUI to be more Gnome-like +* Minor cleanup + Version 1.3 ============================ * Switch to Meson build system @@ -11,7 +21,7 @@ Version 1.3 Version 1.2 ============================ * Corrected PBR calculation -* The main page's tabs now are on the right side instead of the top +* The main page's tabs now are on the right side instead of the top in anticipation of the database Version 1.1 diff --git a/src/BalisticaApplication.vala b/src/BalisticaApplication.vala index 2e88a76..aaf9284 100644 --- a/src/BalisticaApplication.vala +++ b/src/BalisticaApplication.vala @@ -29,11 +29,14 @@ public class Application : Gtk.Application { private const GLib.ActionEntry[] action_entries = { - { "about", about_cb }, - { "help", help_cb }, + // Ordered as they appear in the menu + { "open", open_cb }, + { "save", save_cb }, { "preferences", preferences_cb }, - { "quit", quit_cb }, { "view_log", view_log_cb }, + { "help", help_cb }, + { "about", about_cb }, + { "quit", quit_cb }, } ; /** @@ -182,6 +185,20 @@ public class Application : Gtk.Application { } } + /** + * Open a saved calculation + */ + private void open_cb() { + this.drag_content.openCalculation (this.settings.get_string ("save-directory")) ; + } + + /** + * Save the currnet calculation + */ + private void save_cb() { + this.drag_content.saveCalculation (this.settings.get_string ("save-directory")) ; + } + /** * Show preferences dialog */ diff --git a/src/DragBox.vala b/src/DragBox.vala index cb0ea11..3b685b6 100644 --- a/src/DragBox.vala +++ b/src/DragBox.vala @@ -314,12 +314,12 @@ public class Balistica.DragBox : Gtk.Box { } // Create a save as dialog - Gtk.FileChooserDialog save_dialog = new Gtk.FileChooserDialog ("Save As", + Gtk.FileChooserDialog save_dialog = new Gtk.FileChooserDialog ("_Save As", this.main_window as Gtk.Window, Gtk.FileChooserAction.SAVE, - "Cancel", + "_Cancel", Gtk.ResponseType.CANCEL, - "Save", + "_Save", Gtk.ResponseType.ACCEPT) ; save_dialog.set_default_response (Gtk.ResponseType.ACCEPT) ; @@ -447,6 +447,78 @@ public class Balistica.DragBox : Gtk.Box { this.txtWind_angle.set_text ("0") ; } + /** + * Save the current calculation + */ + public void saveCalculation(string default_save_location) { + // Don't let them save a null result + if( lsln == null ){ + return ; + } + + var save_dialog = new Gtk.FileChooserDialog ("Save current calculation", this.main_window, + Gtk.FileChooserAction.SAVE, + "_Cancel", Gtk.ResponseType.CANCEL, + "_Select", Gtk.ResponseType.ACCEPT) ; + save_dialog.set_current_folder (default_save_location) ; + save_dialog.select_multiple = false ; + if( save_dialog.run () == Gtk.ResponseType.ACCEPT ){ + GLib.File ? file ; + string filename = "" ; + filename = save_dialog.get_filename () ; + if( !filename.has_suffix (".balistica")){ + save_dialog.set_current_name (filename + ".balistica") ; + } + file = save_dialog.get_file () ; + + // If the file already exists, delete it and write a new one + if( file.query_exists ()){ + try { + file.delete () ; + } catch ( Error err ){ + logger.publish (new LogMsg ("Failed to overwrite existing file")) ; + return ; + } + } + + // Prevent null file errors + if( file != null ){ + try { + (save_dialog as Gtk.FileChooser).set_file (file) ; + } catch ( GLib.Error err ){ + logger.publish (new LogMsg ("Error selecting file to save as")) ; + return ; + } + } + + string data = ""; + try { + var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION)); + dos.put_string(data); + } catch ( GLib.Error err ){ + save_dialog.close () ; + logger.publish (new LogMsg ("Error calculation")) ; + return ; + } + } + save_dialog.destroy () ; + } + + /** + * Open a saved calculation + */ + public void openCalculation(string default_save_location) { + var file_chooser = new Gtk.FileChooserDialog ("Choose saved calculation", this.main_window, + Gtk.FileChooserAction.OPEN, + "_Cancel", Gtk.ResponseType.CANCEL, + "_Select", Gtk.ResponseType.ACCEPT) ; + file_chooser.set_current_folder (default_save_location) ; + if( file_chooser.run () == Gtk.ResponseType.ACCEPT ){ + // TODO + } + file_chooser.destroy () ; + } + /** * Clear results grid so a different calculation can be displayed */ diff --git a/src/PreferencesWindow.vala b/src/PreferencesWindow.vala index d056d04..c1e0786 100644 --- a/src/PreferencesWindow.vala +++ b/src/PreferencesWindow.vala @@ -66,10 +66,9 @@ public class Balistica.PreferencesWindow : Gtk.Window { [GtkCallback] public void btnChangeSaveDir_clicked() { var file_chooser = new Gtk.FileChooserDialog ("Choose save location", this, - Gtk.FileChooserAction.OPEN, + Gtk.FileChooserAction.SELECT_FOLDER, "_Cancel", Gtk.ResponseType.CANCEL, "_Select", Gtk.ResponseType.ACCEPT) ; - file_chooser.set_action (Gtk.FileChooserAction.SELECT_FOLDER) ; if( file_chooser.run () == Gtk.ResponseType.ACCEPT ){ txtSaveDir.set_text (file_chooser.get_current_folder ()) ; this.settings.set_string ("save-directory", file_chooser.get_current_folder ()) ; diff --git a/ui/menu.ui b/ui/menu.ui index 1dbda0f..d4e1567 100644 --- a/ui/menu.ui +++ b/ui/menu.ui @@ -2,6 +2,16 @@ +
+ + Open + app.open + + + Save + app.save + +
Preferences