-
Notifications
You must be signed in to change notification settings - Fork 0
/
flistergui.m
151 lines (124 loc) · 3.77 KB
/
flistergui.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function re = flistergui(wd)
% help creating regular expressions for flister
defifnotexist('wd',cd);
handles.wd = wd;
%%
handles.figure = figure(394780);clf
set(gcf,'name','Flister regexp builder','numbertitle','off')
handles.list = uicontrol('style','list','units','normalized','position',[.01 .01 .98 .8],'Max',2);
handles.re = uicontrol('style','edit','units','normalized','position',[.01 .85 .8 .1],'string',getpref('flistergui','re','.*'));
handles.cd = uicontrol('style','pushbutton','units','normalized','position',[.82 .85 .16 .1],'string','Change Dir');
set(handles.re,'Callback',@updatelist)
set(handles.cd,'Callback',@docd)
hctxt_list = uicontextmenu;
uimenu(hctxt_list,'Label','Delete files...','Callback',@delfs);
uimenu(hctxt_list,'Label','Get corresponding re','Callback',@getRE);
set(handles.list,'uicontextmenu',hctxt_list);
hctxt_re = uicontextmenu;
uimenu(hctxt_re,'Label','add token...','Callback',@addtok);
set(handles.re,'uicontextmenu',hctxt_re);
guidata(gcf,handles)
%updatelist(handles.figure);
function addtok(hObject,eventdata)
handles = guidata(hObject);
allfs = get(handles.list,'UserData');
sel = allfs(get(handles.list,'Value'));
ore = get(handles.re,'String');
ex = {'e.g. Condition','e.g. AttendLeft','e.g. AttendRight','',''};
reps = inputdlg({'Label','Alternatives...','','',''},'Token specifications',1,ex);
if isempty(reps)
return
else
for i = 1:numel(reps)
reps{i} = strrep(reps{i},ex{i},'');
end
end
ore = [ore '(?<' reps{1} '>'];
for ireps = 2:numel(reps)
if isempty(reps{ireps})
break
end
ore = [ore reps{ireps} '|'];
end
ore(end) = ')';
set(handles.re,'String',ore);
drawnow
guidata(hObject,handles)
updatelist(handles.list)
function getRE(hObject,eventdata)
handles = guidata(hObject);
allfs = get(handles.list,'UserData');
sel = allfs(get(handles.list,'Value'));
ore = get(handles.re,'String');
re = '';
i = 1;
while 1
if i > numel(ore)
break
end
if not(strcmp(ore(i:min(numel(ore),i+1)),'(?'))
re(end+1) = ore(i);
i = i+1;
continue
end
i = i+3;
re = [re '(?<'];
currlab = '';
while not(strcmp(ore(i),'>'))
currlab = [currlab ore(i)];
re = [re ore(i)];
i = i+1;
end
re = [re '>'];
ucurrlab = unique({sel.(currlab)});
for i_f = 1:numel(ucurrlab)
re = [re ucurrlab{i_f} '|'];
end
re(end) = ')';
while not(strcmp(ore(i),')'))
i = i+1;
end
if strcmp(ore(i),')')
i = i+1;
end
end
set(handles.re,'string',re);
function delfs(hObject,eventdata)
% Callback for delete files context menu
handles = guidata(hObject);
allfs = get(handles.list,'String');
todel = allfs{get(handles.list,'Value')};
rep = questdlg('Are you sure you want to delete these files?','Delete files...','No');
if strcmp(rep,'Yes')
delete(todel{:});
end
function docd(hObject,eventdata)
% callback for Change dir button
handles = guidata(hObject);
handles.wd = uigetdir(handles.wd);
if isequal(handles.wd,0)
return
end
guidata(hObject,handles)
updatelist(handles.list)
function updatelist(hObject, eventdata)
% Callback to update list (e.g. after changing re)
handles = guidata(hObject);
set(handles.re,'string',strtrim(get(handles.re,'string')))
f = flister(get(handles.re,'string'),'dir',handles.wd);
if not(isempty(f))
set(handles.list,'string',regexprep({f.name},handles.wd,''))
else
set(handles.list,'string',{})
end
set(handles.list,'UserData',f);
set(handles.list,'value',1);
assignin('base','flist',f)
assignin('base','re',get(handles.re,'string'))
setpref('flistergui','re',get(handles.re,'String'));
assignin('base','wd',handles.wd)
fprintf('\n')
disp(['We are selecting ' num2str(numel(f)) ' files with regular expression'])
disp(get(handles.re,'string'))
fprintf('\n')
disp(flist_consolidate(f))