Commit ec364f86 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/quicklaunch: add "Ctrl+Shift+Arrow" to rearrange items

This adds support for rearranging items in the grid view and in the
popup, and can move a launcher item freely between the two view.
parent 4066474c
Pipeline #232042 passed with stage
in 1 minute and 37 seconds
......@@ -8,6 +8,7 @@ import QtQuick 2.15
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // for ContextMenu+MenuItem
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.plasmoid 2.0
import org.kde.draganddrop 2.0 as DragAndDrop
import "layout.js" as LayoutManager
......@@ -43,6 +44,97 @@ Item {
event.accepted = true;
break;
}
// BEGIN Arrow keys
if (!(event.modifiers & Qt.ControlModifier) || !(event.modifiers & Qt.ShiftModifier)) {
return;
}
switch (event.key) {
case Qt.Key_Up: {
if (iconItem.isPopupItem && iconItem.itemIndex === 0 && Plasmoid.location === PlasmaCore.Types.TopEdge) {
iconItem.ListView.view.moveItemToGrid(iconItem, url);
break;
} else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.BottomEdge) {
iconItem.GridView.view.moveItemToPopup(iconItem, url);
break;
}
decreaseIndex();
break;
}
case Qt.Key_Down: {
if (iconItem.isPopupItem && iconItem.itemIndex === iconItem.ListView.view.count - 1 && Plasmoid.location === PlasmaCore.Types.BottomEdge) {
iconItem.ListView.view.moveItemToGrid(iconItem, url);
break;
} else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.TopEdge) {
iconItem.GridView.view.moveItemToPopup(iconItem, url);
break;
}
increaseIndex();
break;
}
case Qt.Key_Left: {
if (iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.LeftEdge) {
iconItem.ListView.view.moveItemToGrid(iconItem, url);
break;
} else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.RightEdge) {
iconItem.GridView.view.moveItemToPopup(iconItem, url);
break;
}
decreaseIndex();
break;
}
case Qt.Key_Right: {
if (iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.RightEdge) {
iconItem.ListView.view.moveItemToGrid(iconItem, url);
break;
} else if (!iconItem.isPopupItem && Plasmoid.location === PlasmaCore.Types.LeftEdge) {
iconItem.GridView.view.moveItemToPopup(iconItem, url);
break;
}
increaseIndex();
break;
}
default:
return;
}
event.accepted = true;
// END Arrow keys
}
function decreaseIndex() {
const newIndex = iconItem.itemIndex - 1;
if (newIndex < 0) {
return;
}
if (iconItem.isPopupItem) {
popupModel.moveUrl(iconItem.itemIndex, newIndex);
iconItem.ListView.view.currentIndex = newIndex;
} else {
launcherModel.moveUrl(iconItem.itemIndex, newIndex);
iconItem.GridView.view.currentIndex = newIndex;
}
}
function increaseIndex() {
const newIndex = iconItem.itemIndex + 1;
if (newIndex === (iconItem.isPopupItem ? iconItem.ListView.view.count : iconItem.GridView.view.count)) {
return;
}
if (iconItem.isPopupItem) {
popupModel.moveUrl(iconItem.itemIndex, newIndex);
iconItem.ListView.view.currentIndex = newIndex;
} else {
launcherModel.moveUrl(iconItem.itemIndex, newIndex);
iconItem.GridView.view.currentIndex = newIndex;
}
}
DragAndDrop.DragArea {
......
......@@ -18,6 +18,7 @@ Item {
property bool dragging: false
property alias popupModel : popupModel
property alias listView: listView
width: LayoutManager.popupItemWidth()
height: Math.max(1, popupModel.count) * LayoutManager.popupItemHeight()
......@@ -85,6 +86,12 @@ Item {
highlightMoveDuration: PlasmaCore.Units.longDuration
highlightMoveVelocity: 1
function moveItemToGrid(iconItem, url) {
launcherModel.insertUrl(launcherModel.count, url);
listView.currentIndex = launcherModel.count - 1;
iconItem.removeLauncher();
}
}
Connections {
......
......@@ -118,6 +118,17 @@ Item {
}
delegate: IconItem { }
function moveItemToPopup(iconItem, url) {
if (!popupArrow.visible) {
return;
}
popup.visible = true;
popup.mainItem.popupModel.insertUrl(popup.mainItem.popupModel.count, url);
popup.mainItem.listView.currentIndex = popup.mainItem.popupModel.count - 1;
iconItem.removeLauncher();
}
}
PlasmaCore.IconItem {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment