Skip to content

[v3] Fix save dialog filename not pre-populated on Linux (#4841)#4842

Merged
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
samstanier:v3-alpha-bugfix/linux-save-dialog-filename
Jan 4, 2026
Merged

[v3] Fix save dialog filename not pre-populated on Linux (#4841)#4842
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
samstanier:v3-alpha-bugfix/linux-save-dialog-filename

Conversation

@samstanier

@samstanier samstanier commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Description

The SaveFileDialog.SetFilename() option has no effect on Linux because the filename is never passed to the GTK file chooser. This fix adds support for pre-populating the filename field by calling gtk_file_chooser_set_current_name().

Fixes #4841

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux (Arch - rolling release)

If you checked Linux, please specify the distro and version.

Test Configuration

Wails (v3.0.0-dev) Wails Doctor

System

┌────────────────────────────────────────────────────────────────────────────────────────┐
| Name | Arch Linux |
| Version | Unknown |
| ID | arch |
| Branding | |
| Platform | linux |
| Architecture | amd64 |
| CPU | Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz |
| GPU 1 | GP107GLM [Quadro P2000 Mobile] (NVIDIA Corporation) - Driver: nouveau |
| GPU 2 | CoffeeLake-H GT2 [UHD Graphics 630] (Intel Corporation) - Driver: i915 |
| Memory | 31GB |
└────────────────────────────────────────────────────────────────────────────────────────┘

Build Environment

┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI | v3.0.0-dev |
| Go Version | go1.25.3 X:nodwarf5 |
| Revision | be60783 |
| Modified | false |
| -buildmode | exe |
| -compiler | gc |
| CGO_CFLAGS | |
| CGO_CPPFLAGS | |
| CGO_CXXFLAGS | |
| CGO_ENABLED | 1 |
| CGO_LDFLAGS | |
| DefaultGODEBUG | containermaxprocs=0,decoratemappings=0,tlssha1=1,updatemaxprocs=0,x509sha256skid=0 |
| GOAMD64 | v1 |
| GOARCH | amd64 |
| GOEXPERIMENT | nodwarf5 |
| GOOS | linux |
| vcs | git |
| vcs.modified | false |
| vcs.revision | be60783 |
| vcs.time | 2025-09-08T08:42:14Z |
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

Dependencies

┌──────────────────────────────────────────┐
| gcc | 15.2.1+r301+gf24307422d1d-1 |
| gtk3 | 1:3.24.51-1 |
| npm | 11.6.4 |
| pkg-config | 2.5.1-1 |
| webkit2gtk | 2.50.4-1 |
| |
└──────── * - Optional Dependency ─────────┘

Checking for issues

SUCCESS No issues found

Diagnosis

SUCCESS Your system is ready for Wails development!

Need documentation? Run: wails3 docs
♥ If Wails is useful to you or your company, please consider sponsoring the project: wails3 sponsor

Checklist:

  • I have updated UNRELEASED_CHANGELOG.md with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • [] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Save dialog now correctly pre-populates the filename on Linux.
    • Fixed file drag-and-drop on Windows at non-100% display scaling and corrected file drop coordinates (physical vs CSS pixels).
    • Improved reliability of file drag-and-drop and hover effects on Linux.
    • Restored HTML5 internal drag-and-drop behavior when file drop is enabled on Windows and Linux.
  • Documentation

    • Changelog updated to include these fixes.

✏️ Tip: You can customize this high-level summary in your review settings.

The SaveFileDialog.SetFilename() option had no effect on Linux because
the filename was never passed to the GTK file chooser.

This adds a currentName parameter to runChooserDialog and calls
gtk_file_chooser_set_current_name() for save dialogs when a filename
is specified.

Changes:
- linux_cgo.go: Add currentName parameter and GTK call
- linux_purego.go: Add gtkFileChooserSetCurrentName binding and same fix

Fixes the Linux implementation to match the behaviour on Windows and macOS.
@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Adds passing of a save-filename to the Linux file chooser: runChooserDialog now accepts a currentName and calls gtk_file_chooser_set_current_name for Save dialogs; runSaveFileDialog forwards dialog.filename. Also adds changelog entries documenting related drag-and-drop fixes.

Changes

Cohort / File(s) Summary
Changelog Entry
v3/UNRELEASED_CHANGELOG.md
Added multiple "Fixed" entries, including the SaveFileDialog.SetFilename() fix for Linux (issue #4841) and several drag-and-drop fixes.
Linux CGO implementation
v3/pkg/application/linux_cgo.go
Extended runChooserDialog(..., currentName string); when currentName is non-empty and action is SAVE, calls gtk_file_chooser_set_current_name. Updated runOpenFileDialog to pass "" and runSaveFileDialog to pass dialog.filename.
Linux pure-Go GTK binding
v3/pkg/application/linux_purego.go
Added gtkFileChooserSetCurrentName(pointer, string) binding and registration. Updated runChooserDialog signature and call sites to accept currentName and invoke the new GTK symbol for Save dialogs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #3925: Modifies Linux file-chooser dialog code (runChooserDialog / runOpenFileDialog / runSaveFileDialog); directly related to this change.
  • #4287: Adjusts runChooserDialog and filter handling in the Linux backend; overlaps with the same code paths.

Suggested labels

Bug, Documentation, Linux, v3-alpha, size:S

Suggested reviewers

  • atterpac

Poem

🐰 I nudged a name into the box,
A tiny hop, no paradox.
On Linux now the saver sees,
The filename settles with ease—
A rabbit's nudge, and files feel fox.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly summarizes the main change: fixing the save dialog filename pre-population issue on Linux, directly addressing the problem described in issue #4841.
Description check ✅ Passed The description includes all required sections: clear summary of the change, reference to issue #4841, type of change selected, test configuration with Linux distro/version, and comprehensive wails doctor output.
Linked Issues check ✅ Passed The code changes fully implement the requirements from issue #4841: passing filename parameter through runChooserDialog and calling gtk_file_chooser_set_current_name() for Linux save dialogs to match Windows/macOS behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the save dialog filename pre-population issue on Linux; the changelog entry, linux_cgo.go, and linux_purego.go modifications are all in scope.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 962829a and 8336cce.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@samstanier samstanier changed the base branch from master to v3-alpha December 30, 2025 19:51
@leaanthony

Copy link
Copy Markdown
Member

@CodeRabbit base branch changed. Please review.

@coderabbitai

coderabbitai Bot commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

@leaanthony: I'll review the changes now that the base branch has been updated.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
v3/UNRELEASED_CHANGELOG.md (1)

26-26: Changelog entry looks good.

The entry is well-formatted, includes the issue reference and author attribution, and follows the "Keep a Changelog" guidelines. Consider slightly more descriptive phrasing for clarity (e.g., "Fix SaveFileDialog.SetFilename() not pre-populating the filename on Linux"), but the current entry is entirely acceptable.

v3/pkg/application/linux_purego.go (1)

1061-1065: Core fix implemented correctly for purego.

The implementation properly pre-populates the save dialog filename using the registered GTK function pointer.

Optional: Move constant to global scope

The GtkFileChooserActionSave constant is defined locally at line 1062. For consistency with other GTK constants and potential reusability, consider moving it to the global constants section (around lines 28-63):

 const (
 	nilPointer pointer = 0
 )
 
 const (
 	GSourceRemove int = 0
 
+	// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/gtkfilechooser.h
+	GtkFileChooserActionOpen         = 0
+	GtkFileChooserActionSave         = 1
+	GtkFileChooserActionSelectFolder = 2
+
 	// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gdk/gdkwindow.h#L121
 	GdkHintMinSize = 1 << 1

Then remove the local definition at line 1062.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3256041 and 31c3f07.

📒 Files selected for processing (3)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/linux_cgo.go
  • v3/pkg/application/linux_purego.go
🧰 Additional context used
🧬 Code graph analysis (2)
v3/pkg/application/linux_cgo.go (1)
v3/pkg/application/dialogs.go (1)
  • FileFilter (164-167)
v3/pkg/application/linux_purego.go (1)
v3/pkg/application/dialogs.go (1)
  • FileFilter (164-167)
🔇 Additional comments (9)
v3/pkg/application/linux_cgo.go (4)

1725-1725: LGTM: Function signature extended correctly.

The addition of the currentName parameter to runChooserDialog is well-placed and clearly named.


1775-1782: LGTM: Core fix implemented correctly.

The implementation properly:

  • Pre-populates the filename only for save dialogs
  • Uses the correct GTK API gtk_file_chooser_set_current_name
  • Manages memory correctly (allocates with C.CString and frees with C.free)
  • Includes clear documentation

1857-1858: LGTM: Open dialog correctly passes empty filename.

Open file dialogs correctly pass an empty string for currentName since they don't need filename pre-population.


1940-1941: LGTM: Save dialog correctly passes filename for pre-population.

This change enables the core functionality described in the PR: pre-populating the filename field in save dialogs by passing dialog.filename to runChooserDialog.

v3/pkg/application/linux_purego.go (5)

155-155: LGTM: Function pointer declared correctly.

The gtkFileChooserSetCurrentName function pointer is properly declared with the correct signature matching the GTK C API.


309-309: LGTM: Function pointer registered correctly.

The registration properly binds the Go function pointer to the GTK library symbol gtk_file_chooser_set_current_name.


1029-1029: LGTM: Function signature extended correctly.

The addition of the currentName parameter matches the CGO implementation and maintains consistency between both Linux variants.


1136-1137: LGTM: Open dialog correctly passes empty filename.

Consistent with the CGO implementation, open file dialogs pass an empty string since they don't need filename pre-population.


1218-1219: LGTM: Save dialog correctly passes filename for pre-population.

This change enables the core functionality for the purego implementation, matching the CGO version and fulfilling the PR objective.

@leaanthony leaanthony enabled auto-merge (squash) January 4, 2026 00:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
v3/pkg/application/linux_purego.go (1)

1130-1141: Fix hardcoded action constant in runOpenFileDialog.

Line 1137 passes the hardcoded constant GtkFileChooserActionOpen instead of the computed action variable. This breaks directory selection functionality—when dialog.canChooseDirectories is true, the function should pass GtkFileChooserActionSelectFolder (value 2), but it always passes GtkFileChooserActionOpen (value 0).

The CGO implementation (linux_cgo.go, line 2130) correctly passes the computed action variable. Change line 1137 from GtkFileChooserActionOpen, to action, to match the intended behavior.

🧹 Nitpick comments (1)
v3/pkg/application/linux_purego.go (1)

1032-1068: LGTM! Implementation correctly pre-populates the filename.

The logic correctly calls gtk_file_chooser_set_current_name() only for Save dialogs when a filename is provided, which aligns with GTK documentation and fixes the reported issue.

Minor: Consider extracting the constant to package level.

The constant GtkFileChooserActionSave is defined at both Line 1065 and Line 1205. Consider defining it once at the package level alongside other GTK constants (around lines 32-63) to avoid duplication.

🔎 Proposed refactor to eliminate constant duplication

Define the constant at package level (around line 63):

 	GtkMessageWarning  = 1
 	GtkMessageQuestion = 2
 	GtkMessageError    = 3
+
+	// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/gtkfilechooser.h
+	GtkFileChooserActionOpen         = 0
+	GtkFileChooserActionSave         = 1
+	GtkFileChooserActionSelectFolder = 2
 )

Then remove the local definitions at lines 1065, 1106-1107, and 1205.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31c3f07 and 962829a.

📒 Files selected for processing (3)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/linux_cgo.go
  • v3/pkg/application/linux_purego.go
✅ Files skipped from review due to trivial changes (1)
  • v3/UNRELEASED_CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/linux_cgo.go
🧰 Additional context used
🧬 Code graph analysis (1)
v3/pkg/application/linux_purego.go (1)
v3/pkg/application/dialogs.go (1)
  • FileFilter (164-167)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
🔇 Additional comments (4)
v3/pkg/application/linux_purego.go (4)

155-155: LGTM! Function pointer declaration is correct.

The gtkFileChooserSetCurrentName function pointer follows the established pattern for GTK function declarations in this file.


309-309: LGTM! Function registration is correct.

The purego registration for gtk_file_chooser_set_current_name is properly placed and follows the correct pattern.


1139-1140: LGTM! Correctly passes empty string for open dialogs.

Open dialogs don't need a pre-populated filename, so passing an empty string is correct.


1221-1222: LGTM! This is the key fix for the reported issue.

Passing dialog.filename as the currentName parameter correctly propagates the filename set via SetFilename() to the GTK file chooser, fixing issue #4841.

@leaanthony leaanthony disabled auto-merge January 4, 2026 03:40
@leaanthony leaanthony merged commit 9039051 into wailsapp:v3-alpha Jan 4, 2026
6 of 8 checks passed
@sonarqubecloud

sonarqubecloud Bot commented Jan 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
…) (wailsapp#4842)

The SaveFileDialog.SetFilename() option had no effect on Linux because
the filename was never passed to the GTK file chooser.

This adds a currentName parameter to runChooserDialog and calls
gtk_file_chooser_set_current_name() for save dialogs when a filename
is specified.

Changes:
- linux_cgo.go: Add currentName parameter and GTK call
- linux_purego.go: Add gtkFileChooserSetCurrentName binding and same fix

Fixes the Linux implementation to match the behaviour on Windows and macOS.

Co-authored-by: sas229 <sas229@cam.ac.uk>
Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
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.

[v3] SaveFileDialog.SetFilename() has no effect on Linux

3 participants