diff options
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/nsfns.m | 69 |
2 files changed, 44 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index fca0b104f8c..e0201b2ab1a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-12-31 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * nsfns.m (ns_set_name_as_filename): Always use buffer name for | ||
| 4 | title and buffer filename only for RepresentedFilename. | ||
| 5 | Handle bad UTF-8 in buffer name (Bug#7517). | ||
| 6 | |||
| 1 | 2010-12-30 Jan Djärv <jan.h.d@swipnet.se> | 7 | 2010-12-30 Jan Djärv <jan.h.d@swipnet.se> |
| 2 | 8 | ||
| 3 | * coding.h (ENCODE_UTF_8): Remove "Used by ..." comment. | 9 | * coding.h (ENCODE_UTF_8): Remove "Used by ..." comment. |
diff --git a/src/nsfns.m b/src/nsfns.m index 1b467297651..4de3caa62f7 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -602,12 +602,13 @@ void | |||
| 602 | ns_set_name_as_filename (struct frame *f) | 602 | ns_set_name_as_filename (struct frame *f) |
| 603 | { | 603 | { |
| 604 | NSView *view; | 604 | NSView *view; |
| 605 | Lisp_Object name; | 605 | Lisp_Object name, filename; |
| 606 | Lisp_Object buf = XWINDOW (f->selected_window)->buffer; | 606 | Lisp_Object buf = XWINDOW (f->selected_window)->buffer; |
| 607 | const char *title; | 607 | const char *title; |
| 608 | NSAutoreleasePool *pool; | 608 | NSAutoreleasePool *pool; |
| 609 | struct gcpro gcpro1; | 609 | struct gcpro gcpro1; |
| 610 | Lisp_Object encoded_name; | 610 | Lisp_Object encoded_name, encoded_filename; |
| 611 | NSString *str; | ||
| 611 | NSTRACE (ns_set_name_as_filename); | 612 | NSTRACE (ns_set_name_as_filename); |
| 612 | 613 | ||
| 613 | if (f->explicit_name || ! NILP (f->title) || ns_in_resize) | 614 | if (f->explicit_name || ! NILP (f->title) || ns_in_resize) |
| @@ -615,16 +616,16 @@ ns_set_name_as_filename (struct frame *f) | |||
| 615 | 616 | ||
| 616 | BLOCK_INPUT; | 617 | BLOCK_INPUT; |
| 617 | pool = [[NSAutoreleasePool alloc] init]; | 618 | pool = [[NSAutoreleasePool alloc] init]; |
| 618 | name = XBUFFER (buf)->filename; | 619 | filename = XBUFFER (buf)->filename; |
| 619 | if (NILP (name) || FRAME_ICONIFIED_P (f)) name = XBUFFER (buf)->name; | 620 | name = XBUFFER (buf)->name; |
| 620 | |||
| 621 | if (FRAME_ICONIFIED_P (f) && !NILP (f->icon_name)) | ||
| 622 | name = f->icon_name; | ||
| 623 | 621 | ||
| 624 | if (NILP (name)) | 622 | if (NILP (name)) |
| 625 | name = build_string ([ns_app_name UTF8String]); | 623 | { |
| 626 | else | 624 | if (! NILP (filename)) |
| 627 | CHECK_STRING (name); | 625 | name = Ffile_name_nondirectory (filename); |
| 626 | else | ||
| 627 | name = build_string ([ns_app_name UTF8String]); | ||
| 628 | } | ||
| 628 | 629 | ||
| 629 | GCPRO1 (name); | 630 | GCPRO1 (name); |
| 630 | encoded_name = ENCODE_UTF_8 (name); | 631 | encoded_name = ENCODE_UTF_8 (name); |
| @@ -642,33 +643,39 @@ ns_set_name_as_filename (struct frame *f) | |||
| 642 | return; | 643 | return; |
| 643 | } | 644 | } |
| 644 | 645 | ||
| 645 | if (! FRAME_ICONIFIED_P (f)) | 646 | str = [NSString stringWithUTF8String: SDATA (encoded_name)]; |
| 647 | if (str == nil) str = @"Bad coding"; | ||
| 648 | |||
| 649 | if (FRAME_ICONIFIED_P (f)) | ||
| 650 | [[view window] setMiniwindowTitle: str]; | ||
| 651 | else | ||
| 646 | { | 652 | { |
| 647 | #ifdef NS_IMPL_COCOA | 653 | NSString *fstr; |
| 648 | /* work around a bug observed on 10.3 where | 654 | |
| 649 | setTitleWithRepresentedFilename does not clear out previous state | 655 | if (! NILP (filename)) |
| 650 | if given filename does not exist */ | ||
| 651 | NSString *str = [NSString stringWithUTF8String: SDATA (encoded_name)]; | ||
| 652 | if (![[NSFileManager defaultManager] fileExistsAtPath: str]) | ||
| 653 | { | 656 | { |
| 654 | [[view window] setTitleWithRepresentedFilename: @""]; | 657 | GCPRO1 (filename); |
| 655 | [[view window] setTitle: str]; | 658 | encoded_filename = ENCODE_UTF_8 (filename); |
| 659 | UNGCPRO; | ||
| 660 | |||
| 661 | fstr = [NSString stringWithUTF8String: SDATA (encoded_filename)]; | ||
| 662 | if (fstr == nil) fstr = @""; | ||
| 663 | #ifdef NS_IMPL_COCOA | ||
| 664 | /* work around a bug observed on 10.3 and later where | ||
| 665 | setTitleWithRepresentedFilename does not clear out previous state | ||
| 666 | if given filename does not exist */ | ||
| 667 | if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr]) | ||
| 668 | [[view window] setRepresentedFilename: @""]; | ||
| 669 | #endif | ||
| 656 | } | 670 | } |
| 657 | else | 671 | else |
| 658 | { | 672 | fstr = @""; |
| 659 | [[view window] setTitleWithRepresentedFilename: str]; | 673 | |
| 660 | } | 674 | [[view window] setRepresentedFilename: fstr]; |
| 661 | #else | 675 | [[view window] setTitle: str]; |
| 662 | [[view window] setTitleWithRepresentedFilename: | ||
| 663 | [NSString stringWithUTF8String: SDATA (encoded_name)]]; | ||
| 664 | #endif | ||
| 665 | f->name = name; | 676 | f->name = name; |
| 666 | } | 677 | } |
| 667 | else | 678 | |
| 668 | { | ||
| 669 | [[view window] setMiniwindowTitle: | ||
| 670 | [NSString stringWithUTF8String: SDATA (encoded_name)]]; | ||
| 671 | } | ||
| 672 | [pool release]; | 679 | [pool release]; |
| 673 | UNBLOCK_INPUT; | 680 | UNBLOCK_INPUT; |
| 674 | } | 681 | } |