time | Calls | line |
|---|
| | 114 | function workspaceUpdatedCorrectContext(aEvent, expectVarNames, eventType)
|
| | 115 | % Called by the event listener. Corrects the context by executing
|
| | 116 | % in the user's workspace, using the builtin _dtcallback function.
|
| 3 | 117 | doUpdate = true;
|
< 0.001 | 3 | 118 | varNames = {};
|
| | 119 |
|
< 0.001 | 3 | 120 | if ~expectVarNames
|
| | 121 | varList = [];
|
0.005 | 3 | 122 | elseif isempty(aEvent) || ~isprop(aEvent, 'Details') || ~isfield(aEvent.Details, 'varnames')
|
| | 123 | varList = '';
|
| 3 | 124 | else
|
0.001 | 3 | 125 | varNames = aEvent.Details.varnames.item;
|
< 0.001 | 3 | 126 | if ~iscellstr(varNames) %#ok<ISCLSTR>
|
< 0.001 | 3 | 127 | varNames = {varNames};
|
| 3 | 128 | end
|
| | 129 |
|
< 0.001 | 3 | 130 | if ~isempty(varNames)
|
0.002 | 3 | 131 | varList = join(varNames, ''',''');
|
| | 132 | else
|
| | 133 | varList = '';
|
| 3 | 134 | end
|
| | 135 |
|
| | 136 |
|
< 0.001 | 3 | 137 | isAnsOnlyVariableChange = length(varNames) == 1 && ...
|
| 3 | 138 | strcmp(varNames{1}, 'ans') && ...
|
| 3 | 139 | isfield(aEvent.Details, 'VariablesChangedEvent');
|
| | 140 | % Short circuit for ans updates if ans isn't a variable in
|
| | 141 | % the workspace
|
0.002 | 3 | 142 | if isAnsOnlyVariableChange && ~ismember('ans', evalin('debug', 'who'))
|
0.002 | 3 | 143 | internal.matlab.datatoolsservices.WorkspaceListener.logEvent('Ignoring new ans VariablesChanged event\n');
|
< 0.001 | 3 | 144 | return;
|
| | 145 | end
|
| | 146 |
|
| | 147 | % Throttle amount the updates ignore anything < throttleTime
|
| | 148 | currTime = posixtime(datetime('now'));
|
| | 149 | lastUpdateTime = internal.matlab.datatoolsservices.WorkspaceListener.getSetLastUpdateTime();
|
| | 150 | eventQueuingEnabled = internal.matlab.datatoolsservices.WorkspaceListener.eventQueueEnabled;
|
| | 151 | timeDiff = currTime - lastUpdateTime;
|
| | 152 | if ~isAnsOnlyVariableChange
|
| | 153 | tt = internal.matlab.datatoolsservices.WorkspaceListener.eventThrottleTime;
|
| | 154 | else
|
| | 155 | tt = internal.matlab.datatoolsservices.WorkspaceListener.ansThrottleTime;
|
| | 156 | end
|
| | 157 | if ~(~eventQueuingEnabled || timeDiff >= tt || timeDiff < 0)
|
| | 158 | doUpdate = false;
|
| | 159 | end
|
| | 160 | % If the time difference between updates just for ans
|
| | 161 | % has been more than throttleTime, do the update. Also, if
|
| | 162 | % the time difference is less than 0 (which can happen
|
| | 163 | % in MOL when the location of the MATLAB session is
|
| | 164 | % different from previous logins), also do the update to
|
| | 165 | % get times sync'ed up for this session.
|
| | 166 | internal.matlab.datatoolsservices.WorkspaceListener.getSetLastUpdateTime(currTime);
|
| | 167 | end
|
| | 168 |
|
| | 169 | if doUpdate
|
| | 170 | % Dispatch Event
|
| | 171 | internal.matlab.datatoolsservices.WorkspaceListener.logEvent("Dispatching event(%s) for variables: %s\n", string(eventType), string(varList));
|
| | 172 | internal.matlab.datatoolsservices.WorkspaceListener.executeWorkspaceListeners(varList, eventType);
|
| | 173 | else
|
| | 174 | % Coalesce and Queue event
|
| | 175 | % Always queue ans VariablesChanged events to avoid 2 events
|
| | 176 | % being fired. This will mean all ans updates are delayed
|
| | 177 | % by throttleTime but that should be sufficient to avoid two
|
| | 178 | % events firing.
|
| | 179 | if isAnsOnlyVariableChange
|
| | 180 | % Ignore ans updates as they will cause an infinite
|
| | 181 | % loop. Calling the callbacks triggers workspace
|
| | 182 | % updates around ans. This happens if we execute
|
| | 183 | % either when MATLAB IDLE or via the event queue timer.
|
| | 184 | internal.matlab.datatoolsservices.WorkspaceListener.logEvent('Not queuing new ans VariablesChanged event\n');
|
| | 185 | else
|
| | 186 | internal.matlab.datatoolsservices.WorkspaceListener.queueEvent(varNames, eventType);
|
| | 187 | end
|
| | 188 | end
|
| | 189 | end
|
Other subfunctions in this file are not included in this listing.