mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-25 13:25:37 +00:00
Added filters to file chooser dialogs.
Add .txt when saving files if it's not present (fixes a Windows bug when the default drive name is cleared by typing something else).
This commit is contained in:
+1
-4
@@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -198,15 +198,28 @@ void GscExecutorLogWindow::on_window_save_current_button_clicked()
|
||||
}
|
||||
int result = 0;
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Text Files");
|
||||
specific_filter->add_pattern("*.txt");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Text Files");
|
||||
specific_filter->add_pattern("*.txt");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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);
|
||||
|
||||
@@ -1789,12 +1789,23 @@ void GscInfoWindow::on_save_info_button_clicked()
|
||||
|
||||
std::string filename = drive->get_save_filename();
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Text Files");
|
||||
specific_filter->add_pattern("*.txt");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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()) {
|
||||
|
||||
@@ -1311,10 +1311,21 @@ void GscMainWindow::show_load_virtual_file_chooser()
|
||||
}
|
||||
int result = 0;
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Text Files");
|
||||
specific_filter->add_pattern("*.txt");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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);
|
||||
|
||||
|
||||
@@ -576,6 +576,16 @@ void GscPreferencesWindow::on_smartctl_binary_browse_button_clicked()
|
||||
|
||||
int result = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
Glib::RefPtr<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Executable Files");
|
||||
specific_filter->add_pattern("*.exe");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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.
|
||||
|
||||
@@ -147,12 +147,23 @@ class GscTextWindow : public AppUIResWidget<GscTextWindow<InstanceSwitch>, Insta
|
||||
}
|
||||
int result = 0;
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> specific_filter = Gtk::FileFilter::create();
|
||||
specific_filter->set_name("Text Files");
|
||||
specific_filter->add_pattern("*.txt");
|
||||
|
||||
Glib::RefPtr<Gtk::FileFilter> 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<GtkFileChooserNative> 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<GscTextWindow<InstanceSwitch>, 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<GscTextWindow<InstanceSwitch>, 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);
|
||||
|
||||
Reference in New Issue
Block a user