Skip to content

Commit 8a85015

Browse files
authored
#47 n5 or #10: query field support for copy paste cut undo redo (#49)
1 parent 1ddc50b commit 8a85015

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

SDAppDelegate.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ - (void) analyze:(NSString*)query {
186186
@interface SDAppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate, NSTextFieldDelegate, NSTableViewDataSource, NSTableViewDelegate>
187187

188188
// internal
189+
190+
- (void)createMenu;
189191
@property NSWindow* window;
190192
@property NSArray* choices;
191193
@property NSMutableArray* filteredSortedChoices;
@@ -201,7 +203,35 @@ @implementation SDAppDelegate
201203
/* Starting the app */
202204
/******************************************************************************/
203205

206+
-(void)createMenu {
207+
/* create invisible menubar so that (copy paste cut undo redo) all work */
208+
NSMenu *menubar = [[NSMenu alloc]init];
209+
[NSApp setMainMenu:menubar];
210+
211+
NSMenuItem *menuBarItem = [[NSMenuItem alloc] init];
212+
[menubar addItem:menuBarItem];
213+
NSMenu *myMenu = [[NSMenu alloc]init];
214+
215+
// just FYI: some of those are prone to being renamed by the system
216+
// see https://github.com/tauri-apps/tauri/issues/7828#issuecomment-1723489849
217+
// and https://github.com/electron/electron/blob/706653d5e4d06922f75aa5621533a16fc34d3a77/shell/browser/ui/cocoa/electron_menu_controller.mm#L62
218+
NSMenuItem* copyItem = [[NSMenuItem alloc] initWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
219+
NSMenuItem* pasteItem = [[NSMenuItem alloc] initWithTitle:@"Paste" action:@selector(paste:) keyEquivalent:@"v"];
220+
NSMenuItem* cutItem = [[NSMenuItem alloc] initWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"];
221+
NSMenuItem* undoItem = [[NSMenuItem alloc] initWithTitle:@"Undo" action:@selector(undo:) keyEquivalent:@"z"];
222+
NSMenuItem* redoItem = [[NSMenuItem alloc] initWithTitle:@"Redo" action:@selector(redo:) keyEquivalent:@"z"];
223+
[redoItem setKeyEquivalentModifierMask: NSShiftKeyMask | NSCommandKeyMask];
224+
225+
[myMenu addItem:copyItem];
226+
[myMenu addItem:pasteItem];
227+
[myMenu addItem:cutItem];
228+
[myMenu addItem:undoItem];
229+
[myMenu addItem:redoItem];
230+
[menuBarItem setSubmenu:myMenu];
231+
}
232+
204233
- (void) applicationDidFinishLaunching:(NSNotification *)notification {
234+
[self createMenu];
205235
NSArray* inputItems = [self getInputItems];
206236
// NSLog(@"%ld", [inputItems count]);
207237
// NSLog(@"%@", inputItems);

0 commit comments

Comments
 (0)