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>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
<object class="GtkFileChooserNative" id="filechooser">
|
<object class="GtkFileDialog" id="file_dialog">
|
||||||
<property name="modal">True</property>
|
<property name="modal">True</property>
|
||||||
<property name="action">open</property>
|
|
||||||
<property name="title" translatable="yes">Select your background image</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>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: nightthemeswitcher@romainvigier.fr\n"
|
"Project-Id-Version: nightthemeswitcher@romainvigier.fr\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
<<<<<<< HEAD
|
"POT-Creation-Date: 2025-08-17 17:43+0200\n"
|
||||||
"POT-Creation-Date: 2024-03-24 11:18+0100\n"
|
|
||||||
=======
|
|
||||||
"POT-Creation-Date: 2025-08-17 17:45+0200\n"
|
|
||||||
>>>>>>> 8f766cc (FIX)
|
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@@ -25,7 +21,7 @@ msgstr ""
|
|||||||
msgid "Change background"
|
msgid "Change background"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/data/ui/BackgroundButton.ui:24
|
#: src/data/ui/BackgroundButton.ui:23
|
||||||
msgid "Select your background image"
|
msgid "Select your background image"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -150,6 +146,10 @@ msgstr ""
|
|||||||
msgid "Edit Manual Schedule"
|
msgid "Edit Manual Schedule"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/preferences/BackgroundButton.js:94
|
#: src/preferences/BackgroundButton.js:97
|
||||||
msgid "This image format is not supported."
|
msgid "This image format is not supported."
|
||||||
msgstr ""
|
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';
|
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 {
|
export class BackgroundButton extends Gtk.Button {
|
||||||
#uri;
|
#uri;
|
||||||
|
|
||||||
@@ -19,7 +22,7 @@ export class BackgroundButton extends Gtk.Button {
|
|||||||
GObject.registerClass({
|
GObject.registerClass({
|
||||||
GTypeName: 'BackgroundButton',
|
GTypeName: 'BackgroundButton',
|
||||||
Template: 'resource:///org/gnome/Shell/Extensions/nightthemeswitcher/preferences/ui/BackgroundButton.ui',
|
Template: 'resource:///org/gnome/Shell/Extensions/nightthemeswitcher/preferences/ui/BackgroundButton.ui',
|
||||||
InternalChildren: ['filechooser', 'thumbnail'],
|
InternalChildren: ['file_dialog', 'thumbnail'],
|
||||||
Properties: {
|
Properties: {
|
||||||
uri: GObject.ParamSpec.string(
|
uri: GObject.ParamSpec.string(
|
||||||
'uri',
|
'uri',
|
||||||
@@ -52,7 +55,7 @@ export class BackgroundButton extends Gtk.Button {
|
|||||||
super(params);
|
super(params);
|
||||||
this.#setupSize();
|
this.#setupSize();
|
||||||
this.#setupDropTarget();
|
this.#setupDropTarget();
|
||||||
this.#setupFileChooserFilter();
|
this.#setupFileDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
get uri() {
|
get uri() {
|
||||||
@@ -101,10 +104,12 @@ export class BackgroundButton extends Gtk.Button {
|
|||||||
this.add_controller(dropTarget);
|
this.add_controller(dropTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupFileChooserFilter() {
|
#setupFileDialog() {
|
||||||
this._filechooser.filter = new Gtk.FileFilter();
|
const filter = new Gtk.FileFilter();
|
||||||
this._filechooser.filter.add_pixbuf_formats();
|
filter.set_name(_('Image files'));
|
||||||
this._filechooser.filter.add_mime_type('application/xml');
|
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() {
|
#getSupportedContentTypes() {
|
||||||
@@ -120,22 +125,18 @@ export class BackgroundButton extends Gtk.Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vfunc_mnemonic_activate() {
|
vfunc_mnemonic_activate() {
|
||||||
this.openFileChooser();
|
this.#setURIFromFileDialog();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked(_button) {
|
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() {
|
#updateThumbnail() {
|
||||||
|
|||||||
Reference in New Issue
Block a user