Skip to content

Commit 6cb01bf

Browse files
committed
update ListSelector to enable custom add callback
1 parent 19ea23d commit 6cb01bf

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

widgets/+wt/+enum/ListAddSource.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
classdef ListAddSource
2+
%LISTADDSOURCE Represent add selections for list widget
3+
% Enumerates a list of choices
4+
5+
% Copyright 2021 The MathWorks Inc.
6+
7+
8+
%% Enumerations
9+
enumeration
10+
Items
11+
Custom
12+
end %enumeration
13+
14+
15+
end %classdef
16+

widgets/+wt/ListSelector.m

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
% Indicates whether to allow sort controls %RAJ - Future feature
3838
%Sortable (1,1) matlab.lang.OnOffSwitchState = true
3939

40+
% Inidicates what to do when add button is pressed (select from
41+
% Items or custom using ButtonPushed event or ButtonPushedFcn)
42+
AddSource (1,1) wt.enum.ListAddSource = wt.enum.ListAddSource.Items
43+
4044
end %properties
4145

4246

@@ -152,9 +156,20 @@ function update(obj)
152156
obj.ListBox.Items = obj.Items(selIdx);
153157
obj.ListBox.ItemsData = selIdx;
154158

159+
% Update button enable states
160+
obj.updateEnables();
161+
162+
end %function
163+
164+
165+
function updateEnables(obj)
166+
155167
% Button enables
156168
if obj.Enable
157169

170+
% What is selected?
171+
selIdx = obj.SelectedIndex;
172+
158173
% Highlighted selection in list?
159174
hiliteIdx = obj.getListBoxSelectedIndex();
160175

@@ -196,8 +211,8 @@ function onSelectionChanged(obj,evt)
196211
newValue = itemsData(evt.Value);
197212
end
198213

199-
% Force update
200-
obj.update();
214+
% Update button enable states
215+
obj.updateEnables();
201216

202217
% Trigger event
203218
evtOut = wt.eventdata.ValueChangedData(newValue, oldValue);
@@ -212,7 +227,16 @@ function onButtonPushed(obj,evt)
212227
switch evt.Tag
213228

214229
case 'Add'
215-
obj.promptToAddListItems()
230+
231+
switch obj.AddSource
232+
233+
case wt.enum.ListAddSource.Items
234+
obj.promptToAddListItems()
235+
236+
case wt.enum.ListAddSource.Custom
237+
notify(obj,"ButtonPushed",evt);
238+
239+
end %switch obj.AddSource
216240

217241
case 'Remove'
218242
obj.removeListBoxSelection();

0 commit comments

Comments
 (0)