on xenial help sign in
Reset current item selection on deleted. Fixes: 1378462
5aaaf3aNick Dedekind
qml/Panel/IndicatorPage.qml+12−1
@@ -25,6 +25,7 @@ IndicatorBase {
25 //const
25 //const
26 property string title: rootActionState.title
26 property string title: rootActionState.title
27 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
27 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
28+ readonly property alias factory: _factory
28
29
29 Indicators.UnityMenuModelStack {
30 Indicators.UnityMenuModelStack {
30 id: menuStack
31 id: menuStack
@@ -117,6 +118,16 @@ IndicatorBase {
117 }
118 }
118 }
119 }
119
120
121+ Connections {
122+ target: mainMenu.model ? mainMenu.model : null
123+ onRowsAboutToBeRemoved: {
124+ // track current item deletion.
125+ if (mainMenu.selectedIndex >= first && mainMenu.selectedIndex <= last) {
126+ mainMenu.selectedIndex = -1;
127+ }
128+ }
129+ }
130+
120 delegate: Loader {
131 delegate: Loader {
121 id: loader
132 id: loader
122 objectName: "menuItem" + index
133 objectName: "menuItem" + index
@@ -164,7 +175,7 @@ IndicatorBase {
164 }
175 }
165
176
166 MenuItemFactory {
177 MenuItemFactory {
167− id: factory
178+ id: _factory
168 rootModel: main.menuModel ? main.menuModel : null
179 rootModel: main.menuModel ? main.menuModel : null
169 menuModel: mainMenu.model ? mainMenu.model : null
180 menuModel: mainMenu.model ? mainMenu.model : null
170 }
181 }
tests/qmltests/Panel/tst_IndicatorPage.qml+54−9
@@ -18,6 +18,7 @@ import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19import Unity.Test 0.1 as UT
19import Unity.Test 0.1 as UT
20import Unity.Indicators 0.1 as Indicators
20import Unity.Indicators 0.1 as Indicators
21+import Ubuntu.Settings.Menus 0.1 as Menus
21import "../../../qml/Panel"
22import "../../../qml/Panel"
22
23
23Item {
24Item {
@@ -33,8 +34,24 @@ Item {
33 busName: "com.caninical.indicator.test"
34 busName: "com.caninical.indicator.test"
34 actionsObjectPath: "/com/canonical/indicator/test"
35 actionsObjectPath: "/com/canonical/indicator/test"
35 menuObjectPath: "/com/canonical/indicator/test"
36 menuObjectPath: "/com/canonical/indicator/test"
37+
38+ factory {
39+ _map: {
40+ "default": {
41+ "com.canonical.indicator.test" : testMenu
42+ }
43+ }
44+ }
36 }
45 }
37
46
47+ Component {
48+ id: testMenu
49+ Menus.StandardMenu {
50+ signal menuSelected
51+ signal menuDeselected
52+ }
53+ }
54+
38 property var fullMenuData: [{
55 property var fullMenuData: [{
39 "rowData": { // 1
56 "rowData": { // 1
40 "label": "root",
57 "label": "root",
@@ -51,39 +68,39 @@ Item {
51 },
68 },
52 "submenu": [{
69 "submenu": [{
53 "rowData": { // 1.1
70 "rowData": { // 1.1
54− "label": "menu1",
71+ "label": "menu0",
55 "sensitive": true,
72 "sensitive": true,
56 "isSeparator": false,
73 "isSeparator": false,
57 "icon": "",
74 "icon": "",
58− "type": "",
75+ "type": "com.canonical.indicator.test",
59 "ext": {},
76 "ext": {},
60− "action": "",
77+ "action": "menu0",
61 "actionState": {},
78 "actionState": {},
62 "isCheck": false,
79 "isCheck": false,
63 "isRadio": false,
80 "isRadio": false,
64 "isToggled": false,
81 "isToggled": false,
65 }}, {
82 }}, {
66 "rowData": { // 1.2
83 "rowData": { // 1.2
67− "label": "menu2",
84+ "label": "menu1",
68 "sensitive": true,
85 "sensitive": true,
69 "isSeparator": false,
86 "isSeparator": false,
70 "icon": "",
87 "icon": "",
71− "type": "",
88+ "type": "com.canonical.indicator.test",
72 "ext": {},
89 "ext": {},
73− "action": "",
90+ "action": "menu1",
74 "actionState": {},
91 "actionState": {},
75 "isCheck": false,
92 "isCheck": false,
76 "isRadio": false,
93 "isRadio": false,
77 "isToggled": false,
94 "isToggled": false,
78 }}, {
95 }}, {
79 "rowData": { // row 1.2
96 "rowData": { // row 1.2
80− "label": "menu3",
97+ "label": "menu2",
81 "sensitive": true,
98 "sensitive": true,
82 "isSeparator": false,
99 "isSeparator": false,
83 "icon": "",
100 "icon": "",
84− "type": "",
101+ "type": "com.canonical.indicator.test",
85 "ext": {},
102 "ext": {},
86− "action": "",
103+ "action": "menu2",
87 "actionState": {},
104 "actionState": {},
88 "isCheck": false,
105 "isCheck": false,
89 "isRadio": false,
106 "isRadio": false,
@@ -147,5 +164,33 @@ Item {
147 var mainMenu = findChild(page, "mainMenu");
164 var mainMenu = findChild(page, "mainMenu");
148 tryCompare(mainMenu, "count", data.expectedCount);
165 tryCompare(mainMenu, "count", data.expectedCount);
149 }
166 }
167+
168+ function test_remove_selected_item_data() {
169+ return [
170+ { remove: 0 },
171+ { remove: 2 },
172+ ]
173+ }
174+
175+ function test_remove_selected_item(data) {
176+ var mainMenu = findChild(page, "mainMenu");
177+ initializeMenuData(fullMenuData);
178+
179+ var menuId = "menu"+data.remove
180+
181+ tryCompareFunction(function() { return findChild(page, menuId) !== null;}, true);
182+ var menu = findChild(page, menuId);
183+
184+ menu.menuSelected();
185+ compare(mainMenu.currentIndex, data.remove, "Incorrect index selected");
186+ mainMenu.model.removeRow(data.remove);
187+
188+ compare(mainMenu.currentIndex, -1, "Current index should be reset after current item removal");
189+
190+ // now make sure selecting a new menu works.
191+ var menu1 = findChild(page, "menu1");
192+ menu1.menuSelected();
193+ compare(menu1.selected, true, "Item not selected");
194+ }
150 }
195 }
151}
196}