diff --git a/desktopIconsUtil.js b/desktopIconsUtil.js index f1892cb..a035b99 100644 --- a/desktopIconsUtil.js +++ b/desktopIconsUtil.js @@ -26,7 +26,10 @@ const Gettext = imports.gettext.domain('desktopicons-neo'); const _ = Gettext.gettext; function getDesktopDir() { - let desktopPath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP); + let desktopPath = Prefs.desktopSettings.get_string('desktop-directory'); + if(desktopPath == 'null'){ + desktopPath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP); + } return Gio.File.new_for_commandline_arg(desktopPath); } diff --git a/desktopManager.js b/desktopManager.js index ea768ee..49a8a2d 100644 --- a/desktopManager.js +++ b/desktopManager.js @@ -68,7 +68,13 @@ var DesktopManager = class { this._scriptsDir = DesktopIconsUtil.getScriptsDir(); this.desktopFsId = this._desktopDir.query_info('id::filesystem', Gio.FileQueryInfoFlags.NONE, null).get_attribute_string('id::filesystem'); this._updateWritableByOthers(); - this._monitorDesktopDir = this._desktopDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null); + try{ + this._monitorDesktopDir = this._desktopDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null); + } catch(e){ + logError(e, "schemaSource errored out. Fixing desktop-directory.."); + Prefs.desktopSettings.set_string('desktop-directory', GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)); + this._monitorDesktopDir = this._desktopDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null); + } this._monitorDesktopDir.set_rate_limit(1000); this._monitorDesktopDir.connect('changed', (obj, file, otherFile, eventType) => this._updateDesktopIfChanged(file, otherFile, eventType)); this._monitorScriptDir = this._scriptsDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null); @@ -107,6 +113,12 @@ var DesktopManager = class { this._updateDesktop(); } }); + Prefs.gtkSettings.connect('changed', (obj, key) => { + if (key == 'desktop-directory') { + this._desktopDir = Prefs.gtkSettings.get_string('desktop-directory'); + this._updateDesktop(); + } + }); this._gtkIconTheme = Gtk.IconTheme.get_default() this._gtkIconTheme.connect('changed', () => { this._updateDesktop(); diff --git a/preferences.js b/preferences.js index dbc8ad8..7ca3526 100644 --- a/preferences.js +++ b/preferences.js @@ -24,6 +24,7 @@ const Gio = imports.gi.Gio; const GioSSS = Gio.SettingsSchemaSource; const DesktopIconsUtil = imports.desktopIconsUtil; const Enums = imports.enums; +const DesktopManager = imports.desktopManager; const Gettext = imports.gettext; @@ -68,7 +69,7 @@ function get_schema(schema) { let schemaSource; let schemaFile = Gio.File.new_for_path(GLib.build_filenamev([extensionPath, 'schemas', 'gschemas.compiled'])); if (schemaFile.query_exists(null)) { - schemaSource = GioSSS.new_from_directory(GLib.build_filenamev([extensionPath, 'schemas']), GioSSS.get_default(), false); + schemaSource = GioSSS.new_from_directory(GLib.build_filenamev([extensionPath, 'schemas']), GioSSS.get_default(), false); } else { schemaSource = GioSSS.get_default(); } @@ -107,6 +108,7 @@ function showPreferences() { 'bottom-left': _("Bottom-left corner"), 'bottom-right': _("Bottom-right corner") })); + frame.add(buildFileChooserButton(desktopSettings, 'desktop-directory', _("Desktop directory > " + desktopSettings.get_string('desktop-directory')), _("Set desktop directory"))); frame.add(buildSelector(desktopSettings, 'icon-shape', _("Icon shape"), @@ -163,6 +165,25 @@ function buildSwitcher(settings, key, labelText) { return hbox; } +function buildFileChooserButton(settings, key, labelText, buttonText) { + function activateFileChooser(){hbox.add(filechooser)} + let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 10 }); + let label = new Gtk.Label({ label: labelText, xalign: 0 }); + let button = new Gtk.Button({ label: buttonText }) + let fileChooser = new Gtk.FileChooserNative({ title: "Choose a Directory (You MUST restart the extension to see/apply changes)", action: Gtk.FileChooserAction.SELECT_FOLDER, modal: true }); + button.connect('clicked', () => { + fileChooser.show(); + }); + fileChooser.connect('response', (dlg, response) => { + if (response !== Gtk.ResponseType.ACCEPT) + return; + settings.set_string(key, dlg.get_file().get_path()); + }); + hbox.pack_start(label, true, true, 0); + hbox.add(button); + return hbox; +} + function buildSelector(settings, key, labelText, elements) { let listStore = new Gtk.ListStore(); listStore.set_column_types ([GObject.TYPE_STRING, GObject.TYPE_STRING]); diff --git a/schemas/org.gnome.shell.extensions.desktopicons-neo.gschema.xml b/schemas/org.gnome.shell.extensions.desktopicons-neo.gschema.xml index 1034048..11ded1d 100644 --- a/schemas/org.gnome.shell.extensions.desktopicons-neo.gschema.xml +++ b/schemas/org.gnome.shell.extensions.desktopicons-neo.gschema.xml @@ -37,7 +37,7 @@ Show personal folder Show the personal folder in the desktop. - + true Show trash icon Show the trash icon in the desktop. @@ -52,6 +52,11 @@ Icon shape Set the shape of the icons + + 'null' + Desktop icons working directory + The directory that contains the files that the extension edits, displays, and interacts with. + true Curve corners