on master help sign in
unity8/tests/qmltests/ApplicationMenuDataLoader.qml
99 lines 3.5 kB history raw
1/*
2 * Copyright 2017 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Unity.Application 0.1
20import Unity.ApplicationMenu 0.1
21import Unity.Indicators 0.1 as Indicators
23Object {
25 property alias surfaceManager: sMgrHandler.target
27 Connections {
28 id: sMgrHandler
29 target: null
30 onSurfaceCreated: {
31 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
33 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
34 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
35 }
36 onSurfaceDestroyed: {
37 ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
38 }
39 }
41 function generateTestData(length, depth, submenuInterval, separatorInterval, prefix, root) {
42 var data = [];
43 if (root === undefined) root = true;
45 for (var i = 0; i < length; i++) {
47 var menuName = prefix;
48 if (menuName === undefined) {
49 var chars = Math.random() * 20;
50 menuName = "";
51 for (var x = 0; x < chars; x++) {
52 menuName += String.fromCharCode((Math.random() * 26) + 65);
53 }
54 }
56 var menuCode = String.fromCharCode(i+65);
58 var isSeparator = !root && separatorInterval > 0 && ((i+1) % separatorInterval == 0);
59 var row = {
60 "rowData": { // 1
61 "label": menuName + "&" + menuCode,
62 "sensitive": true,
63 "isSeparator": isSeparator,
64 "icon": "",
65 "ext": {},
66 "action": menuName + menuCode,
67 "actionState": {},
68 "isCheck": false,
69 "isRadio": false,
70 "isToggled": false,
71 "shortcut": ""
72 }
73 }
74 var isSubmenu = root === undefined || root === true || (submenuInterval > 0 && ((i+1) % submenuInterval == 0));
75 if (isSubmenu && !isSeparator && depth > 1) {
76 row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval,prefix, false);
77 }
78 data[i] = row;
79 }
80 return data;
81 }
83 // Test Data
84 property var singleCheckable: [{
85 "rowData": { // 1
86 "label": "checkable1",
87 "sensitive": true,
88 "isSeparator": false,
89 "icon": "",
90 "ext": {},
91 "action": "checkable1",
92 "actionState": {},
93 "isCheck": true,
94 "isRadio": false,
95 "isToggled": false,
96 "shortcut": "Alt+F"
97 }
98 }]