GUI -- Fixed topo toolbar button synchronization with keystroke commands.
- Added toggleNoCb to the toggle button widget. - Added _keyListener property to keyBindings structure, and the invocation of it from keyIn(). - Added keyListener to topoToolbar to synchronize button state. Change-Id: Iffb1dc5d38f2d9010f5e246cfb81a6b3db30d4af
Showing
4 changed files
with
63 additions
and
44 deletions
... | @@ -76,6 +76,7 @@ | ... | @@ -76,6 +76,7 @@ |
76 | gk = kh.globalKeys[key], | 76 | gk = kh.globalKeys[key], |
77 | gcb = fs.isF(gk) || (fs.isA(gk) && fs.isF(gk[0])), | 77 | gcb = fs.isF(gk) || (fs.isA(gk) && fs.isF(gk[0])), |
78 | vk = kh.viewKeys[key], | 78 | vk = kh.viewKeys[key], |
79 | + kl = fs.isF(kh.viewKeys._keyListener), | ||
79 | vcb = fs.isF(vk) || (fs.isA(vk) && fs.isF(vk[0])) || fs.isF(kh.viewFn), | 80 | vcb = fs.isF(vk) || (fs.isA(vk) && fs.isF(vk[0])) || fs.isF(kh.viewFn), |
80 | token = getViewToken(); | 81 | token = getViewToken(); |
81 | 82 | ||
... | @@ -91,6 +92,9 @@ | ... | @@ -91,6 +92,9 @@ |
91 | if (vcb) { | 92 | if (vcb) { |
92 | vcb(token, key, keyCode, event); | 93 | vcb(token, key, keyCode, event); |
93 | } | 94 | } |
95 | + if (kl) { | ||
96 | + kl(key); | ||
97 | + } | ||
94 | } | 98 | } |
95 | } | 99 | } |
96 | 100 | ... | ... |
... | @@ -92,10 +92,15 @@ | ... | @@ -92,10 +92,15 @@ |
92 | is.loadIcon(togDiv, gid, btnSize, true); | 92 | is.loadIcon(togDiv, gid, btnSize, true); |
93 | togDiv.classed('selected', sel); | 93 | togDiv.classed('selected', sel); |
94 | 94 | ||
95 | - function _toggle(b) { | 95 | + function _toggle(b, nocb) { |
96 | sel = (b === undefined) ? !sel : !!b; | 96 | sel = (b === undefined) ? !sel : !!b; |
97 | togDiv.classed('selected', sel); | 97 | togDiv.classed('selected', sel); |
98 | - cbFnc(sel); | 98 | + nocb || cbFnc(sel); |
99 | + } | ||
100 | + | ||
101 | + // toggle the button state without invoking the callback | ||
102 | + function toggleNoCb() { | ||
103 | + _toggle(undefined, true); | ||
99 | } | 104 | } |
100 | 105 | ||
101 | togDiv.on('click', _toggle); | 106 | togDiv.on('click', _toggle); |
... | @@ -104,7 +109,8 @@ | ... | @@ -104,7 +109,8 @@ |
104 | id: id, | 109 | id: id, |
105 | width: buttonWidth, | 110 | width: buttonWidth, |
106 | selected: function () { return sel; }, | 111 | selected: function () { return sel; }, |
107 | - toggle: _toggle | 112 | + toggle: _toggle, |
113 | + toggleNoCb: toggleNoCb | ||
108 | } | 114 | } |
109 | } | 115 | } |
110 | 116 | ... | ... |
... | @@ -69,6 +69,8 @@ | ... | @@ -69,6 +69,8 @@ |
69 | 69 | ||
70 | esc: handleEscape, | 70 | esc: handleEscape, |
71 | 71 | ||
72 | + _keyListener: ttbs.keyListener, | ||
73 | + | ||
72 | _helpFormat: [ | 74 | _helpFormat: [ |
73 | ['O', 'I', 'D', '-', 'H', 'M', 'P', 'B' ], | 75 | ['O', 'I', 'D', '-', 'H', 'M', 'P', 'B' ], |
74 | ['X', 'Z', 'L', 'U', 'R' ], | 76 | ['X', 'Z', 'L', 'U', 'R' ], | ... | ... |
... | @@ -16,73 +16,79 @@ | ... | @@ -16,73 +16,79 @@ |
16 | 16 | ||
17 | /* | 17 | /* |
18 | ONOS GUI -- Topology Toolbar Module. | 18 | ONOS GUI -- Topology Toolbar Module. |
19 | - Defines functions for manipulating the toolbar. | 19 | + Functions for creating and interacting with the toolbar. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | (function () { | 22 | (function () { |
23 | 23 | ||
24 | // injected references | 24 | // injected references |
25 | - var $log, tbs; | 25 | + var $log, tbs, api; |
26 | 26 | ||
27 | - var api, toolbar; | 27 | + // internal state |
28 | + var toolbar, keyData; | ||
28 | 29 | ||
29 | - // buttons | 30 | + // key to button mapping data |
30 | - var togSummary, togInstances, togDetails, | 31 | + var k2b = { |
31 | - togHosts, togOffline, togPorts, togBackground; | 32 | + O: { id: 'summary-tog', gid: 'unknown', isel: true}, |
33 | + I: { id: 'instance-tog', gid: 'uiAttached', isel: true }, | ||
34 | + D: { id: 'details-tog', gid: 'unknown', isel: true }, | ||
35 | + | ||
36 | + H: { id: 'hosts-tog', gid: 'endstation', isel: false }, | ||
37 | + M: { id: 'offline-tog', gid: 'switch', isel: true }, | ||
38 | + P: { id: 'ports-tog', gid: 'unknown', isel: true }, | ||
39 | + B: { id: 'bkgrnd-tog', gid: 'unknown', isel: true } | ||
40 | + }; | ||
32 | 41 | ||
33 | function init(_api_) { | 42 | function init(_api_) { |
34 | api = _api_; | 43 | api = _api_; |
35 | } | 44 | } |
36 | 45 | ||
37 | - // TODO: fix toggle and radio sets to be selected based on the current state | 46 | + function initKeyData() { |
38 | - // current bug: first toggle button, then toggle with key, toggle button doesn't update appearance | 47 | + keyData = d3.map(k2b); |
39 | - | 48 | + keyData.forEach(function(key, value) { |
40 | - | 49 | + var data = api.getActionEntry(key); |
41 | - function getActions() { | 50 | + value.cb = data[0]; // on-click callback |
42 | - togSummary = api.getActionEntry('O'); | 51 | + value.tt = data[1]; // tooltip |
43 | - togInstances = api.getActionEntry('I'); | 52 | + }); |
44 | - togDetails = api.getActionEntry('D'); | ||
45 | - | ||
46 | - togHosts = api.getActionEntry('H'); | ||
47 | - togOffline = api.getActionEntry('M'); | ||
48 | - togPorts = api.getActionEntry('P'); | ||
49 | - togBackground = api.getActionEntry('B'); | ||
50 | - } | ||
51 | - | ||
52 | - function entryCallback(entry) { | ||
53 | - return entry[0]; | ||
54 | } | 53 | } |
55 | 54 | ||
56 | - function entryToolTip(entry) { | 55 | + function addToggle(key) { |
57 | - return entry[1]; | 56 | + var v = keyData.get(key); |
57 | + v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt); | ||
58 | } | 58 | } |
59 | 59 | ||
60 | function addFirstRow() { | 60 | function addFirstRow() { |
61 | - toolbar.addToggle('summary-tog', 'unknown', true, | 61 | + addToggle('O'); |
62 | - entryCallback(togSummary), entryToolTip(togSummary)); | 62 | + addToggle('I'); |
63 | - toolbar.addToggle('instance-tog', 'uiAttached', true, | 63 | + addToggle('D'); |
64 | - entryCallback(togInstances), entryToolTip(togInstances)); | ||
65 | - toolbar.addToggle('details-tog', 'unknown', true, | ||
66 | - entryCallback(togDetails), entryToolTip(togDetails)); | ||
67 | toolbar.addSeparator(); | 64 | toolbar.addSeparator(); |
68 | 65 | ||
69 | - toolbar.addToggle('hosts-tog', 'endstation', false, | 66 | + addToggle('H'); |
70 | - entryCallback(togHosts), entryToolTip(togHosts)); | 67 | + addToggle('M'); |
71 | - toolbar.addToggle('offline-tog', 'switch', true, | 68 | + addToggle('P'); |
72 | - entryCallback(togOffline), entryToolTip(togOffline)); | 69 | + addToggle('B'); |
73 | - toolbar.addToggle('ports-tog', 'unknown', true, | ||
74 | - entryCallback(togPorts), entryToolTip(togPorts)); | ||
75 | - toolbar.addToggle('bkgrnd-tog', 'unknown', true, | ||
76 | - entryCallback(togBackground), entryToolTip(togBackground)); | ||
77 | } | 70 | } |
78 | 71 | ||
79 | function createToolbar() { | 72 | function createToolbar() { |
80 | - getActions(); | 73 | + initKeyData(); |
81 | toolbar = tbs.createToolbar('topo-tbar'); | 74 | toolbar = tbs.createToolbar('topo-tbar'); |
82 | addFirstRow(); | 75 | addFirstRow(); |
83 | toolbar.show(); | 76 | toolbar.show(); |
84 | } | 77 | } |
85 | 78 | ||
79 | + // allows us to ensure the button states track key strokes | ||
80 | + function keyListener(key) { | ||
81 | + var v = keyData.get(key); | ||
82 | + | ||
83 | + if (v) { | ||
84 | + // we have a valid button mapping | ||
85 | + if (v.tog) { | ||
86 | + // it's a toggle button | ||
87 | + v.tog.toggleNoCb(); | ||
88 | + } | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
86 | angular.module('ovTopo') | 92 | angular.module('ovTopo') |
87 | .factory('TopoToolbarService', ['$log', 'ToolbarService', | 93 | .factory('TopoToolbarService', ['$log', 'ToolbarService', |
88 | 94 | ||
... | @@ -92,7 +98,8 @@ | ... | @@ -92,7 +98,8 @@ |
92 | 98 | ||
93 | return { | 99 | return { |
94 | init: init, | 100 | init: init, |
95 | - createToolbar: createToolbar | 101 | + createToolbar: createToolbar, |
102 | + keyListener: keyListener | ||
96 | }; | 103 | }; |
97 | }]); | 104 | }]); |
98 | }()); | 105 | }()); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment