mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-26 23:21:37 +03:00
add launchers validator for syncing launchers
--moving a task now is not synced immediately to other docks. Syncing takes place only in the end. The dock in which the user changed the launchers order sends a signal to other docks to update theirs launchers order. BUG: 401232
This commit is contained in:
parent
97d476a3f0
commit
6c58115f9b
@ -272,4 +272,40 @@ void LaunchersSignals::moveTask(QString layoutName, int senderId, int launcherGr
|
||||
}
|
||||
}
|
||||
|
||||
void LaunchersSignals::validateLaunchersOrder(QString layoutName, int senderId, int launcherGroup, QStringList launchers)
|
||||
{
|
||||
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("extSignalValidateLaunchersOrder(QVariant,QVariant)");
|
||||
|
||||
if (methodIndex == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QMetaMethod method = metaObject->method(methodIndex);
|
||||
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //end of namespace
|
||||
|
@ -56,7 +56,9 @@ public slots:
|
||||
Q_INVOKABLE void addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity);
|
||||
Q_INVOKABLE void removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity);
|
||||
Q_INVOKABLE void urlsDropped(QString layoutName, int launcherGroup, QStringList urls);
|
||||
//!Deprecated because it could create crashes, validateLaunchersOrder provides a better approach
|
||||
Q_INVOKABLE void moveTask(QString layoutName, int senderId, int launcherGroup, int from, int to);
|
||||
Q_INVOKABLE void validateLaunchersOrder(QString layoutName, int senderId, int launcherGroup, QStringList launchers);
|
||||
|
||||
private:
|
||||
QList<Plasma::Applet *> lattePlasmoids(QString layoutName);
|
||||
|
@ -158,11 +158,12 @@ Item {
|
||||
|
||||
var pos = root.dragSource.itemIndex;
|
||||
tasksModel.move(pos, insertAt);
|
||||
if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
//! disable syncing for moving launchers action in favor of validatorOrder launchersSignal
|
||||
/* if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
latteDock.universalLayoutManager.launchersSignals.moveTask(root.managedLayoutName,
|
||||
plasmoid.id,
|
||||
latteDock.launchersGroup, pos, insertAt);
|
||||
}
|
||||
}*/
|
||||
root.separatorsUpdated();
|
||||
ignoreItemTimer.restart();
|
||||
}
|
||||
|
@ -366,6 +366,61 @@ Item {
|
||||
return createLaunchers;
|
||||
}
|
||||
|
||||
function currentLauncherList() {
|
||||
var launch = [];
|
||||
var launchersList = [];
|
||||
|
||||
if (currentLayout) {
|
||||
if (latteDock && latteDock.universalLayoutManager
|
||||
&& latteDock.dockManagedLayout && latteDock.universalSettings
|
||||
&& (latteDock.launchersGroup === Latte.Dock.LayoutLaunchers
|
||||
|| latteDock.launchersGroup === Latte.Dock.GlobalLaunchers)) {
|
||||
|
||||
if (latteDock.launchersGroup === Latte.Dock.LayoutLaunchers) {
|
||||
launchersList = latteDock.dockManagedLayout.launchers;
|
||||
} else if (latteDock.launchersGroup === Latte.Dock.GlobalLaunchers) {
|
||||
launchersList = latteDock.universalSettings.launchers;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
launchersList = plasmoid.configuration.launchers59;
|
||||
}
|
||||
|
||||
|
||||
for(var i=0; i<launchersList.length; ++i){
|
||||
var launcherRecord = launchersList[i];
|
||||
|
||||
if (launcherRecord.indexOf("[") === -1) {
|
||||
//global launcher
|
||||
launch.push(launcherRecord);
|
||||
} else {
|
||||
//launcher assigned to activities
|
||||
var end = launcherRecord.indexOf("\n");
|
||||
var explicitLauncher = launcherRecord.substring(end+1,launcherRecord.length);
|
||||
if (explicitLauncher !== "" && launcherRecord.indexOf(activityInfo.currentActivity) > -1) {
|
||||
launch.push(explicitLauncher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return launch;
|
||||
}
|
||||
|
||||
function currentListViewLauncherList() {
|
||||
var launch = [];
|
||||
|
||||
var tasks = icList.contentItem.children;
|
||||
for(var i=0; i<tasks.length; ++i){
|
||||
var task = icList.childAtIndex(i);
|
||||
|
||||
if (task!==undefined && task.launcherUrl!=="" && tasksModel.launcherInCurrentActivity(task.launcherUrl)) {
|
||||
launch.push(task.launcherUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return launch;
|
||||
}
|
||||
|
||||
/// waiting launchers... this is used in order to check
|
||||
/// a window or startup if its launcher is playing its animation
|
||||
function addWaitingLauncher(launch){
|
||||
@ -434,11 +489,11 @@ Item {
|
||||
|
||||
onDragSourceChanged: {
|
||||
if (dragSource == null) {
|
||||
restoreDraggingPhaseTimer.start();
|
||||
root.draggingFinished();
|
||||
root.signalActionsBlockHiding(-1);
|
||||
|
||||
tasksModel.syncLaunchers();
|
||||
|
||||
restoreDraggingPhaseTimer.start();
|
||||
} else {
|
||||
inDraggingPhase = true;
|
||||
root.signalActionsBlockHiding(1);
|
||||
@ -634,6 +689,17 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function launcherInCurrentActivity(url) {
|
||||
var activities = tasksModel.launcherActivities(url);
|
||||
|
||||
var NULL_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
if (activities.indexOf(NULL_UUID) !== -1 || activities.indexOf(activityInfo.currentActivity) !== -1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
onActivityChanged: {
|
||||
ActivitiesTools.currentActivity = String(activity);
|
||||
}
|
||||
@ -650,6 +716,15 @@ Item {
|
||||
} else if (latteDock.launchersGroup === Latte.Dock.GlobalLaunchers) {
|
||||
latteDock.universalSettings.launchers = launcherList;
|
||||
}
|
||||
|
||||
if (inDraggingPhase) {
|
||||
if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) {
|
||||
latteDock.universalLayoutManager.launchersSignals.validateLaunchersOrder(root.managedLayoutName,
|
||||
plasmoid.id,
|
||||
latteDock.launchersGroup,
|
||||
currentLauncherList());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plasmoid.configuration.launchers59 = launcherList;
|
||||
}
|
||||
@ -1259,6 +1334,120 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Timer{
|
||||
id:launchersOrderValidatorTimer
|
||||
interval: 200
|
||||
|
||||
property var launchers: []
|
||||
|
||||
function launchersAreInSync() {
|
||||
return arraysAreEqual(currentListViewLauncherList(), launchers);
|
||||
}
|
||||
|
||||
function launcherValidPos(url) {
|
||||
for (var i=0; i<launchers.length; ++i) {
|
||||
if (launchers[i] === url) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function arraysAreEqual(list1, list2) {
|
||||
if (list1.length !== list2.length) {
|
||||
console.log(" arrays have different size...")
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i=0; i<list1.length; ++i) {
|
||||
if (list1[i] !== list2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! true if upward is the best way to iterate through current
|
||||
//! in order to make it equal with goal
|
||||
function upwardIsBetter(current, goal)
|
||||
{
|
||||
var tCurrent = current.slice();
|
||||
|
||||
if (!arraysAreEqual(tCurrent, goal)) {
|
||||
for (var i=0; i<tCurrent.length; ++i) {
|
||||
if (tCurrent[i] !== goal[i]) {
|
||||
var val = tCurrent[i];
|
||||
tCurrent.splice(i, 1);
|
||||
tCurrent.splice(goal.indexOf(val), 0, val);
|
||||
|
||||
if (arraysAreEqual(tCurrent, goal)){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
onTriggered: {
|
||||
if (launchersAreInSync()) {
|
||||
stop();
|
||||
console.log("launchers synced at:" + launchers);
|
||||
launchers.length = 0;
|
||||
parabolicManager.updateTasksEdgesIndexes();
|
||||
root.separatorsUpdated();
|
||||
} else {
|
||||
var currentLaunchers = currentListViewLauncherList();
|
||||
|
||||
if (upwardIsBetter(currentLaunchers, launchers)) {
|
||||
console.log("UPWARD....");
|
||||
for (var i=0; i<currentLaunchers.length; ++i) {
|
||||
if (currentLaunchers[i] !== launchers[i]) {
|
||||
var p = launcherValidPos(currentLaunchers[i]);
|
||||
if (p === -1) {
|
||||
console.log("No pos found for :"+currentLaunchers[i] + " at: "+launchers);
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(" moving:" +i + " _ " + p );
|
||||
tasksModel.move(i, p);
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("DOWNWARD....");
|
||||
for (var i=currentLaunchers.length-1; i>=0; --i) {
|
||||
if (currentLaunchers[i] !== launchers[i]) {
|
||||
var p = launcherValidPos(currentLaunchers[i]);
|
||||
if (p === -1) {
|
||||
console.log("No pos found for :"+currentLaunchers[i] + " at: "+launchers);
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(" moving:" +i + " _ " + p );
|
||||
tasksModel.move(i, p);
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("why we reached ??? ");
|
||||
console.log("CURRENT ::: " + currentLaunchers);
|
||||
console.log("VALID ::: " + launchers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////
|
||||
|
||||
//// functions
|
||||
@ -1547,9 +1736,18 @@ Item {
|
||||
|
||||
function extSignalMoveTask(group, from, to) {
|
||||
if (group === latteDock.launchersGroup && !root.dragSource) {
|
||||
tasksModel.move(from, to);
|
||||
//! disable syncing for moving launchers action in favor of validatorOrder launchersSignal
|
||||
/* tasksModel.move(from, to);
|
||||
parabolicManager.updateTasksEdgesIndexes();
|
||||
root.separatorsUpdated();
|
||||
root.separatorsUpdated();*/
|
||||
}
|
||||
}
|
||||
|
||||
function extSignalValidateLaunchersOrder(group, launchers) {
|
||||
if (group === latteDock.launchersGroup && !root.dragSource) {
|
||||
launchersOrderValidatorTimer.stop();
|
||||
launchersOrderValidatorTimer.launchers = launchers;
|
||||
launchersOrderValidatorTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1122,17 +1122,6 @@ MouseArea{
|
||||
}
|
||||
///window previews////
|
||||
|
||||
function launcherIsPresent(url) {
|
||||
var activities = tasksModel.launcherActivities(url);
|
||||
|
||||
var NULL_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
if (activities.indexOf(NULL_UUID) !== -1 || activities.indexOf(activityInfo.currentActivity) !== -1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function modelIndex(){
|
||||
return tasksModel.makeModelIndex(index);
|
||||
}
|
||||
@ -1286,7 +1275,7 @@ MouseArea{
|
||||
function updateVisibilityBasedOnLaunchers(){
|
||||
var launcherExists = !(((tasksModel.launcherPosition(mainItemContainer.launcherUrl) == -1)
|
||||
&& (tasksModel.launcherPosition(mainItemContainer.launcherUrlWithIcon) == -1) )
|
||||
|| !launcherIsPresent(mainItemContainer.launcherUrl));
|
||||
|| !tasksModel.launcherInCurrentActivity(mainItemContainer.launcherUrl));
|
||||
|
||||
if (root.showWindowsOnlyFromLaunchers) {
|
||||
var hideWindow = !launcherExists && mainItemContainer.isWindow;
|
||||
@ -1378,7 +1367,7 @@ MouseArea{
|
||||
|| (tasksModel.launcherPosition(mainItemContainer.launcherUrlWithIcon) !== -1) );
|
||||
|
||||
//startup without launcher
|
||||
var hideStartup = ((!hasShownLauncher || !launcherIsPresent(mainItemContainer.launcherUrl))
|
||||
var hideStartup = ((!hasShownLauncher || !tasksModel.launcherInCurrentActivity(mainItemContainer.launcherUrl))
|
||||
&& mainItemContainer.isStartup);
|
||||
|
||||
if (!Latte.WindowSystem.compositingActive) {
|
||||
|
@ -51,10 +51,30 @@ Item{
|
||||
model:DelegateModel {
|
||||
id: windowsLocalModel
|
||||
model: tasksModel //icList.model
|
||||
rootIndex: tasksModel.makeModelIndex(currentIndex >=0 ? currentIndex : index)
|
||||
/* rootIndex: {
|
||||
if (root.inDraggingPhase) {
|
||||
return tasksModel.makeModelIndex(lastValidIndex);
|
||||
}
|
||||
|
||||
return tasksModel.makeModelIndex(currentIndex >=0 ? currentIndex : index)
|
||||
}*/
|
||||
|
||||
property int currentIndex: -1
|
||||
|
||||
//! Trying to avoid a crash during dragging tasks/launchers
|
||||
Binding{
|
||||
target: windowsLocalModel
|
||||
property: "rootIndex"
|
||||
|
||||
value: {
|
||||
if (root.inDraggingPhase) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tasksModel.makeModelIndex(currentIndex >=0 ? currentIndex : index)
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Item{
|
||||
readonly property string title: display
|
||||
readonly property bool isMinimized: IsMinimized === true ? true : false
|
||||
|
@ -35,7 +35,7 @@ SequentialAnimation {
|
||||
//Animation Add/Remove (4) - the user removes a launcher, animation enabled
|
||||
property bool animation1: ((((tasksModel.launcherPosition(mainItemContainer.launcherUrl) === -1)
|
||||
&& (tasksModel.launcherPosition(mainItemContainer.launcherUrlWithIcon) === -1) )
|
||||
|| !launcherIsPresent(mainItemContainer.launcherUrl))
|
||||
|| !tasksModel.launcherInCurrentActivity(mainItemContainer.launcherUrl))
|
||||
&& !mainItemContainer.isStartup && Latte.WindowSystem.compositingActive)
|
||||
|
||||
property bool animation4: ((mainItemContainer.launcherUrl===root.launcherForRemoval
|
||||
|
@ -118,7 +118,7 @@ SequentialAnimation{
|
||||
|
||||
//Animation Add/Remove (2) - when is window with no launcher, animations enabled
|
||||
//Animation Add/Remove (3) - when is launcher with no window, animations enabled
|
||||
var animation2 = ((!hasShownLauncher || !launcherIsPresent(mainItemContainer.launcherUrl))
|
||||
var animation2 = ((!hasShownLauncher || !tasksModel.launcherInCurrentActivity(mainItemContainer.launcherUrl))
|
||||
&& mainItemContainer.isWindow
|
||||
&& Latte.WindowSystem.compositingActive);
|
||||
|
||||
@ -134,7 +134,7 @@ SequentialAnimation{
|
||||
|
||||
|
||||
//startup without launcher, animation should be blocked
|
||||
var launcherExists = !(!hasShownLauncher || !launcherIsPresent(mainItemContainer.launcherUrl));
|
||||
var launcherExists = !(!hasShownLauncher || !tasksModel.launcherInCurrentActivity(mainItemContainer.launcherUrl));
|
||||
|
||||
//var hideStartup = launcherExists && mainItemContainer.isStartup; //! fix #976
|
||||
var hideWindow = root.showWindowsOnlyFromLaunchers && !launcherExists && mainItemContainer.isWindow;
|
||||
|
Loading…
Reference in New Issue
Block a user