From 1d7c1123afa4799487a9022a51e21656d2d767cc Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 22 Oct 2021 12:54:08 +0200 Subject: [PATCH 1/3] Add indicator for recent icon names in prefs dialog [why] When someone wants to exchange an icon with a custom one the icon name is needed. That can be nontrivial to find it out. [how] Just collect all icon names that we encountered since the extension has been started and list these names below the icon replacement table in the settings dialog. Signed-off-by: Fini Jastrow --- extension.js | 3 ++ indicatorStatusIcon.js | 8 +++++ prefs.js | 29 +++++++++++++++++-- ....shell.extensions.appindicator.gschema.xml | 5 ++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/extension.js b/extension.js index 81fbf928..7fd1392f 100644 --- a/extension.js +++ b/extension.js @@ -21,6 +21,7 @@ const Extension = imports.misc.extensionUtils.getCurrentExtension(); const StatusNotifierWatcher = Extension.imports.statusNotifierWatcher; const TrayIconsManager = Extension.imports.trayIconsManager; const Util = Extension.imports.util; +const SettingsManager = Extension.imports.settingsManager; let statusNotifierWatcher = null; let isEnabled = false; @@ -42,6 +43,8 @@ function init() { watchDog.destroy(); }; /* eslint-enable no-undef */ + const settings = SettingsManager.getDefaultGSettings(); + settings.reset('recent-icons'); // clear in preparation of new collection } // FIXME: when entering/leaving the lock screen, the extension might be enabled/disabled rapidly. diff --git a/indicatorStatusIcon.js b/indicatorStatusIcon.js index adfeb2d2..a0fc14d1 100644 --- a/indicatorStatusIcon.js +++ b/indicatorStatusIcon.js @@ -17,6 +17,7 @@ /* exported IndicatorStatusIcon, IndicatorStatusTrayIcon */ const Clutter = imports.gi.Clutter; +const GLib = imports.gi.GLib; const GObject = imports.gi.GObject; const St = imports.gi.St; @@ -182,6 +183,13 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon { } }); + const settings = SettingsManager.getDefaultGSettings(); + const iconIDs = settings.get_value('recent-icons').deep_unpack(); + if (this._indicator.id && !iconIDs.includes(this._indicator.id)) { + iconIDs.push(this._indicator.id); + settings.set_value('recent-icons', new GLib.Variant('as', iconIDs)); + } + this._showIfReady(); } diff --git a/prefs.js b/prefs.js index fb014c49..80a94c37 100644 --- a/prefs.js +++ b/prefs.js @@ -48,7 +48,7 @@ class AppIndicatorPreferences extends Gtk.Box { margin_end: 30, margin_top: 30, margin_bottom: 30 }); - this.custom_icons_vbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, + this.custom_icons_vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, spacing: 10, margin_start: 10, margin_end: 10, @@ -286,10 +286,33 @@ class AppIndicatorPreferences extends Gtk.Box { customTreeView.insert_column(customAttentionIconColumn, 2); customTreeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH); - if (imports.gi.versions.Gtk === '4.0') + const iconIDListStore = new Gtk.ListStore(); + iconIDListStore.set_column_types([ + GObject.TYPE_STRING, + ]); + const iconIDs = this._settings.get_value('recent-icons').deep_unpack(); + iconIDs.forEach(v => { + iconIDListStore.set(iconIDListStore.append(), [0], [v]); + }); + const iconIDTreeView = new Gtk.TreeView({ + model: iconIDListStore, + }); + const iconIDTreeViewColumn = new Gtk.TreeViewColumn({ + title: 'Recent Indicator IDs', + }); + const standardCellRenderer = new Gtk.CellRendererText(); + iconIDTreeViewColumn.pack_start(standardCellRenderer, true); + iconIDTreeViewColumn.add_attribute(standardCellRenderer, 'text', 0); + iconIDTreeView.insert_column(iconIDTreeViewColumn, 0); + iconIDTreeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH); + + if (imports.gi.versions.Gtk === '4.0') { this.custom_icons_vbox.append(customTreeView); - else + this.custom_icons_vbox.append(iconIDTreeView); + } else { this.custom_icons_vbox.pack_start(customTreeView, false, false, 0); + this.custom_icons_vbox.pack_start(iconIDTreeView, true, true, 0); + } cellrenderer.connect('edited', (w, path, text) => { this.selection = customTreeView.get_selection(); diff --git a/schemas/org.gnome.shell.extensions.appindicator.gschema.xml b/schemas/org.gnome.shell.extensions.appindicator.gschema.xml index 4fac8bf6..b5a66c3d 100644 --- a/schemas/org.gnome.shell.extensions.appindicator.gschema.xml +++ b/schemas/org.gnome.shell.extensions.appindicator.gschema.xml @@ -41,5 +41,10 @@ Custom icons Replace any icons with custom icons from themes + + [] + Recent icon IDs + List of recently encountered icon ids + From 4ab72835ba6d0f4f2ba0aa87caadae397f251570 Mon Sep 17 00:00:00 2001 From: aunetx Date: Thu, 3 Mar 2022 23:49:47 +0100 Subject: [PATCH 2/3] Improve icon id retrieving mechanism in preferences - update the list when an indicator is added while preferences are open - fixes a bug where the icons are not added any more once the extension is started (the reason why `_addToRecentIcons` is called in `_showIfReady`) --- indicatorStatusIcon.js | 18 +++++++++++------- prefs.js | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/indicatorStatusIcon.js b/indicatorStatusIcon.js index a0fc14d1..b319c396 100644 --- a/indicatorStatusIcon.js +++ b/indicatorStatusIcon.js @@ -183,13 +183,6 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon { } }); - const settings = SettingsManager.getDefaultGSettings(); - const iconIDs = settings.get_value('recent-icons').deep_unpack(); - if (this._indicator.id && !iconIDs.includes(this._indicator.id)) { - iconIDs.push(this._indicator.id); - settings.set_value('recent-icons', new GLib.Variant('as', iconIDs)); - } - this._showIfReady(); } @@ -243,6 +236,16 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon { } } + _addToRecentIcons() { + const settings = SettingsManager.getDefaultGSettings(); + const iconIDs = settings.get_value('recent-icons').deep_unpack(); + + if (this._indicator.id && !iconIDs.includes(this._indicator.id)) { + iconIDs.push(this._indicator.id); + settings.set_value('recent-icons', new GLib.Variant('as', iconIDs)); + } + } + _showIfReady() { if (!this.isReady()) return; @@ -250,6 +253,7 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon { this._updateLabel(); this._updateStatus(); this._updateMenu(); + this._addToRecentIcons(); super._showIfReady(); } diff --git a/prefs.js b/prefs.js index 80a94c37..7abc9491 100644 --- a/prefs.js +++ b/prefs.js @@ -290,16 +290,27 @@ class AppIndicatorPreferences extends Gtk.Box { iconIDListStore.set_column_types([ GObject.TYPE_STRING, ]); - const iconIDs = this._settings.get_value('recent-icons').deep_unpack(); - iconIDs.forEach(v => { - iconIDListStore.set(iconIDListStore.append(), [0], [v]); - }); + const iconIDListTrack = []; const iconIDTreeView = new Gtk.TreeView({ model: iconIDListStore, }); const iconIDTreeViewColumn = new Gtk.TreeViewColumn({ title: 'Recent Indicator IDs', }); + + const updateRecentIcons = () => { + const iconIDs = this._settings.get_value('recent-icons').deep_unpack(); + iconIDs.forEach(v => { + if (!iconIDListTrack.includes(v)) { + iconIDListStore.set(iconIDListStore.append(), [0], [v]); + iconIDListTrack.push(v); + } + }); + }; + + this._settings.connect('changed::recent-icons', updateRecentIcons); + updateRecentIcons(); + const standardCellRenderer = new Gtk.CellRendererText(); iconIDTreeViewColumn.pack_start(standardCellRenderer, true); iconIDTreeViewColumn.add_attribute(standardCellRenderer, 'text', 0); From b7bcf10bb40e36150666415681fd31a18db90e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Hamy?= Date: Tue, 9 Apr 2024 10:14:52 +0200 Subject: [PATCH 3/3] Fix badly merged master branch --- extension.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension.js b/extension.js index 157eda9f..945bab43 100644 --- a/extension.js +++ b/extension.js @@ -47,13 +47,13 @@ export default class DashToDockExtension extends Extension.Extension { this._watchDog = null; }; /* eslint-enable no-undef */ - const settings = SettingsManager.getDefaultGSettings(); - settings.reset('recent-icons'); // clear in preparation of new collection } enable() { this._isEnabled = true; SettingsManager.initialize(this); + const settings = SettingsManager.getDefault().gsettings; + settings.reset('recent-icons'); // clear in preparation of new collection Util.tryCleanupOldIndicators(); this._maybeEnableAfterNameAvailable(); TrayIconsManager.TrayIconsManager.initialize();