diff options
| author | Jan Djärv | 2013-07-06 19:58:41 +0200 |
|---|---|---|
| committer | Jan Djärv | 2013-07-06 19:58:41 +0200 |
| commit | 1afb1d071576f7884a475c04955fc33126f70221 (patch) | |
| tree | 96ed2d6b2ca528e3b3778db14e2cd41a7361bb73 /src | |
| parent | 23de972aa74fce7360b263d639ffbd674931e408 (diff) | |
| download | emacs-1afb1d071576f7884a475c04955fc33126f70221.tar.gz emacs-1afb1d071576f7884a475c04955fc33126f70221.zip | |
* lisp/files.el (write-file): Do not display confirm dialog for NS,
it does its own dialog, which can't be cancelled.
* src/nsfns.m: Remove panelOK.
(ns_fd_data): New.
(ns_run_file_dialog): New function.
(Fns_read_file_name): Fill in ns_fd_data, post an event and start the
event loop, so file dialog is popped up by ns_run_file_dialog, called
by sendEvent (Bug#14578).
(EmacsSavePanel, EmacsOpenPanel): Remove ok and cancel methods.
* src/nsterm.h (NSSavePanel): Update comment.
(NSAPP_DATA2_RUNFILEDIALOG): Define.
(ns_run_file_dialog): Declare.
* src/nsterm.m (sendEvent:): Handle NSAPP_DATA2_RUNFILEDIALOG.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 16 | ||||
| -rw-r--r-- | src/nsfns.m | 121 | ||||
| -rw-r--r-- | src/nsterm.h | 6 | ||||
| -rw-r--r-- | src/nsterm.m | 21 |
4 files changed, 96 insertions, 68 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 9bf1840baac..b95488c1e70 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2013-07-06 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * nsterm.m (sendEvent:): Handle NSAPP_DATA2_RUNFILEDIALOG. | ||
| 4 | |||
| 5 | * nsterm.h (NSSavePanel): Update comment. | ||
| 6 | (NSAPP_DATA2_RUNFILEDIALOG): Define. | ||
| 7 | (ns_run_file_dialog): Declare. | ||
| 8 | |||
| 9 | * nsfns.m: Remove panelOK. | ||
| 10 | (ns_fd_data): New. | ||
| 11 | (ns_run_file_dialog): New function. | ||
| 12 | (Fns_read_file_name): Fill in ns_fd_data, post an event and start the | ||
| 13 | event loop, so file dialog is popped up by ns_run_file_dialog, called | ||
| 14 | by sendEvent (Bug#14578). | ||
| 15 | (EmacsSavePanel, EmacsOpenPanel): Remove ok and cancel methods. | ||
| 16 | |||
| 1 | 2013-07-06 Eli Zaretskii <eliz@gnu.org> | 17 | 2013-07-06 Eli Zaretskii <eliz@gnu.org> |
| 2 | 18 | ||
| 3 | * xdisp.c (default_line_pixel_height): New function. | 19 | * xdisp.c (default_line_pixel_height): New function. |
diff --git a/src/nsfns.m b/src/nsfns.m index 1e075995c11..b8f46e461fa 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -89,9 +89,6 @@ extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle; | |||
| 89 | Lisp_Object Qbuffered; | 89 | Lisp_Object Qbuffered; |
| 90 | Lisp_Object Qfontsize; | 90 | Lisp_Object Qfontsize; |
| 91 | 91 | ||
| 92 | /* hack for OS X file panels */ | ||
| 93 | char panelOK = 0; | ||
| 94 | |||
| 95 | EmacsTooltip *ns_tooltip = nil; | 92 | EmacsTooltip *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 */ |
| @@ -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 | ||
| 1396 | static 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 | |||
| 1407 | void | ||
| 1408 | ns_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 | ||
| 1400 | DEFUN ("ns-read-file-name", Fns_read_file_name, Sns_read_file_name, 1, 5, 0, | 1432 | DEFUN ("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 | { |
| @@ -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. |
diff --git a/src/nsterm.h b/src/nsterm.h index fd8c9baa3e4..745b8a4145b 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -286,8 +286,7 @@ typedef float EmacsCGFloat; | |||
| 286 | /* ========================================================================== | 286 | /* ========================================================================== |
| 287 | 287 | ||
| 288 | File open/save panels | 288 | File open/save panels |
| 289 | This and next override methods to work around OS X behavior of | 289 | This and next override methods to handle keyboard input in panels. |
| 290 | restarting application loop when user dismisses panel. | ||
| 291 | 290 | ||
| 292 | ========================================================================== */ | 291 | ========================================================================== */ |
| 293 | 292 | ||
| @@ -838,6 +837,9 @@ extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object contents, | |||
| 838 | #define NSAPP_DATA2_RUNASSCRIPT 10 | 837 | #define NSAPP_DATA2_RUNASSCRIPT 10 |
| 839 | extern void ns_run_ascript (void); | 838 | extern void ns_run_ascript (void); |
| 840 | 839 | ||
| 840 | #define NSAPP_DATA2_RUNFILEDIALOG 11 | ||
| 841 | extern void ns_run_file_dialog (void); | ||
| 842 | |||
| 841 | extern const char *ns_etc_directory (void); | 843 | extern const char *ns_etc_directory (void); |
| 842 | extern const char *ns_exec_path (void); | 844 | extern const char *ns_exec_path (void); |
| 843 | extern const char *ns_load_path (void); | 845 | extern const char *ns_load_path (void); |
diff --git a/src/nsterm.m b/src/nsterm.m index 93f693fe55e..97a6313489d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -4419,15 +4419,22 @@ ns_term_shutdown (int sig) | |||
| 4419 | /* NSTRACE (sendEvent); */ | 4419 | /* NSTRACE (sendEvent); */ |
| 4420 | /*fprintf (stderr, "received event of type %d\t%d\n", type);*/ | 4420 | /*fprintf (stderr, "received event of type %d\t%d\n", type);*/ |
| 4421 | 4421 | ||
| 4422 | #ifdef NS_IMPL_COCOA | 4422 | if (type == NSApplicationDefined) |
| 4423 | if (type == NSApplicationDefined | ||
| 4424 | && [theEvent data2] == NSAPP_DATA2_RUNASSCRIPT) | ||
| 4425 | { | 4423 | { |
| 4426 | ns_run_ascript (); | 4424 | switch ([theEvent data2]) |
| 4427 | [self stop: self]; | 4425 | { |
| 4428 | return; | 4426 | #ifdef NS_IMPL_COCOA |
| 4429 | } | 4427 | case NSAPP_DATA2_RUNASSCRIPT: |
| 4428 | ns_run_ascript (); | ||
| 4429 | [self stop: self]; | ||
| 4430 | return; | ||
| 4430 | #endif | 4431 | #endif |
| 4432 | case NSAPP_DATA2_RUNFILEDIALOG: | ||
| 4433 | ns_run_file_dialog (); | ||
| 4434 | [self stop: self]; | ||
| 4435 | return; | ||
| 4436 | } | ||
| 4437 | } | ||
| 4431 | 4438 | ||
| 4432 | if (type == NSCursorUpdate && window == nil) | 4439 | if (type == NSCursorUpdate && window == nil) |
| 4433 | { | 4440 | { |