Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
23 changes: 20 additions & 3 deletions src/BalisticaApplication.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
} ;

/**
Expand Down Expand Up @@ -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
*/
Expand Down
78 changes: 75 additions & 3 deletions src/DragBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;
Expand Down Expand Up @@ -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
*/
Expand Down
3 changes: 1 addition & 2 deletions src/PreferencesWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()) ;
Expand Down
10 changes: 10 additions & 0 deletions ui/menu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<menu id="appmenu">
<section>
<item>
<attribute name="label" translatable="yes">Open</attribute>
<attribute name="action">app.open</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save</attribute>
<attribute name="action">app.save</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Preferences</attribute>
Expand Down