Hi,

awesome!

So is the attached patch OK? (Not sure why a method like this exists at all, but hey.)

Lubos

On Wed, 19 Jun 2013 18:22:36 +0100, David Chisnall wrote:
Hi Lubos,

Take a look in -base.  I wrote some support stuff that makes this
easy.  There's a macro for declaring block types and another for
invoking them.  These work with clang and gcc (you can only create
blocks with clang, but you can call them via the macros).  It's
recommended to build -base with clang if you want to use blocks, or
you'll end up with the runtime detecting type mismatches on selectors,
but it will still work if you compile it with gcc.

David

On 19 Jun 2013, at 18:19, Luboš Doležel <[email protected]> wrote:

Hi,

I was playing around with NSSavePanel and noticed gnustep-gui doesn't support methods such as

- (void)beginSheetModalForWindow:(NSWindow *)window completionHandler:(void (^)(NSInteger result))handler

I also couldn't find any other method that would use blocks. Since there already is blocks support in libobjc2, it's a shame.

Now I understand that blocks support is something that needs to be detected and enabled by configure, so that runtimes/compilers without blocks still work.

Well, I don't feel up to the task of doing the detection, but would like to contribute methods like the one above. Could someone else please introduce the required changes? :-)
Index: Headers/AppKit/NSSavePanel.h
===================================================================
--- Headers/AppKit/NSSavePanel.h	(revision 36733)
+++ Headers/AppKit/NSSavePanel.h	(working copy)
@@ -34,6 +34,7 @@
 #ifndef _GNUstep_H_NSSavePanel
 #define _GNUstep_H_NSSavePanel
 #import <GNUstepBase/GSVersionMacros.h>
+#import <GNUstepBase/GSBlocks.h>
 
 #import <AppKit/NSPanel.h>
 
@@ -206,6 +207,12 @@
 		    contextInfo: (void *)contextInfo;
 #endif
 
+#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
+DEFINE_BLOCK_TYPE(GSSavePanelCompletionHandler, void, NSInteger);
+- (void) beginSheetModalForWindow:(NSWindow *)window
+               completionHandler:(GSSavePanelCompletionHandler)handler;
+#endif
+
 /*
  * Reading Save Information
  */
Index: Source/NSSavePanel.m
===================================================================
--- Source/NSSavePanel.m	(revision 36733)
+++ Source/NSSavePanel.m	(working copy)
@@ -1110,6 +1110,13 @@
   return [self runModalForDirectory: [self directory] file: [self filename]];
 }
 
+- (void) beginSheetModalForWindow:(NSWindow *)window
+                completionHandler:(GSSavePanelCompletionHandler)handler
+{
+  NSInteger result = [self runModal];
+  CALL_BLOCK(handler, result);
+}
+
 /**<p> Initializes the panel to the directory specified by path and,
   optionally, the file specified by filename, then displays it and
   begins its modal event loop; path and filename can be empty
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to