on 3327de0 help sign in
unity8/tests/qmltests/ApplicationMenuDataLoader.qml
83 lines 2.9 kB history raw
1import QtQuick 2.4
2import Ubuntu.Components 1.3
3import Unity.Application 0.1
4import Unity.ApplicationMenu 0.1
5import Unity.Indicators 0.1 as Indicators
7Object {
9 property alias surfaceManager: sMgrHandler.target
11 Connections {
12 id: sMgrHandler
13 target: null
14 onSurfaceCreated: {
15 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
17 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
18 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
19 }
20 onSurfaceDestroyed: {
21 ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
22 }
23 }
25 function generateTestData(length, depth, submenuInterval, separatorInterval, prefix, root) {
26 var data = [];
27 if (root === undefined) root = true;
29 for (var i = 0; i < length; i++) {
31 var menuName = prefix;
32 if (menuName === undefined) {
33 var chars = Math.random() * 20;
34 menuName = "";
35 for (var x = 0; x < chars; x++) {
36 menuName += String.fromCharCode((Math.random() * 26) + 65);
37 }
38 }
40 var menuCode = String.fromCharCode(i+65);
42 var isSeparator = !root && separatorInterval > 0 && ((i+1) % separatorInterval == 0);
43 var row = {
44 "rowData": { // 1
45 "label": menuName + "&" + menuCode,
46 "sensitive": true,
47 "isSeparator": isSeparator,
48 "icon": "",
49 "ext": {},
50 "action": menuName + menuCode,
51 "actionState": {},
52 "isCheck": false,
53 "isRadio": false,
54 "isToggled": false,
55 "shortcut": ""
56 }
57 }
58 var isSubmenu = root === undefined || root === true || (submenuInterval > 0 && ((i+1) % submenuInterval == 0));
59 if (isSubmenu && !isSeparator && depth > 1) {
60 row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval,prefix, false);
61 }
62 data[i] = row;
63 }
64 return data;
65 }
67 // Test Data
68 property var singleCheckable: [{
69 "rowData": { // 1
70 "label": "checkable1",
71 "sensitive": true,
72 "isSeparator": false,
73 "icon": "",
74 "ext": {},
75 "action": "checkable1",
76 "actionState": {},
77 "isCheck": true,
78 "isRadio": false,
79 "isToggled": false,
80 "shortcut": "Alt+F"
81 }
82 }]