Add project menu with upload/download items

This commit is contained in:
Dietrich Epp 2023-05-07 01:51:00 -04:00
parent 37929beede
commit 1f1407bb0e
6 changed files with 45 additions and 5 deletions

View File

@ -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,

View File

@ -15,6 +15,9 @@ enum {
iFile_SaveAs = 6,
iFile_Revert = 7,
iFile_Quit = 9,
iProject_Upload = 1,
iProject_Download = 2,
};
// Quit the application.

View File

@ -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,
}
};

View File

@ -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)

View File

@ -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,

View File

@ -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