on e1659ca help sign in
unity8/tests/qmltests/ApplicationMenuDataLoader.qml
75 lines 2.6 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 onSurfaceCreated: {
14 var fakeMenuPath = "/" + surface.persistentId.replace(/\W+/g, "");
16 ApplicationMenuRegistry.RegisterSurfaceMenu(surface.persistentId, fakeMenuPath, fakeMenuPath, ":1");
17 Indicators.UnityMenuModelCache.setCachedModelData(fakeMenuPath, generateTestData(4, 3, 2, 3, "menu"));
18 }
19 onSurfaceDestroyed: {
20 ApplicationMenuRegistry.UnregisterSurfaceMenu(persistentSurfaceId, "/app");
21 }
22 }
24 function generateTestData(length, depth, submenuInterval, separatorInterval, prefix, root) {
25 var data = [];
26 if (root === undefined) root = true;
28 if (prefix === undefined) prefix = "menu"
30 for (var i = 0; i < length; i++) {
32 var menuCode = String.fromCharCode(i+65);
34 var isSeparator = !root && separatorInterval > 0 && ((i+1) % separatorInterval == 0);
35 var row = {
36 "rowData": { // 1
37 "label": prefix + "&" + menuCode,
38 "sensitive": true,
39 "isSeparator": isSeparator,
40 "icon": "",
41 "ext": {},
42 "action": prefix + menuCode,
43 "actionState": {},
44 "isCheck": false,
45 "isRadio": false,
46 "isToggled": false,
47 "shortcut": ""
48 }
49 }
50 var isSubmenu = root === undefined || root === true || (submenuInterval > 0 && ((i+1) % submenuInterval == 0));
51 if (isSubmenu && !isSeparator && depth > 1) {
52 row["submenu"] = generateTestData(length, depth-1, submenuInterval, separatorInterval, prefix + menuCode + ".", false);
53 }
54 data[i] = row;
55 }
56 return data;
57 }
59 // Test Data
60 property var singleCheckable: [{
61 "rowData": { // 1
62 "label": "checkable1",
63 "sensitive": true,
64 "isSeparator": false,
65 "icon": "",
66 "ext": {},
67 "action": "checkable1",
68 "actionState": {},
69 "isCheck": true,
70 "isRadio": false,
71 "isToggled": false,
72 "shortcut": "Alt+F"
73 }
74 }]