[gnome-shell-extensions/wip/cxiong/handle-locale-changes] Reload specials when XDG user dirs changes
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/cxiong/handle-locale-changes] Reload specials when XDG user dirs changes
- Date: Sat, 25 Nov 2017 03:56:38 +0000 (UTC)
commit 9a5b35a6b889d7c3afb85f9c40560ea5cd91e1fc
Author: Carl Xiong <xiongc05 gmail com>
Date: Tue Mar 17 19:30:13 2015 +0800
Reload specials when XDG user dirs changes
Fixes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/12
extensions/places-menu/placeDisplay.js | 38 ++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
---
diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js
index ba316bf..964e0b6 100644
--- a/extensions/places-menu/placeDisplay.js
+++ b/extensions/places-menu/placeDisplay.js
@@ -235,6 +235,28 @@ var PlacesManager = new Lang.Class({
this._showDesktopIconsChangedId =
this._settings.connect('changed::show-desktop-icons',
Lang.bind(this, this._updateSpecials));
+
+ // unlike bookmark file, XDG's 'user-dirs.dirs' here only serves as a
+ // signal gnerator: when 'reload_user_special_dirs_cache' should be
+ // invoked, not a definitive source for user special dirs, which is
+ // handled by GLib as before.
+ this._userDirsFile = this._findUserDirsFile();
+ this._userDirsTimeoutId = 0;
+ this._userDirsMonitor = null;
+
+ if (this._userDirsFile) {
+ this._userDirsMonitor = this._userDirsFile.monitor_file(Gio.FileMonitorFlags.NONE, null);
+ this._userDirsMonitor.connect('changed', Lang.bind(this, function () {
+ if (this._userDirsTimeoutId > 0)
+ return;
+ /* Defensive event compression */
+ this._userDirsTimeoutId = Mainloop.timeout_add(100, Lang.bind(this, function () {
+ this._userDirsTimeoutId = 0;
+ this._updateSpecials();
+ return false;
+ }));
+ }));
+ }
this._updateSpecials();
/*
@@ -308,6 +330,9 @@ var PlacesManager = new Lang.Class({
if (this._settings.get_boolean('show-desktop-icons'))
dirs.push(GLib.UserDirectory.DIRECTORY_DESKTOP);
+ // Reload cache s.t. the changes on disk would appear here immediately
+ GLib.reload_user_special_dirs_cache();
+
for (let i = 0; i < dirs.length; i++) {
let specialPath = GLib.get_user_special_dir(dirs[i]);
if (specialPath == null || specialPath == homePath)
@@ -414,6 +439,19 @@ var PlacesManager = new Lang.Class({
this.emit('network-updated');
},
+ _findUserDirsFile: function() {
+ let paths = [
+ GLib.build_filenamev([GLib.get_user_config_dir(), 'user-dirs.dirs']),
+ ];
+
+ for (let i = 0; i < paths.length; i++) {
+ if (GLib.file_test(paths[i], GLib.FileTest.EXISTS))
+ return Gio.File.new_for_path(paths[i]);
+ }
+
+ return null;
+ },
+
_findBookmarksFile: function() {
let paths = [
GLib.build_filenamev([GLib.get_user_config_dir(), 'gtk-3.0', 'bookmarks']),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]