diff src/nsmenu.m @ 101797:2dad5b4d31d5

* nsmenu.m (pop_down_menu): New function. (ns_popup_dialog): Call it on unwind. (EmacsDialogPanel-runDialogAt:): Check popup_activated_flag and call timer_check() (Bug#2154). (EmacsMenu-menuNeedsUpdate:): Don't call ns_update_menu if handling_signal is set. (EmacsMenu-fillWithWidgetValue:): Set submenu title. * s/darwin.h: Same and NO_SOCK_SIGIO as well. * nsterm.m (ns_read_socket): Same and don't set handling_signal. * keyboard.c (poll_for_input_1, handle_async_input): Set handling_signal under HAVE_NS.
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Wed, 04 Feb 2009 11:31:28 +0000
parents cfaf6934d659
children 2ce0c9304190
line wrap: on
line diff
--- a/src/nsmenu.m	Wed Feb 04 10:49:04 2009 +0000
+++ b/src/nsmenu.m	Wed Feb 04 11:31:28 2009 +0000
@@ -573,7 +573,10 @@
      since key equivalents are handled through emacs.
      On Leopard, even keystroke events generate SystemDefined events, but
      their subtype is 8. */
-  if ([event type] != NSSystemDefined || [event subtype] == 8)
+  if ([event type] != NSSystemDefined || [event subtype] == 8
+      /* Also, don't try this if from an event picked up asynchronously,
+         as lots of lisp evaluation happens in ns_update_menubar. */
+      || handling_signal != 0)
     return;
 /*fprintf (stderr, "Updating menu '%s'\n", [[self title] UTF8String]); NSLog (@"%@\n", event); */
   ns_update_menubar (frame, 1, self);
@@ -688,7 +691,7 @@
 
       if (wv->contents)
         {
-          EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: @"Submenu"];
+          EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]];
 
           [self setSubmenu: submenu forItem: item];
           [submenu fillWithWidgetValue: wv->contents];
@@ -1485,6 +1488,20 @@
 
    ========================================================================== */
 
+
+static Lisp_Object
+pop_down_menu (Lisp_Object arg)
+{
+  struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
+  popup_activated_flag = 0;
+  BLOCK_INPUT;
+  [((EmacsDialogPanel *) (p->pointer)) close];
+  [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
+  UNBLOCK_INPUT;
+  return Qnil;
+}
+
+
 Lisp_Object
 ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
 {
@@ -1539,13 +1556,18 @@
   p.y = (int)f->top_pos + (FRAME_LINE_HEIGHT (f) * f->text_lines)/2;
   dialog = [[EmacsDialogPanel alloc] initFromContents: contents
                                            isQuestion: isQ];
-  popup_activated_flag = 1;
-  tem = [dialog runDialogAt: p];
-  popup_activated_flag = 0;
+  {
+    int specpdl_count = SPECPDL_INDEX ();
+    record_unwind_protect (pop_down_menu, make_save_value (dialog, 0));
+    popup_activated_flag = 1;
+    tem = [dialog runDialogAt: p];
+    popup_activated_flag = 0;
+    unbind_to (specpdl_count, Qnil);
+  }
 
   [dialog close];
+  [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
 
-  [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
   return tem;
 }
 
@@ -1858,12 +1880,14 @@
   [self orderFront: NSApp];
 
   session = [NSApp beginModalSessionForWindow: self];
-  while ((ret = [NSApp runModalSession: session]) == NSRunContinuesResponse)
+  while (popup_activated_flag
+         && (ret = [NSApp runModalSession: session]) == NSRunContinuesResponse)
     {
-    (e = [NSApp nextEventMatchingMask: NSAnyEventMask
-                            untilDate: [NSDate distantFuture]
-                               inMode: NSModalPanelRunLoopMode
-                              dequeue: NO]);
+      timer_check (1);  // for timers.el, indep of atimers; might not return
+      e = [NSApp nextEventMatchingMask: NSAnyEventMask
+                             untilDate: [NSDate dateWithTimeIntervalSinceNow: 1]
+                                inMode: NSModalPanelRunLoopMode
+                               dequeue: NO];
 /*fprintf (stderr, "ret = %d\te = %p\n", ret, e);*/
     }
   [NSApp endModalSession: session];
@@ -1878,7 +1902,6 @@
 @end
 
 
-
 /* ==========================================================================
 
     Lisp definitions