Fix services menu empty on OSX 1.6+.
authorJan Djärv <jan.h.d@swipnet.se>
Fri, 8 Jul 2011 08:11:35 +0000 (10:11 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Fri, 8 Jul 2011 08:11:35 +0000 (10:11 +0200)
* nsfns.m (Fx_open_connection): Remove NSStringPboardType from
ns_return_types.
(Fns_list_services): Just return Qnil on 10.6, code not working there.

* nsmenu.m (ns_update_menubar): Remove useless setDelegate call
on svcsMenu.

* nsselect.m (ns_get_local_selection): Change to extern (Bug#8842).

* nsterm.h (MAC_OS_X_VERSION_10_6): Define here instead of nsterm.m.
(ns_get_local_selection): Declare.

* nsterm.m (QUTF8_STRING): Declare.
(initFrameFromEmacs): Call registerServicesMenuSendTypes.
(validRequestorForSendType): Return type is (id).
Change indexOfObjectIdenticalTo to indexOfObject.
Check if we have local selection before returning self (Bug#8842).
(writeSelectionToPasteboard): Put local selection into paste board
if we have a local selection (Bug#8842).
(syms_of_nsterm): DEFSYM QUTF8_STRING.

src/ChangeLog
src/nsfns.m
src/nsmenu.m
src/nsselect.m
src/nsterm.h
src/nsterm.m

index 4cacc67..c925b32 100644 (file)
@@ -1,3 +1,26 @@
+2011-07-08  Jan Djärv  <jan.h.d@swipnet.se>
+
+       * nsselect.m (ns_get_local_selection): Change to extern (Bug#8842).
+
+       * nsmenu.m (ns_update_menubar): Remove useless setDelegate call
+       on svcsMenu (Bug#8842).
+
+       * nsfns.m (Fx_open_connection): Remove NSStringPboardType from
+       ns_return_types.
+       (Fns_list_services): Just return Qnil on 10.6, code not working there.
+
+       * nsterm.m (QUTF8_STRING): Declare.
+       (initFrameFromEmacs): Call registerServicesMenuSendTypes.
+       (validRequestorForSendType): Return type is (id).
+       Change indexOfObjectIdenticalTo to indexOfObject.
+       Check if we have local selection before returning self (Bug#8842).
+       (writeSelectionToPasteboard): Put local selection into paste board
+       if we have a local selection (Bug#8842).
+       (syms_of_nsterm): DEFSYM QUTF8_STRING.
+
+       * nsterm.h (MAC_OS_X_VERSION_10_6): Define here instead of nsterm.m.
+       (ns_get_local_selection): Declare.
+
 2011-07-07  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * keymap.c (describe_map_tree): Don't insert a double newline at
index cdf3500..d124f61 100644 (file)
@@ -1728,8 +1728,8 @@ terminate Emacs if we can't open the connection.
 
   /* Register our external input/output types, used for determining
      applicable services and also drag/drop eligibility. */
-  ns_send_types = [[NSArray arrayWithObject: NSStringPboardType] retain];
-  ns_return_types = [[NSArray arrayWithObject: NSStringPboardType] retain];
+  ns_send_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] retain];
+  ns_return_types = [[NSArray arrayWithObjects: nil] retain];
   ns_drag_types = [[NSArray arrayWithObjects:
                             NSStringPboardType,
                             NSTabularTextPboardType,
@@ -1876,6 +1876,10 @@ DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
        doc: /* List available Nextstep services by querying NSApp.  */)
      (void)
 {
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+  /* You can't get services like this in 10.6+.  */
+  return Qnil;
+#else
   Lisp_Object ret = Qnil;
   NSMenu *svcs;
   id delegate;
@@ -1919,6 +1923,7 @@ DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
 
   ret = interpret_services_menu (svcs, Qnil, ret);
   return ret;
+#endif
 }
 
 
index 2a2f952..0d25b82 100644 (file)
@@ -457,7 +457,6 @@ ns_update_menubar (struct frame *f, int deep_p, EmacsMenu *submenu)
             {
               /* but we need to make sure it will update on demand */
               [svcsMenu setFrame: f];
-              [svcsMenu setDelegate: svcsMenu];
             }
           else
 #endif
index 950fb1f..aeb2a3e 100644 (file)
@@ -175,7 +175,7 @@ ns_string_to_pasteboard_internal (id pb, Lisp_Object str, NSString *gtype)
 }
 
 
-static Lisp_Object
+Lisp_Object
 ns_get_local_selection (Lisp_Object selection_name,
                        Lisp_Object target_type)
 {
index 7459087..b442973 100644 (file)
@@ -25,6 +25,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_NS
 
+#ifdef NS_IMPL_COCOA
+#ifndef MAC_OS_X_VERSION_10_6
+#define MAC_OS_X_VERSION_10_6 1060
+#endif
+#endif
+
 #ifdef __OBJC__
 
 /* ==========================================================================
@@ -700,6 +706,8 @@ extern void check_ns (void);
 extern Lisp_Object ns_map_event_to_object ();
 extern Lisp_Object ns_string_from_pasteboard ();
 extern void ns_string_to_pasteboard ();
+extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
+                                           Lisp_Object target_type);
 extern void nxatoms_of_nsselect ();
 extern int ns_lisp_to_cursor_type ();
 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
index 52e0dc6..ac95409 100644 (file)
@@ -134,11 +134,12 @@ static unsigned convert_ns_to_X_keysym[] =
   0x1B,                                0x1B   /* escape */
 };
 
-
 static Lisp_Object Qmodifier_value;
 Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper, Qnone;
 extern Lisp_Object Qcursor_color, Qcursor_type, Qns, Qleft;
 
+static Lisp_Object QUTF8_STRING;
+
 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
    the maximum font size to NOT antialias.  On GNUstep there is currently
    no way to control this behavior. */
@@ -5364,6 +5365,9 @@ ns_term_shutdown (int sig)
 
   [self allocateGState];
 
+  [NSApp registerServicesMenuSendTypes: ns_send_types
+                           returnTypes: ns_return_types];
+
   ns_window_num++;
   return self;
 }
@@ -5735,13 +5739,17 @@ ns_term_shutdown (int sig)
 }
 
 
-- validRequestorForSendType: (NSString *)typeSent
-                 returnType: (NSString *)typeReturned
+- (id) validRequestorForSendType: (NSString *)typeSent
+                      returnType: (NSString *)typeReturned
 {
   NSTRACE (validRequestorForSendType);
-  if ([ns_send_types indexOfObjectIdenticalTo: typeSent] != NSNotFound &&
-      [ns_return_types indexOfObjectIdenticalTo: typeSent] != NSNotFound)
-    return self;
+  if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound
+      && (typeReturned == nil
+          || [ns_return_types indexOfObject: typeSent] != NSNotFound))
+    {
+      if (! NILP (ns_get_local_selection (QPRIMARY, QUTF8_STRING)))
+        return self;
+    }
 
   return [super validRequestorForSendType: typeSent
                                returnType: typeReturned];
@@ -5765,8 +5773,28 @@ ns_term_shutdown (int sig)
 
 - (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pb types: (NSArray *)types
 {
-  /* supposed to write for as many of types as we are able */
-  return NO;
+  NSArray *typesDeclared;
+  Lisp_Object val;
+
+  /* We only support NSStringPboardType */
+  if ([types containsObject:NSStringPboardType] == NO) {
+    return NO;
+  }
+
+  val = ns_get_local_selection (QPRIMARY, QUTF8_STRING);
+  if (CONSP (val) && SYMBOLP (XCAR (val)))
+    {
+      val = XCDR (val);
+      if (CONSP (val) && NILP (XCDR (val)))
+        val = XCAR (val);
+    }
+  if (! STRINGP (val))
+    return NO;
+
+  typesDeclared = [NSArray arrayWithObject:NSStringPboardType];
+  [pb declareTypes:typesDeclared owner:nil];
+  ns_string_to_pasteboard (pb, val);
+  return YES;
 }
 
 
@@ -6390,6 +6418,8 @@ syms_of_nsterm (void)
   DEFSYM (Qsuper, "super");
   DEFSYM (Qcontrol, "control");
   DEFSYM (Qnone, "none");
+  DEFSYM (QUTF8_STRING, "UTF8_STRING");
+
   Fput (Qalt, Qmodifier_value, make_number (alt_modifier));
   Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier));
   Fput (Qmeta, Qmodifier_value, make_number (meta_modifier));