jcs
/amend
/amendments
/10
main: Implement plumbing to open a file from Finder at startup
If a .repo file was double-clicked in Finder, open it instead of
showing the Open dialog
jcs made amendment 10 over 3 years ago
--- main.c Mon Oct 18 09:22:19 2021
+++ main.c Tue Oct 19 23:37:45 2021
@@ -40,8 +40,9 @@ main(void)
EventRecord event;
WindowPtr event_win;
GrafPtr old_port;
+ AppFile finder_file;
struct repo *repo;
- short event_in, i, did_initial_open = 0;
+ short event_in, i, did_initial_open = 0, finder_action, finder_count;
char key;
InitGraf(&thePort);
@@ -72,6 +73,9 @@ main(void)
HLock(commit_list_ldef_h);
((tCodeStub *)*commit_list_ldef_h)->addr = &commit_list_ldef;
+ /* see if we were started by double-clicking a .repo file */
+ CountAppFiles(&finder_action, &finder_count);
+
while (!quitting) {
WaitNextEvent(everyEvent, &event, 5L, 0L);
@@ -80,7 +84,14 @@ main(void)
if (cur_browser)
browser_idle(cur_browser);
else if (!did_initial_open) {
- repo = repo_open();
+ if (finder_count) {
+ GetAppFiles(1, &finder_file);
+ ClrAppFiles(1);
+ finder_count = 0;
+ repo = repo_open(&finder_file);
+ } else
+ repo = repo_open(NULL);
+
if (repo)
cur_browser = browser_init(repo);
did_initial_open = 1;
@@ -204,7 +215,7 @@ handle_menu(long menu_id)
/* TODO: don't close unless we open a new repo */
if (cur_browser)
cur_browser_close();
- if ((repo = repo_open()))
+ if ((repo = repo_open(NULL)))
cur_browser = browser_init(repo);
break;
}
--- repo.c Mon Oct 18 17:12:17 2021
+++ repo.c Tue Oct 19 23:35:44 2021
@@ -31,17 +31,22 @@ short repo_get_file_attrs(struct repo *repo, Str255 fi
short repo_file_update(struct repo *repo, struct repo_file *file);
struct repo *
-repo_open(void)
+repo_open(AppFile *file)
{
Point pt = { 75, 100 };
SFReply reply;
SFTypeList types;
+ if (file) {
+ reply.vRefNum = file->vRefNum;
+ memcpy(&reply.fName, file->fName, sizeof(reply.fName));
+ } else {
types[0] = REPO_TYPE;
SFGetFile(pt, NULL, NULL, 1, &types, NULL, &reply);
if (!reply.good)
return NULL;
+ }
return repo_init(reply);
}
--- repo.h Mon Oct 18 15:08:25 2021
+++ repo.h Tue Oct 19 23:36:18 2021
@@ -70,7 +70,7 @@ struct repo {
short next_commit_id;
};
-struct repo *repo_open(void);
+struct repo *repo_open(AppFile *file);
struct repo *repo_create(void);
void repo_close(struct repo *repo);
struct repo_commit *repo_parse_commit(Handle hcommit);