-
Notifications
You must be signed in to change notification settings - Fork 0
/
namesdialog.m
63 lines (48 loc) · 1.39 KB
/
namesdialog.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function names = namesdialog(names)
global nameToAdd idxToDelete
names = names(1:end-1);
nameToAdd = [];
idxToDelete = [];
d = dialog('Position',[300 300 250 200],'Name','Add or Delete');
txt = uicontrol('Parent',d,...
'Style','text',...
'Position',[20 130 210 40],...
'String','Name to delete'); %#ok<*NASGU>
popup = uicontrol('Parent',d,...
'Style','popup',...
'Position',[50 125 150 25],...
'String',['None', names],...
'Callback',@popup_callback);
txt1 = uicontrol('Parent',d,...
'Style','text',...
'Position',[20 65 210 40],...
'String','Name to add'); %#ok<*NASGU>
edit1 = uicontrol('Parent',d,...
'Style','edit',...
'Position',[50 60 150 25],...
'String','Mouse, Mickey',...
'Callback',@edit1_callback);
btn = uicontrol('Parent',d,...
'Position',[89 20 70 25],...
'String','Close',...
'Callback','delete(gcf)');
uiwait(d);
names(idxToDelete) = [];
names = [names, nameToAdd];
names = [sort(unique(names)),'Add / Delete'];
function popup_callback(popup,~)
global idxToDelete
idx = popup.Value;
if idx == 1
idxToDelete = [];
else
idxToDelete = idx-1;
end
function edit1_callback(edit1,~)
global nameToAdd
newName = edit1.String;
if strncmp(newName,'Mouse',5) || length(newName)<4 || ~contains(newName,',')
nameToAdd = [];
else
nameToAdd = newName;
end