8#if defined(__APPLE__) && defined(__MACH__)
10#include <TargetConditionals.h>
12#import <CoreText/CoreText.h>
14#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
17#elif TARGET_OS_MAC == 1
19#import <Cocoa/Cocoa.h>
21@interface AppDelegate : NSObject <NSApplicationDelegate>
33- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
38 NSMenu *mainMenu = [NSApp mainMenu];
40 NSMenuItem *fileMenuItem = [mainMenu itemWithTitle:@"File"];
42 NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"];
43 fileMenuItem = [[NSMenuItem alloc] initWithTitle:@"File" action:nil keyEquivalent:@""];
44 [fileMenuItem setSubmenu:fileMenu];
46 NSMenuItem *openItem = [[NSMenuItem alloc] initWithTitle:@"Open"
47 action:@selector(openFileAction:)
49 [fileMenu addItem:openItem];
52 NSMenu *openRecentMenu = [[NSMenu alloc] initWithTitle:@"Open Recent"];
53 NSMenuItem *openRecentMenuItem = [[NSMenuItem alloc] initWithTitle:@"Open Recent"
56 [openRecentMenuItem setSubmenu:openRecentMenu];
57 [fileMenu addItem:openRecentMenuItem];
60 [fileMenu addItem:[NSMenuItem separatorItem]];
63 NSMenuItem *saveItem = [[NSMenuItem alloc] initWithTitle:@"Save" action:nil keyEquivalent:@"s"];
64 [fileMenu addItem:saveItem];
67 [fileMenu addItem:[NSMenuItem separatorItem]];
70 NSMenu *optionsMenu = [[NSMenu alloc] initWithTitle:@"Options"];
71 NSMenuItem *optionsMenuItem = [[NSMenuItem alloc] initWithTitle:@"Options"
74 [optionsMenuItem setSubmenu:optionsMenu];
77 NSMenuItem *flagItem = [[NSMenuItem alloc] initWithTitle:@"Flag"
78 action:@selector(toggleFlagAction:)
80 [flagItem setTarget:self];
81 [flagItem setState:NSControlStateValueOff];
82 [optionsMenu addItem:flagItem];
83 [fileMenu addItem:optionsMenuItem];
85 [mainMenu insertItem:fileMenuItem atIndex:1];
88 NSMenuItem *editMenuItem = [mainMenu itemWithTitle:@"Edit"];
90 NSMenu *editMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
91 editMenuItem = [[NSMenuItem alloc] initWithTitle:@"Edit" action:nil keyEquivalent:@""];
92 [editMenuItem setSubmenu:editMenu];
94 NSMenuItem *undoItem = [[NSMenuItem alloc] initWithTitle:@"Undo" action:nil keyEquivalent:@"z"];
96 [editMenu addItem:undoItem];
98 NSMenuItem *redoItem = [[NSMenuItem alloc] initWithTitle:@"Redo" action:nil keyEquivalent:@"Z"];
100 [editMenu addItem:redoItem];
103 [editMenu addItem:[NSMenuItem separatorItem]];
105 NSMenuItem *cutItem = [[NSMenuItem alloc] initWithTitle:@"Cut"
106 action:@selector(cutAction:)
108 [editMenu addItem:cutItem];
110 NSMenuItem *copyItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:nil keyEquivalent:@"c"];
111 [editMenu addItem:copyItem];
113 NSMenuItem *pasteItem = [[NSMenuItem alloc] initWithTitle:@"Paste"
117 [editMenu addItem:pasteItem];
120 [editMenu addItem:[NSMenuItem separatorItem]];
122 NSMenuItem *selectAllItem = [[NSMenuItem alloc] initWithTitle:@"Select All"
126 [editMenu addItem:selectAllItem];
128 [mainMenu insertItem:editMenuItem atIndex:2];
131 NSMenuItem *viewMenuItem = [mainMenu itemWithTitle:@"View"];
133 NSMenu *viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
134 viewMenuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
135 [viewMenuItem setSubmenu:viewMenu];
138 NSMenuItem *emulatorViewItem = [[NSMenuItem alloc] initWithTitle:@"Emulator View"
142 [viewMenu addItem:emulatorViewItem];
145 NSMenuItem *hexEditorViewItem = [[NSMenuItem alloc] initWithTitle:@"Hex Editor View"
149 [viewMenu addItem:hexEditorViewItem];
152 NSMenuItem *disassemblyViewItem = [[NSMenuItem alloc] initWithTitle:@"Disassembly View"
156 [viewMenu addItem:disassemblyViewItem];
159 NSMenuItem *memoryViewItem = [[NSMenuItem alloc] initWithTitle:@"Memory View"
163 [viewMenu addItem:memoryViewItem];
166 [viewMenu addItem:[NSMenuItem separatorItem]];
169 NSMenuItem *toggleFullscreenItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Fullscreen"
173 [viewMenu addItem:toggleFullscreenItem];
175 [mainMenu insertItem:viewMenuItem atIndex:3];
178 NSMenuItem *helpMenuItem = [mainMenu itemWithTitle:@"Help"];
180 NSMenu *helpMenu = [[NSMenu alloc] initWithTitle:@"Help"];
181 helpMenuItem = [[NSMenuItem alloc] initWithTitle:@"Help" action:nil keyEquivalent:@""];
182 [helpMenuItem setSubmenu:helpMenu];
185 NSMenuItem *documentationItem = [[NSMenuItem alloc] initWithTitle:@"Documentation"
188 [helpMenu addItem:documentationItem];
190 [mainMenu insertItem:helpMenuItem atIndex:4];
195- (void)newFileAction:(
id)sender {
196 NSLog(
@"New File action triggered");
199- (void)toggleFlagAction:(
id)sender {
200 NSMenuItem *flagItem = (NSMenuItem *)sender;
201 if ([flagItem state] == NSControlStateValueOff) {
202 [flagItem setState:NSControlStateValueOn];
204 [flagItem setState:NSControlStateValueOff];
208- (void)openFileAction:(
id)sender {
212 NSAlert *alert = [[NSAlert alloc] init];
213 [alert setMessageText:@"Error"];
214 [alert setInformativeText:@"Failed to load file."];
215 [alert addButtonWithTitle:@"OK"];
220- (void)cutAction:(
id)sender {
224- (void)openRecentFileAction:(
id)sender {
225 NSLog(
@"Open Recent File action triggered");
230extern "C" void yaze_initialize_cococa() {
233 [NSApplication sharedApplication];
234 [NSApp setDelegate:delegate];
235 [NSApp finishLaunching];
239extern "C" void yaze_run_cocoa_app_delegate(
const char *filename) {
240 yaze_initialize_cococa();
246 if (
auto status = controller.
OnLoad(); !status.ok()) {
static std::shared_ptr< Rom > shared_rom_
Main controller for the application.
absl::Status OnEntry(std::string filename="")
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
#define RETURN_VOID_IF_ERROR(expression)