-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilePicker.m
More file actions
65 lines (53 loc) · 1.73 KB
/
filePicker.m
File metadata and controls
65 lines (53 loc) · 1.73 KB
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
64
65
function filePicker(callback, datadir, title)
if nargin < 1
callback = @defaultCallback;
end
if nargin < 2
defaultdir = 'Z:\Work\Matlab\ProbeStation\Data';
datadir = getGlobal('ProbeStation_DataPath');
if isempty(datadir)
datadir = uigetdir(defaultdir, 'Pick Result Directory');
if isnumeric(datadir) && datadir == 0
return;
end
end
end
content = dir([datadir '\*.mat']);
hFig = fig(func2str(callback));
pos = get(hFig, 'Position');
set(hFig, 'Position', [pos(1:2) 160 300]);
set(hFig, 'Toolbar', 'none', 'Menubar', 'none');
hLst = uicontrol(hFig, 'Style', 'listbox');
n = length(content);
for k = 1:n
strings{k} = content(k).name;
data{k} = fullfile(datadir, content(k).name);
end
set(hLst, 'String', strings);
set(hLst, 'UserData', data);
set(hLst, 'Callback', @(hObj, event)onClick(hObj, event, callback));
set(hLst, 'Units', 'normalized');
set(hLst, 'Position', [0 0 1 1]);
foldernames = strsplit(datadir, filesep);
if nargin < 3
title = sprintf('%s @ %s', func2str(callback), foldernames{end});
end
set(hFig, 'NumberTitle', 'off', 'Name', title);
end
function onClick(hObj, eventdata, callback)
[value, string] = selectedListItem(hObj);
callback(string, value);
hFig = get(hObj, 'Parent');
figure(hFig);
end
function defaultCallback(filename, fullname)
disp(file);
end
function [value string] = selectedListItem(hList)
indices = get(hList, 'Value');
strings = get(hList, 'String');
values = get(hList, 'UserData');
index = indices(1);
value = values{index};
string = strings{index};
end