Skip to content

Commit 00943d5

Browse files
committed
gpaste-reloaded: add option to reverse history order (fixes #8042)
remove redundant comments
1 parent 3dc7082 commit 00943d5

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

gpaste-reloaded@feuerfuchs.eu/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is a completely re-written GPaste applet based on the [gnome shell extensio
66
* Support for multiple histories
77
* Manually add entries to the history
88
* Unlimited instances
9+
* Option to reverse the history order so that new items appear at the bottom of the menu
910

1011

1112
# Installation

gpaste-reloaded@feuerfuchs.eu/files/gpaste-reloaded@feuerfuchs.eu/6.4/applet.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class GPasteApplet extends Applet.IconApplet {
146146
this._appletSettings.bind("display-searchbar", "displaySearchBar", this._onDisplaySettingsUpdated);
147147
this._appletSettings.bind("display-gpaste-ui", "displayGPasteUI", this._onDisplaySettingsUpdated);
148148
this._appletSettings.bind("display-empty-history", "displayEmptyHistory", this._onDisplaySettingsUpdated);
149+
this._appletSettings.bind("reverse-history-order", "reverseHistory", this._onDisplaySettingsUpdated);
149150

150151
this._appletSettings.bind("kb-show-history", "kbShowHistory", this._onKeybindingUpdated);
151152
this._onKeybindingUpdated();
@@ -254,6 +255,9 @@ class GPasteApplet extends Applet.IconApplet {
254255

255256
this.msepBottom2.actor.visible = this.displayGPasteUI;
256257
this.mitemUI.actor.visible = this.displayGPasteUI;
258+
259+
// any change to these settings may require re-rendering the history
260+
this._onSettingsUpdated();
257261
}
258262

259263
/*
@@ -273,10 +277,6 @@ class GPasteApplet extends Applet.IconApplet {
273277
}
274278
}
275279

276-
if (this.mitemSearch.entry.get_text() == '') {
277-
this._historyItems[0].actor.set_style("font-weight: bold;");
278-
}
279-
280280
this.refresh(oldSize);
281281
}
282282

@@ -352,6 +352,9 @@ class GPasteApplet extends Applet.IconApplet {
352352
* Refresh the history items
353353
*/
354354
refresh (startID) {
355+
// clear any previous styling before we repopulate
356+
this._historyItems.forEach(item => item.actor.set_style(null));
357+
355358
if (this._searchResults.length > 0) { // Search field isn't empty
356359
this.search(this.mitemSearch.getText());
357360
} else {
@@ -364,7 +367,9 @@ class GPasteApplet extends Applet.IconApplet {
364367
}
365368

366369
for (let i = startID; i < size; ++i) {
367-
this._historyItems[i].setIndex(i);
370+
// if reverseHistory is enabled we flip the index we ask for
371+
const idx = this.reverseHistory ? (size - 1 - i) : i;
372+
this._historyItems[i].setIndex(idx);
368373
}
369374
for (let i = size; i < maxSize; ++i) {
370375
this._historyItems[i].setIndex(-1);
@@ -374,6 +379,10 @@ class GPasteApplet extends Applet.IconApplet {
374379
this.mitemHistoryIsEmpty.actor.show();
375380
} else {
376381
this.mitemHistoryIsEmpty.actor.hide();
382+
// highlight the item that corresponds to the newest element
383+
const highlightPos = this.reverseHistory ? size - 1 : 0;
384+
if (highlightPos >= 0 && highlightPos < this._historyItems.length)
385+
this._historyItems[highlightPos].actor.set_style("font-weight: bold;");
377386
}
378387
});
379388
}
@@ -397,14 +406,18 @@ class GPasteApplet extends Applet.IconApplet {
397406
results = maxSize;
398407
}
399408

409+
// if we're showing results in reverse order we should flip the array
410+
const ordered = this.reverseHistory ? this._searchResults.slice().reverse() : this._searchResults;
411+
400412
this._historyItems.slice(0, results).forEach((item, index) => {
401-
item.setUuid(this._searchResults[index]);
413+
item.setUuid(ordered[index]);
402414
});
403415
this._historyItems.slice(results, maxSize).forEach((item, index) => {
404416
item.setIndex(-1);
405417
});
406418

407-
this._historyItems[0].actor.set_style(null);
419+
// clear styling from all items when searching
420+
this._historyItems.forEach(item => item.actor.set_style(null));
408421

409422
if (results == 0) { // There aren't any results, display "(No results)"
410423
this.mitemNoSearchResults.actor.show();
@@ -417,7 +430,6 @@ class GPasteApplet extends Applet.IconApplet {
417430

418431
this._searchResults = [];
419432
this.refresh(0);
420-
this._historyItems[0].actor.set_style("font-weight: bold;");
421433
}
422434
}
423435

@@ -572,6 +584,17 @@ class GPasteApplet extends Applet.IconApplet {
572584
this.mitemTrack.setToggleState(state);
573585
}
574586

587+
/*
588+
* Called whenever settings change that affect how the history is presented
589+
*/
590+
_onSettingsUpdated() {
591+
if (this._searchResults.length > 0) {
592+
this.search(this.mitemSearch.getText());
593+
} else {
594+
this.refresh(0);
595+
}
596+
}
597+
575598
//
576599
// Overrides
577600
// ---------------------------------------------------------------------------------

gpaste-reloaded@feuerfuchs.eu/files/gpaste-reloaded@feuerfuchs.eu/6.4/settings-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
"type": "checkbox",
3434
"description": "Display 'Empty history'"
3535
},
36+
"reverse-history-order": {
37+
"default": false,
38+
"type": "checkbox",
39+
"description": "Reverse history order (newest at bottom)"
40+
},
3641

3742
"key-bindings": {
3843
"type": "header",

0 commit comments

Comments
 (0)