Commit 5b47e3d8 authored by Mart Lubbers's avatar Mart Lubbers

share project template setup code between IDE and cpm

parent b7247445
Pipeline #24352 passed with stage
in 1 minute and 5 seconds
......@@ -229,49 +229,29 @@ pm_new_project_using_template ps
Just prt_path_name
| not (equal_suffix ".prt" (RemovePath prt_path_name))
-> okNotice ["The file \"" +++ prt_path_name +++ "\" is not a project template file (.prt)."] ps
# (startupdir,ps) = getStup ps
((ok,project,err),ps) = accFiles (read_project_template_file prt_path_name startupdir) ps
| not ok
-> okNotice [err] ps
# (mpath,ps) = selectOutputFile "New Project..." (MakeProjectPathname path) ps
-> case mpath of
Nothing
-> ps
Just project_file_path
# (_,ps) = close_all_project_windows (create_new_project_using_template path project_file_path project) ps
-> ps
# (startupdir,ps) = getStup ps
((ok,project,err),ps) = accFiles (read_project_template_file prt_path_name startupdir) ps
| not ok
-> okNotice [err] ps
# (mpath,ps) = selectOutputFile "New Project..." (MakeProjectPathname path) ps
-> case mpath of
Nothing
-> ps
Just project_file_path
# (_, ps) = close_all_project_windows (setup_new_project_using_template path project_file_path project) ps
-> ps
create_new_project_using_template :: !String !String !Project !*(PSt *General) -> (!Bool,!*PSt *General);
create_new_project_using_template path project_file_path project ps
setup_new_project_using_template :: !String !String !Project !*(PSt *General) -> *(!Bool, !*PSt *General);
setup_new_project_using_template path project_file_path project ps
# ps = pm_shut ps // just in case
template_root_dir = PR_GetRootDir project
({compopts,cgenopts,linkopts,applopts},ps) = getPrefs ps
eo = {eo = {newlines=HostNativeNewlineConvention}, pos_size = NoWindowPosAndSize}
ps = setProjectFilePath project_file_path ps
project = PR_SetRoot path eo compopts project
project = PR_SetExecPath (MakeExecPathname path) project
project = set_root_directory_of_project (RemoveFilename project_file_path) template_root_dir project
ps = appProject (const project) ps
# ((ok, project), ps) = accFiles (create_new_project_using_template path project_file_path compopts eo project) ps
| not ok
= (False, okNotice ["Unable to create project", "Error setting up project from the given project template"] ps)
# ps = appProject (const project) ps
ps = selectProjectTarget getTargets ps
= show_new_project project_file_path ps
where
set_root_directory_of_project :: !{#Char} !{#Char} !Project -> Project
set_root_directory_of_project project_file_dir template_root_dir project
| size project_file_dir<=size template_root_dir || project_file_dir % (0,size template_root_dir-1)<>template_root_dir
= change_root_directory_of_project "." project_file_dir project
# (n_removed_dirs,project_dir) = count_dirs_to_be_removed 0 (size template_root_dir) project_file_dir
| project_dir==template_root_dir
= change_root_directory_of_project (createArray (n_removed_dirs+1) '.') template_root_dir project
= change_root_directory_of_project "." project_file_dir project
count_dirs_to_be_removed :: !Int !Int !{#Char} -> (!Int,!{#Char})
count_dirs_to_be_removed n_removed_dirs template_root_dir_size project_dir
# project_dir_up = RemoveFilename project_dir
| size project_dir_up==size project_dir
= (n_removed_dirs,project_dir)
| size project_dir_up>template_root_dir_size
= count_dirs_to_be_removed (n_removed_dirs+1) template_root_dir_size project_dir_up
= (n_removed_dirs+1,project_dir_up)
pm_open :: !*(PSt *General) -> *PSt *General;
pm_open ps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment