diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index 715a1cc..3f45008 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -48,10 +48,7 @@ Per-line selftest error highlighting. Tab highlighting according to error severity. Increase tab sizes in Windows. - -Check why temperature is not SCT by default. - -add .txt to saved output files. + Info and Prefs windows. diff --git a/gsmartcontrol/src/gsc_executor_log_window.cpp b/gsmartcontrol/src/gsc_executor_log_window.cpp index 222fa58..fb43b66 100644 --- a/gsmartcontrol/src/gsc_executor_log_window.cpp +++ b/gsmartcontrol/src/gsc_executor_log_window.cpp @@ -198,15 +198,28 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() } int result = 0; + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Text Files"); + specific_filter->add_pattern("*.txt"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); + if (!last_dir.empty()) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog.get()), ".txt"); + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); #else @@ -219,9 +232,14 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() dialog.set_do_overwrite_confirmation(true); + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); + if (!last_dir.empty()) dialog.set_current_folder(last_dir); + dialog.set_current_name(".txt"); + // Show the dialog and wait for a user response result = dialog.run(); // the main cycle blocks here #endif @@ -240,6 +258,10 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked() #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); + if (file.rfind(".txt") != (file.size() - std::strlen(".txt"))) { + file += ".txt"; + } + hz::File f(file); if (!f.put_contents(entry->std_output)) { gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this); @@ -293,15 +315,28 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() } int result = 0; + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Text Files"); + specific_filter->add_pattern("*.txt"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); + if (!last_dir.empty()) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog.get()), ".txt"); + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); #else @@ -314,9 +349,14 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() dialog.set_do_overwrite_confirmation(true); + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); + if (!last_dir.empty()) dialog.set_current_folder(last_dir); + dialog.set_current_name(".txt"); + // Show the dialog and wait for a user response result = dialog.run(); // the main cycle blocks here #endif @@ -335,6 +375,10 @@ void GscExecutorLogWindow::on_window_save_all_button_clicked() #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); + if (file.rfind(".txt") != (file.size() - std::strlen(".txt"))) { + file += ".txt"; + } + hz::File f(file); if (!f.put_contents(exss.str())) { gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this); diff --git a/gsmartcontrol/src/gsc_info_window.cpp b/gsmartcontrol/src/gsc_info_window.cpp index 525863d..7adba15 100644 --- a/gsmartcontrol/src/gsc_info_window.cpp +++ b/gsmartcontrol/src/gsc_info_window.cpp @@ -1789,12 +1789,23 @@ void GscInfoWindow::on_save_info_button_clicked() std::string filename = drive->get_save_filename(); + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Text Files"); + specific_filter->add_pattern("*.txt"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); + if (!last_dir.empty()) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); @@ -1813,6 +1824,9 @@ void GscInfoWindow::on_save_info_button_clicked() dialog.set_do_overwrite_confirmation(true); + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); + if (!last_dir.empty()) dialog.set_current_folder(last_dir); @@ -1837,6 +1851,10 @@ void GscInfoWindow::on_save_info_button_clicked() #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); + if (file.rfind(".txt") != (file.size() - std::strlen(".txt"))) { + file += ".txt"; + } + hz::File f(file); std::string data = this->drive->get_full_output(); if (data.empty()) { diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index 6c6bddf..d1f7097 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -1311,10 +1311,21 @@ void GscMainWindow::show_load_virtual_file_chooser() } int result = 0; + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Text Files"); + specific_filter->add_pattern("*.txt"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Load Data From...", this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL), g_object_unref); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); + if (!last_dir.empty()) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); } @@ -1329,6 +1340,9 @@ void GscMainWindow::show_load_virtual_file_chooser() dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); + if (!last_dir.empty()) dialog.set_current_folder(last_dir); diff --git a/gsmartcontrol/src/gsc_preferences_window.cpp b/gsmartcontrol/src/gsc_preferences_window.cpp index 9d23ad8..45c004e 100644 --- a/gsmartcontrol/src/gsc_preferences_window.cpp +++ b/gsmartcontrol/src/gsc_preferences_window.cpp @@ -576,6 +576,16 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked() int result = 0; +#ifdef _WIN32 + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Executable Files"); + specific_filter->add_pattern("*.exe"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); +#endif + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Choose Smartctl Binary...", this->gobj(), GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL), g_object_unref); @@ -583,6 +593,11 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked() if (path.is_absolute()) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog.get()), path.c_str()); +#ifdef _WIN32 + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); +#endif + result = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog.get())); #else @@ -593,6 +608,11 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked() dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); +#ifdef _WIN32 + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); +#endif + // Note: This works on absolute paths only (otherwise it's gtk warning). if (path.is_absolute()) dialog.set_filename(path.str()); // change to its dir and select it if exists. diff --git a/gsmartcontrol/src/gsc_text_window.h b/gsmartcontrol/src/gsc_text_window.h index bb7a7e0..b9da5e2 100644 --- a/gsmartcontrol/src/gsc_text_window.h +++ b/gsmartcontrol/src/gsc_text_window.h @@ -147,12 +147,23 @@ class GscTextWindow : public AppUIResWidget, Insta } int result = 0; + Glib::RefPtr specific_filter = Gtk::FileFilter::create(); + specific_filter->set_name("Text Files"); + specific_filter->add_pattern("*.txt"); + + Glib::RefPtr all_filter = Gtk::FileFilter::create(); + all_filter->set_name("All Files"); + all_filter->add_pattern("*"); + #if GTK_CHECK_VERSION(3, 20, 0) hz::scoped_ptr dialog(gtk_file_chooser_native_new( "Save Data As...", this->gobj(), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL), g_object_unref); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog.get()), true); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), specific_filter->gobj()); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj()); + if (!last_dir.empty()) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog.get()), last_dir.c_str()); @@ -171,6 +182,9 @@ class GscTextWindow : public AppUIResWidget, Insta dialog.set_do_overwrite_confirmation(true); + dialog.add_filter(specific_filter); + dialog.add_filter(all_filter); + if (!last_dir.empty()) dialog.set_current_folder(last_dir); @@ -195,6 +209,10 @@ class GscTextWindow : public AppUIResWidget, Insta #endif rconfig::set_data("gui/drive_data_open_save_dir", last_dir); + if (file.rfind(".txt") != (file.size() - std::strlen(".txt"))) { + file += ".txt"; + } + hz::File f(file); if (!f.put_contents(this->contents_)) { // this will send to debug_ too. gui_show_error_dialog("Cannot save data to file", f.get_error_utf8(), this);