Skip to content

Commit df9b2d2

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

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-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: 25 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,8 @@ class GPasteApplet extends Applet.IconApplet {
254255

255256
this.msepBottom2.actor.visible = this.displayGPasteUI;
256257
this.mitemUI.actor.visible = this.displayGPasteUI;
258+
259+
this._onSettingsUpdated();
257260
}
258261

259262
/*
@@ -273,10 +276,6 @@ class GPasteApplet extends Applet.IconApplet {
273276
}
274277
}
275278

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

@@ -352,6 +351,8 @@ class GPasteApplet extends Applet.IconApplet {
352351
* Refresh the history items
353352
*/
354353
refresh (startID) {
354+
this._historyItems.forEach(item => item.actor.set_style(null));
355+
355356
if (this._searchResults.length > 0) { // Search field isn't empty
356357
this.search(this.mitemSearch.getText());
357358
} else {
@@ -364,7 +365,8 @@ class GPasteApplet extends Applet.IconApplet {
364365
}
365366

366367
for (let i = startID; i < size; ++i) {
367-
this._historyItems[i].setIndex(i);
368+
const idx = this.reverseHistory ? (size - 1 - i) : i;
369+
this._historyItems[i].setIndex(idx);
368370
}
369371
for (let i = size; i < maxSize; ++i) {
370372
this._historyItems[i].setIndex(-1);
@@ -374,6 +376,9 @@ class GPasteApplet extends Applet.IconApplet {
374376
this.mitemHistoryIsEmpty.actor.show();
375377
} else {
376378
this.mitemHistoryIsEmpty.actor.hide();
379+
const highlightPos = this.reverseHistory ? size - 1 : 0;
380+
if (highlightPos >= 0 && highlightPos < this._historyItems.length)
381+
this._historyItems[highlightPos].actor.set_style("font-weight: bold;");
377382
}
378383
});
379384
}
@@ -397,14 +402,16 @@ class GPasteApplet extends Applet.IconApplet {
397402
results = maxSize;
398403
}
399404

405+
const ordered = this.reverseHistory ? this._searchResults.slice().reverse() : this._searchResults;
406+
400407
this._historyItems.slice(0, results).forEach((item, index) => {
401-
item.setUuid(this._searchResults[index]);
408+
item.setUuid(ordered[index]);
402409
});
403410
this._historyItems.slice(results, maxSize).forEach((item, index) => {
404411
item.setIndex(-1);
405412
});
406413

407-
this._historyItems[0].actor.set_style(null);
414+
this._historyItems.forEach(item => item.actor.set_style(null));
408415

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

418425
this._searchResults = [];
419426
this.refresh(0);
420-
this._historyItems[0].actor.set_style("font-weight: bold;");
421427
}
422428
}
423429

@@ -572,6 +578,17 @@ class GPasteApplet extends Applet.IconApplet {
572578
this.mitemTrack.setToggleState(state);
573579
}
574580

581+
/*
582+
* Called whenever settings change that affect how the history is presented
583+
*/
584+
_onSettingsUpdated() {
585+
if (this._searchResults.length > 0) {
586+
this.search(this.mitemSearch.getText());
587+
} else {
588+
this.refresh(0);
589+
}
590+
}
591+
575592
//
576593
// Overrides
577594
// ---------------------------------------------------------------------------------

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)