Skip to content

Fix Save As txt format from View Output window#105

Closed
Claude wants to merge 2 commits intomainfrom
claude/fix-save-log-as-txt
Closed

Fix Save As txt format from View Output window#105
Claude wants to merge 2 commits intomainfrom
claude/fix-save-log-as-txt

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Mar 4, 2026

  • Fix txt_selected computation to use #if GTK_CHECK_VERSION(3, 20, 0) blocks: gtk_file_chooser_get_filter() in GTK ≥ 3.20 branch, dialog.get_filter() == txt_filter in Gtk::FileChooserDialog branch
  • Normalize file extension to lowercase before comparison to handle .TXT/.JSON on Windows
  • Fix format/extension consistency: respect explicit .json/.txt extension from filename; only fall back to filter selection when no known extension is present, then append the correct extension
Original prompt

This section details on the original issue you should resolve

<issue_title>Save log as txt not working from "View Output" window</issue_title>
<issue_description> - GSmartControl version: 2.0.2

  • OS: Windows 10 / Parted Magic 2025_04_01

Save log as txt is not working from "View Output" window.

This was improved in #76 but not completely.

  1. Open "Device information"
  2. Click on "View Output"
  3. Text window opens showing JSON output
  4. Click on "SaveAs"
  5. Dialog is offering Save as type = "JSON and Text files"
  6. Here is the unexpected behaviour:
  • it is not possible to save in .txt format, since there is no multiple selection of "JSON and Text Files" / "JSON files"/ "txt files" / "All files" as in the "Save As" dialog that opens from "Device Information" windows and file is always saved in JSON format.
  • changing file extension manually to .txt still saves in JSON format.

Apart from correcting inability to save as .txt from "View Output" window, I also have two suggestions to improve this process.

  1. Have two buttons labeled "View JSON output" and "View text output", saving from each would automatically choose the right save format and file name extension and would also show correctly formatted text (either JSON or text) in the "View output" window. This would also allow correct format to be copied and pasted without having to save file.
  2. Consider adding Preferences option to choose preferred save format for all save dialogs.</issue_description>

Comments on the Issue (you are @claude[agent] in this section)


🔒 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.

Co-authored-by: ashaduri <2302268+ashaduri@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Fix issue with saving log as txt from View Output window Fix Save As txt format from View Output window Mar 4, 2026
@ashaduri ashaduri requested a review from Copilot March 6, 2026 14:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GscTextWindow and reading "smartctl/output" from the property repository when saving as text.
  • Updated GscInfoWindow to provide the StorageDevicePtr to 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.

Comment on lines 244 to +245

bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj();
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines 247 to 249
if (file.extension() != ".json" && file.extension() != ".txt") {
file += ".json";
file += (txt_selected ? ".txt" : ".json");
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +245 to +246
bool txt_selected = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) == txt_filter->gobj();

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 247 to +252
if (file.extension() != ".json" && file.extension() != ".txt") {
file += ".json";
file += (txt_selected ? ".txt" : ".json");
}

bool save_txt = txt_selected || file.extension() == ".txt";

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 uses AI. Check for mistakes.
@ashaduri
Copy link
Copy Markdown
Owner

ashaduri commented Mar 7, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 7, 2026

@copilot apply changes based on the comments in this thread

Applied all three fixes from the review thread (commit 0f0d5b6):

  1. Filter query conditionaltxt_selected is now inside #if GTK_CHECK_VERSION(3, 20, 0) blocks: uses gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) for the native dialog path and dialog.get_filter() == txt_filter for the Gtk::FileChooserDialog path.

  2. Case-insensitive extension – The extension is lowercased via std::transform before comparison, so .TXT/.JSON on Windows are handled correctly.

  3. Format/extension consistency – If the filename already has a known extension (.json/.txt, after lowercasing), it takes precedence over the selected filter. Only when no known extension is present does the filter determine format, and the matching extension is then appended.

@ashaduri
Copy link
Copy Markdown
Owner

ashaduri commented Mar 7, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 7, 2026

@copilot apply changes based on the comments in this thread

All three changes from the review thread are applied in commit 94f927d:

  1. txt_selected conditional – now inside #if GTK_CHECK_VERSION(3, 20, 0) blocks, using gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog.get())) for the native path and dialog.get_filter() == txt_filter for the Gtk::FileChooserDialog path.
  2. Case-insensitive extension – extension lowercased via std::transform before any comparison, handling .TXT/.JSON on Windows.
  3. Format/extension consistency – explicit .json/.txt extension in the filename takes priority over filter selection; only when no known extension is present does the filter determine format, then the matching extension is appended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save log as txt not working from "View Output" window

4 participants