Fix Save As txt format from View Output window#105
Conversation
Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the “View Output” window’s Save As behavior so users can actually save text output as .txt (and not always JSON), aligning it with the Device Info window’s save format selection behavior.
Changes:
- Added separate “JSON Files” and “Text Files” filters to the View Output window’s Save As dialog and used the selected filter to choose output format/extension.
- Enabled saving text-formatted smartctl output by passing the drive pointer into
GscTextWindowand reading"smartctl/output"from the property repository when saving as text. - Updated
GscInfoWindowto provide theStorageDevicePtrto the View Output window.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/gui/gsc_text_window.h | Adds filter-based save format selection and optional drive-backed retrieval of text output for .txt saves. |
| src/gui/gsc_info_window.cpp | Passes the drive pointer into the View Output window to enable text-output saves. |
|
|
||
| bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj(); |
There was a problem hiding this comment.
txt_selected is computed via gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())), but in the #else branch (Gtk::FileChooserDialog dialog(...)) there is no dialog.get(). This will fail to compile when building against GTK < 3.20. Please make the filter query conditional: use gtk_file_chooser_get_filter() only in the GtkFileChooserNative branch, and use the gtkmm API (e.g., dialog.get_filter() compared to txt_filter) in the Gtk::FileChooserDialog branch.
| bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj(); | |
| #if GTK_CHECK_VERSION(3, 20, 0) | |
| bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj(); | |
| #else | |
| bool txt_selected = dialog.get_filter() == txt_filter; | |
| #endif |
| if (file.extension() != ".json" && file.extension() != ".txt") { | ||
| file += ".json"; | ||
| file += (txt_selected ? ".txt" : ".json"); | ||
| } |
There was a problem hiding this comment.
The extension checks are case-sensitive (.txt/.json). On Windows it’s easy to end up with .TXT / .JSON, which would be treated as “no recognized extension” and cause an extra extension to be appended (e.g. file.TXT.json). Normalize the extension (e.g. lowercase) before comparisons to avoid surprising filenames.
| bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj(); | ||
|
|
There was a problem hiding this comment.
txt_selected uses gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())), but dialog is a Gtk::FileChooserDialog (no .get()) when GTK_CHECK_VERSION(3, 20, 0) is false. This makes the <3.20 build path fail to compile. Compute the selected filter inside the same #if/#else branches (e.g., use dialog.get_filter() in the Gtk::FileChooserDialog branch).
| if (file.extension() != ".json" && file.extension() != ".txt") { | ||
| file += ".json"; | ||
| file += (txt_selected ? ".txt" : ".json"); | ||
| } | ||
|
|
||
| bool save_txt = txt_selected || file.extension() == ".txt"; | ||
|
|
There was a problem hiding this comment.
Format detection can become inconsistent when the Text filter is selected but the user types a .json filename: save_txt becomes true due to txt_selected, but the extension is left as .json, so text output may be written into a .json file. Consider deriving the format primarily from an explicit .json/.txt extension (if provided), otherwise from the selected filter, and then enforcing the matching extension (replace/append) to keep name and contents consistent.
|
@copilot apply changes based on the comments in this thread |
Applied all three fixes from the review thread (commit
|
|
@copilot apply changes based on the comments in this thread |
All three changes from the review thread are applied in commit
|
txt_selectedcomputation to use#if GTK_CHECK_VERSION(3, 20, 0)blocks:gtk_file_chooser_get_filter()in GTK ≥ 3.20 branch,dialog.get_filter() == txt_filterinGtk::FileChooserDialogbranch.TXT/.JSONon Windows.json/.txtextension from filename; only fall back to filter selection when no known extension is present, then append the correct extensionOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.