Home > vbmeg > functions > gui > project_mgr_dir > create_new_project_callback.m

create_new_project_callback

PURPOSE ^

callback function for create_new_project gui.

SYNOPSIS ^

function create_new_project_callback(fig, hObj)

DESCRIPTION ^

 callback function for create_new_project gui.
 [USAGE]
    create_new_project_callback(fig);
 [IN]
     fig : create_new_figure gui.
    hObj : event component handle.
 [OUT]
    none

 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 create_new_project_callback(fig, hObj)
0002 % callback function for create_new_project gui.
0003 % [USAGE]
0004 %    create_new_project_callback(fig);
0005 % [IN]
0006 %     fig : create_new_figure gui.
0007 %    hObj : event component handle.
0008 % [OUT]
0009 %    none
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 %
0015 % --- Previous check
0016 %
0017 if ~exist('fig', 'var') || isempty(fig) || ~ishandle(fig)
0018     error('fig is a required parameter.');
0019 end
0020 
0021 %
0022 % --- Main Procedure
0023 %
0024 
0025 % load data (@see create_new_project)
0026 data = guidata(fig);
0027 H = data.H; % component handles
0028 
0029 switch(hObj)
0030     case H.project_root_push
0031         directory = dir_dialog(get(H.project_root_edit, 'String'));
0032         if directory ~= 0
0033             set(H.project_root_edit, 'String', directory);
0034             if ~isempty(get(H.project_name_edit, 'String'))
0035                 set(H.OK_push, 'Enable', 'on');
0036             end
0037         end
0038     case H.OK_push
0039         [H, err, project_filename] = make_project(H);
0040         data.err = err;
0041         data.cancelled = false;
0042         data.project_filename = project_filename;
0043         set(fig, 'Visible', 'off');
0044     case {H.CANCEL_push, H.figure}
0045         data.cancelled = true;
0046         data.err = false;
0047         data.project_filename = [];
0048         set(fig, 'Visible', 'off');
0049 end
0050 
0051 % save data
0052 guidata(fig, data);
0053 
0054 %
0055 % --- Inner function
0056 %
0057 function [H, err, project_file] = make_project(H)
0058 % This function asks project_file_mgr to make a new project file.
0059 %
0060 % [IN]
0061 %    H : gui component handles
0062 % [OUT]
0063 %    H   : gui component handles
0064 %    err : true(failed to make project file) or false.
0065 %    project_file : project file name
0066 %
0067    proj_root = get(H.project_root_edit, 'String');
0068    project_name = get(H.project_name_edit, 'String');
0069 
0070    name = strrep(project_name, ' ', '_');
0071    name = strrep(name, '/', '_');
0072    name = strrep(name, '\', '_');
0073 
0074    project_file = [proj_root filesep name, '.prj.mat'];
0075    err = false;
0076    
0077    write_file = false;
0078    
0079    % parameter check
0080    if isempty(proj_root)
0081        msgbox('project_root does not selected.', 'notice');
0082        err = true;
0083        return;
0084    end
0085    
0086    if isempty(project_name)
0087        msgbox('project_name is empty.', 'notice');
0088        err = true;
0089        return;
0090    end
0091    
0092    % confirm file make?
0093    dlg_str = ['Create new project? (project_name : ' project_name ')'];
0094    button = questdlg(dlg_str,...
0095                    'create project',...
0096                    'Yes', 'No',... % choice button type
0097                    'Yes');          % default choice
0098    if strcmp(button, 'Yes')
0099        % file already exist?
0100        if exist(project_file, 'file')
0101            % overwrite yes
0102            button = questdlg('project file already exists, overwrite?',...
0103                            'confirm',...
0104                            'Yes', 'No', ...
0105                            'No');
0106            if strcmp(button, 'Yes')
0107                delete(project_file);
0108                write_file = true;
0109            else
0110                H.cancelled = true;
0111            end
0112        else
0113            % new file create
0114            write_file = true;
0115        end
0116    end
0117 
0118    % create project file
0119    if write_file
0120        err = project_file_mgr('make', project_file, project_name, proj_root);
0121        if err
0122            msgbox('project file create failed.', 'notice');
0123        else
0124            H.project_filename = project_file;
0125            msgbox('project file is created.', 'notice');
0126        end
0127    end

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