-
Notifications
You must be signed in to change notification settings - Fork 0
/
Browser.m
306 lines (250 loc) · 9.91 KB
/
Browser.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
function varargout = Browser(varargin)
% BROWSER MATLAB code for Browser.fig
% The Browser allows to:
% - open files one by one in Preview for analysis
% - regroup files into albums
%
% Browser_OpeningFc: [line 61]
% disables certain buttons by default
%
%% Loading
% addbutton_Callback: [line 124]
% interactively add files to the filelist. Enables
% the disabled buttons.
%
% importbutton_Callback: [line 273]
% allows to import an entire album to the fileliste.
% (reads the text file to get all the reference pathes of the files in
% the album)
%% Other functions
% deletebutton_Callback: [line 160]
% deletes the selected file from file list
%
% previewbutton_Callback: [line 185]
% opens up preview for the single file selected
%
%% Albums
% makebutton_Callback: [line 254]
% displays message explaining how to make an album
%
% albumbutton_Callback: [line 208]
% creates an ablum in the form of a text file with the references
% (pathes) of all the files composing the album
%
%% Required External Functions and GUI
% Preview.m / Preview.fig
% Last Modified by GUIDE v2.5 09-May-2018 17:37:30
%% Opening Code
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Browser_OpeningFcn, ...
'gui_OutputFcn', @Browser_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Browser is made visible.
function Browser_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Browser (see VARARGIN)
% Choose default command line output for Browser
handles.output = hObject;
set(handles.deletebutton,'Enable','off');
set(handles.previewbutton,'Enable','off');
set(handles.albumbutton, 'Enable', 'off');
set(handles.makebutton, 'Enable', 'off');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Browser wait for user response (see UIRESUME)
% uiwait(handles.Browser);
% --- Outputs from this function are returned to the command line.
function varargout = Browser_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in filelist.
function filelist_Callback(hObject, eventdata, handles)
% hObject handle to filelist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns filelist contents as cell array
% contents{get(hObject,'Value')} returns selected item from filelist
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function filelist_CreateFcn(hObject, eventdata, handles)
% hObject handle to filelist (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
handles.Files={};
handles.filelist={};
disp('Deleting everything');
guidata(hObject, handles);
% --- Executes on button press in addbutton.
function addbutton_Callback(hObject, eventdata, handles)
% hObject handle to addbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
%handles.filelist.Max=2;
set(handles.filelist, 'Max', 2);
try
%load appropriate file
[filename, path]=uigetfile('*.mat','Select the MATLAB code file', 'MultiSelect' , 'on');
if isequal(filename, 0)
%user canceled
return;
end
%whether 1 file added or multiple, adds all of them to filelist.
filename = cellstr(filename);
for k = 1:length(filename)
handles.Files = [handles.Files; cellstr(fullfile(path, filename{k})) ];
end
set(handles.filelist, 'String', handles.Files);
set(handles.deletebutton,'Enable','on');
set(handles.previewbutton,'Enable','on');
set(handles.makebutton, 'Enable', 'on');
catch
errordlg(['There was a problem loading the files.'],'Load Error!');
return;
end
guidata(hObject, handles);
% --- Executes on button press in deletebutton.
function deletebutton_Callback(hObject, eventdata, handles)
% hObject handle to deletebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
List = handles.filelist;
indexedFilelist = get(List,'value');
%index of selected element of the list
newPlace = indexedFilelist(1)-1;
%will be deleted so index minus one
if (newPlace <=0) newPlace = 1; end
Filenames = get(List,'String');
%names of those that will be deleted
if ~isempty(Filenames)
Filenames(indexedFilelist) = [];
handles.Files=Filenames;
set(List,'String', handles.Files,'value', newPlace);
end
guidata(hObject, handles);
% --- Executes on button press in previewbutton.
function previewbutton_Callback(hObject, eventdata, handles)
% hObject handle to previewbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
List = handles.filelist;
indexedFilelist = get(List,'value');
if(length(indexedFilelist)~=1)
f = msgbox({'Files are previewed one by one.'; ...
'Only one file can be selected: please unselect till only one remains.'}, ...
'Selection Error for Preview' );
else
Filenames = get(List,'String');
handles.analysis_file = Filenames(indexedFilelist);
guidata(hObject, handles);
%set(gcf,'Visible','off');
%visibility of Browser / Preview
Preview;
end
guidata(hObject, handles);
% --- Executes on button press in albumbutton.
function albumbutton_Callback(hObject, eventdata, handles)
% hObject handle to albumbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
albumIndexes=get(handles.filelist,'value');
%choose name: prompt...
prompt={'Enter the name of your album'};
dlg_title= 'Album Name Specification';
num_lines=1;
answer=inputdlg(prompt,dlg_title,num_lines);
%indicate path: uigetdir
selpath = uigetdir;
%make it: mkdir
try
newFolder=fullfile(selpath,answer{1});
if ~exist(newFolder, 'dir')
mkdir(newFolder);
else
errordlg(['Such a folder already exists.'],'Folder Overwrite Danger.');
return;
end
%Saves text file with references to all files of album
albumname=strcat(answer{1},'.txt');
%album has the same name as the folder in which it is
album=fullfile(newFolder,albumname);
fileID=fopen(album,'w');
Filenames = get(handles.filelist,'String');
i=1;
while( i<=length(albumIndexes))
fileNameToSave=Filenames{albumIndexes(i)};
fprintf(fileID,'%s\n', fileNameToSave);
i=i+1;
end
fclose(fileID);
catch
errordlg(['New Album folder could not be created.'],'Album Creation Error!');
return;
end
guidata(hObject, handles);
% --- Executes on button press in makebutton.
function makebutton_Callback(hObject, eventdata, handles)
% hObject handle to makebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (length(handles.filelist) >= 1)
f = msgbox({'The minimum number of files for an album is 2.'; ...
'Note: To select multiple files use "command" or "control" as appropriate to your OS.'}, ...
'Making an album Important Information' ); if (length(get(handles.filelist,'value')) > 1) set(handles.albumbutton, 'Enable', 'on'); end
else
errordlg(['Files must be opened in browser before making album.'],'Make Album Error!');
return;
end
guidata(hObject, handles);
% --- Executes on button press in importbutton.
function importbutton_Callback(hObject, eventdata, handles)
% hObject handle to importbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.filelist, 'Max', 2);
try
%load appropriate file
[filename, path]=uigetfile('*.txt','Select the album reference text file', 'MultiSelect' , 'on');
if isequal(filename, 0)
%user canceled
return;
end
fileToOpen=fullfile(path,filename);
albumFiles=importdata(fileToOpen, '\t');
Filenames = get(handles.filelist,'String');
k=1;
while(k<=length(albumFiles))
handles.Files = [handles.Files; cellstr(albumFiles{k}) ];
k=k+1;
end
set(handles.filelist, 'String', handles.Files);
set(handles.deletebutton,'Enable','on');
set(handles.previewbutton,'Enable','on');
set(handles.albumbutton, 'Enable', 'on');
set(handles.makebutton, 'Enable', 'on');
catch
end
guidata(hObject, handles);