@ -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 ) {
/ / g l o b a l l a u n c h e r
launch . push ( launcherRecord ) ;
} else {
/ / l a u n c h e r a s s i g n e d t o a c t i v i t i e s
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 ;
}
/ / / w a i t i n g l a u n c h e r s . . . t h i s i s u s e d i n o r d e r t o c h e c k
/ / / a w i n d o w o r s t a r t u p i f i t s l a u n c h e r i s p l a y i n g i t s a n i m a t i o n
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 ;
}
/ / ! t r u e i f u p w a r d i s t h e b e s t w a y t o i t e r a t e t h r o u g h c u r r e n t
/ / ! i n o r d e r t o m a k e i t e q u a l w i t h g o a l
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 ) ;
}
}
}
/ / / / / / / / /
/ / / / f u n c t i o n s
@ -1547,9 +1736,18 @@ Item {
function extSignalMoveTask ( group , from , to ) {
if ( group === latteDock . launchersGroup && ! root . dragSource ) {
tasksModel . move ( from , to ) ;
/ / ! d i s a b l e s y n c i n g f o r m o v i n g l a u n c h e r s a c t i o n i n f a v o r o f v a l i d a t o r O r d e r l a u n c h e r s S i g n a l
/ * t a s k s M o d e l . m o v e ( f r o m , t o ) ;
parabolicManager . updateTasksEdgesIndexes ( ) ;
root . separatorsUpdated ( ) ;
root . separatorsUpdated ( ) ; * /
}
}
function extSignalValidateLaunchersOrder ( group , launchers ) {
if ( group === latteDock . launchersGroup && ! root . dragSource ) {
launchersOrderValidatorTimer . stop ( ) ;
launchersOrderValidatorTimer . launchers = launchers ;
launchersOrderValidatorTimer . start ( ) ;
}
}