respect max favorite count when dropping

This commit is contained in:
Marco Martin 2021-02-16 13:37:50 +01:00
parent e01cf0b6a2
commit ed91354960

View file

@ -218,11 +218,16 @@ Item {
onDragEnter: { onDragEnter: {
event.accept(event.proposedAction); event.accept(event.proposedAction);
launcherDragManager.active = true;
} }
onDragMove: { onDragMove: {
let posInFavorites = favoriteStrip.mapFromItem(this, event.x, event.y); let posInFavorites = favoriteStrip.mapFromItem(this, event.x, event.y);
if (posInFavorites.y > 0) { if (posInFavorites.y > 0) {
if (plasmoid.nativeInterface.applicationListModel.favoriteCount >= plasmoid.nativeInterface.applicationListModel.maxFavoriteCount ) {
launcherDragManager.hideSpacer();
} else {
launcherDragManager.showSpacerAtPos(event.x, event.y, favoriteStrip); launcherDragManager.showSpacerAtPos(event.x, event.y, favoriteStrip);
}
appletsLayout.hidePlaceHolder(); appletsLayout.hidePlaceHolder();
} else { } else {
appletsLayout.showPlaceHolderAt( appletsLayout.showPlaceHolderAt(
@ -237,16 +242,22 @@ Item {
onDragLeave: { onDragLeave: {
appletsLayout.hidePlaceHolder(); appletsLayout.hidePlaceHolder();
launcherDragManager.active = false;
} }
preventStealing: true preventStealing: true
onDrop: { onDrop: {
launcherDragManager.active = false;
if (event.mimeData.formats[0] === "text/x-plasma-phone-homescreen-launcher") { if (event.mimeData.formats[0] === "text/x-plasma-phone-homescreen-launcher") {
let storageId = event.mimeData.getDataAsByteArray("text/x-plasma-phone-homescreen-launcher"); let storageId = event.mimeData.getDataAsByteArray("text/x-plasma-phone-homescreen-launcher");
let posInFavorites = favoriteStrip.flow.mapFromItem(this, event.x, event.y); let posInFavorites = favoriteStrip.flow.mapFromItem(this, event.x, event.y);
if (posInFavorites.y > 0) { if (posInFavorites.y > 0) {
if (plasmoid.nativeInterface.applicationListModel.favoriteCount >= plasmoid.nativeInterface.applicationListModel.maxFavoriteCount ) {
return;
}
plasmoid.nativeInterface.applicationListModel.addFavorite(storageId, 0, ApplicationListModel.Favorites) plasmoid.nativeInterface.applicationListModel.addFavorite(storageId, 0, ApplicationListModel.Favorites)
let item = launcherRepeater.itemAt(0); let item = launcherRepeater.itemAt(0);