]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve font dialog on macOS
authorPo Lu <luangruo@yahoo.com>
Mon, 2 May 2022 07:06:58 +0000 (15:06 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 2 May 2022 07:06:58 +0000 (15:06 +0800)
* src/nsterm.m ([EmacsView changeFont:]): Don't exit loop here
on macOS.
([EmacsView noteUserSelectedFont]): New function.
([EmacsView showFontPanel]): Add explicit "OK" button on macOS.

src/nsterm.m

index f9d46c73d7316f23ebcaaf62fc5e167634a5e413..f2bf1c1c4a9a5cd36695d59543aea430962911fe 100644 (file)
@@ -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;