Skip to content

Commit 3983063

Browse files
committed
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 <ulf.fini.jastrow@desy.de>
1 parent ca543e5 commit 3983063

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

extension.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Extension = imports.misc.extensionUtils.getCurrentExtension();
2121
const StatusNotifierWatcher = Extension.imports.statusNotifierWatcher;
2222
const TrayIconsManager = Extension.imports.trayIconsManager;
2323
const Util = Extension.imports.util;
24+
const SettingsManager = Extension.imports.settingsManager;
2425

2526
let statusNotifierWatcher = null;
2627
let isEnabled = false;
@@ -42,6 +43,8 @@ function init() {
4243
watchDog.destroy();
4344
};
4445
/* eslint-enable no-undef */
46+
const settings = SettingsManager.getDefaultGSettings();
47+
settings.reset('recent-icons'); // clear in preparation of new collection
4548
}
4649

4750
// FIXME: when entering/leaving the lock screen, the extension might be enabled/disabled rapidly.

indicatorStatusIcon.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/* exported IndicatorStatusIcon, IndicatorStatusTrayIcon */
1818

1919
const Clutter = imports.gi.Clutter;
20+
const GLib = imports.gi.GLib;
2021
const GObject = imports.gi.GObject;
2122
const St = imports.gi.St;
2223

@@ -182,6 +183,13 @@ class AppIndicatorsIndicatorStatusIcon extends BaseStatusIcon {
182183
}
183184
});
184185

186+
const settings = SettingsManager.getDefaultGSettings();
187+
const iconIDs = settings.get_value('recent-icons').deep_unpack();
188+
if (this._indicator.id && !iconIDs.includes(this._indicator.id)) {
189+
iconIDs.push(this._indicator.id);
190+
settings.set_value('recent-icons', new GLib.Variant('as', iconIDs));
191+
}
192+
185193
this._showIfReady();
186194
}
187195

prefs.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AppIndicatorPreferences extends Gtk.Box {
4848
margin_end: 30,
4949
margin_top: 30,
5050
margin_bottom: 30 });
51-
this.custom_icons_vbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
51+
this.custom_icons_vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
5252
spacing: 10,
5353
margin_start: 10,
5454
margin_end: 10,
@@ -286,10 +286,33 @@ class AppIndicatorPreferences extends Gtk.Box {
286286
customTreeView.insert_column(customAttentionIconColumn, 2);
287287
customTreeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH);
288288

289-
if (imports.gi.versions.Gtk === '4.0')
289+
const iconIDListStore = new Gtk.ListStore();
290+
iconIDListStore.set_column_types([
291+
GObject.TYPE_STRING,
292+
]);
293+
const iconIDs = this._settings.get_value('recent-icons').deep_unpack();
294+
iconIDs.forEach(v => {
295+
iconIDListStore.set(iconIDListStore.append(), [0], [v]);
296+
});
297+
const iconIDTreeView = new Gtk.TreeView({
298+
model: iconIDListStore,
299+
});
300+
const iconIDTreeViewColumn = new Gtk.TreeViewColumn({
301+
title: 'Recent Indicator IDs',
302+
});
303+
const standardCellRenderer = new Gtk.CellRendererText();
304+
iconIDTreeViewColumn.pack_start(standardCellRenderer, true);
305+
iconIDTreeViewColumn.add_attribute(standardCellRenderer, 'text', 0);
306+
iconIDTreeView.insert_column(iconIDTreeViewColumn, 0);
307+
iconIDTreeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH);
308+
309+
if (imports.gi.versions.Gtk === '4.0') {
290310
this.custom_icons_vbox.append(customTreeView);
291-
else
311+
this.custom_icons_vbox.append(iconIDTreeView);
312+
} else {
292313
this.custom_icons_vbox.pack_start(customTreeView, false, false, 0);
314+
this.custom_icons_vbox.pack_start(iconIDTreeView, true, true, 0);
315+
}
293316

294317
cellrenderer.connect('edited', (w, path, text) => {
295318
this.selection = customTreeView.get_selection();

schemas/org.gnome.shell.extensions.appindicator.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
<summary>Custom icons</summary>
4242
<description>Replace any icons with custom icons from themes</description>
4343
</key>
44+
<key name="recent-icons" type="as">
45+
<default>[]</default>
46+
<summary>Recent icon IDs</summary>
47+
<description>List of recently encountered icon ids</description>
48+
</key>
4449
</schema>
4550
</schemalist>

0 commit comments

Comments
 (0)