Bug 162995 - gtk4: Extra controls are missing in file dialog
Summary: gtk4: Extra controls are missing in file dialog
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
25.2.0.0 alpha0+
Hardware: All Linux (All)
: medium normal
Assignee: Michael Weghorn
URL:
Whiteboard: target:25.8.0
Keywords:
Depends on:
Blocks: Gtk4
  Show dependency treegraph
 
Reported: 2024-09-16 16:48 UTC by Michael Weghorn
Modified: 2025-03-07 20:43 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Weghorn 2024-09-16 16:48:14 UTC
Steps to reproduce:

1) Start Writer, using the gtk4 VCL plugin on Linux
2) press Ctrl+Shift+S to open the save dialog

Actual result:
The file dialog opens. However, extra controls like the "Save with password" or "Encrypt with GPG key" checkboxes seen with the gtk3, gen or qt6 VCL plugins are not there, making that functionality unavailable.

Expected result:
Above-mentioned checkboxes (and more) should be present, allowing e.g. to save a file protected by a password.

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: a4a2cfa1bf746a4c1d379757c99d35ef5ac42cd3
CPU threads: 32; OS: Linux 6.10; UI render: default; VCL: gtk4
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: CL threaded
Comment 1 Caolán McNamara 2024-09-17 11:28:31 UTC
Code for these is in vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx in SalGtkFilePicker::SalGtkFilePicker I think. There are various GTK_CHECK_VERSION conditionals in there, but I think it should generally work so hopefully something minor like requiring these to be explicitly shown where maybe that was implicit in earlier versions of gtk
Comment 2 Michael Weghorn 2024-09-17 12:35:52 UTC
(In reply to Caolán McNamara from comment #1)
> Code for these is in vcl/unx/gtk3/fpicker/SalGtkFilePicker.cxx in
> SalGtkFilePicker::SalGtkFilePicker I think. There are various
> GTK_CHECK_VERSION conditionals in there, but I think it should generally
> work so hopefully something minor like requiring these to be explicitly
> shown where maybe that was implicit in earlier versions of gtk

This line there looks relevant:

#if !GTK_CHECK_VERSION(4, 0, 0)
    gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER( m_pDialog ), m_pVBox );
#endif

Items are added to m_pVBox for GTK 4 as well, but I don't see where m_pVBox is added to the file chooser.

`gtk_file_chooser_set_extra_widget` seems gone for GTK 4, the doc for GtkFileChooser [1] mentions this instead:

> You can add extra widgets to a file chooser to provide options that are not
> present in the default design, by using gtk_file_chooser_add_choice(). Each
> choice has an identifier and a user visible label; additionally, each choice
> can have multiple options. If a choice has no option, it will be rendered as a
> check button with the given label; if a choice has options, it will be rendered
> as a combo box.

The doc also mentions that GtkFileChooser is deprecated in GTK 4.10 and GtkFileDialog [2] should be used instead. For that one, I don't see any mention of being able to add custom widgets in the doc.


[1] https://docs.gtk.org/gtk4/iface.FileChooser.html
[2] https://docs.gtk.org/gtk4/class.FileDialog.html
Comment 3 Caolán McNamara 2024-09-17 15:29:31 UTC
Ah, forgot all that, maybe gtk_file_chooser_add_choice could be made to work (or a replacement dialog of our own that uses GtkFileChooserWidget). All those are deprecated too of course. Life is very difficult for an existing application with gtk4.
Comment 4 Michael Weghorn 2025-03-07 07:36:23 UTC
(In reply to Caolán McNamara from comment #3)
> Ah, forgot all that, maybe gtk_file_chooser_add_choice could be made to work
> (or a replacement dialog of our own that uses GtkFileChooserWidget). All
> those are deprecated too of course. Life is very difficult for an existing
> application with gtk4.

Thanks. I think gtk_file_chooser_add_choice wouldn't be flexible enough for our needs, but using GtkFileChooserWidget indeed works.
Change series doing that pending in Gerrit now: https://gerrit.libreoffice.org/c/core/+/182610
Comment 5 Michael Weghorn 2025-03-07 07:39:43 UTC
(In reply to Michael Weghorn from comment #4)
> Change series doing that pending in Gerrit now:
> https://gerrit.libreoffice.org/c/core/+/182610

With that in place, there's still the problem that e.g. the "Version" combobox in the "File" -> "Open" dialog doesn't contain any values, which IIUC is due to the lack of the "selection-changed" signal that's used in gtk3:

From SalGtkFilePicker::execute:

#if !GTK_CHECK_VERSION(4, 0, 0)
    mnHID_SelectionChange =
        g_signal_connect(m_pFileChooser, "selection-changed",
            G_CALLBACK( selection_changed_cb ), static_cast<gpointer>(this) );
#else
    // no replacement in 4-0 that I can see :-(
    mnHID_SelectionChange = 0;
#endif

Related: https://discourse.gnome.org/t/gtk4-filechooser-selection-changed-signal-alternative/12180
Comment 6 Michael Weghorn 2025-03-07 13:19:04 UTC
(In reply to Michael Weghorn from comment #4)
> I think gtk_file_chooser_add_choice wouldn't be flexible enough for
> our needs, but using GtkFileChooserWidget indeed works.
> Change series doing that pending in Gerrit now:
> https://gerrit.libreoffice.org/c/core/+/182610

Thinking about it again, it's not even necessary to have a custom GtkDialog with a GtkFileChooserWidget, but it's sufficient to add the widget with the custom controls to the content area of the existing GtkFileChooserDialog (that can be retrieved using `gtk_dialog_get_content_area`), which the updated change series does now.
Comment 7 Commit Notification 2025-03-07 17:05:01 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/521bcdc4535555a45934a6e224a96aa87bbef659

tdf#162995 gtk4: Show extra controls in file dialog

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 8 Commit Notification 2025-03-07 17:05:04 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/678a00dc1eb3ae12ef2d83f6ae12fd6cdf000626

tdf#162995 gtk: Initially hide custom file dialog controls

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 9 Michael Weghorn 2025-03-07 19:20:24 UTC
(In reply to Michael Weghorn from comment #5)
> With that in place, there's still the problem that e.g. the "Version"
> combobox in the "File" -> "Open" dialog doesn't contain any values, which
> IIUC is due to the lack of the "selection-changed" signal that's used in
> gtk3:
> [...]

https://gerrit.libreoffice.org/c/core/+/182640 is a potential solution for this, but relies on GTK implementation details due to lack of corresponding API.
Comment 10 Commit Notification 2025-03-07 20:42:37 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/122de03c9693089b2b7b9f26a6faf33d9ecce417

tdf#162995 gtk4: Handle file dialog selection changes

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2025-03-07 20:42:40 UTC
Michael Weghorn committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/76bd6bf83309c50177fc230231755b8aaffb1e77

tdf#162995 gtk4: Add combobox in file dialog after its label

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.