aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsfns.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m90
1 files changed, 87 insertions, 3 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index a483f847dec..0d9ebe0ef50 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -88,7 +88,7 @@ Lisp_Object Qfontsize;
88/* hack for OS X file panels */ 88/* hack for OS X file panels */
89char panelOK = 0; 89char panelOK = 0;
90 90
91EmacsTooltip *ns_tooltip; 91EmacsTooltip *ns_tooltip = nil;
92 92
93/* Need forward declaration here to preserve organizational integrity of file */ 93/* Need forward declaration here to preserve organizational integrity of file */
94Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object); 94Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
@@ -1477,7 +1477,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1477 [panel setCanChooseFiles: YES]; 1477 [panel setCanChooseFiles: YES];
1478 } 1478 }
1479 1479
1480 block_input (); 1480 block_input ();
1481#if defined (NS_IMPL_COCOA) && \ 1481#if defined (NS_IMPL_COCOA) && \
1482 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 1482 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1483 if (! NILP (mustmatch) || ! NILP (dir_only_p)) 1483 if (! NILP (mustmatch) || ! NILP (dir_only_p))
@@ -2544,6 +2544,75 @@ Value is t if tooltip was open, nil otherwise. */)
2544 2544
2545 ========================================================================== */ 2545 ========================================================================== */
2546 2546
2547/*
2548 Handle arrow/function/control keys and copy/paste/cut in file dialogs.
2549 Return YES if handeled, NO if not.
2550 */
2551static BOOL
2552handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent)
2553{
2554 NSString *s;
2555 int i;
2556 BOOL ret = NO;
2557
2558 if ([theEvent type] != NSKeyDown) return NO;
2559 s = [theEvent characters];
2560
2561 for (i = 0; i < [s length]; ++i)
2562 {
2563 int ch = (int) [s characterAtIndex: i];
2564 switch (ch)
2565 {
2566 case NSHomeFunctionKey:
2567 case NSDownArrowFunctionKey:
2568 case NSUpArrowFunctionKey:
2569 case NSLeftArrowFunctionKey:
2570 case NSRightArrowFunctionKey:
2571 case NSPageUpFunctionKey:
2572 case NSPageDownFunctionKey:
2573 case NSEndFunctionKey:
2574 [panel sendEvent: theEvent];
2575 ret = YES;
2576 break;
2577 /* As we don't have the standard key commands for
2578 copy/paste/cut/select-all in our edit menu, we must handle
2579 them here. TODO: handle Emacs key bindings for copy/cut/select-all
2580 here, paste works, because we have that in our Edit menu.
2581 I.e. refactor out code in nsterm.m, keyDown: to figure out the
2582 correct modifier.
2583 */
2584 case 'x': // Cut
2585 case 'c': // Copy
2586 case 'v': // Paste
2587 case 'a': // Select all
2588 if ([theEvent modifierFlags] & NSCommandKeyMask)
2589 {
2590 [NSApp sendAction:
2591 (ch == 'x'
2592 ? @selector(cut:)
2593 : (ch == 'c'
2594 ? @selector(copy:)
2595 : (ch == 'v'
2596 ? @selector(paste:)
2597 : @selector(selectAll:))))
2598 to:nil from:panel];
2599 ret = YES;
2600 }
2601 default:
2602 // Send all control keys, as the text field supports C-a, C-f, C-e
2603 // C-b and more.
2604 if ([theEvent modifierFlags] & NSControlKeyMask)
2605 {
2606 [panel sendEvent: theEvent];
2607 ret = YES;
2608 }
2609 break;
2610 }
2611 }
2612
2613
2614 return ret;
2615}
2547 2616
2548@implementation EmacsSavePanel 2617@implementation EmacsSavePanel
2549#ifdef NS_IMPL_COCOA 2618#ifdef NS_IMPL_COCOA
@@ -2572,6 +2641,14 @@ Value is t if tooltip was open, nil otherwise. */)
2572{ 2641{
2573 return ns_directory_from_panel (self); 2642 return ns_directory_from_panel (self);
2574} 2643}
2644
2645- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2646{
2647 BOOL ret = handlePanelKeys (self, theEvent);
2648 if (! ret)
2649 ret = [super performKeyEquivalent:theEvent];
2650 return ret;
2651}
2575@end 2652@end
2576 2653
2577 2654
@@ -2609,7 +2686,14 @@ Value is t if tooltip was open, nil otherwise. */)
2609{ 2686{
2610 return ns_directory_from_panel (self); 2687 return ns_directory_from_panel (self);
2611} 2688}
2612 2689- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2690{
2691 // NSOpenPanel inherits NSSavePanel, so passing self is OK.
2692 BOOL ret = handlePanelKeys (self, theEvent);
2693 if (! ret)
2694 ret = [super performKeyEquivalent:theEvent];
2695 return ret;
2696}
2613@end 2697@end
2614 2698
2615 2699