|
3 | 3 | % |
4 | 4 | % MLAPPTOOLS methods: |
5 | 5 |
|
6 | | - properties |
7 | | - % TODO: Move generic portions of repeated dojo query strings here |
8 | | - % to reduce copypasta errors as the number of methods expands |
9 | | - end |
10 | | - |
11 | 6 | methods |
12 | 7 | function obj = mlapptools |
13 | 8 | % Dummy constructor so we don't return an empty class instance |
|
19 | 14 | function textAlign(uielement, alignment) |
20 | 15 | alignment = lower(alignment); |
21 | 16 | mlapptools.validatealignmentstr(alignment) |
22 | | - mlapptools.togglewarnings('off') |
23 | 17 |
|
24 | 18 | rez = ''; |
25 | 19 | while ~strcmp(rez, sprintf('"%s"', alignment)) |
26 | 20 | try |
27 | 21 | % Get a handle to the webwindow |
28 | | - win = struct(struct(uielement.Parent).Controller).Container.CEF; |
| 22 | + win = mlapptools.getwebwindow(uielement.Parent); |
29 | 23 |
|
30 | 24 | % Find which element of the DOM we want to edit |
31 | | - data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId); |
| 25 | + data_tag = mlapptools.getdatatag(uielement); |
32 | 26 |
|
33 | 27 | % Manipulate the DOM via a JS command |
34 | | - widgetquerystr = sprintf('dojo.getAttr(dojo.query("[data-tag^=''%s''] > div")[0], "widgetid")', data_tag); |
35 | | - widgetID = win.executeJS(widgetquerystr); |
36 | | - widgetID = widgetID(2:end-1); |
| 28 | + widgetID = mlapptools.getwidgetID(win, data_tag); |
37 | 29 |
|
38 | 30 | alignsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "textAlign", "%s")', widgetID, alignment); |
39 | 31 | rez = win.executeJS(alignsetstr); |
40 | | - catch |
| 32 | + catch err |
| 33 | + % TODO: Check the error so we're not catching errors indiscriminately |
41 | 34 | pause(1); % Give the figure (webpage) some more time to load |
42 | 35 | end |
43 | 36 | end |
44 | | - mlapptools.togglewarnings('on') |
| 37 | + |
45 | 38 | end |
46 | 39 | end |
47 | 40 |
|
48 | 41 | methods (Static, Access = private) |
| 42 | + function [win] = getwebwindow(uifigurewindow) |
| 43 | + % TODO: Check that we've been passed an app designer figure window |
| 44 | + mlapptools.togglewarnings('off') |
| 45 | + win = struct(struct(uifigurewindow).Controller).Container.CEF; |
| 46 | + mlapptools.togglewarnings('on') |
| 47 | + end |
| 48 | + |
| 49 | + function [data_tag] = getdatatag(uielement) |
| 50 | + mlapptools.togglewarnings('off') |
| 51 | + data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId); |
| 52 | + mlapptools.togglewarnings('on') |
| 53 | + end |
| 54 | + |
| 55 | + function [widgetID] = getwidgetID(win, data_tag) |
| 56 | + widgetquerystr = sprintf('dojo.getAttr(dojo.query("[data-tag^=''%s''] > div")[0], "widgetid")', data_tag); |
| 57 | + widgetID = win.executeJS(widgetquerystr); |
| 58 | + widgetID = widgetID(2:end-1); |
| 59 | + end |
| 60 | + |
49 | 61 | function togglewarnings(togglestr) |
50 | 62 | switch lower(togglestr) |
51 | 63 | case 'on' |
|
0 commit comments