Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
adb198a
Added ability to copy TextView via CMD+C
ScraperMan2002 May 16, 2025
79d6d7c
Remove TestAddCode. That was just to help me understand how everythin…
ScraperMan2002 May 16, 2025
a7dcb5e
Get rid of useless line [item setTarget: nil]; to simplify the code.
ScraperMan2002 May 16, 2025
1aea868
Added ability to "select all" for the text in Properties.
ScraperMan2002 May 17, 2025
a52ca4c
Merge branch 'ares-emulator:master' into CMDA
ScraperMan2002 May 17, 2025
d6314dc
Merge pull request #1 from ScraperMan2002/CMDA
ScraperMan2002 May 17, 2025
8bdaf1d
Moved all the Menu Item initailizations from Window to Application. W…
ScraperMan2002 May 17, 2025
991daae
Merge remote-tracking branch 'refs/remotes/PrivateAres/master'
ScraperMan2002 May 17, 2025
485df6a
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 17, 2025
6760d27
-Put constructMenu into autoreleasepool to get rid of leaked data
ScraperMan2002 May 17, 2025
df76401
Remove tracked .DS_Store and update .gitignore
ScraperMan2002 May 17, 2025
ed79e37
Remove reamining tracked .DS_Stores
ScraperMan2002 May 17, 2025
211c1b0
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 19, 2025
13bf81d
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 25, 2025
cceb52c
Change the window size of the Configuration window so that on MacOS t…
ScraperMan2002 May 25, 2025
36e0e72
Added ability for Memory Editor to switch memory value format between…
ScraperMan2002 May 26, 2025
5adf5d3
Merge branch 'ares-emulator:master' into master
ScraperMan2002 May 26, 2025
0d370ea
Added ability to switch between binary, octal, and hexidecimal in Win…
ScraperMan2002 May 27, 2025
8753f2a
Added ability for HexData to switch between Binary, Octal, and Hexade…
ScraperMan2002 May 27, 2025
1177c19
Added setBase() so the program can compile correctly.
ScraperMan2002 May 27, 2025
93469e5
Fixed further bugs with not using state().base and with to_string not…
ScraperMan2002 May 27, 2025
da4c507
Got rid of using std::invalid_argument. Might as well just simply "th…
ScraperMan2002 May 27, 2025
433da54
Major Edits to hex-edit on MacOS:
ScraperMan2002 May 29, 2025
c7fad92
Merge pull request #2 from ScraperMan2002/hexedit-edit-branch-with-si…
ScraperMan2002 May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved all the Menu Item initailizations from Window to Application. W…
…ARNING: I have no idea how all this works. This could be buggy. I highly recommend the person who approves of this push to please take a look at it and fix any bugs. Because I have no clue why this worked, and I don't have any more patience with fixing whatever will be thrown in the future.
  • Loading branch information
ScraperMan2002 committed May 17, 2025
commit 8bdaf1d2246e8ed933e07dee6363afdfd45bd93a
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ tests/arm7tdmi/tests
tests/m68000/tests
thirdparty/libchdr/deps/zlib-*/zconf.h
thirdparty/libchdr/deps/zlib-*/zconf.h.included
ares/build*
98 changes: 98 additions & 0 deletions hiro/cocoa/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,103 @@

@implementation CocoaDelegate : NSObject

-(void) constructMenu {
NSBundle* bundle = [NSBundle mainBundle];
NSDictionary* dictionary = [bundle infoDictionary];
NSString* applicationName = [dictionary objectForKey:@"CFBundleDisplayName"];

menuBar = [[NSMenu alloc] init];

NSMenuItem* item;
string text;

rootMenu = [[NSMenu alloc] init];
item = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[item setSubmenu:rootMenu];
[menuBar addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@…", applicationName] action:@selector(menuAbout) keyEquivalent:@""];
[item setTarget:self];
[rootMenu addItem:item];
[rootMenu addItem:[NSMenuItem separatorItem]];

item = [[NSMenuItem alloc] initWithTitle:@"Preferences…" action:@selector(menuPreferences) keyEquivalent:@""];
[item setTarget:self];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @",";
[rootMenu addItem:item];

[rootMenu addItem:[NSMenuItem separatorItem]];

NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle:@"Services"];
item = [[NSMenuItem alloc] initWithTitle:@"Services" action:nil keyEquivalent:@""];
[item setTarget:self];
[item setSubmenu:servicesMenu];
[rootMenu addItem:item];
[rootMenu addItem:[NSMenuItem separatorItem]];
[NSApp setServicesMenu:servicesMenu];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Hide %@", applicationName] action:@selector(hide:) keyEquivalent:@""];
[item setTarget:NSApp];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @"h";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@""];
[item setTarget:NSApp];
[item setTarget:NSApp];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand | NSEventModifierFlagOption;
item.keyEquivalent = @"h";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[item setTarget:NSApp];
[rootMenu addItem:item];

[rootMenu addItem:[NSMenuItem separatorItem]];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Quit %@", applicationName] action:@selector(menuQuit) keyEquivalent:@""];
[item setTarget:self];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @"q";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Edit"] action:nil keyEquivalent:@""];
editMenu = [[NSMenu alloc] init];
[item setSubmenu:editMenu];
[menuBar addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Cut"] action:@selector(cut:) keyEquivalent:@"x"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Copy"] action:@selector(copy:) keyEquivalent:@"c"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Paste"] action:@selector(paste:) keyEquivalent:@"v"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Select All"] action:@selector(selectAll:) keyEquivalent:@"a"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

[NSApp setMainMenu:menuBar];
}

-(void) menuAbout {
hiro::Application::Cocoa::doAbout();
}

-(void) menuPreferences {
hiro::Application::Cocoa::doPreferences();
}

-(void) menuQuit {
hiro::Application::Cocoa::doQuit();
}

-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender {
using hiro::Application;
if(Application::state().cocoa.onQuit) Application::Cocoa::doQuit();
Expand Down Expand Up @@ -115,6 +212,7 @@ auto pApplication::initialize() -> void {
cocoaDelegate = [[CocoaDelegate alloc] init];
[NSApp setDelegate:cocoaDelegate];
}
[cocoaDelegate constructMenu];
}

}
Expand Down
8 changes: 8 additions & 0 deletions hiro/cocoa/application.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#if defined(Hiro_Application)

@interface CocoaDelegate : NSObject <NSApplicationDelegate> {
@public
NSMenu* menuBar;
NSMenu* rootMenu;
NSMenu* editMenu;
}
-(void) constructMenu;
-(void) menuAbout;
-(void) menuPreferences;
-(void) menuQuit;
-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender;
-(BOOL) applicationShouldHandleReopen:(NSApplication*)application hasVisibleWindows:(BOOL)flag;
-(void) run:(NSTimer*)timer;
Expand Down
9 changes: 0 additions & 9 deletions hiro/cocoa/widget/text-edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
return self;
}

- (BOOL) validateMenuItem:(NSMenuItem *) menuItem {
SEL action = menuItem.action;
if (action == @selector(copy:) ||
action == @selector(selectAll:)) {
return YES;
}
return [super validateMenuItem:menuItem];
}

-(NSTextView*) content {
return content;
}
Expand Down
3 changes: 1 addition & 2 deletions hiro/cocoa/widget/text-edit.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#if defined(Hiro_TextEdit)

@interface CocoaTextEdit : NSScrollView <NSTextViewDelegate, NSMenuItemValidation> {
@interface CocoaTextEdit : NSScrollView <NSTextViewDelegate> {
@public
hiro::mTextEdit* textEdit;
NSTextView* content;
}
-(BOOL) validateMenuItem:(NSMenuItem *) menuItem;
-(id) initWith:(hiro::mTextEdit&)textEdit;
-(NSTextView*) content;
-(void) configure;
Expand Down
97 changes: 2 additions & 95 deletions hiro/cocoa/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-(id) initWith:(hiro::mWindow&)windowReference {
window = &windowReference;

NSUInteger style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
if(window->state.resizable) style |= NSWindowStyleMaskResizable;

Expand All @@ -19,76 +19,7 @@
NSString* applicationName = [dictionary objectForKey:@"CFBundleDisplayName"];
string hiroName = hiro::Application::state().name ? hiro::Application::state().name : string{"hiro"};
if(applicationName == nil) applicationName = [NSString stringWithUTF8String:hiroName];

menuBar = [[NSMenu alloc] init];

NSMenuItem* item;
string text;

rootMenu = [[NSMenu alloc] init];
item = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[item setSubmenu:rootMenu];
[menuBar addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@…", applicationName] action:@selector(menuAbout) keyEquivalent:@""];
[item setTarget:self];
[rootMenu addItem:item];
[rootMenu addItem:[NSMenuItem separatorItem]];

item = [[NSMenuItem alloc] initWithTitle:@"Preferences…" action:@selector(menuPreferences) keyEquivalent:@""];
[item setTarget:self];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @",";
[rootMenu addItem:item];

[rootMenu addItem:[NSMenuItem separatorItem]];

NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle:@"Services"];
item = [[NSMenuItem alloc] initWithTitle:@"Services" action:nil keyEquivalent:@""];
[item setTarget:self];
[item setSubmenu:servicesMenu];
[rootMenu addItem:item];
[rootMenu addItem:[NSMenuItem separatorItem]];
[NSApp setServicesMenu:servicesMenu];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Hide %@", applicationName] action:@selector(hide:) keyEquivalent:@""];
[item setTarget:NSApp];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @"h";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@""];
[item setTarget:NSApp];
[item setTarget:NSApp];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand | NSEventModifierFlagOption;
item.keyEquivalent = @"h";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[item setTarget:NSApp];
[rootMenu addItem:item];

[rootMenu addItem:[NSMenuItem separatorItem]];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Quit %@", applicationName] action:@selector(menuQuit) keyEquivalent:@""];
[item setTarget:self];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
item.keyEquivalent = @"q";
[rootMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Edit"] action:nil keyEquivalent:@""];
editMenu = [[NSMenu alloc] init];
[item setSubmenu:editMenu];
[menuBar addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Copy"] action:@selector(copy:) keyEquivalent:@"c"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Select All"] action:@selector(selectAll:) keyEquivalent:@"a"];
item.keyEquivalentModifierMask = NSEventModifierFlagCommand;
[editMenu addItem:item];

statusBar = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[statusBar setAlignment:NSTextAlignmentLeft];
[statusBar setBordered:YES];
Expand All @@ -111,12 +42,6 @@
return YES;
}

-(void) windowDidBecomeMain:(NSNotification*)notification {
if(window->state.menuBar) {
[NSApp setMainMenu:menuBar];
}
}

-(void) windowDidMove:(NSNotification*)notification {
if(auto p = window->self()) p->moveEvent();
}
Expand Down Expand Up @@ -144,19 +69,7 @@
}

-(NSMenu*) menuBar {
return menuBar;
}

-(void) menuAbout {
hiro::Application::Cocoa::doAbout();
}

-(void) menuPreferences {
hiro::Application::Cocoa::doPreferences();
}

-(void) menuQuit {
hiro::Application::Cocoa::doQuit();
return [NSApp mainMenu];
}

-(NSTextField*) statusBar {
Expand All @@ -177,12 +90,6 @@ namespace hiro {

auto pWindow::construct() -> void {
cocoaWindow = [[CocoaWindow alloc] initWith:self()];

static bool once = true;
if(once) {
once = false;
[NSApp setMainMenu:[cocoaWindow menuBar]];
}
}

auto pWindow::destruct() -> void {
Expand Down
9 changes: 1 addition & 8 deletions hiro/cocoa/window.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#if defined(Hiro_Window)

@interface CocoaWindow : NSWindow <NSWindowDelegate, NSMenuDelegate> {
@interface CocoaWindow : NSWindow <NSWindowDelegate> {
@public
hiro::mWindow* window;
NSMenu* menuBar;
NSMenu* rootMenu;
NSMenu* editMenu;
NSMenuItem* disableGatekeeper;
NSTextField* statusBar;
}
-(id) initWith:(hiro::mWindow&)window;
-(BOOL) canBecomeKeyWindow;
-(BOOL) canBecomeMainWindow;
-(void) windowDidBecomeMain:(NSNotification*)notification;
-(void) windowDidMove:(NSNotification*)notification;
-(void) windowDidResize:(NSNotification*)notification;
-(BOOL) windowShouldClose:(id)sender;
-(NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender;
-(BOOL) performDragOperation:(id<NSDraggingInfo>)sender;
-(NSMenu*) menuBar;
-(void) menuAbout;
-(void) menuPreferences;
-(void) menuQuit;
-(NSTextField*) statusBar;
@end

Expand Down