From 1f1407bb0edd93e64287572e797cda3cf98cf985 Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Sun, 7 May 2023 01:51:00 -0400 Subject: [PATCH] Add project menu with upload/download items --- macos/main.c | 9 +++++++-- macos/main.h | 3 +++ macos/menu.r | 13 +++++++++++++ macos/project.c | 21 +++++++++++++++++++-- macos/project.h | 3 ++- macos/resources.h | 1 + 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/macos/main.c b/macos/main.c index ac73375..8e26115 100644 --- a/macos/main.c +++ b/macos/main.c @@ -55,11 +55,12 @@ static void HandleClose(WindowRef window) static void AdjustMenus(void) { WindowRef window; - MenuHandle fileMenu; + MenuHandle fileMenu, projectMenu; ProjectHandle project; Boolean hasDocument = FALSE; fileMenu = GetMenuHandle(rMENU_File); + projectMenu = GetMenuHandle(rMENU_Project); window = FrontWindow(); if (window != NULL) { switch (GetWindowKind(window)) { @@ -67,7 +68,7 @@ static void AdjustMenus(void) project = (ProjectHandle)GetWRefCon(window); ASSERT(project != NULL); hasDocument = TRUE; - ProjectAdjustMenus(project, fileMenu); + ProjectAdjustMenus(project, fileMenu, projectMenu); break; } } @@ -83,6 +84,10 @@ static void AdjustMenus(void) } EnableItem(fileMenu, iFile_Quit); } + if (projectMenu != NULL && !hasDocument) { + DisableItem(projectMenu, iProject_Upload); + DisableItem(projectMenu, iProject_Download); + } } // HandleMenuCommand handles a menu command. The top 16 bits store the menu ID, diff --git a/macos/main.h b/macos/main.h index 957cb66..e22d638 100644 --- a/macos/main.h +++ b/macos/main.h @@ -15,6 +15,9 @@ enum { iFile_SaveAs = 6, iFile_Revert = 7, iFile_Quit = 9, + + iProject_Upload = 1, + iProject_Download = 2, }; // Quit the application. diff --git a/macos/menu.r b/macos/menu.r index e737a6a..8317d3b 100644 --- a/macos/menu.r +++ b/macos/menu.r @@ -6,6 +6,7 @@ resource 'MBAR' (rMBAR_Main) {{ rMENU_Apple, rMENU_File, rMENU_Edit, + rMENU_Project, }}; resource 'MENU' (rMENU_Apple, preload) { @@ -54,3 +55,15 @@ resource 'MENU' (rMENU_Edit, preload) { "Clear", noIcon, noKey, noMark, plain, } }; + +resource 'MENU' (rMENU_Project, preload) { + rMENU_Project, + textMenuProc, + 0b01111111111111111111111111111111, + enabled, + "Project", + { + "Upload Files", noIcon, "U", noMark, plain, + "Download Files", noIcon, "D", noMark, plain, + } +}; diff --git a/macos/project.c b/macos/project.c index 8a55487..64cba70 100644 --- a/macos/project.c +++ b/macos/project.c @@ -449,15 +449,32 @@ void ProjectOpen(FSSpec *spec, ScriptCode script) ProjectCreateWindow(project); } -void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu) +static Boolean ProjectHasDirectory(ProjectHandle project, int which) +{ + struct Project *projectp = *project; + return projectp->dirs[which].alias != NULL || + projectp->dirs[which].path != NULL; +} + +void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu, + MenuHandle projectMenu) { - (void)project; if (fileMenu != NULL) { EnableItem(fileMenu, iFile_Close); EnableItem(fileMenu, iFile_Save); EnableItem(fileMenu, iFile_SaveAs); EnableItem(fileMenu, iFile_Revert); } + if (projectMenu != NULL) { + if (ProjectHasDirectory(project, kDirLocal) && + ProjectHasDirectory(project, kDirRemote)) { + EnableItem(projectMenu, iProject_Upload); + EnableItem(projectMenu, iProject_Download); + } else { + DisableItem(projectMenu, iProject_Upload); + DisableItem(projectMenu, iProject_Download); + } + } } static void ProjectClose(WindowRef window, ProjectHandle project) diff --git a/macos/project.h b/macos/project.h index f467235..a65db08 100644 --- a/macos/project.h +++ b/macos/project.h @@ -14,7 +14,8 @@ void ProjectNew(void); void ProjectOpen(FSSpec *spec, ScriptCode script); // ProjectAdjustMenus adjusts menus before selecting a menu item. -void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu); +void ProjectAdjustMenus(ProjectHandle project, MenuHandle fileMenu, + MenuHandle projectMenu); // ProjectCommand handles a menu command or equivalent. void ProjectCommand(WindowRef window, ProjectHandle project, int menuID, diff --git a/macos/resources.h b/macos/resources.h index ac76469..1a8307e 100644 --- a/macos/resources.h +++ b/macos/resources.h @@ -26,6 +26,7 @@ #define rMENU_Apple 128 #define rMENU_File 129 #define rMENU_Edit 130 +#define rMENU_Project 131 /* STR# Error messages. */ #define rSTRS_Errors 128