Allow dropping images on background button

This commit is contained in:
Romain Vigier
2022-02-23 21:30:28 +01:00
parent 6243e9b8f3
commit 496fccadb2
2 changed files with 47 additions and 12 deletions
+15 -11
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Night Theme Switcher\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-19 11:38+0100\n"
"POT-Creation-Date: 2022-02-23 21:30+0100\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"
@@ -17,34 +17,38 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/modules/TimerOndemand.js:206
#: src/modules/TimerOndemand.js:213
msgid "Turn Night Mode On"
msgstr ""
#: src/modules/TimerOndemand.js:206
#: src/modules/TimerOndemand.js:213
msgid "Turn Night Mode Off"
msgstr ""
#: src/modules/TimerOndemand.js:218
#: src/modules/TimerOndemand.js:228
msgid "Extension Settings"
msgstr ""
#: src/modules/TimerOndemand.js:227
#: src/modules/TimerOndemand.js:237
msgid "Night Mode Off"
msgstr ""
#: src/modules/TimerOndemand.js:227
#: src/modules/TimerOndemand.js:237
msgid "Night Mode On"
msgstr ""
#: src/modules/TimerOndemand.js:228
#: src/modules/TimerOndemand.js:238
msgid "Turn On"
msgstr ""
#: src/modules/TimerOndemand.js:228
#: src/modules/TimerOndemand.js:238
msgid "Turn Off"
msgstr ""
#: src/preferences/BackgroundButton.js:61
msgid "Only JPEG, PNG, TIFF and XML files can be set as background image."
msgstr ""
#: src/preferences/SchedulePage.js:45 src/preferences/ui/SchedulePage.ui:63
msgid "Night Light"
msgstr ""
@@ -61,15 +65,15 @@ msgstr ""
msgid "On-demand"
msgstr ""
#: src/preferences/SchedulePage.js:90
#: src/preferences/SchedulePage.js:91
msgid "None"
msgstr ""
#: src/preferences/SchedulePage.js:91
#: src/preferences/SchedulePage.js:92
msgid "Top bar"
msgstr ""
#: src/preferences/SchedulePage.js:92
#: src/preferences/SchedulePage.js:93
msgid "System menu"
msgstr ""
+32 -1
View File
@@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2021, 2022 Romain Vigier <contact AT romainvigier.fr>
// SPDX-License-Identifier: GPL-3.0-or-later
const { Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk } = imports.gi;
const { Adw, Gdk, GdkPixbuf, Gio, GLib, GObject, Gtk } = imports.gi;
const { extensionUtils } = imports.misc;
const Me = extensionUtils.getCurrentExtension();
const _ = extensionUtils.gettext;
var BackgroundButton = GObject.registerClass({
@@ -37,6 +38,36 @@ var BackgroundButton = GObject.registerClass({
),
},
}, class BackgroundButton extends Gtk.Button {
constructor(props = {}) {
super(props);
this.#setupDropTarget();
}
#setupDropTarget() {
const dropTarget = Gtk.DropTarget.new(Gio.File.$gtype, Gdk.DragAction.COPY);
dropTarget.connect('drop', (_target, file, _x, _y) => {
const contentType = Gio.content_type_guess(file.get_basename(), null)[0];
if (
Gio.content_type_equals(contentType, 'image/jpeg') ||
Gio.content_type_equals(contentType, 'image/png') ||
Gio.content_type_equals(contentType, 'image/tiff') ||
Gio.content_type_equals(contentType, 'application/xml')
) {
this.uri = file.get_uri();
return true;
} else {
if (this.root instanceof Adw.PreferencesWindow) {
this.root.add_toast(new Adw.Toast({
title: _('Only JPEG, PNG, TIFF and XML files can be set as background image.'),
timeout: 10,
}));
}
return false;
}
});
this.add_controller(dropTarget);
}
openFileChooser() {
this._filechooser.transient_for = this.get_root();
this._filechooser.show();