Skip to content

Commit 2ad7d73

Browse files
committed
Fix logic errors, add another WidgetID race
See #1
1 parent 067c389 commit 2ad7d73

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

mlapptools.m

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ function textAlign(uielement, alignment)
2121
mlapptools.validatealignmentstr(alignment)
2222

2323
% Get a handle to the webwindow
24-
win = mlapptools.getwebwindow(uielement.Parent);
24+
win = mlapptools.getWebWindow(uielement.Parent);
2525

2626
% Find which element of the DOM we want to edit
27-
data_tag = mlapptools.getdatatag(uielement);
27+
data_tag = mlapptools.getDataTag(uielement);
2828

2929
% Manipulate the DOM via a JS command
30-
widgetID = mlapptools.getwidgetID(win, data_tag);
30+
widgetID = mlapptools.getWidgetID(win, data_tag);
3131

3232
alignsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "textAlign", "%s")', widgetID, alignment);
3333
win.executeJS(alignsetstr);
@@ -38,13 +38,13 @@ function fontWeight(uielement, weight)
3838
weight = mlapptools.validatefontweight(weight);
3939

4040
% Get a handle to the webwindow
41-
win = mlapptools.getwebwindow(uielement.Parent);
41+
win = mlapptools.getWebWindow(uielement.Parent);
4242

4343
% Find which element of the DOM we want to edit
44-
data_tag = mlapptools.getdatatag(uielement);
44+
data_tag = mlapptools.getDataTag(uielement);
4545

4646
% Manipulate the DOM via a JS command
47-
widgetID = mlapptools.getwidgetID(win, data_tag);
47+
widgetID = mlapptools.getWidgetID(win, data_tag);
4848

4949
fontwtsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "font-weight", "%s")', widgetID, weight);
5050
win.executeJS(fontwtsetstr);
@@ -55,13 +55,13 @@ function fontcolor(uielement, newcolor)
5555
newcolor = mlapptools.validateCSScolor(newcolor);
5656

5757
% Get a handle to the webwindow
58-
win = mlapptools.getwebwindow(uielement.Parent);
58+
win = mlapptools.getWebWindow(uielement.Parent);
5959

6060
% Find which element of the DOM we want to edit
61-
data_tag = mlapptools.getdatatag(uielement);
61+
data_tag = mlapptools.getDataTag(uielement);
6262

6363
% Manipulate the DOM via a JS command
64-
widgetID = mlapptools.getwidgetID(win, data_tag);
64+
widgetID = mlapptools.getWidgetID(win, data_tag);
6565

6666
fontwtsetstr = sprintf('dojo.style(dojo.query("#%s")[0], "color", "%s")', widgetID, newcolor);
6767
win.executeJS(fontwtsetstr);
@@ -70,7 +70,7 @@ function fontcolor(uielement, newcolor)
7070

7171

7272
methods (Static, Access = private)
73-
function [win] = getwebwindow(uifigurewindow)
73+
function [win] = getWebWindow(uifigurewindow)
7474
% TODO: Check that we've been passed an app designer figure window
7575
mlapptools.togglewarnings('off')
7676

@@ -90,23 +90,23 @@ function fontcolor(uielement, newcolor)
9090
end
9191
mlapptools.togglewarnings('on')
9292

93-
if toc < mlapptools.querytimeout
94-
msgID = 'mlapptools:getwidgetID:QueryTimeout';
93+
if toc >= mlapptools.querytimeout
94+
msgID = 'mlapptools:getWidgetID:QueryTimeout';
9595
error(msgID, ...
9696
'WidgetID query timed out after %u seconds, UI needs more time to load', ...
9797
mlapptools.querytimeout);
9898
end
9999
end
100100

101101

102-
function [data_tag] = getdatatag(uielement)
102+
function [data_tag] = getDataTag(uielement)
103103
mlapptools.togglewarnings('off')
104104
data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId);
105105
mlapptools.togglewarnings('on')
106106
end
107107

108108

109-
function [widgetID] = getwidgetID(win, data_tag)
109+
function [widgetID] = getWidgetID(win, data_tag)
110110
widgetquerystr = sprintf('dojo.getAttr(dojo.query("[data-tag^=''%s''] > div")[0], "widgetid")', data_tag);
111111

112112
tic
@@ -116,7 +116,8 @@ function fontcolor(uielement, newcolor)
116116
widgetID = widgetID(2:end-1);
117117
break
118118
catch err
119-
if ~isempty(strfind(err.message, 'JavaScript error: Uncaught ReferenceError: dojo is not defined'))
119+
if ~isempty(strfind(err.message, 'JavaScript error: Uncaught ReferenceError: dojo is not defined')) || ...
120+
~isempty(strfind(err.message, 'Cannot read property ''widgetid'' of null'))
120121
pause(0.01)
121122
else
122123
mlapptools.togglewarnings('on')
@@ -126,8 +127,8 @@ function fontcolor(uielement, newcolor)
126127
end
127128
mlapptools.togglewarnings('on')
128129

129-
if toc < mlapptools.querytimeout
130-
msgID = 'mlapptools:getwidgetID:QueryTimeout';
130+
if toc >= mlapptools.querytimeout
131+
msgID = 'mlapptools:getWidgetID:QueryTimeout';
131132
error(msgID, ...
132133
'WidgetID query timed out after %u seconds, UI needs more time to load', ...
133134
mlapptools.querytimeout);

0 commit comments

Comments
 (0)