mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-26 23:21:37 +03:00
publish internal separators indexes after dragging
This commit is contained in:
parent
67ce3441a4
commit
a2fc2edc30
@ -265,5 +265,42 @@ void LaunchersSignals::moveTask(QString layoutName, int senderId, int launcherGr
|
||||
}
|
||||
|
||||
|
||||
void LaunchersSignals::internalSeparators(QString layoutName, int senderId, int launcherGroup,
|
||||
QStringList separators, QStringList indexes)
|
||||
{
|
||||
Dock::LaunchersGroup group = static_cast<Dock::LaunchersGroup>(launcherGroup);
|
||||
|
||||
if ((Dock::LaunchersGroup)group == Dock::UniqueLaunchers) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString lName = (group == Dock::LayoutLaunchers) ? layoutName : "";
|
||||
|
||||
foreach (auto applet, lattePlasmoids(lName)) {
|
||||
if (applet->id() != senderId) {
|
||||
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) {
|
||||
const auto &childItems = appletInterface->childItems();
|
||||
|
||||
if (childItems.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (QQuickItem *item : childItems) {
|
||||
if (auto *metaObject = item->metaObject()) {
|
||||
int methodIndex = metaObject->indexOfMethod("extSignalInternalSeparators(QVariant,QVariant,QVariant)");
|
||||
|
||||
if (methodIndex == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QMetaMethod method = metaObject->method(methodIndex);
|
||||
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, separators), Q_ARG(QVariant, indexes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //end of namespace
|
||||
|
@ -50,6 +50,8 @@ public slots:
|
||||
Q_INVOKABLE void removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity);
|
||||
Q_INVOKABLE void urlsDropped(QString layoutName, int launcherGroup, QStringList urls);
|
||||
Q_INVOKABLE void moveTask(QString layoutName, int senderId, int launcherGroup, int from, int to);
|
||||
Q_INVOKABLE void internalSeparators(QString layoutName, int senderId, int launcherGroup,
|
||||
QStringList separators, QStringList indexes);
|
||||
|
||||
private:
|
||||
QList<Plasma::Applet *> lattePlasmoids(QString layoutName);
|
||||
|
@ -148,7 +148,9 @@ Item {
|
||||
var pos = root.dragSource.itemIndex;
|
||||
tasksModel.move(pos, insertAt);
|
||||
if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
latteDock.universalLayoutManager.launchersSignals.moveTask(plasmoid.id, latteDock.launchersGroup, pos, insertAt);
|
||||
latteDock.universalLayoutManager.launchersSignals.moveTask(root.managedLayoutName,
|
||||
plasmoid.id,
|
||||
latteDock.launchersGroup, pos, insertAt);
|
||||
}
|
||||
|
||||
ignoreItemTimer.restart();
|
||||
|
@ -53,6 +53,57 @@ Item {
|
||||
Connections{
|
||||
target: root
|
||||
onTasksCountChanged:parManager.updateTasksEdgesIndexes();
|
||||
onDragSourceChanged: {
|
||||
if (!root.dragSource && parManager.hasInternalSeparator) {
|
||||
//! Send the internal separators to other docks
|
||||
var tasks = icList.contentItem.children;
|
||||
var size = icList.contentItem.children.length;
|
||||
var tempSeparatorsArray = [];
|
||||
var tempSeparatorsIndexes = [];
|
||||
|
||||
for(var i=0; i<size; ++i){
|
||||
if (i>=icList.contentItem.children.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (tasks[i] && tasks[i].isSeparator) {
|
||||
tempSeparatorsArray.push(tasks[i].launcherUrl);
|
||||
tempSeparatorsIndexes.push(tasks[i].itemIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (tempSeparatorsArray.length > 0) {
|
||||
if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
//reorder to lowest
|
||||
for(var i=0; i<tempSeparatorsIndexes.length; ++i) {
|
||||
var lowIndex = i;
|
||||
for(var j=i; j<tempSeparatorsIndexes.length; ++j) {
|
||||
if (tempSeparatorsIndexes[j]<tempSeparatorsIndexes[lowIndex]) {
|
||||
lowIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (lowIndex !== i) {
|
||||
//moving
|
||||
var tempInd = tempSeparatorsIndexes[lowIndex];
|
||||
tempSeparatorsIndexes.splice(lowIndex, 1);
|
||||
tempSeparatorsIndexes.splice(i, 0, tempInd);
|
||||
|
||||
var tempName = tempSeparatorsArray[lowIndex];
|
||||
tempSeparatorsArray.splice(lowIndex, 1);
|
||||
tempSeparatorsArray.splice(i, 0, tempName);
|
||||
}
|
||||
}
|
||||
|
||||
latteDock.universalLayoutManager.launchersSignals.internalSeparators(root.managedLayoutName,
|
||||
plasmoid.id,
|
||||
latteDock.launchersGroup,
|
||||
tempSeparatorsArray,
|
||||
tempSeparatorsIndexes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: updateTasksEdgesIndexes();
|
||||
@ -553,8 +604,8 @@ Item {
|
||||
|
||||
tasksModel.move(from, to);
|
||||
if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
latteDock.universalLayoutManager.launchersSignals.moveTask(root.managedLayoutName,
|
||||
plasmoid.id, latteDock.launchersGroup, from, to);
|
||||
latteDock.universalLayoutManager.launchersSignals.moveTask(root.managedLayoutName,
|
||||
plasmoid.id, latteDock.launchersGroup, from, to);
|
||||
}
|
||||
|
||||
if (isSeparator(launcherUrl)) {
|
||||
|
@ -1473,6 +1473,37 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function extSignalInternalSeparators(group, separators, indexes) {
|
||||
if (group === latteDock.launchersGroup && !root.dragSource) {
|
||||
var tasks = icList.contentItem.children;
|
||||
var size = icList.contentItem.children.length;
|
||||
|
||||
for(var i=0; i<separators.length; ++i) {
|
||||
var curIndex = -1;
|
||||
var toIndex = Number(indexes[i]);
|
||||
|
||||
for(var j=0; j<size; ++j) {
|
||||
if (j>=icList.contentItem.children.length){
|
||||
break;
|
||||
}
|
||||
|
||||
if (tasks[j] && tasks[j].launcherUrl === separators[i]) {
|
||||
curIndex = tasks[j].itemIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if ((curIndex !== -1) && (curIndex!==toIndex)) {
|
||||
if (toIndex>=icList.contentItem.children.length) {
|
||||
toIndex = icList.contentItem.children.length-1;
|
||||
}
|
||||
|
||||
console.log("Fix internal separator pos, from :: " +curIndex + " to :: " + toIndex);
|
||||
tasksModel.move(curIndex, toIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! END ::: external launchers signals in order to update the tasks model
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user