From 040307e686062d739de14f07cc1c95010c613d01 Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Sun, 17 Aug 2025 17:46:10 +0200 Subject: [PATCH] Background Button: Replace deprecated GtkFileChooser with GtkFileDialog --- src/data/ui/BackgroundButton.ui | 5 +-- src/po/nightthemeswitcher@romainvigier.fr.pot | 14 +++---- src/preferences/BackgroundButton.js | 39 ++++++++++--------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/data/ui/BackgroundButton.ui b/src/data/ui/BackgroundButton.ui index 24a77ba..adcfbd3 100644 --- a/src/data/ui/BackgroundButton.ui +++ b/src/data/ui/BackgroundButton.ui @@ -18,11 +18,8 @@ SPDX-License-Identifier: GPL-3.0-or-later - + True - open Select your background image - False - diff --git a/src/po/nightthemeswitcher@romainvigier.fr.pot b/src/po/nightthemeswitcher@romainvigier.fr.pot index 82b940d..bf00601 100644 --- a/src/po/nightthemeswitcher@romainvigier.fr.pot +++ b/src/po/nightthemeswitcher@romainvigier.fr.pot @@ -8,11 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: nightthemeswitcher@romainvigier.fr\n" "Report-Msgid-Bugs-To: \n" -<<<<<<< HEAD -"POT-Creation-Date: 2024-03-24 11:18+0100\n" -======= -"POT-Creation-Date: 2025-08-17 17:45+0200\n" ->>>>>>> 8f766cc (FIX) +"POT-Creation-Date: 2025-08-17 17:43+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -25,7 +21,7 @@ msgstr "" msgid "Change background" msgstr "" -#: src/data/ui/BackgroundButton.ui:24 +#: src/data/ui/BackgroundButton.ui:23 msgid "Select your background image" msgstr "" @@ -150,6 +146,10 @@ msgstr "" msgid "Edit Manual Schedule" msgstr "" -#: src/preferences/BackgroundButton.js:94 +#: src/preferences/BackgroundButton.js:97 msgid "This image format is not supported." msgstr "" + +#: src/preferences/BackgroundButton.js:109 +msgid "Image files" +msgstr "" diff --git a/src/preferences/BackgroundButton.js b/src/preferences/BackgroundButton.js index 456628e..4083576 100644 --- a/src/preferences/BackgroundButton.js +++ b/src/preferences/BackgroundButton.js @@ -12,6 +12,9 @@ import Gtk from 'gi://Gtk'; import { gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; +Gio._promisify(Gtk.FileDialog.prototype, 'open', 'open_finish'); + + export class BackgroundButton extends Gtk.Button { #uri; @@ -19,7 +22,7 @@ export class BackgroundButton extends Gtk.Button { GObject.registerClass({ GTypeName: 'BackgroundButton', Template: 'resource:///org/gnome/Shell/Extensions/nightthemeswitcher/preferences/ui/BackgroundButton.ui', - InternalChildren: ['filechooser', 'thumbnail'], + InternalChildren: ['file_dialog', 'thumbnail'], Properties: { uri: GObject.ParamSpec.string( 'uri', @@ -52,7 +55,7 @@ export class BackgroundButton extends Gtk.Button { super(params); this.#setupSize(); this.#setupDropTarget(); - this.#setupFileChooserFilter(); + this.#setupFileDialog(); } get uri() { @@ -101,10 +104,12 @@ export class BackgroundButton extends Gtk.Button { this.add_controller(dropTarget); } - #setupFileChooserFilter() { - this._filechooser.filter = new Gtk.FileFilter(); - this._filechooser.filter.add_pixbuf_formats(); - this._filechooser.filter.add_mime_type('application/xml'); + #setupFileDialog() { + const filter = new Gtk.FileFilter(); + filter.set_name(_('Image files')); + this.#getSupportedContentTypes().forEach(type => filter.add_mime_type(type)); + this._file_dialog.filters = Gio.ListStore.new(Gtk.FileFilter); + this._file_dialog.filters.append(filter); } #getSupportedContentTypes() { @@ -120,22 +125,18 @@ export class BackgroundButton extends Gtk.Button { } vfunc_mnemonic_activate() { - this.openFileChooser(); - } - - openFileChooser() { - this._filechooser.transient_for = this.get_root(); - this._filechooser.show(); - } - - onFileChooserResponse(fileChooser, responseId) { - if (responseId !== Gtk.ResponseType.ACCEPT) - return; - this.uri = fileChooser.get_file().get_uri(); + this.#setURIFromFileDialog(); } onClicked(_button) { - this.openFileChooser(); + this.#setURIFromFileDialog(); + } + + async #setURIFromFileDialog() { + try { + const file = await this._file_dialog.open(this.get_root(), null); + this.uri = file.get_uri(); + } catch {} } #updateThumbnail() {