From 2bad1924f44a0732f8eaef573f7cee4e3c97f170 Mon Sep 17 00:00:00 2001
From: Michail Vourlakos <mvourlakos@gmail.com>
Date: Wed, 27 Mar 2019 20:14:20 +0200
Subject: [PATCH] support enabledRole for ComboBoxes

--more specific disable CopyDock when all
screen edges are occupied in the current
view screen
---
 declarativeimports/components/ComboBox.qml            |  2 ++
 declarativeimports/components/ComboBoxButton.qml      |  2 ++
 declarativeimports/components/ItemDelegate.qml        |  3 +++
 .../contents/configuration/LatteDockConfiguration.qml | 11 ++++++++---
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/declarativeimports/components/ComboBox.qml b/declarativeimports/components/ComboBox.qml
index d712381b9..75744d07c 100644
--- a/declarativeimports/components/ComboBox.qml
+++ b/declarativeimports/components/ComboBox.qml
@@ -46,10 +46,12 @@ T.ComboBox {
     property bool forcePressed: false
     property int minimumPopUpWidth: 150
     property int popUpRelativeX: 0
+    property string enabledRole
     property string iconRole
 
     delegate: ItemDelegate {
         width: control.popup.width
+        enabled: control.enabledRole ? (Array.isArray(control.model) ? modelData[control.enabledRole] : model[control.enabledRole]) : true
         text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
         icon: control.iconRole ? (Array.isArray(control.model) ? modelData[control.iconRole] : model[control.iconRole]) : ''
         highlighted: mouseArea.pressed ? listView.currentIndex == index : control.currentIndex == index
diff --git a/declarativeimports/components/ComboBoxButton.qml b/declarativeimports/components/ComboBoxButton.qml
index 74464eb13..74b20d167 100644
--- a/declarativeimports/components/ComboBoxButton.qml
+++ b/declarativeimports/components/ComboBoxButton.qml
@@ -49,6 +49,7 @@ Rectangle {
     property bool comboBoxBlankSpaceForEmptyIcons: false
     property bool comboBoxForcePressed: false
     property int comboBoxMinimumPopUpWidth: 150
+    property string comboBoxEnabledRole: ""
     property string comboBoxTextRole: ""
     property string comboBoxIconRole: ""
 
@@ -81,6 +82,7 @@ Rectangle {
 
         enabled: comboBoxEnabled
 
+        enabledRole: comboBoxEnabledRole
         iconRole: comboBoxIconRole
         textRole: comboBoxTextRole
 
diff --git a/declarativeimports/components/ItemDelegate.qml b/declarativeimports/components/ItemDelegate.qml
index 2332fb2e5..826c9ea0f 100644
--- a/declarativeimports/components/ItemDelegate.qml
+++ b/declarativeimports/components/ItemDelegate.qml
@@ -46,6 +46,7 @@ T.CheckDelegate {
         Layout.leftMargin: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0
         Layout.rightMargin: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0
         spacing: units.smallSpacing
+        enabled: control.enabled
 
         PlasmaCore.IconItem {
             height: parent.height
@@ -77,6 +78,7 @@ T.CheckDelegate {
     //background: Private.DefaultListItemBackground {}
     background: Rectangle {
         visible: control.ListView.view ? control.ListView.view.highlight === null : true
+        enabled: control.enabled
         opacity: {
             if (control.highlighted || control.pressed) {
                 return 0.7;
@@ -86,6 +88,7 @@ T.CheckDelegate {
 
             return 0;
         }
+
         color: theme.highlightColor
     }
 }
diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml
index ffe7c2653..2adfa7fc0 100644
--- a/shell/package/contents/configuration/LatteDockConfiguration.qml
+++ b/shell/package/contents/configuration/LatteDockConfiguration.qml
@@ -459,6 +459,9 @@ FocusScope {
             function updateEnabled() {
                 var screenFreeEdges = latteView.managedLayout.qmlFreeEdges(latteView.positioner.currentScreenId);
                 actionsComboBtn.buttonEnabled = latteView.managedLayout.viewsCount<4 && screenFreeEdges.length > 0
+                if (actionsModel.count > 0) {
+                    actionsModel.get(0).enabled = actionsComboBtn.buttonEnabled;
+                }
                 removeView.enabled = latteView.managedLayout.viewsCount>1 /*&& !(latteView.managedLayout.viewsWithTasks()===1 && latteView.tasksPresent())*/
             }
 
@@ -473,8 +476,9 @@ FocusScope {
                 buttonIconSource: "list-add"
                 buttonToolTip: i18n("Add a new dock")
 
-                comboBoxEnabled: buttonEnabled
+                comboBoxEnabled: true
                 comboBoxBlankSpaceForEmptyIcons: true
+                comboBoxEnabledRole: "enabled"
                 comboBoxTextRole: "name"
                 comboBoxIconRole: "icon"
                 comboBoxMinimumPopUpWidth: actionsModel.count > 1 ? dialog.width / 2 : 150
@@ -495,6 +499,7 @@ FocusScope {
 
                     Component.onCompleted:{
                         actionsComboBtn.addModel();
+                        actionButtons.updateEnabled();
                     }
 
                     onActivated: {
@@ -525,7 +530,7 @@ FocusScope {
                 function addModel() {
                     actionsModel.clear();
 
-                    var copy = {actionId: 'copy:', name: i18n("Copy Dock"), icon: 'edit-copy'};
+                    var copy = {actionId: 'copy:', enabled: true, name: i18n("Copy Dock"), icon: 'edit-copy'};
                     actionsModel.append(copy);
 
                     var tempActiveLayouts = layoutManager.activeLayoutsNames();
@@ -548,7 +553,7 @@ FocusScope {
 
                 function emptyModel() {
                     actionsModel.clear();
-                    var copy = {actionId: 'copy:', name: i18n("Copy Dock"), icon: 'edit-copy'};
+                    var copy = {actionId: 'copy:', enabled: true, name: i18n("Copy Dock"), icon: 'edit-copy'};
                     actionsModel.append(copy);
                     actionsComboBtn.comboBox.currentIndex = -1;
                 }