AmendHub

Download:

jcs

/

amend

/

amendments

/

52

repo: In "Add Files" dialog, only show files that can be added

Filter out files in directories other than the repo's, and filter out
files that already exist in the repo

jcs made amendment 52 over 2 years ago
--- repo.c Wed Jan 19 17:27:55 2022 +++ repo.c Thu Jan 20 10:34:17 2022 @@ -33,6 +33,7 @@ short repo_file_update(struct repo *repo, struct repo_ unsigned short repo_diff_header(struct repo *repo, struct repo_commit *commit, char **ret); short repo_migrate(struct repo *repo, short is_new); +pascal Boolean repo_add_file_filter(struct FileParam *pbp); struct repo * repo_open(AppFile *file) @@ -414,10 +415,38 @@ repo_show_diff_text(struct repo *repo, struct repo_com free(dtext); } +static long repo_add_file_filter_repo_dir; +static struct repo *repo_add_file_filter_repo; + +pascal Boolean +repo_add_file_filter(struct FileParam *pbp) +{ + static Str255 file_filter_fname; + short n; + + if (CurDirStore != repo_add_file_filter_repo_dir) + /* not in same dir as repo, filter out */ + return true; + + memcpy(file_filter_fname, pbp->ioNamePtr, pbp->ioNamePtr[0] + 1); + PtoCstr(file_filter_fname); + + for (n = 0; n < repo_add_file_filter_repo->nfiles; n++) { + if (strcmp(repo_add_file_filter_repo->files[n]->filename, + (char *)file_filter_fname) == 0) + /* already in the repo, filter out */ + return true; + } + + return false; +} + struct repo_file * repo_add_file(struct repo *repo) { Point pt = { 75, 100 }; + CInfoPBRec pb; + WDPBRec wdir = { 0 }; SFReply reply; Str255 repofname, repopath, newpath; Handle new_fileh; @@ -425,9 +454,19 @@ repo_add_file(struct repo *repo) struct repo_file_attrs attrs; unsigned long zero; char *data; - short i; + short i, error; - SFGetFile(pt, "\p", NULL, -1, 0, NULL, &reply); + /* tell SFGetFile we only want to accept files from this dir */ + wdir.ioVRefNum = wdir.ioWDVRefNum = repo->bile->vrefnum; + wdir.ioNamePtr = (StringPtr)&repo->bile->filename; + if (PBGetWDInfo(&wdir, 0) != noErr) { + warn("Failed looking up repo directory"); + return NULL; + } + repo_add_file_filter_repo = repo; + repo_add_file_filter_repo_dir = wdir.ioWDDirID; + + SFGetFile(pt, "\p", repo_add_file_filter, -1, 0, NULL, &reply); if (!reply.good) return NULL;