aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsfns.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m127
1 files changed, 65 insertions, 62 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 1e075995c11..6eebb4d2567 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -89,9 +89,6 @@ extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
89Lisp_Object Qbuffered; 89Lisp_Object Qbuffered;
90Lisp_Object Qfontsize; 90Lisp_Object Qfontsize;
91 91
92/* hack for OS X file panels */
93char panelOK = 0;
94
95EmacsTooltip *ns_tooltip = nil; 92EmacsTooltip *ns_tooltip = nil;
96 93
97/* Need forward declaration here to preserve organizational integrity of file */ 94/* Need forward declaration here to preserve organizational integrity of file */
@@ -888,7 +885,7 @@ ns_appkit_version_str (void)
888 885
889#ifdef NS_IMPL_GNUSTEP 886#ifdef NS_IMPL_GNUSTEP
890 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION)); 887 sprintf(tmp, "gnustep-gui-%s", Xstr(GNUSTEP_GUI_VERSION));
891#elif defined(NS_IMPL_COCOA) 888#elif defined (NS_IMPL_COCOA)
892 sprintf(tmp, "apple-appkit-%.2f", NSAppKitVersionNumber); 889 sprintf(tmp, "apple-appkit-%.2f", NSAppKitVersionNumber);
893#else 890#else
894 tmp = "ns-unknown"; 891 tmp = "ns-unknown";
@@ -905,7 +902,7 @@ ns_appkit_version_int (void)
905{ 902{
906#ifdef NS_IMPL_GNUSTEP 903#ifdef NS_IMPL_GNUSTEP
907 return GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION; 904 return GNUSTEP_GUI_MAJOR_VERSION * 100 + GNUSTEP_GUI_MINOR_VERSION;
908#elif defined(NS_IMPL_COCOA) 905#elif defined (NS_IMPL_COCOA)
909 return (int)NSAppKitVersionNumber; 906 return (int)NSAppKitVersionNumber;
910#endif 907#endif
911 return 0; 908 return 0;
@@ -1396,6 +1393,41 @@ DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
1396 return Qnil; 1393 return Qnil;
1397} 1394}
1398 1395
1396static struct
1397{
1398 id panel;
1399 BOOL ret;
1400#if ! defined (NS_IMPL_COCOA) || \
1401 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
1402 NSString *dirS, *initS;
1403 BOOL no_types;
1404#endif
1405} ns_fd_data;
1406
1407void
1408ns_run_file_dialog (void)
1409{
1410 if (ns_fd_data.panel == nil) return;
1411#if defined (NS_IMPL_COCOA) && \
1412 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1413 ns_fd_data.ret = [ns_fd_data.panel runModal];
1414#else
1415 if (ns_fd_data.no_types)
1416 {
1417 ns_fd_data.ret = [ns_fd_data.panel
1418 runModalForDirectory: ns_fd_data.dirS
1419 file: ns_fd_data.initS];
1420 }
1421 else
1422 {
1423 ns_fd_data.ret = [ns_fd_data.panel
1424 runModalForDirectory: ns_fd_data.dirS
1425 file: ns_fd_data.initS
1426 types: nil];
1427 }
1428#endif
1429 ns_fd_data.panel = nil;
1430}
1399 1431
1400DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0, 1432DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0,
1401 doc: /* Use a graphical panel to read a file name, using prompt PROMPT. 1433 doc: /* Use a graphical panel to read a file name, using prompt PROMPT.
@@ -1420,6 +1452,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1420 [NSString stringWithUTF8String: SSDATA (dir)]; 1452 [NSString stringWithUTF8String: SSDATA (dir)];
1421 NSString *initS = NILP (init) || !STRINGP (init) ? nil : 1453 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
1422 [NSString stringWithUTF8String: SSDATA (init)]; 1454 [NSString stringWithUTF8String: SSDATA (init)];
1455 NSEvent *nxev;
1423 1456
1424 check_window_system (NULL); 1457 check_window_system (NULL);
1425 1458
@@ -1440,7 +1473,6 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1440 [panel setTreatsFilePackagesAsDirectories: YES]; 1473 [panel setTreatsFilePackagesAsDirectories: YES];
1441 [panel setDelegate: fileDelegate]; 1474 [panel setDelegate: fileDelegate];
1442 1475
1443 panelOK = 0;
1444 if (! NILP (dir_only_p)) 1476 if (! NILP (dir_only_p))
1445 { 1477 {
1446 [panel setCanChooseDirectories: YES]; 1478 [panel setCanChooseDirectories: YES];
@@ -1454,7 +1486,9 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1454 [panel setCanChooseFiles: YES]; 1486 [panel setCanChooseFiles: YES];
1455 } 1487 }
1456 1488
1457 block_input (); 1489 block_input ();
1490 ns_fd_data.panel = panel;
1491 ns_fd_data.ret = NO;
1458#if defined (NS_IMPL_COCOA) && \ 1492#if defined (NS_IMPL_COCOA) && \
1459 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 1493 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1460 if (! NILP (mustmatch) || ! NILP (dir_only_p)) 1494 if (! NILP (mustmatch) || ! NILP (dir_only_p))
@@ -1465,19 +1499,32 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1465 else 1499 else
1466 [panel setNameFieldStringValue: @""]; 1500 [panel setNameFieldStringValue: @""];
1467 1501
1468 ret = [panel runModal];
1469#else 1502#else
1470 if (NILP (mustmatch) && NILP (dir_only_p)) 1503 ns_fd_data.no_types = NILP (mustmatch) && NILP (dir_only_p);
1471 { 1504 ns_fd_data.dirS = dirS;
1472 ret = [panel runModalForDirectory: dirS file: initS]; 1505 ns_fd_data.initS = initS;
1473 }
1474 else
1475 {
1476 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1477 }
1478#endif 1506#endif
1479 1507
1480 ret = (ret == NSOKButton) || panelOK; 1508 /* runModalForDirectory/runModal restarts the main event loop when done,
1509 so we must start an event loop and then pop up the file dialog.
1510 The file dialog may pop up a confirm dialog after Ok has been pressed,
1511 so we can not simply pop down on the Ok/Cancel press.
1512 */
1513 nxev = [NSEvent otherEventWithType: NSApplicationDefined
1514 location: NSMakePoint (0, 0)
1515 modifierFlags: 0
1516 timestamp: 0
1517 windowNumber: [[NSApp mainWindow] windowNumber]
1518 context: [NSApp context]
1519 subtype: 0
1520 data1: 0
1521 data2: NSAPP_DATA2_RUNFILEDIALOG];
1522
1523 [NSApp postEvent: nxev atStart: NO];
1524 while (ns_fd_data.panel != nil)
1525 [NSApp run];
1526
1527 ret = (ns_fd_data.ret == NSOKButton);
1481 1528
1482 if (ret) 1529 if (ret)
1483 { 1530 {
@@ -2446,7 +2493,7 @@ Internal use only, use `display-monitor-attributes-list' instead. */)
2446 vy = (short) (primary_display_height - 2493 vy = (short) (primary_display_height -
2447 vfr.size.height - vfr.origin.y); 2494 vfr.size.height - vfr.origin.y);
2448 } 2495 }
2449 2496
2450 m->geom.x = (short) fr.origin.x; 2497 m->geom.x = (short) fr.origin.x;
2451 m->geom.y = y; 2498 m->geom.y = y;
2452 m->geom.width = (unsigned short) fr.size.width; 2499 m->geom.width = (unsigned short) fr.size.width;
@@ -2755,25 +2802,6 @@ handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent)
2755} 2802}
2756 2803
2757@implementation EmacsSavePanel 2804@implementation EmacsSavePanel
2758#ifdef NS_IMPL_COCOA
2759/* --------------------------------------------------------------------------
2760 These are overridden to intercept on OS X: ending panel restarts NSApp
2761 event loop if it is stopped. Not sure if this is correct behavior,
2762 perhaps should check if running and if so send an appdefined.
2763 -------------------------------------------------------------------------- */
2764- (void) ok: (id)sender
2765{
2766 [super ok: sender];
2767 panelOK = 1;
2768 [NSApp stop: self];
2769}
2770- (void) cancel: (id)sender
2771{
2772 [super cancel: sender];
2773 [NSApp stop: self];
2774}
2775#endif
2776
2777- (BOOL)performKeyEquivalent:(NSEvent *)theEvent 2805- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2778{ 2806{
2779 BOOL ret = handlePanelKeys (self, theEvent); 2807 BOOL ret = handlePanelKeys (self, theEvent);
@@ -2785,31 +2813,6 @@ handlePanelKeys (NSSavePanel *panel, NSEvent *theEvent)
2785 2813
2786 2814
2787@implementation EmacsOpenPanel 2815@implementation EmacsOpenPanel
2788#ifdef NS_IMPL_COCOA
2789/* --------------------------------------------------------------------------
2790 These are overridden to intercept on OS X: ending panel restarts NSApp
2791 event loop if it is stopped. Not sure if this is correct behavior,
2792 perhaps should check if running and if so send an appdefined.
2793 -------------------------------------------------------------------------- */
2794- (void) ok: (id)sender
2795{
2796 [super ok: sender];
2797
2798 // If not choosing directories, and Open is pressed on a directory, return.
2799 if (! [self canChooseDirectories] && ns_directory_from_panel (self) &&
2800 ! ns_filename_from_panel (self))
2801 return;
2802
2803 panelOK = 1;
2804 [NSApp stop: self];
2805}
2806- (void) cancel: (id)sender
2807{
2808 [super cancel: sender];
2809 [NSApp stop: self];
2810}
2811
2812#endif
2813- (BOOL)performKeyEquivalent:(NSEvent *)theEvent 2816- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
2814{ 2817{
2815 // NSOpenPanel inherits NSSavePanel, so passing self is OK. 2818 // NSOpenPanel inherits NSSavePanel, so passing self is OK.