Skip to content

Commit 0225b1e

Browse files
committed
app superclasses - handle better the default session naming when adding a new session in a multisession app, also remove an extra call to update
1 parent e8a784a commit 0225b1e

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

widgets/+wt/+apps/AbstractSessionApp.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
?wt.apps.BaseMultiSessionApp}) AbstractSessionApp < wt.apps.BaseApp
33
% Abstract base class for Widgets Toolbox app with 1+ sessions
44

5-
% Copyright 2024-2025 The MathWorks Inc.
5+
% Copyright 2024-2025 The MathWorks Inc.
66

77

88
%% Abstract Public Properties
@@ -248,11 +248,12 @@ function saveSession_Internal(app, useSaveAs, session)
248248
cleanupObj = onCleanup(@()delete(dlg));
249249

250250
% Save the session
251+
% This will trigger update if path updates and/or session
252+
% is no longer dirty
251253
session.save(sessionPath);
252254

253-
% Update the app in case filepath changed
255+
% Update the title
254256
app.updateTitle()
255-
app.update()
256257

257258
end %if strlength(sessionPath)
258259

widgets/+wt/+apps/BaseMultiSessionApp.m

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
% Number of sessions loaded
2929
NumSessions (1,1) double
3030

31+
% Names of sessions loaded
32+
SessionNames (:,1) string
33+
34+
% Names of sessions for display, with * for unsaved session
35+
SessionDisplayNames (:,1) string
36+
3137
% Currently selected session
3238
SelectedSession wt.model.BaseSession
3339

@@ -57,6 +63,27 @@
5763
value = numel(app.Session);
5864
end
5965

66+
function value = get.SessionNames(app)
67+
numSessions = app.NumSessions;
68+
value = repmat("",numSessions,1');
69+
if numSessions > 0
70+
isValidSession = isvalid(app.Session);
71+
value(isValidSession) = [app.Session(isValidSession).Name];
72+
end
73+
end
74+
75+
function value = get.SessionDisplayNames(app)
76+
numSessions = app.NumSessions;
77+
value = repmat("",numSessions,1');
78+
if numSessions > 0
79+
isValidSession = isvalid(app.Session);
80+
value(isValidSession) = [app.Session(isValidSession).Name];
81+
isDirty = false(numSessions, 1);
82+
isDirty(isValidSession) = [app.Session(isValidSession).Dirty];
83+
value(isDirty) = value(isDirty) + " *";
84+
end
85+
end
86+
6087
function value = get.SelectedSession(app)
6188
value = app.Session( app.SelectedSessionIndex );
6289
end
@@ -126,11 +153,22 @@ function close(app)
126153
% Store the session
127154
% This also triggers app.update(), app.updateTitle()
128155
if isempty(app.Session)
156+
129157
app.Session = session;
158+
130159
else
160+
161+
% Ensure a unique name
162+
thisName = matlab.lang.makeUniqueStrings(...
163+
session.Name, app.SessionNames);
164+
session.FilePath = thisName;
165+
session.Dirty = false;
166+
167+
% Append the session
131168
app.Session(end+1) = session;
132-
% Don't select by default, but concrete app may do this
133-
end
169+
% Don't select it by default, but concrete app may do this
170+
171+
end %if
134172

135173
end %function
136174

widgets/+wt/+model/BaseSession.m

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
end
6666
end
6767
end
68+
6869

6970

7071
%% Public methods (subclass may override these)
@@ -138,28 +139,6 @@ function save(session, filePath)
138139
end %methods
139140

140141

141-
% %% Hidden methods
142-
% methods (Hidden)
143-
%
144-
% function setFilePathSilently(obj, filePath)
145-
% % Set FilePath without triggering change notifications
146-
%
147-
% % Define arguments
148-
% arguments
149-
% obj (1,1) wt.model.BaseModel
150-
% filePath (1,1) string
151-
% end
152-
%
153-
% oldValue = obj.EnableChangeListeners;
154-
% obj.EnableChangeListeners = false;
155-
% obj.FilePath = filePath;
156-
% obj.EnableChangeListeners = oldValue;
157-
%
158-
% end %function
159-
%
160-
% end %methods
161-
162-
163142
%% Protected methods (subclass may override these)
164143
methods (Access = protected)
165144

@@ -200,7 +179,7 @@ function onModelChanged(obj,evt)
200179
end %function
201180

202181
end %methods
203-
182+
204183

205184
%% Accessors
206185
methods

0 commit comments

Comments
 (0)