Skip to content

Commit 441600d

Browse files
committed
Changes to TemplateBaseSingleSessionApp that were missed in last commit
1 parent 02757c8 commit 441600d

File tree

1 file changed

+65
-44
lines changed

1 file changed

+65
-44
lines changed

widgets/examples/templates/TemplateBaseSingleSessionApp.m

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
classdef TemplateBaseSingleSessionApp < wt.apps.BaseSingleSessionApp
22
% Implements a template for a BaseSingleSessionApp
33

4+
% Copyright 2022-2025 The MathWorks Inc.
5+
46

57
%% Internal Components
68
% Create properties here for each control, layout, or view component
@@ -16,11 +18,11 @@
1618
% (BaseApp already brings "Grid", the main Grid layout in the window)
1719
Tab1Grid matlab.ui.container.GridLayout
1820
Tab2Grid matlab.ui.container.GridLayout
19-
Panel1Grid matlab.ui.container.GridLayout
21+
SessionDescriptionPanelGrid matlab.ui.container.GridLayout
2022
Panel2Grid matlab.ui.container.GridLayout
2123

2224
% Panels
23-
Panel1 matlab.ui.container.Panel
25+
SessionDescriptionPanel matlab.ui.container.Panel
2426
Panel2 matlab.ui.container.Panel
2527

2628
% Tabs
@@ -37,13 +39,17 @@
3739
NewButton matlab.ui.control.Button
3840
OpenButton matlab.ui.control.Button
3941
SaveButton matlab.ui.control.Button
42+
SaveAsButton matlab.ui.control.Button
4043
ExportGTButton matlab.ui.control.Button
4144
HelpButton matlab.ui.control.Button
4245

4346
% View Components
4447
%View1 namespace.ClassName
4548
%View2 namespace.ClassName
4649

50+
% Session information components
51+
SessionDescription matlab.ui.control.TextArea
52+
4753
% Temporary label components
4854
Panel1Text matlab.ui.control.Label
4955
Panel2Text matlab.ui.control.Label
@@ -71,11 +77,11 @@ function setup(app)
7177
% Create toolbar (split out for brevity)
7278
app.createToolbar()
7379

74-
% Create a panel
75-
app.Panel1 = uipanel(app.Grid);
76-
app.Panel1.Title = "Panel 1";
77-
app.Panel1.Layout.Row = [2 3];
78-
app.Panel1.Layout.Column = 1;
80+
% Create a panel for session description
81+
app.SessionDescriptionPanel = uipanel(app.Grid);
82+
app.SessionDescriptionPanel.Title = "Session Description:";
83+
app.SessionDescriptionPanel.Layout.Row = [2 3];
84+
app.SessionDescriptionPanel.Layout.Column = 1;
7985

8086
% Create a panel
8187
app.Panel2 = uipanel(app.Grid);
@@ -97,19 +103,18 @@ function setup(app)
97103
app.Tab2.Title = 'Tab 2';
98104

99105
% Create grid layouts to position content inside each container
100-
app.Panel1Grid = uigridlayout(app.Panel1, [1,1],"Padding", 0);
106+
app.SessionDescriptionPanelGrid = uigridlayout(...
107+
app.SessionDescriptionPanel, [1,1],"Padding", 0);
101108
app.Panel2Grid = uigridlayout(app.Panel2, [1,1],"Padding", 0);
102109
app.Tab1Grid = uigridlayout(app.Tab1, [1,1],"Padding", 0);
103110
app.Tab2Grid = uigridlayout(app.Tab2, [1,1],"Padding", 0);
104111

105-
% Place some temporary content in each container
106-
app.Panel1Text = uilabel(app.Panel1Grid);
107-
app.Panel1Text.Text = "Panel 1 Contents";
108-
app.Panel1Text.HorizontalAlignment = "center";
109-
app.Panel1Text.FontSize = 30;
110-
app.Panel1Text.Layout.Row = 1;
111-
app.Panel1Text.Layout.Column = 1;
112+
% Put a description for the selected session
113+
app.SessionDescription = uitextarea(app.SessionDescriptionPanelGrid);
114+
app.SessionDescription.ValueChangedFcn = ...
115+
@(~,evt)onSessionDescriptionChanged(app,evt);
112116

117+
% Place some temporary content in each container
113118
app.Panel2Text = uilabel(app.Panel2Grid);
114119
app.Panel2Text.Text = "Panel 2 Contents";
115120
app.Panel2Text.HorizontalAlignment = "center";
@@ -154,20 +159,18 @@ function createToolbar(app)
154159
% File Section
155160
app.FileSection = wt.toolbar.HorizontalSection();
156161
app.FileSection.Title = "FILE";
162+
app.FileSection.ButtonPushedFcn = @(~,evt)onFileToolbarButtonPushed(app,evt);
163+
157164
app.NewButton = app.FileSection.addButton('add_24.png','New Session');
158165
app.OpenButton = app.FileSection.addButton('folder_24.png','Open Session');
159166
app.SaveButton = app.FileSection.addButton('save_24.png','Save Session');
167+
app.SaveAsButton = app.FileSection.addButton("saveClean_24.png","Save As");
160168
app.FileSection.ComponentWidth(:) = 55;
161169

162170
% Help Section
163171
app.HelpSection = wt.toolbar.HorizontalSection();
164172
app.HelpSection.Title = "HELP";
165173
app.HelpButton = app.HelpSection.addButton('help_24.png','Help');
166-
167-
% Attach callbacks
168-
app.NewButton.ButtonPushedFcn = @(h,e)onNewButton(app);
169-
app.OpenButton.ButtonPushedFcn = @(h,e)onOpenButton(app);
170-
app.SaveButton.ButtonPushedFcn = @(h,e)onSaveButton(app);
171174
app.HelpButton.ButtonPushedFcn = @(h,e)onHelpButton(app);
172175

173176
% Add all toolbar sections to the toolbar
@@ -202,12 +205,29 @@ function update(app)
202205
% during callbacks or other changes that require contents to
203206
% refresh.
204207

208+
% Update the session description text
209+
app.SessionDescription.Value = app.Session.Description;
210+
211+
% Update toolbar button enables
212+
app.updateToolbarEnables()
213+
205214
% Examples:
206215
%app.View1.Model = sessionObj;
207216
%app.View2.Model = sessionObj;
208217

209218
end %function
210219

220+
221+
function updateToolbarEnables(app)
222+
223+
% Get the session states
224+
hasDirtySession = isscalar(app.Session) && app.Session.Dirty;
225+
226+
% File toolbar enables
227+
app.SaveButton.Enable = hasDirtySession;
228+
229+
end %function
230+
211231
end %methods
212232

213233

@@ -225,34 +245,44 @@ function onTabChanged(app,evt)
225245
end %function
226246

227247

228-
function onNewButton(app)
229-
% Triggered when the toolbar button is pressed
248+
function onSessionDescriptionChanged(app,evt)
249+
% Triggered on editing a session description
230250

231-
% (this method is optional if using the toolbar)
251+
% Get the new value
252+
newValue = join(string(evt.Value), newline);
232253

233-
% Create a new session
234-
app.Session = app.createNewSession();
254+
% Update the session description
255+
app.Session.Description = newValue;
235256

236257
end %function
237258

238259

239-
function onOpenButton(app)
240-
% Triggered when the toolbar button is pressed
260+
function onFileToolbarButtonPushed(app,evt)
241261

242-
% (this method is optional if using the toolbar)
262+
% Which button was pressed?
263+
switch evt.Button
243264

244-
app.loadSession()
245-
app.update()
265+
case app.NewButton
246266

247-
end %function
267+
% Add a new session
268+
app.newSession();
248269

270+
case app.OpenButton
249271

250-
function onSaveButton(app)
251-
% Triggered when the toolbar button is pressed
272+
% Prompt and load a session
273+
app.loadSession();
252274

253-
% (this method is optional if using the toolbar)
275+
case app.SaveButton
276+
277+
% Save the selected session
278+
app.saveSession(false);
279+
280+
case app.SaveAsButton
254281

255-
app.saveSession(true);
282+
% Save the selected session as different file
283+
app.saveSession(true);
284+
285+
end %switch
256286

257287
end %function
258288

@@ -268,13 +298,4 @@ function onHelpButton(app)
268298

269299
end %methods
270300

271-
272-
273-
%% Private Methods
274-
methods ( Access = private )
275-
276-
% (optionally add any internal methods here)
277-
278-
end %methods
279-
280301
end %classdef

0 commit comments

Comments
 (0)