0001 function create_new_project_callback(fig, hObj)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if ~exist('fig', 'var') || isempty(fig) || ~ishandle(fig)
0018 error('fig is a required parameter.');
0019 end
0020
0021
0022
0023
0024
0025
0026 data = guidata(fig);
0027 H = data.H;
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
0052 guidata(fig, data);
0053
0054
0055
0056
0057 function [H, err, project_file] = make_project(H)
0058
0059
0060
0061
0062
0063
0064
0065
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
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
0093 dlg_str = ['Create new project? (project_name : ' project_name ')'];
0094 button = questdlg(dlg_str,...
0095 'create project',...
0096 'Yes', 'No',...
0097 'Yes');
0098 if strcmp(button, 'Yes')
0099
0100 if exist(project_file, 'file')
0101
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
0114 write_file = true;
0115 end
0116 end
0117
0118
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