function Dir = prjDir(OldDir, tip)
% Dir = prjDir(OldDir,TIP);
% unde Dir, oldDir sint struct din Options
% TIP can be 'sursa', 'dest', 'load', 'save'
%
% 14.02.2009 - for Quadra v.0.5.2, update folder/file navigation
% in order to use uigetfolder as in ver.2007
if nargin < 1, OldDir = uConstr('Dir'); end;
if nargin < 2, tip = 'sursa'; end;
Dir=OldDir;
switch tip
case 'sursa'
[filename, pathname] = uigetfile({'*.jpg; *.gif; *.tif'; }, ...
'Open Target Directory by clicking on any image inside it');
if isequal(filename,0) || isequal(pathname,0)
disp('Directory not set, keeping the old one.');
else Dir.Src = pathname;
end;
case {'dest'}
if ~isdir(Dir.Dest), Dir.Dest = pwd; end;
pathname = uigetdir(Dir.Dest, ...
'pick dest.directory - rendered images will be stored there');
% was :
% pathname = uigetfolder('choose destination directory where all rendered images will be stored', Dir.Dest);
if isequal(pathname,0)
disp('Directory not set, preserving the old one.');
else
Dir.Dest = pathname;
end;
case {'lastopen'}
if ~isdir(Dir.lastopen)
Dir.lastopen = pwd;
Dir.loadok = 0;
end;
pathname = uigetdir(Dir.lastopen, 'add all images in a directory (non-recursive)');
% was :
% pathname = uigetfolder('add all images in a directory (non-recursive)', Dir.lastopen);
if isempty(pathname) || (isnumeric(pathname) && pathname == 0)
disp('...nothing added');
Dir.loadok = 0;
else
Dir.lastopen = pathname;
Dir.loadok = 1;
end;
case {'save'}
[filename, pathname] = uiputfile('*.mat', ...
'Salveaza proiectul');
if isequal(filename,0) || isequal(pathname,0)
disp('Quadra file not found, reverting to old.');
else
disp(['Save To : ', pathname filename]);
Dir.PrjName = [ pathname filename];
end;
case 'load'
eval(['cd ' Dir.working]);
[filename, pathname] = uigetfile({'*.mat'; }, ...
'Load a Quadra project ');
if isequal(filename,0) || isequal(pathname,0)
disp('Quadra file not found, reverting to old.');
else
disp(['checking project file : ', pathname filename]);
Dir.PrjName = [ pathname filename];
end;
end;