Home > vbmeg > functions > common > utility > dir_dialog_dir > dir_dialog.m

dir_dialog

PURPOSE ^

This function creates a directory choice dialog.

SYNOPSIS ^

function varargout = dir_dialog(varargin)

DESCRIPTION ^

 This function creates a directory choice dialog.
 Usage:
  dir = dir_dialog(start_dir, move_mode);
        or
  dir = dir_dialog; % start_dir is 'C:'     (Windows)
                    %              '/home'  (Unix, Linux)

 [IN] start_dir : directory select starting point.
 [IN] move_mode : true or false (able to omit)
                  true  : We can move to all directory.(default)
                  false : We only to move to lower directory than start_dir.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = dir_dialog(varargin)
0002 % This function creates a directory choice dialog.
0003 % Usage:
0004 %  dir = dir_dialog(start_dir, move_mode);
0005 %        or
0006 %  dir = dir_dialog; % start_dir is 'C:'     (Windows)
0007 %                    %              '/home'  (Unix, Linux)
0008 %
0009 % [IN] start_dir : directory select starting point.
0010 % [IN] move_mode : true or false (able to omit)
0011 %                  true  : We can move to all directory.(default)
0012 %                  false : We only to move to lower directory than start_dir.
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 if nargin == 0  % no input argument
0018 
0019     if ispc % Windows
0020         [varargout{1}] = init('C:', true);
0021     else    % Unix/Linux
0022         [varargout{1}] = init('~', true);
0023     end
0024 
0025 else
0026     try
0027         if nargout == 0
0028             init(varargin{:})
0029         else
0030             [varargout{1}] = init(varargin{:}); % FEVAL switchyard
0031         end
0032     catch
0033         disp(lasterr);
0034     end
0035 end
0036 
0037 % --------------------------------------------------------------------
0038 function dir = init(start_dir, move_mode)
0039     % directory movable area
0040     if ~exist('move_mode', 'var')
0041         move_mode = true; % We can move to all directory
0042     end
0043     
0044     % directory check
0045     if (dir_dialog_callback('IsdirOK', start_dir) == false) | isempty(start_dir) 
0046         start_dir = pwd;
0047     end
0048     
0049     fig = openfig(mfilename,'reuse');
0050 
0051     % Generate a structure of handles to pass to callbacks, and store it.
0052     handles = guihandles(fig);
0053 
0054     % Initialize
0055     handles.START_DIR   = start_dir;
0056     handles.mypath      = start_dir;
0057     handles.move_mode   = move_mode;
0058 
0059     % disk drive detection
0060     if ispc & handles.move_mode == true
0061         dir_dialog_callback('set_drive_info', handles, start_dir);
0062     else
0063         % UNIX, LINUX doesn't have a disk drive.
0064         set(handles.drive_label, 'Visible', 'off');
0065         set(handles.drive_popup, 'Visible', 'off');
0066     end
0067 
0068     % display start_dir
0069     handles = dir_dialog_callback('update_listbox', handles);
0070 
0071     % save data
0072     guidata(fig, handles);
0073 
0074     % User operation is done in the wait loop.
0075     waitfor(handles.browser, 'Visible', 'off');
0076     
0077     % When user operation is finished, loop is dropping out.
0078     handles = guidata(handles.browser);
0079     dir = handles.mypath;
0080     delete(handles.browser);
0081

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005