Skip to content

Commit b2c4418

Browse files
committed
feat: configure action on Panel Colorizer widget click
- Toggle Panel Colorizer - Switch between selected presets - Show popup with all presets closes: #135 refs: luisbocanegra/plasma-panel-modes-switcher#5
1 parent eba4a14 commit b2c4418

File tree

6 files changed

+272
-43
lines changed

6 files changed

+272
-43
lines changed

package/contents/config/main.xml

+18
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,23 @@
5151
type="String">
5252
<default>{"widgets":[], "reloadInterval": 250}</default>
5353
</entry>
54+
<entry name="widgetClickMode" type="Enum">
55+
<choices>
56+
<choice name="TogglePanelColorizer"/>
57+
<choice name="SwitchPresets"/>
58+
<choice name="ShowPopup"/>
59+
</choices>
60+
<default>0</default>
61+
</entry>
62+
<entry
63+
name="switchPresets"
64+
type="String">
65+
<default>[]</default>
66+
</entry>
67+
<entry
68+
name="switchPresetsIndex"
69+
type="Int">
70+
<default>0</default>
71+
</entry>
5472
</group>
5573
</kcfg>

package/contents/ui/CompactRepresentation.qml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import QtQuick
22
import QtQuick.Layouts
33
import org.kde.kirigami as Kirigami
44
import org.kde.plasma.core as PlasmaCore
5-
import org.kde.plasma.plasmoid
65
import "components" as Components
76

87
MouseArea {
@@ -12,10 +11,11 @@ MouseArea {
1211
property real itemSize: Math.min(compact.height, compact.width)
1312
property string icon
1413

14+
signal widgetClicked()
15+
1516
hoverEnabled: true
1617
onClicked: {
17-
plasmoid.configuration.isEnabled = !plasmoid.configuration.isEnabled
18-
plasmoid.configuration.writeConfig();
18+
widgetClicked()
1919
}
2020

2121

package/contents/ui/code/enum.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const WidgetClickModes = {
2+
TogglePanelColorizer: 0,
3+
SwitchPresets: 1,
4+
ShowPopup: 2,
5+
};

package/contents/ui/code/globals.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,8 @@ const ignoredConfigs = [
257257
"objectName",
258258
"lastPreset",
259259
"presetAutoloading",
260-
"configurationOverrides"
260+
"configurationOverrides",
261+
"widgetClickMode",
262+
"switchPresets",
263+
"switchPresetsIndex"
261264
]

package/contents/ui/configPresetAutoload.qml

+83-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.kde.plasma.plasmoid
88
import org.kde.plasma.plasma5support as P5Support
99
import "components" as Components
1010
import "code/utils.js" as Utils
11+
import "code/enum.js" as Enum
1112

1213
KCM.SimpleKCM {
1314
id:root
@@ -24,8 +25,17 @@ KCM.SimpleKCM {
2425
property string cfg_presetAutoloading
2526
property var autoLoadConfig: JSON.parse(cfg_presetAutoloading)
2627

28+
property alias cfg_widgetClickMode: widgetClickModeCombo.currentIndex
29+
readonly property list<string> widgetClickModes: ["Toggle Panel Colorizer", "Switch presets", "Show popup"]
30+
31+
property string cfg_switchPresets
32+
property var switchPresets: JSON.parse(cfg_switchPresets)
33+
34+
property var presetsList: []
35+
2736
function updateConfig() {
2837
cfg_presetAutoloading = JSON.stringify(autoLoadConfig, null, null)
38+
cfg_switchPresets = JSON.stringify(switchPresets, null, null)
2939
}
3040

3141
ListModel {
@@ -44,36 +54,35 @@ KCM.SimpleKCM {
4454
// console.log(stdout);
4555
if(cmd === listPresetsCmd) {
4656
if (stdout.length === 0) return
47-
presetsModel.append(
48-
{
49-
"name": i18n("Do nothing"),
50-
"value": "",
51-
}
52-
)
5357

5458
const out = stdout.trim().split("\n")
5559
for (const line of out) {
56-
let builtin = false
5760
const parts = line.split(":")
5861
const path = parts[parts.length -1]
5962
let name = path.split("/")
6063
name = name[name.length-1]
6164
const dir = parts[1]
62-
if (line.startsWith("b:")) {
63-
builtin = true
64-
}
6565
console.error(dir)
66+
const preset = {
67+
"name": name,
68+
"value": dir,
69+
}
6670
presetsModel.append(
67-
{
68-
"name": name,
69-
"value": dir,
70-
}
71+
preset
7172
)
73+
presetsList.push(preset)
7274
}
7375
}
76+
if (presetsList.length && switchPresets.length) {
77+
switchPresets = pruneMissingPresets(switchPresets)
78+
}
7479
}
7580
}
7681

82+
function pruneMissingPresets(switchPresets) {
83+
return switchPresets.filter(saved => presetsList.some(p => p.value === saved))
84+
}
85+
7786
function getIndex(model, savedValue) {
7887
for (let i = 0; i < model.count; i++) {
7988
if (model.get(i).value === savedValue) {
@@ -111,6 +120,13 @@ KCM.SimpleKCM {
111120
}
112121

113122
Kirigami.FormLayout {
123+
124+
Kirigami.Separator {
125+
Kirigami.FormData.isSection: true
126+
Kirigami.FormData.label: i18n("Environment")
127+
Layout.fillWidth: true
128+
}
129+
114130
CheckBox {
115131
id: enabledCheckbox
116132
Kirigami.FormData.label: i18n("Enabled:")
@@ -205,6 +221,59 @@ KCM.SimpleKCM {
205221
currentIndex: getIndex(model, autoLoadConfig.normal)
206222
enabled: enabledCheckbox.checked
207223
}
224+
225+
Kirigami.Separator {
226+
Kirigami.FormData.isSection: true
227+
Kirigami.FormData.label: i18n("Widget Click")
228+
Layout.fillWidth: true
229+
}
230+
231+
ComboBox {
232+
id: widgetClickModeCombo
233+
Kirigami.FormData.label: "Action:"
234+
model: widgetClickModes
235+
}
236+
237+
ColumnLayout {
238+
Layout.fillWidth: true
239+
ScrollView {
240+
enabled: cfg_widgetClickMode === Enum.WidgetClickModes.SwitchPresets
241+
Layout.fillWidth: true
242+
Layout.preferredHeight: Math.min(implicitHeight+20, 200)
243+
ListView {
244+
id: listView
245+
model: presetsModel
246+
Layout.preferredWidth: Math.min(width+50, 100)
247+
reuseItems: true
248+
clip: true
249+
focus: true
250+
activeFocusOnTab: true
251+
keyNavigationEnabled: true
252+
delegate: RowLayout {
253+
width: ListView.view.width
254+
CheckBox {
255+
id: presetCheckbox
256+
text: model.name
257+
checked: switchPresets.includes(model.value)
258+
Layout.rightMargin: Kirigami.Units.smallSpacing * 4
259+
onCheckedChanged: {
260+
if (checked) {
261+
if (!switchPresets.includes(model.value)) {
262+
switchPresets.push(model.value)
263+
}
264+
} else {
265+
switchPresets = switchPresets.filter(p => p !== model.value)
266+
}
267+
updateConfig()
268+
}
269+
}
270+
}
271+
highlight: Item {}
272+
highlightMoveDuration: 0
273+
highlightResizeDuration: 0
274+
}
275+
}
276+
}
208277
}
209278
}
210279
}

0 commit comments

Comments
 (0)