diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 3d5ee906f..8692011c8 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -633,8 +633,21 @@ int DockCorona::docksCount() const int docks{0}; for (const auto &view : m_dockViews) { - if (view && view->containment() - && !view->containment()->destroyed()) { + if (view && view->containment() && !view->containment()->destroyed()) { + ++docks; + } + } + + // qDebug() << docks << "docks on screen:" << screen; + return docks; +} + +int DockCorona::docksCount(QScreen *screen) const +{ + int docks{0}; + + for (const auto &view : m_dockViews) { + if (view && view->screen() == screen && !view->containment()->destroyed()) { ++docks; } } diff --git a/app/dockcorona.h b/app/dockcorona.h index e43e76c81..4550be6fe 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -69,8 +69,10 @@ public: QList freeEdges(int screen) const; QList freeEdges(QScreen *screen) const; - int docksCount(int screen) const; int docksCount() const; + int docksCount(int screen) const; + int docksCount(QScreen *screen) const; + int noDocksWithTasks() const; int screenForContainment(const Plasma::Containment *containment) const override; diff --git a/app/dockview.cpp b/app/dockview.cpp index bca7078ba..6acf7288b 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -124,6 +124,7 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool dockWindo if (dockCorona) { connect(dockCorona, &DockCorona::docksCountChanged, this, &DockView::docksCountChanged); + connect(this, &DockView::docksCountChanged, this, &DockView::totalDocksCountChanged); connect(dockCorona, &DockCorona::dockLocationChanged, this, &DockView::dockLocationChanged); connect(dockCorona, &DockCorona::dockLocationChanged, this, [&]() { //! check if an edge has been freed for a primary dock @@ -788,7 +789,17 @@ int DockView::docksCount() const { auto dockCorona = qobject_cast(corona()); - if (!dockCorona || !this->containment()) + if (!dockCorona) + return 0; + + return dockCorona->docksCount(screen()); +} + +int DockView::totalDocksCount() const +{ + auto dockCorona = qobject_cast(corona()); + + if (!dockCorona) return 0; return dockCorona->docksCount(); @@ -1247,12 +1258,14 @@ bool DockView::event(QEvent *e) QList DockView::freeEdges() const { - if (!this->corona() || !this->containment()) { + DockCorona *dockCorona = qobject_cast(this->corona()); + + if (!dockCorona) { const QList emptyEdges; return emptyEdges; } - const auto edges = corona()->freeEdges(this->containment()->screen()); + const auto edges = dockCorona->freeEdges(screen()); QList edgesInt; foreach (Plasma::Types::Location edge, edges) { diff --git a/app/dockview.h b/app/dockview.h index a9781061d..ad64e1f24 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -60,6 +60,7 @@ class DockView : public PlasmaQuick::ContainmentView { Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged) + Q_PROPERTY(int totalDocksCount READ totalDocksCount NOTIFY totalDocksCountChanged) Q_PROPERTY(int x READ x NOTIFY xChanged) Q_PROPERTY(int y READ y NOTIFY yChanged) Q_PROPERTY(int width READ width NOTIFY widthChanged) @@ -102,6 +103,7 @@ public: int currentThickness() const; int docksCount() const; + int totalDocksCount() const; bool behaveAsPlasmaPanel() const; void setBehaveAsPlasmaPanel(bool behavior); @@ -218,6 +220,7 @@ signals: void screenGeometryChanged(); void sessionChanged(); void shadowChanged(); + void totalDocksCountChanged(); void xChanged(); void yChanged(); diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index b7aec0343..cbdf4d175 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -277,11 +277,14 @@ PlasmaCore.FrameSvgItem { spacing: units.largeSpacing - property int docksCount: dock.docksCount + Connections{ + target: dock + onDocksCountChanged: actionButtons.updateEnabled(); + } - onDocksCountChanged: { - addDock.enabled = docksCount < 4 && dock.freeEdges().length > 0 - removeDock.enabled = (docksCount>1) && !(dock.docksWithTasks()===1 && dock.tasksPresent()) + function updateEnabled() { + addDock.enabled = dock.docksCount < 4 && dock.freeEdges().length > 0 + removeDock.enabled = dock.docksCount>1 && !(dock.docksWithTasks()===1 && dock.tasksPresent()) } PlasmaComponents.Button { @@ -291,17 +294,27 @@ PlasmaCore.FrameSvgItem { PlasmaComponents.ComboBox { id: actionsCmb - anchors.fill: parent + enabled: addDock.enabled - Component.onCompleted:{ + function addModel() { var actions = [] - actions.push(" " + i18n("Copy Dock")); actionsCmb.model = actions; actionsCmb.currentIndex = -1; } + function emptyModel() { + var actions = [] + actions.push(" "); + actionsCmb.model = actions; + actionsCmb.currentIndex = -1; + } + + Component.onCompleted:{ + addModel(); + } + onActivated: { if (index==0) { dock.copyDock(); @@ -309,6 +322,13 @@ PlasmaCore.FrameSvgItem { actionsCmb.currentIndex = -1; } + + onEnabledChanged: { + if (enabled) + addModel(); + else + emptyModel(); + } } @@ -338,8 +358,7 @@ PlasmaCore.FrameSvgItem { text: i18n("Remove") iconSource: "edit-delete" - opacity: enabled ? 1 : 0 - //enabled: dock.docksCount > 1 + opacity: dock.totalDocksCount > 1 ? 1 : 0 tooltip: i18n("Remove current dock") onClicked: dock.removeDock()