Verified Commit 351e9787 authored by ivan tkachenko's avatar ivan tkachenko
Browse files

[applets/showdesktop] Refactor peek/minimize controllers, and bind actions' text

Factoring out an "interface" (if one can call it like that in QML) for
the two operation modes removes all the decision making from the main
file, and delegates things like description text and toggle() method to
implementations. It turns ?trinary: mess into a set of simple and
straightforward bindings.

Test plan: applet works correctly in both configurations, on X11 and
Wayland; it's menu actions have adaptive text labels, and triggering
the one that matches applet's mode (primary controller) also updates
the highlight (active applet) indicator.
parent d0650e23
/*
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQml 2.15
QtObject {
/**
* Whether the effect is currently active, and can be deactivated.
*/
property bool active
property string titleActive
property string titleInactive
property string descriptionActive
property string descriptionInactive
readonly property string title: active ? titleActive : titleInactive
readonly property string description: active ? descriptionActive : descriptionInactive
// virtual
function toggle() {}
}
......@@ -2,19 +2,23 @@
SPDX-FileCopyrightText: 2015 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2016 Anthony Fieroni <bvbfan@abv.bg>
SPDX-FileCopyrightText: 2018 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQml 2.15
import org.kde.taskmanager 0.1 as TaskManager
QtObject {
Controller {
id: controller
readonly property string title: active ? i18nc("@action:button", "Restore All Minimized Windows") : i18nc("@action", "Minimize All Windows")
readonly property string description: active ? i18nc("@info:tooltip", "Restores the previously minimized windows") : i18n("Shows the Desktop by minimizing all windows")
titleActive: i18nc("@action:button", "Restore All Minimized Windows")
titleInactive: i18nc("@action:button", "Minimize All Windows")
descriptionActive: i18nc("@info:tooltip", "Restores the previously minimized windows")
descriptionInactive: i18nc("@info:tooltip", "Shows the Desktop by minimizing all windows")
readonly property QtObject tasksModel: TaskManager.TasksModel {
id: tasksModel
......@@ -42,11 +46,6 @@ QtObject {
}
}
/**
* Whether the "minimize all" effect is activated
*/
property bool active: false
/**
* List of persistent model indexes from task manager model of
* clients minimized by us
......@@ -83,6 +82,7 @@ QtObject {
minimizedClients = [];
}
// override
function toggle() {
if (active) {
deactivate();
......
/*
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import org.kde.plasma.private.showdesktop 0.1
Controller {
id: controller
titleActive: i18nc("@action:button", "Stop Peeking at Desktop")
titleInactive: i18nc("@action:button", "Peek at Desktop")
descriptionActive: i18nc("@info:tooltip", "Moves windows back to their original positions")
descriptionInactive: i18nc("@info:tooltip", "Temporarily reveals the Desktop by moving open windows into screen corners")
active: showdesktop.showingDesktop
// override
function toggle() {
showdesktop.toggleDesktop();
}
readonly property ShowDesktop showdesktop: ShowDesktop {
id: showdesktop
}
}
/*
SPDX-FileCopyrightText: 2014 Ashish Madeti <ashishmadeti@gmail.com>
SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -12,8 +13,6 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.private.showdesktop 0.1
MouseArea {
id: root
......@@ -26,23 +25,11 @@ MouseArea {
*/
readonly property bool isMinimizeAll: Plasmoid.pluginName === "org.kde.plasma.minimizeall"
readonly property alias isMinimizing: minimizeAllController.active
readonly property Controller primaryController: isMinimizeAll ? minimizeAllController : peekController
Plasmoid.icon: Plasmoid.configuration.icon
Plasmoid.title: {
if (isMinimizeAll) {
return minimizeAllController.title;
}
return showdesktop.showingDesktop ? i18nc("@action:button", "Stop Peeking at Desktop") : i18nc("@action:button", "Peek at Desktop");
}
Plasmoid.toolTipSubText: {
if (isMinimizeAll) {
return minimizeAllController.description;
}
return showdesktop.showingDesktop ? i18nc("@info:tooltip", "Moves windows back to their original positions") : i18n("Temporarily reveals the Desktop by moving open windows into screen corners");
}
Plasmoid.title: primaryController.title
Plasmoid.toolTipSubText: primaryController.description
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
......@@ -56,13 +43,7 @@ MouseArea {
activeFocusOnTab: true
hoverEnabled: true
Plasmoid.onActivated: {
if (isMinimizeAll) {
minimizeAllController.toggle();
} else {
showdesktop.toggleDesktop();
}
}
Plasmoid.onActivated: primaryController.toggle();
onClicked: Plasmoid.activated();
Keys.onPressed: {
......@@ -80,8 +61,8 @@ MouseArea {
Accessible.description: Plasmoid.toolTipSubText
Accessible.role: Accessible.Button
ShowDesktop {
id: showdesktop
PeekController {
id: peekController
}
MinimizeAllController {
......@@ -90,7 +71,7 @@ MouseArea {
PlasmaCore.IconItem {
anchors.fill: parent
active: root.containsMouse || showdesktop.showingDesktop
active: root.containsMouse || primaryController.active
source: Plasmoid.icon
}
......@@ -152,13 +133,7 @@ MouseArea {
}
return prefix;
}
opacity: {
if (isMinimizeAll) {
return minimizeAllController.active ? 1 : 0;
}
return showdesktop.showingDesktop ? 1 : 0;
}
opacity: primaryController.active ? 1 : 0
Behavior on opacity {
NumberAnimation {
......@@ -180,14 +155,21 @@ MouseArea {
minimizeAllController.toggle();
}
function action_showdesktop() {
showdesktop.toggleDesktop();
function action_peek() {
peekController.toggle();
}
Component.onCompleted: {
Plasmoid.setAction("minimizeall", "");
Plasmoid.action("minimizeall").text = Qt.binding(() => minimizeAllController.title);
var action;
Plasmoid.setAction("showdesktop", i18nc("@action:button", "Peek at Desktop"));
Plasmoid.setAction("minimizeall", "");
action = Plasmoid.action("minimizeall")
action.text = Qt.binding(() => minimizeAllController.title);
action.toolTip = Qt.binding(() => minimizeAllController.description);
Plasmoid.setAction("peek", "");
action = Plasmoid.action("peek")
action.text = Qt.binding(() => peekController.title);
action.toolTip = Qt.binding(() => peekController.description);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment