diff options
| author | Jan Djärv | 2013-03-16 14:52:12 +0100 |
|---|---|---|
| committer | Jan Djärv | 2013-03-16 14:52:12 +0100 |
| commit | 8f2906f551da4a06c0097887e8ad61b8144baeac (patch) | |
| tree | d262fad9285dde83ce3cc99777007de5091296d2 /src | |
| parent | 3f53a2bd1aeabffce2dcbb29cb4e36eb46ca6240 (diff) | |
| download | emacs-8f2906f551da4a06c0097887e8ad61b8144baeac.tar.gz emacs-8f2906f551da4a06c0097887e8ad61b8144baeac.zip | |
* nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New
functions.
(Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose
directories. If filename is nil, get directory name.
Use getFilename and getDirectory.
(getFilename, getDirectory): New methods for EmacsSavePanel and
EmacsOpenPanel.
(ok:): In EmacsOpenPanel, if we can't choose directories, just return.
* nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename
and getDirectory.
Fixes: debbugs:13932
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 14 | ||||
| -rw-r--r-- | src/nsfns.m | 66 | ||||
| -rw-r--r-- | src/nsterm.h | 4 |
3 files changed, 80 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 288996fffb2..d924772abad 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2013-03-16 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename | ||
| 4 | and getDirectory. | ||
| 5 | |||
| 6 | * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New | ||
| 7 | functions. | ||
| 8 | (Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose | ||
| 9 | directories. If filename is nil, get directory name (Bug#13932). | ||
| 10 | Use getFilename and getDirectory. | ||
| 11 | (getFilename, getDirectory): New methods for EmacsSavePanel and | ||
| 12 | EmacsOpenPanel. | ||
| 13 | (ok:): In EmacsOpenPanel, if we can't choose directories, just return. | ||
| 14 | |||
| 1 | 2013-03-15 Paul Eggert <eggert@cs.ucla.edu> | 15 | 2013-03-15 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 16 | ||
| 3 | * coding.c (decode_coding_gap): Fix typo caught by static checking. | 17 | * coding.c (decode_coding_gap): Fix typo caught by static checking. |
diff --git a/src/nsfns.m b/src/nsfns.m index e4dde5fb894..ef18acaa045 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -261,6 +261,29 @@ ns_display_info_for_name (Lisp_Object name) | |||
| 261 | return dpyinfo; | 261 | return dpyinfo; |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | static NSString * | ||
| 265 | ns_filename_from_panel (NSSavePanel *panel) | ||
| 266 | { | ||
| 267 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 268 | NSURL *url = [panel URL]; | ||
| 269 | NSString *str = [url path]; | ||
| 270 | return str; | ||
| 271 | #else | ||
| 272 | return [panel filename]; | ||
| 273 | #endif | ||
| 274 | } | ||
| 275 | |||
| 276 | static NSString * | ||
| 277 | ns_directory_from_panel (NSSavePanel *panel) | ||
| 278 | { | ||
| 279 | #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 280 | NSURL *url = [panel directoryURL]; | ||
| 281 | NSString *str = [url path]; | ||
| 282 | return str; | ||
| 283 | #else | ||
| 284 | return [panel directory]; | ||
| 285 | #endif | ||
| 286 | } | ||
| 264 | 287 | ||
| 265 | static Lisp_Object | 288 | static Lisp_Object |
| 266 | interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) | 289 | interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) |
| @@ -1471,7 +1494,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) | |||
| 1471 | Lisp_Object init, Lisp_Object dir_only_p) | 1494 | Lisp_Object init, Lisp_Object dir_only_p) |
| 1472 | { | 1495 | { |
| 1473 | static id fileDelegate = nil; | 1496 | static id fileDelegate = nil; |
| 1474 | int ret; | 1497 | BOOL ret; |
| 1475 | id panel; | 1498 | id panel; |
| 1476 | Lisp_Object fname; | 1499 | Lisp_Object fname; |
| 1477 | 1500 | ||
| @@ -1508,6 +1531,13 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) | |||
| 1508 | [panel setCanChooseDirectories: YES]; | 1531 | [panel setCanChooseDirectories: YES]; |
| 1509 | [panel setCanChooseFiles: NO]; | 1532 | [panel setCanChooseFiles: NO]; |
| 1510 | } | 1533 | } |
| 1534 | else | ||
| 1535 | { | ||
| 1536 | /* This is not quite what the documentation says, but it is compatible | ||
| 1537 | with the Gtk+ code. Also, the menu entry says "Open File...". */ | ||
| 1538 | [panel setCanChooseDirectories: NO]; | ||
| 1539 | [panel setCanChooseFiles: YES]; | ||
| 1540 | } | ||
| 1511 | 1541 | ||
| 1512 | block_input (); | 1542 | block_input (); |
| 1513 | #if defined (NS_IMPL_COCOA) && \ | 1543 | #if defined (NS_IMPL_COCOA) && \ |
| @@ -1528,15 +1558,19 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */) | |||
| 1528 | } | 1558 | } |
| 1529 | else | 1559 | else |
| 1530 | { | 1560 | { |
| 1531 | [panel setCanChooseDirectories: YES]; | ||
| 1532 | ret = [panel runModalForDirectory: dirS file: initS types: nil]; | 1561 | ret = [panel runModalForDirectory: dirS file: initS types: nil]; |
| 1533 | } | 1562 | } |
| 1534 | #endif | 1563 | #endif |
| 1535 | 1564 | ||
| 1536 | ret = (ret == NSOKButton) || panelOK; | 1565 | ret = (ret == NSOKButton) || panelOK; |
| 1537 | 1566 | ||
| 1538 | if (ret) | 1567 | if (ret) |
| 1539 | fname = build_string ([[panel filename] UTF8String]); | 1568 | { |
| 1569 | NSString *str = [panel getFilename]; | ||
| 1570 | if (! str) str = [panel getDirectory]; | ||
| 1571 | if (! str) ret = NO; | ||
| 1572 | else fname = build_string ([str UTF8String]); | ||
| 1573 | } | ||
| 1540 | 1574 | ||
| 1541 | [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; | 1575 | [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; |
| 1542 | unblock_input (); | 1576 | unblock_input (); |
| @@ -2603,6 +2637,14 @@ Value is t if tooltip was open, nil otherwise. */) | |||
| 2603 | [NSApp stop: self]; | 2637 | [NSApp stop: self]; |
| 2604 | } | 2638 | } |
| 2605 | #endif | 2639 | #endif |
| 2640 | - (NSString *) getFilename | ||
| 2641 | { | ||
| 2642 | return ns_filename_from_panel (self); | ||
| 2643 | } | ||
| 2644 | - (NSString *) getDirectory | ||
| 2645 | { | ||
| 2646 | return ns_directory_from_panel (self); | ||
| 2647 | } | ||
| 2606 | @end | 2648 | @end |
| 2607 | 2649 | ||
| 2608 | 2650 | ||
| @@ -2616,6 +2658,12 @@ Value is t if tooltip was open, nil otherwise. */) | |||
| 2616 | - (void) ok: (id)sender | 2658 | - (void) ok: (id)sender |
| 2617 | { | 2659 | { |
| 2618 | [super ok: sender]; | 2660 | [super ok: sender]; |
| 2661 | |||
| 2662 | // If not choosing directories, and Open is pressed on a directory, return. | ||
| 2663 | if (! [self canChooseDirectories] && [self getDirectory] && | ||
| 2664 | ! [self getFilename]) | ||
| 2665 | return; | ||
| 2666 | |||
| 2619 | panelOK = 1; | 2667 | panelOK = 1; |
| 2620 | [NSApp stop: self]; | 2668 | [NSApp stop: self]; |
| 2621 | } | 2669 | } |
| @@ -2624,7 +2672,17 @@ Value is t if tooltip was open, nil otherwise. */) | |||
| 2624 | [super cancel: sender]; | 2672 | [super cancel: sender]; |
| 2625 | [NSApp stop: self]; | 2673 | [NSApp stop: self]; |
| 2626 | } | 2674 | } |
| 2675 | |||
| 2627 | #endif | 2676 | #endif |
| 2677 | - (NSString *) getFilename | ||
| 2678 | { | ||
| 2679 | return ns_filename_from_panel (self); | ||
| 2680 | } | ||
| 2681 | - (NSString *) getDirectory | ||
| 2682 | { | ||
| 2683 | return ns_directory_from_panel (self); | ||
| 2684 | } | ||
| 2685 | |||
| 2628 | @end | 2686 | @end |
| 2629 | 2687 | ||
| 2630 | 2688 | ||
diff --git a/src/nsterm.h b/src/nsterm.h index 41dbaf3c0f7..6bd04b96684 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 267 | @interface EmacsSavePanel : NSSavePanel | 267 | @interface EmacsSavePanel : NSSavePanel |
| 268 | { | 268 | { |
| 269 | } | 269 | } |
| 270 | - (NSString *) getFilename; | ||
| 271 | - (NSString *) getDirectory; | ||
| 270 | @end | 272 | @end |
| 271 | @interface EmacsOpenPanel : NSOpenPanel | 273 | @interface EmacsOpenPanel : NSOpenPanel |
| 272 | { | 274 | { |
| 273 | } | 275 | } |
| 276 | - (NSString *) getFilename; | ||
| 277 | - (NSString *) getDirectory; | ||
| 274 | @end | 278 | @end |
| 275 | 279 | ||
| 276 | @interface EmacsFileDelegate : NSObject | 280 | @interface EmacsFileDelegate : NSObject |