Compare commits

...
Author SHA1 Message Date
anthropic-code-agent[bot]andashaduri c940b200c1 Fix Save log as txt from View Output window
Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com>
2026-03-04 21:54:59 +00:00
anthropic-code-agent[bot] 5ba5928210 Initial plan 2026-03-04 21:49:39 +00:00
2 changed files with 41 additions and 1 deletions
+3
View File
@@ -828,6 +828,9 @@ void GscInfoWindow::on_view_output_button_clicked()
if (!filename.empty())
win->set_save_filename(filename);
// Pass the drive pointer so text output can be accessed when saving
win->set_drive(drive_);
win->show();
}
+38 -1
View File
@@ -24,6 +24,7 @@ Copyright:
#include "applib/app_builder_widget.h"
#include "applib/app_gtkmm_tools.h"
#include "applib/storage_device.h"
@@ -130,6 +131,13 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
}
/// Set the drive pointer for accessing text output when saving
void set_drive(const StorageDevicePtr& drive)
{
drive_ = drive;
}
protected:
@@ -163,6 +171,14 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
specific_filter->add_pattern("*.json");
specific_filter->add_pattern("*.txt");
Glib::RefPtr<Gtk::FileFilter> json_filter = Gtk::FileFilter::create();
json_filter->set_name(_("JSON Files"));
json_filter->add_pattern("*.json");
Glib::RefPtr<Gtk::FileFilter> txt_filter = Gtk::FileFilter::create();
txt_filter->set_name(_("Text Files"));
txt_filter->add_pattern("*.txt");
Glib::RefPtr<Gtk::FileFilter> all_filter = Gtk::FileFilter::create();
all_filter->set_name(_("All Files"));
all_filter->add_pattern("*");
@@ -175,6 +191,8 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
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()), json_filter->gobj());
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), txt_filter->gobj());
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog.get()), all_filter->gobj());
if (!last_dir.empty())
@@ -196,6 +214,8 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
dialog.set_do_overwrite_confirmation(true);
dialog.add_filter(specific_filter);
dialog.add_filter(json_filter);
dialog.add_filter(txt_filter);
dialog.add_filter(all_filter);
if (!last_dir.empty())
@@ -222,16 +242,31 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
#endif
rconfig::set_data("gui/drive_data_open_save_dir", last_dir);
bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj();
if (file.extension() != ".json" && file.extension() != ".txt") {
file += ".json";
file += (txt_selected ? ".txt" : ".json");
}
bool save_txt = txt_selected || file.extension() == ".txt";
std::string text;
if (std::holds_alternative<std::string>(contents_)) {
text = std::get<std::string>(contents_);
} else {
text = std::get<Glib::ustring>(contents_);
}
// If saving as text and drive is available, try to get text-formatted output
if (save_txt && drive_) {
if (auto p = drive_->get_property_repository().lookup_property("smartctl/output"); !p.empty()) {
const std::string text_output = p.get_value<std::string>();
if (!text_output.empty()) {
text = text_output;
}
}
}
auto ec = hz::fs_file_put_contents(file, text);
if (ec) {
gui_show_error_dialog(_("Cannot save data to file"), ec.message(), this);
@@ -269,6 +304,8 @@ class GscTextWindow : public AppBuilderWidget<GscTextWindow<InstanceSwitch>, Ins
std::string save_filename_; ///< Default filename for Save As
StorageDevicePtr drive_; ///< Drive pointer for accessing text output (optional)
};