Skip to content

Commit

Permalink
#47 n5 or #10: query field support for copy paste cut undo redo (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
750 authored Nov 23, 2024
1 parent 1ddc50b commit 8a85015
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions SDAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ - (void) analyze:(NSString*)query {
@interface SDAppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate, NSTextFieldDelegate, NSTableViewDataSource, NSTableViewDelegate>

// internal

- (void)createMenu;
@property NSWindow* window;
@property NSArray* choices;
@property NSMutableArray* filteredSortedChoices;
Expand All @@ -201,7 +203,35 @@ @implementation SDAppDelegate
/* Starting the app */
/******************************************************************************/

-(void)createMenu {
/* create invisible menubar so that (copy paste cut undo redo) all work */
NSMenu *menubar = [[NSMenu alloc]init];
[NSApp setMainMenu:menubar];

NSMenuItem *menuBarItem = [[NSMenuItem alloc] init];
[menubar addItem:menuBarItem];
NSMenu *myMenu = [[NSMenu alloc]init];

// just FYI: some of those are prone to being renamed by the system
// see https://github.com/tauri-apps/tauri/issues/7828#issuecomment-1723489849
// and https://github.com/electron/electron/blob/706653d5e4d06922f75aa5621533a16fc34d3a77/shell/browser/ui/cocoa/electron_menu_controller.mm#L62
NSMenuItem* copyItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
NSMenuItem* pasteItem = [[NSMenuItem alloc] initWithTitle:@"Paste" action:@selector(paste:) keyEquivalent:@"v"];
NSMenuItem* cutItem = [[NSMenuItem alloc] initWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"];
NSMenuItem* undoItem = [[NSMenuItem alloc] initWithTitle:@"Undo" action:@selector(undo:) keyEquivalent:@"z"];
NSMenuItem* redoItem = [[NSMenuItem alloc] initWithTitle:@"Redo" action:@selector(redo:) keyEquivalent:@"z"];
[redoItem setKeyEquivalentModifierMask: NSShiftKeyMask | NSCommandKeyMask];

[myMenu addItem:copyItem];
[myMenu addItem:pasteItem];
[myMenu addItem:cutItem];
[myMenu addItem:undoItem];
[myMenu addItem:redoItem];
[menuBarItem setSubmenu:myMenu];
}

- (void) applicationDidFinishLaunching:(NSNotification *)notification {
[self createMenu];
NSArray* inputItems = [self getInputItems];
// NSLog(@"%ld", [inputItems count]);
// NSLog(@"%@", inputItems);
Expand Down

0 comments on commit 8a85015

Please sign in to comment.