From 873192318f1e814fa2ec67392f102db9bd7607a8 Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Thu, 20 Apr 2023 21:41:31 -0400 Subject: [PATCH] Show open dialog for open menu item --- lib/defs.h | 6 ++++++ macos/main.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/defs.h b/lib/defs.h index 8774a4b..cb1527c 100644 --- a/lib/defs.h +++ b/lib/defs.h @@ -128,6 +128,12 @@ Boolean ResizeHandle(Handle h, Size newSize); // Fill memory with zeroes. void MemClear(void *ptr, Size size); +// ============================================================================= +// Utility Macros +// ============================================================================= + +#define ARRAY_COUNT(x) (sizeof(x) / sizeof(*(x))) + // ============================================================================= // Assertions // ============================================================================= diff --git a/macos/main.c b/macos/main.c index 51e0fb9..83599f0 100644 --- a/macos/main.c +++ b/macos/main.c @@ -3,10 +3,13 @@ // Mozilla Public License, version 2.0. See LICENSE.txt for details. #include "macos/main.h" +#include "lib/defs.h" #include "macos/error.h" #include "macos/project.h" #include "macos/resources.h" +#include + #ifndef __MWERKS__ // Link error if defined with CodeWarrior. QDGlobals qd; @@ -17,6 +20,17 @@ void QuitApp(void) ExitToShell(); } +// kFileTypes is a list of all file types that we can open. +static const OSType kFileTypes[] = {kTypeProject}; + +// HandleOpen handles the Open menu command. +static void HandleOpen(void) +{ + StandardFileReply sfreply; + + StandardGetFile(NULL, ARRAY_COUNT(kFileTypes), kFileTypes, &sfreply); +} + // HandleClose handles a request to close the given window. static void HandleClose(WindowRef window) { @@ -57,7 +71,7 @@ static void AdjustMenus(void) if (fileMenu != NULL) { EnableItem(fileMenu, iFile_New); - DisableItem(fileMenu, iFile_Open); + EnableItem(fileMenu, iFile_Open); if (!hasDocument) { DisableItem(fileMenu, iFile_Close); DisableItem(fileMenu, iFile_Save); @@ -95,6 +109,9 @@ static void HandleMenuCommand(long command) case iFile_New: ProjectNew(); return; + case iFile_Open: + HandleOpen(); + return; case iFile_Quit: QuitApp(); return;