@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013-2014 Canonical Ltd.
2+ * Copyright 2013-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -25,26 +25,47 @@ PageStack {
2525 id: root
2626
2727 property var submenuIndex: undefined
28− property string context
2928 property QtObject menuModel: null
29+ property Component factory
3030
3131 Connections {
32+ id: dynamicChanges
3233 target: root.menuModel
34+ property bool ready: false
3335
3436 // fix async creation with signal from model before it's finished.
35− onRowsInserted: root.reset()
36− onRowsRemoved: root.reset()
37− onModelReset: root.reset()
37+ onRowsInserted: {
38+ if (submenuIndex !== undefined && first <= submenuIndex) {
39+ reset(true);
40+ }
41+ }
42+ onRowsRemoved: {
43+ if (submenuIndex !== undefined && first <= submenuIndex) {
44+ reset(true);
45+ }
46+ }
47+ onModelReset: {
48+ if (root.submenuIndex !== undefined) {
49+ reset(true);
50+ }
51+ }
3852 }
3953
4054 Component.onCompleted: {
41− reset();
55+ reset(true);
56+ dynamicChanges.ready = true;
4257 }
4358
44− function reset() {
45− clear();
46− var model = submenuIndex == undefined ? menuModel : menuModel.submenu(submenuIndex)
47− push(pageComponent, { "menuModel": model });
59+ function reset(clearModel) {
60+ if (clearModel) {
61+ clear();
62+ var model = submenuIndex == undefined ? menuModel : menuModel.submenu(submenuIndex)
63+ if (model) {
64+ push(pageComponent, { "menuModel": model });
65+ }
66+ } else {
67+ root.currentPage.reset();
68+ }
4869 }
4970
5071 Component {
@@ -56,13 +77,12 @@ PageStack {
5677 property alias title: backLabel.title
5778 property bool isSubmenu: false
5879
59− MenuItemFactory {
60− id: factory
61− context: root.context
62− rootModel: root.menuModel ? root.menuModel : null
63− menuModel: mainMenu.model ? mainMenu.model : null
80+ function reset() {
81+ mainMenu.positionViewAtBeginning();
6482 }
6583
84+ property QtObject factory: root.factory.createObject(page, { menuModel: page.menuModel } )
85+
6686 header: PageHeader {
6787 id: backLabel
6888 visible: page.isSubmenu
@@ -151,7 +171,7 @@ PageStack {
151171 visible: status == Loader.Ready
152172
153173 property int modelIndex: index
154− sourceComponent: factory.load(model)
174+ sourceComponent: page.factory.load(model)
155175
156176 onLoaded: {
157177 if (item.hasOwnProperty("selected")) {
@@ -174,7 +194,7 @@ PageStack {
174194 if (model.hasSubmenu) {
175195 root.push(pageComponent, {
176196 "isSubmenu": true,
177− "title": model.label,
197+ "title": model.label.replace(/_|&/, ""),
178198 "menuModel": page.menuModel.submenu(modelIndex)
179199 });
180200 }
@@ -202,10 +222,4 @@ PageStack {
202222 }
203223 }
204224 }
205−
206−// function reset()
207−// {
208−// menuStack.reset();
209−// mainMenu.positionViewAtBeginning();
210−// }
211225}