From: Po Lu Date: Mon, 2 May 2022 07:06:58 +0000 (+0800) Subject: Improve font dialog on macOS X-Git-Tag: emacs-29.0.90~1931^2~140 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a6a4f1d6d16bfc4d33c09d6d5a8038786d8e1325;p=emacs.git Improve font dialog on macOS * src/nsterm.m ([EmacsView changeFont:]): Don't exit loop here on macOS. ([EmacsView noteUserSelectedFont]): New function. ([EmacsView showFontPanel]): Add explicit "OK" button on macOS. --- diff --git a/src/nsterm.m b/src/nsterm.m index f9d46c73d73..f2bf1c1c4a9 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -6170,9 +6170,19 @@ ns_font_desc_to_font_spec (NSFontDescriptor *desc, NSFont *font) if (font_panel_result) [font_panel_result retain]; +#ifndef NS_IMPL_COCOA + font_panel_active = NO; + [NSApp stop: self]; +#endif +} + +#ifdef NS_IMPL_COCOA +- (void) noteUserSelectedFont +{ font_panel_active = NO; [NSApp stop: self]; } +#endif - (Lisp_Object) showFontPanel { @@ -6180,6 +6190,10 @@ ns_font_desc_to_font_spec (NSFontDescriptor *desc, NSFont *font) struct font *font = FRAME_OUTPUT_DATA (emacsframe)->font; NSFont *nsfont, *result; struct timespec timeout; +#ifdef NS_IMPL_COCOA + NSButton *button; + BOOL canceled; +#endif #ifdef NS_IMPL_GNUSTEP nsfont = ((struct nsfont_info *) font)->nsfont; @@ -6187,6 +6201,21 @@ ns_font_desc_to_font_spec (NSFontDescriptor *desc, NSFont *font) nsfont = (NSFont *) macfont_get_nsctfont (font); #endif +#ifdef NS_IMPL_COCOA + /* FIXME: this button could be made a lot prettier, but I don't know + how. */ + button = [[NSButton alloc] initWithFrame: NSMakeRect (0, 0, 192, 40)]; + [button setTitle: @"OK"]; + [button setTarget: self]; + [button setAction: @selector (noteUserSelectedFont)]; + [button setButtonType: NSButtonTypeMomentaryPushIn]; + [button setHidden: NO]; + + [[fm fontPanel: YES] setAccessoryView: button]; + [button release]; + [[fm fontPanel: YES] setDefaultButtonCell: [button cell]]; +#endif + [fm setSelectedFont: nsfont isMultiple: NO]; [fm orderFrontFontPanel: NSApp]; @@ -6195,13 +6224,23 @@ ns_font_desc_to_font_spec (NSFontDescriptor *desc, NSFont *font) block_input (); while (font_panel_active - && [[fm fontPanel: YES] isVisible]) +#ifdef NS_IMPL_COCOA + && (canceled = [[fm fontPanel: YES] isVisible]) +#else + && [[fm fontPanel: YES] isVisible] +#endif + ) ns_select_1 (0, NULL, NULL, NULL, &timeout, NULL, YES); unblock_input (); if (font_panel_result) [font_panel_result autorelease]; +#ifdef NS_IMPL_COCOA + if (!canceled) + font_panel_result = nil; +#endif + result = font_panel_result; font_panel_result = nil;