Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/package/contents/ui/main.qml
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 28 | MouseArea { | |||
---|---|---|---|---|---|
53 | property Component plasmoidItemComponent | 53 | property Component plasmoidItemComponent | ||
54 | 54 | | |||
55 | Plasmoid.onExpandedChanged: { | 55 | Plasmoid.onExpandedChanged: { | ||
56 | if (!plasmoid.expanded) { | 56 | if (!plasmoid.expanded) { | ||
57 | dialog.visible = plasmoid.expanded; | 57 | dialog.visible = plasmoid.expanded; | ||
58 | } | 58 | } | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | readonly property var categoryOrder: [ | ||||
62 | "ApplicationStatus", "Communications", "SystemServices", | ||||
63 | "Hardware", "UnknownCategory" | ||||
64 | ] | ||||
65 | function getCategoryOrder(item) { | ||||
mart: as convention we usually don't have getFoo as names (and this is not getting a property… | |||||
What about indexForItemCategory? I need to pass in item not category because of special treatment of notifications. Also I'll rename itemCompare to compareItems. Pitel: What about `indexForItemCategory`? I need to pass in item not category because of special… | |||||
66 | if (item.itemId == "org.kde.plasma.notifications") { | ||||
67 | return -1 | ||||
68 | } | ||||
69 | var i = categoryOrder.indexOf(item.category) | ||||
70 | return i == -1 ? categoryOrder.length : i | ||||
71 | } | ||||
72 | | ||||
73 | function itemCompare(a, b) { | ||||
74 | var categoryDiff = getCategoryOrder(a) - getCategoryOrder(b) | ||||
75 | return categoryDiff != 0 ? categoryDiff : a.text.localeCompare(b.text) | ||||
76 | } | ||||
77 | | ||||
78 | function reorderItem(item, container) { | ||||
79 | if (container.children.length == 0) { | ||||
mart: i like the logic, but add some comments on what is doing | |||||
80 | item.parent = container | ||||
81 | } else { | ||||
82 | var i = 0; | ||||
83 | while (i < container.children.length && | ||||
84 | itemCompare(container.children[i], item) < 0) { | ||||
85 | i++ | ||||
86 | } | ||||
87 | | ||||
88 | if (i == container.children.length) { | ||||
89 | var other = container.children[i - 1] | ||||
90 | if (item != other) { | ||||
91 | plasmoid.nativeInterface.reorderItemAfter(item, other) | ||||
92 | } | ||||
93 | } else { | ||||
94 | var other = container.children[i] | ||||
95 | if (item != other) { | ||||
96 | plasmoid.nativeInterface.reorderItemBefore(item, other) | ||||
97 | } | ||||
98 | } | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
61 | function updateItemVisibility(item) { | 102 | function updateItemVisibility(item) { | ||
62 | switch (item.effectiveStatus) { | 103 | switch (item.effectiveStatus) { | ||
63 | case PlasmaCore.Types.HiddenStatus: | 104 | case PlasmaCore.Types.HiddenStatus: | ||
64 | if (item.parent == invisibleEntriesContainer) { | 105 | if (item.parent != invisibleEntriesContainer) { | ||
65 | return; | | |||
66 | } | | |||
67 | | ||||
68 | item.parent = invisibleEntriesContainer; | 106 | item.parent = invisibleEntriesContainer; | ||
107 | } | ||||
69 | break; | 108 | break; | ||
70 | 109 | | |||
71 | case PlasmaCore.Types.ActiveStatus: | 110 | case PlasmaCore.Types.ActiveStatus: | ||
72 | if (visibleLayout.children.length == 0) { | 111 | reorderItem(item, visibleLayout) | ||
73 | item.parent = visibleLayout; | | |||
74 | //notifications is always the first | | |||
75 | } else if (visibleLayout.children[0].itemId == "org.kde.plasma.notifications" && | | |||
76 | item.itemId != "org.kde.plasma.notifications") { | | |||
77 | plasmoid.nativeInterface.reorderItemAfter(item, visibleLayout.children[0]); | | |||
78 | } else if (visibleLayout.children[0] != item) { | | |||
79 | plasmoid.nativeInterface.reorderItemBefore(item, visibleLayout.children[0]); | | |||
80 | } | | |||
81 | break; | 112 | break; | ||
82 | 113 | | |||
83 | case PlasmaCore.Types.PassiveStatus: | 114 | case PlasmaCore.Types.PassiveStatus: | ||
84 | 115 | reorderItem(item, hiddenLayout) | |||
85 | if (hiddenLayout.children.length == 0) { | | |||
86 | item.parent = hiddenLayout; | | |||
87 | //notifications is always the first | | |||
88 | } else if (hiddenLayout.children[0].itemId == "org.kde.plasma.notifications" && | | |||
89 | item.itemId != "org.kde.plasma.notifications") { | | |||
90 | plasmoid.nativeInterface.reorderItemAfter(item, hiddenLayout.children[0]); | | |||
91 | } else if (hiddenLayout.children[0] != item) { | | |||
92 | plasmoid.nativeInterface.reorderItemBefore(item, hiddenLayout.children[0]); | | |||
93 | } | | |||
94 | item.x = 0; | 116 | item.x = 0; | ||
95 | break; | 117 | break; | ||
96 | } | 118 | } | ||
97 | } | 119 | } | ||
98 | 120 | | |||
99 | onWheel: { | 121 | onWheel: { | ||
100 | // Don't propagate unhandled wheel events | 122 | // Don't propagate unhandled wheel events | ||
101 | wheel.accepted = true; | 123 | wheel.accepted = true; | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |
as convention we usually don't have getFoo as names (and this is not getting a property anyways)
i would like a more descriptive name like indexForCategory and have the category as parameter instead of the item