on xenial help sign in
Fixed menu selection on initial add.
3c079c0Nick Dedekind
plugins/Unity/Indicators/qml/IndicatorPage.qml+32−5
@@ -60,7 +60,34 @@ IndicatorBase {
60 // Only allow flicking if the content doesn't fit on the page
60 // Only allow flicking if the content doesn't fit on the page
61 interactive: contentHeight > height
61 interactive: contentHeight > height
62
62
63+ property int selectedIndex: -1
64+ property bool blockCurrentIndexChange: false
65+ // for count = 0
66+ onCountChanged: {
67+ if (count == 0 && selectedIndex != -1) {
68+ selectedIndex = -1;
69+ }
70+ }
71+ // for highlight following
72+ onSelectedIndexChanged: {
63− currentIndex: -1
73+ if (currentIndex != selectedIndex) {
74+ var blocked = blockCurrentIndexChange;
75+ blockCurrentIndexChange = true;
76+
77+ currentIndex = selectedIndex;
78+
79+ blockCurrentIndexChange = blocked;
80+ }
81+ }
82+ // for item addition/removal
83+ onCurrentIndexChanged: {
84+ if (!blockCurrentIndexChange) {
85+ if (selectedIndex != -1 && selectedIndex != currentIndex) {
86+ selectedIndex = currentIndex;
87+ }
88+ }
89+ }
90+
64 delegate: Item {
91 delegate: Item {
65 id: menuDelegate
92 id: menuDelegate
66
93
@@ -90,9 +117,9 @@ IndicatorBase {
90 }
117 }
91
118
92 if (item.hasOwnProperty("menuSelected")) {
119 if (item.hasOwnProperty("menuSelected")) {
93− item.menuSelected = Qt.binding(function() { return mainMenu.currentIndex == index; });
120+ item.menuSelected = Qt.binding(function() { return mainMenu.selectedIndex == index; });
94− item.selectMenu.connect(function() { mainMenu.currentIndex = index; });
121+ item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
95− item.deselectMenu.connect(function() { mainMenu.currentIndex = -1; });
122+ item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
96 }
123 }
97 if (item.hasOwnProperty("menu")) {
124 if (item.hasOwnProperty("menu")) {
98 item.menu = Qt.binding(function() { return model; });
125 item.menu = Qt.binding(function() { return model; });
@@ -149,7 +176,7 @@ IndicatorBase {
149
176
150 function reset()
177 function reset()
151 {
178 {
152− mainMenu.currentIndex = -1;
179+ mainMenu.selectedIndex = -1;
153 mainMenu.positionViewAtBeginning();
180 mainMenu.positionViewAtBeginning();
154 }
181 }
155}
182}