[plasma/plasma-desktop] containments/panel: Panel: expose reorderApplets() function for scripting

Marco Martin <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 21cbb732ab85093b6c89340fe93396edae824a35 by Marco Martin.
Committed on 06/08/2026 at 13:41.
Pushed by mart into branch 'master'.

Panel: expose reorderApplets() function for scripting

Expose a reorderApplets function which takes a list of applet
ids and reorders the known applets consistent to such list.

Depends from https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/6895

CCBUG:523675

M  +17   -0    containments/panel/LayoutManager.js
M  +8    -0    containments/panel/main.qml

https://invent.kde.org/plasma/plasma-desktop/-/commit/21cbb732ab85093b6c89340fe93396edae824a35

diff --git a/containments/panel/LayoutManager.js b/containments/panel/LayoutManager.js
index fe0863f57c..2ab706d349 100644
--- a/containments/panel/LayoutManager.js
+++ b/containments/panel/LayoutManager.js
@@ -93,6 +93,23 @@ function save() {
     updateMargins();
 }
 
+function reorderApplets(order) {
+    let containerById = {};
+
+    for (let i = 0; i < appletsModel.count; ++i) {
+        let container = appletsModel.get(i).applet.parent;
+        containerById[container.applet.Plasmoid.id] = container
+    }
+
+    let i = 0;
+    order.forEach((appletId) => {
+        if (appletId in containerById) {
+            move(containerById[appletId], i);
+        }
+        ++i;
+    });
+}
+
 function childAtCoordinates(x, y) {
     if (root.isHorizontal) {
         y = layout.height / 2;
diff --git a/containments/panel/main.qml b/containments/panel/main.qml
index 7f8910b6fc..55034a2416 100644
--- a/containments/panel/main.qml
+++ b/containments/panel/main.qml
@@ -77,6 +77,13 @@ ContainmentItem {
         }
         return "";
     }
+
+    // This function is called externally by the Plasma scripting language to setup
+    // the panel layout
+    function reorderApplets(order) {
+        LayoutManager.reorderApplets(order);
+    }
+
 //END functions
 
 //BEGIN connections
@@ -140,6 +147,7 @@ ContainmentItem {
         });
         component.destroy();
     }
+
 //END connections
 
     TapHandler {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.