function name_of_file = savegmtdlg(varargin)
% SAVEGMTDLG Application M-file for savegmtdlg.fig
% FIG = SAVEGMTDLG launch savegmtdlg GUI.
% SAVEGMTDLG('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.0 19-Jul-2002 03:38:12
if nargin <= 1 % LAUNCH GUI
if nargin == 0
initial_dir = pwd;
elseif nargin == 1 & exist(varargin{1},'dir')
initial_dir = varargin{1};
else
errordlg('Input argument must be a valid directory','Input Argument Error!')
return
end
fig = openfig(mfilename,'reuse');
% Use system color scheme for figure:
set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));
% Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
load_lsbMain(initial_dir,handles);
% Wait for callbacks to run and window to be dismissed:
uiwait(fig);
if ~ishandle(fig)
name_of_file='246cancel963_cancel';
else
handles=guidata(fig);
name_of_file=handles.name_of_file;
delete(fig);
end
%if nargout > 0
% varargout{1} = fig;
%end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
catch
disp(lasterr);
end
end
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
function load_lsbMain(dir_path,handles)
cd (dir_path)
dir_struct = dir(dir_path);
handles.file_names = {dir_struct.name}';
handles.is_dir = [dir_struct.isdir];
guidata(handles.fgrSavedlg,handles)
j=1;
for i=1:length(handles.is_dir)
if handles.is_dir(i)==1
tempArray{j}=handles.file_names{i};
j=j+1;
end
end
temp_level=j;
for i=1:length(handles.is_dir)
[path21,name21,ext21,ver21] = fileparts(dir_struct(i).name);
if strcmp(ext21,'.gtm')
tempArray{j}=handles.file_names{i};
j=j+1;
end
end
handles.dirlevel=temp_level;
guidata(handles.fgrSavedlg,handles)
set(handles.lsbMain,'String',tempArray,'Value',1)
set(handles.txtPath,'String',pwd)
% --------------------------------------------------------------------
function varargout = lsbMain_Callback(h, eventdata, handles, varargin)
index_selected = get(handles.lsbMain,'Value');
file_list = get(handles.lsbMain,'String');
filename = file_list{index_selected};
if strcmp(get(handles.fgrSavedlg,'SelectionType'),'open')
if index_selected < handles.dirlevel
cd (filename)
load_lsbMain(pwd,handles)
else
button = questdlg('File allready exists. Do you want to overwrite it?',...
'Continue Operation','Yes','No','No');
if strcmp(button,'Yes')
handles.name_of_file=filename;
guidata(h,handles);
uiresume(handles.fgrSavedlg);
end
end
else
if index_selected >= handles.dirlevel
set(handles.edtFileName,'String',filename)
else
set(handles.edtFileName,'String','')
end
end
% --------------------------------------------------------------------
function varargout = pupSaveAsType_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = psbSave_Callback(h, eventdata, handles, varargin)
filename=get(handles.edtFileName,'String');
file_list=get(handles.lsbMain,'String');
vrethike=0;
for i=handles.dirlevel:length([file_list])
if strcmp(file_list{i},filename)
vrethike=1;
end
end
if vrethike
button = questdlg('File allready exists. Do you want to overwrite it?',...
'Continue Operation','Yes','No','No');
if strcmp(button,'Yes')
handles.name_of_file=filename;
guidata(h,handles);
uiresume(handles.fgrSavedlg);
end
else
[path22,name22,ext22,ver22] = fileparts(filename);
if strcmp(ext22,'.gtm')
if ~strcmp(name22,'')
handles.name_of_file=filename;
guidata(h,handles);
uiresume(handles.fgrSavedlg);
end
elseif strcmp(ext22,'')
if ~strcmp(name22,'')
filename=[filename '.gtm'];
handles.name_of_file=filename;
guidata(h,handles);
uiresume(handles.fgrSavedlg);
end
else
msgbox('Not a vald extension','Error!','help','','','modal')
end
end
% --------------------------------------------------------------------
function varargout = psbCancel_Callback(h, eventdata, handles, varargin)
handles.name_of_file='246cancel963_cancel';
guidata(h,handles);
uiresume(handles.fgrSavedlg);
% --------------------------------------------------------------------
function varargout = edtFileName_Callback(h, eventdata, handles, varargin)