on xenial help sign in
Reset current item selection on deleted. Fixes: 1378462

Approved by: Albert Astals Cid

commit5aaaf3a8a0dd17699be3d34874e4d46bc6667b5f authorNick Dedekind <nick.dedekind@canonical.com> dateTue 4 Nov 2014, 12:54 (12 years ago) parentbebdf635825628
2 files changed+66−10
qml/Panel/IndicatorPage.qml+12−1 tests/qmltests/Panel/tst_IndicatorPage.qml+54−9
qml/Panel/IndicatorPage.qml+12−1
@@ -25,6 +25,7 @@ IndicatorBase {
2525 //const
2626 property string title: rootActionState.title
2727 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
28+ readonly property alias factory: _factory
2829
2930 Indicators.UnityMenuModelStack {
3031 id: menuStack
@@ -117,6 +118,16 @@ IndicatorBase {
117118 }
118119 }
119120
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+
120131 delegate: Loader {
121132 id: loader
122133 objectName: "menuItem" + index
@@ -164,7 +175,7 @@ IndicatorBase {
164175 }
165176
166177 MenuItemFactory {
167− id: factory
178+ id: _factory
168179 rootModel: main.menuModel ? main.menuModel : null
169180 menuModel: mainMenu.model ? mainMenu.model : null
170181 }
tests/qmltests/Panel/tst_IndicatorPage.qml+54−9
@@ -18,6 +18,7 @@ import QtQuick 2.0
1818import QtTest 1.0
1919import Unity.Test 0.1 as UT
2020import Unity.Indicators 0.1 as Indicators
21+import Ubuntu.Settings.Menus 0.1 as Menus
2122import "../../../qml/Panel"
2223
2324Item {
@@ -33,8 +34,24 @@ Item {
3334 busName: "com.caninical.indicator.test"
3435 actionsObjectPath: "/com/canonical/indicator/test"
3536 menuObjectPath: "/com/canonical/indicator/test"
37+
38+ factory {
39+ _map: {
40+ "default": {
41+ "com.canonical.indicator.test" : testMenu
42+ }
43+ }
44+ }
3645 }
3746
47+ Component {
48+ id: testMenu
49+ Menus.StandardMenu {
50+ signal menuSelected
51+ signal menuDeselected
52+ }
53+ }
54+
3855 property var fullMenuData: [{
3956 "rowData": { // 1
4057 "label": "root",
@@ -51,39 +68,39 @@ Item {
5168 },
5269 "submenu": [{
5370 "rowData": { // 1.1
54− "label": "menu1",
71+ "label": "menu0",
5572 "sensitive": true,
5673 "isSeparator": false,
5774 "icon": "",
58− "type": "",
75+ "type": "com.canonical.indicator.test",
5976 "ext": {},
60− "action": "",
77+ "action": "menu0",
6178 "actionState": {},
6279 "isCheck": false,
6380 "isRadio": false,
6481 "isToggled": false,
6582 }}, {
6683 "rowData": { // 1.2
67− "label": "menu2",
84+ "label": "menu1",
6885 "sensitive": true,
6986 "isSeparator": false,
7087 "icon": "",
71− "type": "",
88+ "type": "com.canonical.indicator.test",
7289 "ext": {},
73− "action": "",
90+ "action": "menu1",
7491 "actionState": {},
7592 "isCheck": false,
7693 "isRadio": false,
7794 "isToggled": false,
7895 }}, {
7996 "rowData": { // row 1.2
80− "label": "menu3",
97+ "label": "menu2",
8198 "sensitive": true,
8299 "isSeparator": false,
83100 "icon": "",
84− "type": "",
101+ "type": "com.canonical.indicator.test",
85102 "ext": {},
86− "action": "",
103+ "action": "menu2",
87104 "actionState": {},
88105 "isCheck": false,
89106 "isRadio": false,
@@ -147,5 +164,33 @@ Item {
147164 var mainMenu = findChild(page, "mainMenu");
148165 tryCompare(mainMenu, "count", data.expectedCount);
149166 }
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+ }
150195 }
151196}