Background Button: Replace deprecated GtkFileChooser with GtkFileDialog
This commit is contained in:
@@ -18,11 +18,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
<object class="GtkFileChooserNative" id="filechooser">
|
||||
<object class="GtkFileDialog" id="file_dialog">
|
||||
<property name="modal">True</property>
|
||||
<property name="action">open</property>
|
||||
<property name="title" translatable="yes">Select your background image</property>
|
||||
<property name="select-multiple">False</property>
|
||||
<signal name="response" handler="onFileChooserResponse" swapped="no"/>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
@@ -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 <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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 ""
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user