Skip to content

Commit

Permalink
Add indicator for recent icon names in prefs dialog
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
Finii committed Oct 22, 2021
1 parent ca543e5 commit 3983063
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions indicatorStatusIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down
29 changes: 26 additions & 3 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions schemas/org.gnome.shell.extensions.appindicator.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
<summary>Custom icons</summary>
<description>Replace any icons with custom icons from themes</description>
</key>
<key name="recent-icons" type="as">
<default>[]</default>
<summary>Recent icon IDs</summary>
<description>List of recently encountered icon ids</description>
</key>
</schema>
</schemalist>

0 comments on commit 3983063

Please sign in to comment.