[gnome-shell/eos3.8: 104/255] appDisplay: Add moveItem()
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/eos3.8: 104/255] appDisplay: Add moveItem()
- Date: Wed, 10 Jun 2020 19:06:43 +0000 (UTC)
commit ddca9b4e0d42d02f46bb0e7bd2fe3a4cb2c0dd18
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Jul 2 17:41:15 2019 -0300
appDisplay: Add moveItem()
This is a handy function to implement changing an icon's position
in the grid.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/603
js/ui/appDisplay.js | 30 ++++++++++++++++++++++++++++++
js/ui/iconGrid.js | 16 ++++++++++++++++
2 files changed, 46 insertions(+)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index e1ca87eeef..5714af6676 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -213,6 +213,36 @@ var BaseAppView = GObject.registerClass({
return a.name.localeCompare(b.name);
}
+ moveItem(item, newPosition) {
+ let visibleItems = this._orderedItems.filter(item => item.visible);
+
+ // Avoid overflow
+ if (newPosition >= visibleItems.length)
+ return -1;
+
+ let targetId = visibleItems[newPosition].id;
+
+ let visibleIndex = visibleItems.indexOf(item);
+ if (newPosition > visibleIndex)
+ newPosition -= 1;
+
+ // Remove from the old position
+ let itemIndex = this._orderedItems.indexOf(item);
+
+ let realPosition = -1;
+ if (itemIndex != -1) {
+ this._orderedItems.splice(itemIndex, 1);
+ realPosition = this._grid.moveItem(item, newPosition);
+ this._orderedItems.splice(realPosition, 0, item);
+ } else {
+ realPosition = this._orderedItems.indexOf(targetId);
+ }
+
+ this._iconGridLayout.repositionIcon(item.id, targetId, this.id);
+
+ return realPosition;
+ }
+
_selectAppInternal(id) {
if (this._items.has(id))
this._items.get(id).navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 7c87f224bf..1f9aa1d4f8 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -664,6 +664,22 @@ var IconGrid = GObject.registerClass({
this.add_actor(item);
}
+ moveItem(item, newPosition) {
+ if (!this.contains(item)) {
+ log('Cannot move item not contained by the IconGrid');
+ return;
+ }
+
+ let children = this.get_children();
+ let visibleChildren = children.filter(c => c.is_visible());
+ let visibleChildAtPosition = visibleChildren[newPosition];
+ let realPosition = children.indexOf(visibleChildAtPosition);
+
+ this.set_child_at_index(item, realPosition);
+
+ return realPosition;
+ }
+
removeItem(item) {
this.remove_child(item);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]