Commit bfe0f301 authored by Marco Martin's avatar Marco Martin
Browse files

put selection of which items are visible in a popup menu

the comboboix of a very rarely used feature right
in the header area is super noisy, looks misaligned and puts the feature
in a too much prominent role.
Put everything under a popup menu, mustually exclusive actions will be
shown as radiobuttons
parent de32e865
......@@ -41,26 +41,6 @@ ColumnLayout {
text: i18nc("Minimize the length of this string as much as possible", "Allow automatic sleep and screen locking")
checked: true
}
PlasmaComponents3.ToolButton {
icon.name: "documentinfo"
onClicked: plasmoid.action("energyinformationkcm").trigger()
visible: batterymonitor.kcmEnergyInformationAuthorized
PlasmaComponents3.ToolTip {
text: plasmoid.action("energyinformationkcm").text
}
}
PlasmaComponents3.ToolButton {
icon.name: "configure"
onClicked: plasmoid.action("powerdevilkcm").trigger()
visible: batterymonitor.kcmsAuthorized
PlasmaComponents3.ToolTip {
text: plasmoid.action("powerdevilkcm").text
}
}
}
ColumnLayout {
......
......@@ -98,16 +98,6 @@ ColumnLayout {
text: i18n("Clear history")
}
}
PlasmaComponents3.ToolButton {
visible: plasmoid.action("configure").enabled
icon.name: "configure"
onClicked: plasmoid.action("configure").trigger()
PlasmaComponents3.ToolTip {
text: plasmoid.action("configure").text
}
Accessible.name: plasmoid.action("configure").text
}
}
}
......
......@@ -38,86 +38,21 @@ PlasmaComponents3.Page {
Layout.minimumWidth: units.gridUnit * 12
Layout.minimumHeight: units.gridUnit * 12
header: PlasmaExtras.PlasmoidHeading {
id: headerToolbarContainer
header: PlasmaExtras.BasicPlasmoidHeading {
visible: plasmoid.containmentType !== PlasmaCore.Types.CustomEmbeddedContainment || devicenotifier.mountedRemovables > 1
PlasmaComponents3.ToolButton {
id: unmountAll
visible: devicenotifier.mountedRemovables > 1;
RowLayout {
width: parent.width
icon.name: "media-eject"
text: i18n("Remove All")
PlasmaComponents3.Label {
text: i18n("Show:")
}
PlasmaComponents3.ComboBox {
id: displayModeCombobox
Layout.preferredWidth: units.gridUnit * 11
model: [i18n("Removable devices"),
i18n("Non-removable devices"),
i18n("All devices")
]
currentIndex: {
if (plasmoid.configuration.removableDevices) {
return 0
} else if (plasmoid.configuration.nonRemovableDevices) {
return 1
} else {
return 2
}
}
onActivated: {
switch (currentIndex) {
case 0:
plasmoid.configuration.removableDevices = true;
plasmoid.configuration.nonRemovableDevices = false;
plasmoid.configuration.allDevices = false;
break;
case 1:
plasmoid.configuration.removableDevices = false;
plasmoid.configuration.nonRemovableDevices = true;
plasmoid.configuration.allDevices = false;
break;
case 2:
plasmoid.configuration.removableDevices = false;
plasmoid.configuration.nonRemovableDevices = false;
plasmoid.configuration.allDevices = true;
break
}
}
}
Item {
Layout.fillWidth: true
}
PlasmaComponents3.ToolButton {
id: unmountAll
visible: devicenotifier.mountedRemovables > 1
&& displayModeCombobox.currentIndex === 0 /* removables only */
icon.name: "media-eject"
text: i18n("Remove All")
PlasmaComponents3.ToolTip {
text: i18n("Click to safely remove all devices")
}
}
// TODO: Once the automounter KCM is ported to QML, embed it in the
// config window and change the action to open the config window
PlasmaComponents3.ToolButton {
icon.name: "configure"
onClicked: plasmoid.action("openAutomounterKcm").trigger()
visible: devicenotifier.openAutomounterKcmAuthorized
Accessible.name: plasmoid.action("openAutomounterKcm").text
PlasmaComponents3.ToolTip {
text: plasmoid.action("openAutomounterKcm").text
}
PlasmaComponents3.ToolTip {
text: i18n("Click to safely remove all devices")
}
}
}
MouseArea {
id: fullRepMouseArea
hoverEnabled: true
......@@ -183,7 +118,7 @@ PlasmaComponents3.Page {
target: plasmoid
onExpandedChanged: {
if (!plasmoid.expanded) {
statusSource.clearMessage()
statusSource.clearMessage();
}
}
}
......
......@@ -225,13 +225,37 @@ Item {
}
}
property var showRemovableDevicesAction
property var showNonRemovableDevicesAction
property var showAllDevicesAction
Component.onCompleted: {
if (sdSource.connectedSources.count === 0) {
Plasmoid.status = PlasmaCore.Types.PassiveStatus;
}
plasmoid.setAction("showRemovableDevices", i18n("Removable Devices"), "drive-removable-media");
devicenotifier.showRemovableDevicesAction = plasmoid.action("showRemovableDevices");
devicenotifier.showRemovableDevicesAction.checkable = true;
devicenotifier.showRemovableDevicesAction.checked = Qt.binding(() => {return plasmoid.configuration.removableDevices;});
plasmoid.setActionGroup("showRemovableDevices", "devicesShown");
plasmoid.setAction("showNonRemovableDevices", i18n("Non Removable Devices"), "drive-harddisk");
devicenotifier.showNonRemovableDevicesAction = plasmoid.action("showNonRemovableDevices");
devicenotifier.showNonRemovableDevicesAction.checkable = true;
devicenotifier.showNonRemovableDevicesAction.checked = Qt.binding(() => {return plasmoid.configuration.nonRemovableDevices;});
plasmoid.setActionGroup("showNonRemovableDevices", "devicesShown");
plasmoid.setAction("showAllDevices", i18n("All Devices"));
devicenotifier.showAllDevicesAction = plasmoid.action("showAllDevices");
devicenotifier.showAllDevicesAction.checkable = true;
devicenotifier.showAllDevicesAction.checked = Qt.binding(() => {return plasmoid.configuration.allDevices;});
plasmoid.setActionGroup("showAllDevices", "devicesShown");
plasmoid.setActionSeparator("sep");
if (devicenotifier.openAutomounterKcmAuthorized) {
plasmoid.setAction("openAutomounterKcm", i18nc("Open auto mounter kcm", "Configure Removable Devices"), "drive-removable-media")
plasmoid.setAction("openAutomounterKcm", i18nc("Open auto mounter kcm", "Configure Removable Devices..."), "configure")
}
}
......@@ -239,6 +263,24 @@ Item {
KCMShell.openSystemSettings("device_automounter_kcm")
}
function action_showRemovableDevices() {
plasmoid.configuration.removableDevices = true;
plasmoid.configuration.nonRemovableDevices = false;
plasmoid.configuration.allDevices = false;
}
function action_showNonRemovableDevices() {
plasmoid.configuration.removableDevices = false;
plasmoid.configuration.nonRemovableDevices = true;
plasmoid.configuration.allDevices = false;
}
function action_showAllDevices() {
plasmoid.configuration.removableDevices = false;
plasmoid.configuration.nonRemovableDevices = false;
plasmoid.configuration.allDevices = true;
}
Plasmoid.onExpandedChanged: {
popupEventSlot(plasmoid.expanded);
}
......
......@@ -172,16 +172,6 @@ PlasmaComponents3.Page {
Layout.fillWidth: true
}
PlasmaComponents3.ToolButton {
icon.name: "configure"
visible: plasmoid.action("openKcm").enabled
onClicked: plasmoid.action("openKcm").trigger()
PlasmaComponents3.ToolTip {
text: plasmoid.action("openKcm").text
}
}
PlasmaComponents3.ToolButton {
icon.name: "edit-clear-history"
enabled: plasmoid.action("clearHistory").visible
......
......@@ -89,12 +89,16 @@ void SystemTrayContainer::ensureSystrayExists()
m_innerContainment->setParent(this);
connect(containment(), &Plasma::Containment::screenChanged, m_innerContainment.data(), &Plasma::Containment::reactToScreenChange);
if (formFactor() == Plasma::Types::Horizontal || formFactor() == Plasma::Types::Vertical) {
m_innerContainment->setFormFactor(formFactor());
} else {
m_innerContainment->setFormFactor(Plasma::Types::Horizontal);
}
m_innerContainment->setLocation(location());
if (m_innerContainment) {
m_innerContainment->setLocation(location());
}
m_internalSystray = m_innerContainment->property("_plasma_graphicObject").value<QQuickItem *>();
emit internalSystrayChanged();
......@@ -122,6 +126,7 @@ void SystemTrayContainer::constraintsEvent(Plasma::Types::Constraints constraint
m_innerContainment->setLocation(location());
}
}
if (constraints & Plasma::Types::FormFactorConstraint) {
if (m_innerContainment) {
if (formFactor() == Plasma::Types::Horizontal || formFactor() == Plasma::Types::Vertical) {
......
......@@ -22,6 +22,9 @@ import QtQuick 2.12
import QtQuick.Layouts 1.12
import org.kde.plasma.core 2.0 as PlasmaCore
// We still need PC2 here for that version of Menu, as PC2 Menu is still very problematic with QActions
// Not being a proper popup window, makes it a showstopper to be used in Plasma
import org.kde.plasma.components 2.0 as PC2
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
......@@ -87,18 +90,92 @@ Item {
}
PlasmaComponents.ToolButton {
// Don't show when displaying an applet's own view since then
// there would be two configure buttons and that would be weird
// TODO: in the future make this button context-sensitive so
// that it triggers the config action for whatever applet is
// being viewed, and then hide the applet's own config button
// if both would be shown at the same time
visible: !activeApplet && plasmoid.action("configure").enabled
id: actionsButton
visible: visibleActions > 0
checked: configMenu.status !== PC2.DialogStatus.Closed
property QtObject applet: activeApplet || plasmoid
onAppletChanged: {
configMenu.clearMenuItems();
updateVisibleActions();
}
property int visibleActions: 0
property QtObject singleAction
function updateVisibleActions() {
let newSingleAction = null;
let newVisibleActions = 0;
for (let i in applet.contextualActions) {
let action = applet.contextualActions[i];
if (action.visible && action !== actionsButton.applet.action("configure")) {
newVisibleActions++;
newSingleAction = action;
action.changed.connect(() => {updateVisibleActions()});
}
}
if (newVisibleActions > 1) {
newSingleAction = null;
}
visibleActions = newVisibleActions;
singleAction = newSingleAction;
}
Connections {
target: actionsButton.applet
function onContextualActionsChanged() {updateVisibleActions();}
}
icon.name: "application-menu"
checkable: visibleActions > 1
contentItem.opacity: visibleActions > 1
// NOTE: it needs an IconItem because QtQuickControls2 buttons cannot load QIcons as their icon
PlasmaCore.IconItem {
parent: actionsButton
anchors.centerIn: parent
active: actionsButton.hovered
implicitWidth: PlasmaCore.Units.iconSizes.smallMedium
implicitHeight: implicitWidth
source: actionsButton.singleAction !== null ? actionsButton.singleAction.icon : ""
visible: actionsButton.singleAction
}
onToggled: {
if (checked) {
configMenu.openRelative();
} else {
configMenu.close();
}
}
onClicked: {
if (singleAction) {
singleAction.trigger();
}
}
PlasmaComponents.ToolTip {
text: actionsButton.singleAction ? actionsButton.singleAction.text : i18n("More actions")
}
PC2.Menu {
id: configMenu
visualParent: actionsButton
placement: PlasmaCore.Types.BottomPosedLeftAlignedPopup
}
Instantiator {
model: actionsButton.applet.contextualActions
delegate: PC2.MenuItem {
id: menuItem
action: modelData
}
onObjectAdded: {
if (object !== actionsButton.applet.action("configure")) {
configMenu.addMenuItem(object);
}
}
}
}
PlasmaComponents.ToolButton {
icon.name: "configure"
onClicked: plasmoid.action("configure").trigger()
visible: actionsButton.applet && actionsButton.applet.action("configure")
PlasmaComponents.ToolTip {
text: plasmoid.action("configure").text
text: parent.visible ? actionsButton.applet.action("configure").text : ""
}
onClicked: actionsButton.applet.action("configure").trigger();
}
PlasmaComponents.ToolButton {
......
Markdown is supported
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