GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/native/cocoa.m: wrap all cocoa alterations in an exception 
 handler. this solves the cross-thread EXC_BAD_ACCESS crash.
 * shoes/app.c: no need to remove the timers twice. (it's done in 
 shoes_app_clear already.)
 * lib/shoes/setup.rb: Shoes.visit isn't threadsafe, for some reason.  i 
 think there is some GC screwiness in there.
why (author)
Fri Oct 10 23:45:31 -0700 2008
commit  9191255455f39aa49b44f1c8e6dab95d33e01f07
tree    a68fdd78f156fa62833f61d27d5c553fe338f10d
parent  83dac2517a41140f3ccd7fc8f825b5b4967886bc
...
327
328
329
330
 
331
332
333
...
327
328
329
 
330
331
332
333
0
@@ -327,7 +327,7 @@ else
0
 
0
   case PLATFORM when /darwin/
0
     DLEXT = "dylib"
0
- LINUX_CFLAGS << " -DSHOES_QUARTZ -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fpascal-strings #{Config::CONFIG["CFLAGS"]} -x objective-c"
0
+ LINUX_CFLAGS << " -DSHOES_QUARTZ -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fpascal-strings #{Config::CONFIG["CFLAGS"]} -x objective-c -fobjc-exceptions"
0
     LINUX_LDFLAGS = "-framework Cocoa -framework Carbon -dynamiclib -Wl,-single_module #{Config::CONFIG["LDFLAGS"]} INSTALL_NAME"
0
     LINUX_LIB_NAMES << 'pixman-1' << 'jpeg.62'
0
     if ENV['VIDEO']
...
48
49
50
51
52
53
54
55
 
 
 
 
 
 
 
56
57
58
59
60
...
66
67
68
 
 
 
 
69
70
71
...
131
132
133
134
135
136
 
137
138
139
...
48
49
50
 
 
 
 
 
51
52
53
54
55
56
57
58
 
59
60
61
...
67
68
69
70
71
72
73
74
75
76
...
136
137
138
 
 
 
139
140
141
142
0
@@ -48,13 +48,14 @@ class Shoes::Setup
0
         end
0
 
0
         start do
0
- Thread.start(self.app) do |app|
0
- begin
0
- setup.start(app)
0
- rescue => e
0
- puts e.message
0
+ @th =
0
+ Thread.start(self.app) do |app|
0
+ begin
0
+ setup.start(app)
0
+ rescue => e
0
+ puts e.message
0
+ end
0
             end
0
- end
0
         end
0
       end
0
 
0
@@ -66,6 +67,10 @@ class Shoes::Setup
0
           stroke rgb(0.7, 0.7, 0.9, 1.0 - (i * 0.1))
0
           oval(@logo.left - i, @logo.top - i, @logo.width + (i * 2))
0
         end
0
+ if @script
0
+ Shoes.visit(@script)
0
+ close
0
+ end
0
       end
0
     end
0
   end
0
@@ -131,9 +136,7 @@ class Shoes::Setup
0
       ui.progress count, total
0
     end
0
     Gem::DefaultUserInteraction.ui = old_ui
0
-
0
- Shoes.visit(@script)
0
- app.close
0
+ app.instance_variable_set("@script", @script)
0
   end
0
 
0
   def svn(dir, save_as = nil, &blk)
...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
306
307
308
 
309
310
311
312
 
 
 
 
 
 
 
313
314
315
0
@@ -306,18 +306,10 @@ shoes_app_visit(shoes_app *app, char *path)
0
   shoes_exec exec;
0
   shoes_canvas *canvas;
0
   VALUE meth;
0
- VALUE ary = rb_ary_dup(app->extras);
0
   Data_Get_Struct(app->canvas, shoes_canvas, canvas);
0
 
0
   canvas->slot->scrolly = 0;
0
   shoes_native_slot_clear(canvas);
0
- for (i = 0; i < RARRAY_LEN(ary); i++)
0
- {
0
- VALUE timer = rb_ary_entry(ary, i);
0
- if (!NIL_P(timer))
0
- rb_funcall(timer, s_remove, 0);
0
- }
0
-
0
   shoes_app_clear(app);
0
   shoes_app_reset_styles(app);
0
   meth = rb_funcall(cShoes, s_run, 1, app->location = rb_str_new2(path));
...
14
15
16
 
 
 
 
 
 
17
18
19
...
643
644
645
646
647
 
 
 
 
648
649
650
...
698
699
700
701
 
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
 
 
 
 
 
 
 
 
718
719
720
...
723
724
725
726
 
727
728
729
...
736
737
738
739
740
741
 
742
743
744
...
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
782
783
...
838
839
840
841
 
842
843
844
845
846
847
 
848
849
850
...
884
885
886
887
 
888
889
890
891
892
893
894
895
 
896
897
898
...
975
976
977
978
979
980
 
981
982
983
...
1006
1007
1008
1009
1010
1011
 
1012
1013
1014
...
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
 
 
 
 
 
 
 
 
 
 
1041
1042
1043
...
1054
1055
1056
1057
 
1058
1059
1060
...
1078
1079
1080
1081
 
1082
1083
1084
...
1099
1100
1101
1102
 
1103
1104
1105
...
1115
1116
1117
1118
1119
1120
 
1121
1122
1123
...
1144
1145
1146
1147
1148
1149
1150
1151
 
 
 
 
 
1152
1153
1154
...
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
 
 
 
 
 
 
 
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
 
 
 
 
 
 
 
 
1231
1232
1233
...
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1266
1267
1268
...
1274
1275
1276
1277
1278
1279
1280
1281
1282
 
 
 
 
 
 
 
 
 
1283
1284
1285
...
14
15
16
17
18
19
20
21
22
23
24
25
...
649
650
651
 
 
652
653
654
655
656
657
658
...
706
707
708
 
709
710
711
712
713
714
 
715
716
717
 
 
 
 
 
 
 
718
719
720
721
722
723
724
725
726
727
728
...
731
732
733
 
734
735
736
737
...
744
745
746
 
 
 
747
748
749
750
...
758
759
760
 
761
762
763
764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
...
844
845
846
 
847
848
849
850
851
852
 
853
854
855
856
...
890
891
892
 
893
894
895
896
897
898
 
 
 
899
900
901
902
...
979
980
981
 
 
 
982
983
984
985
...
1008
1009
1010
 
 
 
1011
1012
1013
1014
...
1026
1027
1028
 
1029
1030
 
 
 
 
 
 
 
 
 
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
...
1054
1055
1056
 
1057
1058
1059
1060
...
1078
1079
1080
 
1081
1082
1083
1084
...
1099
1100
1101
 
1102
1103
1104
1105
...
1115
1116
1117
 
 
 
1118
1119
1120
1121
...
1142
1143
1144
 
 
 
 
 
1145
1146
1147
1148
1149
1150
1151
1152
...
1177
1178
1179
 
1180
 
 
 
 
 
 
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
 
1194
1195
1196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
 
1217
1218
 
 
 
 
 
 
 
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
...
1248
1249
1250
 
 
 
 
 
 
 
 
 
 
 
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
...
1273
1274
1275
 
 
 
 
 
 
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
0
@@ -14,6 +14,12 @@
0
 
0
 #define INIT NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
0
 #define RELEASE [pool release]
0
+#define COCOA_DO(statements) do {\
0
+ INIT; \
0
+ @try { statements; } \
0
+ @catch (NSException *e) { ; } \
0
+ RELEASE; \
0
+} while (0)
0
 
0
 @implementation ShoesEvents
0
 - (id)init
0
@@ -643,8 +649,10 @@ void shoes_native_slot_lengthen(SHOES_SLOT_OS *slot, int height, int endy)
0
   if (slot->vscroll)
0
   {
0
     float s = slot->scrolly * 1., e = endy * 1., h = height * 1., d = (endy - height) * 1.;
0
- [slot->vscroll setFloatValue: (d > 0 ? s / d : 0) knobProportion: (h / e)];
0
- [slot->vscroll setHidden: endy <= height ? YES : NO];
0
+ COCOA_DO({
0
+ [slot->vscroll setFloatValue: (d > 0 ? s / d : 0) knobProportion: (h / e)];
0
+ [slot->vscroll setHidden: endy <= height ? YES : NO];
0
+ });
0
   }
0
 }
0
 
0
@@ -698,23 +706,23 @@ shoes_native_app_resized(shoes_app *app)
0
 void
0
 shoes_native_app_title(shoes_app *app, char *msg)
0
 {
0
- [app->os.window setTitle: [NSString stringWithUTF8String: msg]];
0
+ COCOA_DO([app->os.window setTitle: [NSString stringWithUTF8String: msg]]);
0
 }
0
 
0
 shoes_code
0
 shoes_native_app_open(shoes_app *app, char *path, int dialog)
0
 {
0
- INIT;
0
   unsigned int mask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
0
   shoes_code code = SHOES_OK;
0
 
0
- if (app->resizable)
0
- mask |= NSResizableWindowMask;
0
- app->os.window = [[ShoesWindow alloc] initWithContentRect: NSMakeRect(0, 0, app->width, app->height)
0
- styleMask: mask backing: NSBackingStoreBuffered defer: NO];
0
- [app->os.window prepareWithApp: app->self];
0
- app->slot->view = [app->os.window contentView];
0
- RELEASE;
0
+ COCOA_DO({
0
+ if (app->resizable)
0
+ mask |= NSResizableWindowMask;
0
+ app->os.window = [[ShoesWindow alloc] initWithContentRect: NSMakeRect(0, 0, app->width, app->height)
0
+ styleMask: mask backing: NSBackingStoreBuffered defer: NO];
0
+ [app->os.window prepareWithApp: app->self];
0
+ app->slot->view = [app->os.window contentView];
0
+ });
0
 
0
 quit:
0
   return code;
0
@@ -723,7 +731,7 @@ quit:
0
 void
0
 shoes_native_app_show(shoes_app *app)
0
 {
0
- [app->os.window orderFront: nil];
0
+ COCOA_DO([app->os.window orderFront: nil]);
0
 }
0
 
0
 void
0
@@ -736,9 +744,7 @@ shoes_native_loop()
0
 void
0
 shoes_native_app_close(shoes_app *app)
0
 {
0
- INIT;
0
- [app->os.window close];
0
- RELEASE;
0
+ COCOA_DO([app->os.window close]);
0
 }
0
 
0
 void
0
@@ -752,32 +758,32 @@ shoes_browser_open(char *url)
0
 void
0
 shoes_slot_init(VALUE c, SHOES_SLOT_OS *parent, int x, int y, int width, int height, int scrolls, int toplevel)
0
 {
0
- INIT;
0
   shoes_canvas *canvas;
0
   SHOES_SLOT_OS *slot;
0
   Data_Get_Struct(c, shoes_canvas, canvas);
0
 
0
- slot = shoes_slot_alloc(canvas, parent, toplevel);
0
- slot->controls = parent->controls;
0
- slot->view = [[ShoesView alloc] initWithFrame: NSMakeRect(x, y, width, height) andCanvas: c];
0
- [slot->view setAutoresizesSubviews: NO];
0
- if (toplevel)
0
- [slot->view setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
0
- slot->vscroll = NULL;
0
- if (scrolls)
0
- {
0
- slot->vscroll = [[NSScroller alloc] initWithFrame:
0
- NSMakeRect(width - [NSScroller scrollerWidth], 0, [NSScroller scrollerWidth], height)];
0
- [slot->vscroll setEnabled: YES];
0
- [slot->vscroll setTarget: slot->view];
0
- [slot->vscroll setAction: @selector(scroll:)];
0
- [slot->view addSubview: slot->vscroll];
0
- }
0
- if (parent->vscroll)
0
- [parent->view addSubview: slot->view positioned: NSWindowBelow relativeTo: parent->vscroll];
0
- else
0
- [parent->view addSubview: slot->view];
0
- RELEASE;
0
+ COCOA_DO({
0
+ slot = shoes_slot_alloc(canvas, parent, toplevel);
0
+ slot->controls = parent->controls;
0
+ slot->view = [[ShoesView alloc] initWithFrame: NSMakeRect(x, y, width, height) andCanvas: c];
0
+ [slot->view setAutoresizesSubviews: NO];
0
+ if (toplevel)
0
+ [slot->view setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
0
+ slot->vscroll = NULL;
0
+ if (scrolls)
0
+ {
0
+ slot->vscroll = [[NSScroller alloc] initWithFrame:
0
+ NSMakeRect(width - [NSScroller scrollerWidth], 0, [NSScroller scrollerWidth], height)];
0
+ [slot->vscroll setEnabled: YES];
0
+ [slot->vscroll setTarget: slot->view];
0
+ [slot->vscroll setAction: @selector(scroll:)];
0
+ [slot->view addSubview: slot->vscroll];
0
+ }
0
+ if (parent->vscroll)
0
+ [parent->view addSubview: slot->view positioned: NSWindowBelow relativeTo: parent->vscroll];
0
+ else
0
+ [parent->view addSubview: slot->view];
0
+ });
0
 }
0
 
0
 void
0
@@ -838,13 +844,13 @@ shoes_native_canvas_resize(shoes_canvas *canvas)
0
 void
0
 shoes_native_control_hide(SHOES_CONTROL_REF ref)
0
 {
0
- [ref setHidden: YES];
0
+ COCOA_DO([ref setHidden: YES]);
0
 }
0
 
0
 void
0
 shoes_native_control_show(SHOES_CONTROL_REF ref)
0
 {
0
- [ref setHidden: NO];
0
+ COCOA_DO([ref setHidden: NO]);
0
 }
0
 
0
 static void
0
@@ -884,15 +890,13 @@ shoes_native_control_repaint(SHOES_CONTROL_REF ref, shoes_place *p1,
0
 void
0
 shoes_native_control_focus(SHOES_CONTROL_REF ref)
0
 {
0
- [[ref window] makeFirstResponder: ref];
0
+ COCOA_DO([[ref window] makeFirstResponder: ref]);
0
 }
0
 
0
 void
0
 shoes_native_control_remove(SHOES_CONTROL_REF ref, shoes_canvas *canvas)
0
 {
0
- INIT;
0
- [ref removeFromSuperview];
0
- RELEASE;
0
+ COCOA_DO([ref removeFromSuperview]);
0
 }
0
 
0
 void
0
@@ -975,9 +979,7 @@ shoes_native_edit_line_get_text(SHOES_CONTROL_REF ref)
0
 void
0
 shoes_native_edit_line_set_text(SHOES_CONTROL_REF ref, char *msg)
0
 {
0
- INIT;
0
- [ref setStringValue: [NSString stringWithUTF8String: msg]];
0
- RELEASE;
0
+ COCOA_DO([ref setStringValue: [NSString stringWithUTF8String: msg]]);
0
 }
0
 
0
 SHOES_CONTROL_REF
0
@@ -1006,9 +1008,7 @@ shoes_native_edit_box_get_text(SHOES_CONTROL_REF ref)
0
 void
0
 shoes_native_edit_box_set_text(SHOES_CONTROL_REF ref, char *msg)
0
 {
0
- INIT;
0
- [[[(ShoesTextView *)ref textStorage] mutableString] setString: [NSString stringWithUTF8String: msg]];
0
- RELEASE;
0
+ COCOA_DO([[[(ShoesTextView *)ref textStorage] mutableString] setString: [NSString stringWithUTF8String: msg]]);
0
 }
0
 
0
 SHOES_CONTROL_REF
0
@@ -1026,18 +1026,18 @@ shoes_native_list_box(VALUE self, shoes_canvas *canvas, shoes_place *place, VALU
0
 void
0
 shoes_native_list_box_update(SHOES_CONTROL_REF ref, VALUE ary)
0
 {
0
- INIT;
0
   long i;
0
   ShoesPopUpButton *pop = (ShoesPopUpButton *)ref;
0
- [pop removeAllItems];
0
- for (i = 0; i < RARRAY_LEN(ary); i++)
0
- {
0
- VALUE msg_s = shoes_native_to_s(rb_ary_entry(ary, i));
0
- char *msg = RSTRING_PTR(msg_s);
0
- [[pop menu] insertItemWithTitle: [NSString stringWithUTF8String: msg] action: nil
0
- keyEquivalent: @"" atIndex: i];
0
- }
0
- RELEASE;
0
+ COCOA_DO({
0
+ [pop removeAllItems];
0
+ for (i = 0; i < RARRAY_LEN(ary); i++)
0
+ {
0
+ VALUE msg_s = shoes_native_to_s(rb_ary_entry(ary, i));
0
+ char *msg = RSTRING_PTR(msg_s);
0
+ [[pop menu] insertItemWithTitle: [NSString stringWithUTF8String: msg] action: nil
0
+ keyEquivalent: @"" atIndex: i];
0
+ }
0
+ });
0
 }
0
 
0
 VALUE
0
@@ -1054,7 +1054,7 @@ shoes_native_list_box_set_active(SHOES_CONTROL_REF ref, VALUE ary, VALUE item)
0
 {
0
   int idx = rb_ary_index_of(ary, item);
0
   if (idx < 0) return;
0
- [(ShoesPopUpButton *)ref selectItemAtIndex: idx];
0
+ COCOA_DO([(ShoesPopUpButton *)ref selectItemAtIndex: idx]);
0
 }
0
 
0
 SHOES_CONTROL_REF
0
@@ -1078,7 +1078,7 @@ shoes_native_progress_get_fraction(SHOES_CONTROL_REF ref)
0
 void
0
 shoes_native_progress_set_fraction(SHOES_CONTROL_REF ref, double perc)
0
 {
0
- [(NSProgressIndicator *)ref setDoubleValue: perc * 100.];
0
+ COCOA_DO([(NSProgressIndicator *)ref setDoubleValue: perc * 100.]);
0
 }
0
 
0
 SHOES_CONTROL_REF
0
@@ -1099,7 +1099,7 @@ shoes_native_check_get(SHOES_CONTROL_REF ref)
0
 void
0
 shoes_native_check_set(SHOES_CONTROL_REF ref, int on)
0
 {
0
- [(ShoesButton *)ref setState: on ? NSOnState : NSOffState];
0
+ COCOA_DO([(ShoesButton *)ref setState: on ? NSOnState : NSOffState]);
0
 }
0
 
0
 SHOES_CONTROL_REF
0
@@ -1115,9 +1115,7 @@ shoes_native_radio(VALUE self, shoes_canvas *canvas, shoes_place *place, VALUE a
0
 void
0
 shoes_native_timer_remove(shoes_canvas *canvas, SHOES_TIMER_REF ref)
0
 {
0
- INIT;
0
- [ref invalidate];
0
- RELEASE;
0
+ COCOA_DO([ref invalidate]);
0
 }
0
 
0
 SHOES_TIMER_REF
0
@@ -1144,11 +1142,11 @@ shoes_native_clipboard_get(shoes_app *app)
0
 void
0
 shoes_native_clipboard_set(shoes_app *app, VALUE string)
0
 {
0
- INIT;
0
- [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
0
- [[NSPasteboard generalPasteboard] setString: [NSString stringWithUTF8String: RSTRING_PTR(string)]
0
- forType: NSStringPboardType];
0
- RELEASE;
0
+ COCOA_DO({
0
+ [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
0
+ [[NSPasteboard generalPasteboard] setString: [NSString stringWithUTF8String: RSTRING_PTR(string)]
0
+ forType: NSStringPboardType];
0
+ });
0
 }
0
 
0
 VALUE
0
@@ -1179,55 +1177,53 @@ shoes_native_dialog_color(shoes_app *app)
0
 VALUE
0
 shoes_dialog_alert(VALUE self, VALUE msg)
0
 {
0
- INIT;
0
   VALUE answer = Qnil;
0
- msg = shoes_native_to_s(msg);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes says:"
0
- defaultButton: @"OK" alternateButton: nil otherButton: nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(msg)]];
0
- [alert runModal];
0
- RELEASE;
0
+ COCOA_DO({
0
+ msg = shoes_native_to_s(msg);
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes says:"
0
+ defaultButton: @"OK" alternateButton: nil otherButton: nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(msg)]];
0
+ [alert runModal];
0
+ });
0
   return Qnil;
0
 }
0
 
0
 VALUE
0
 shoes_dialog_ask(int argc, VALUE *argv, VALUE self)
0
 {
0
- INIT;
0
   VALUE quiz, attr = Qnil, answer = Qnil;
0
   rb_scan_args(argc, argv, "11", &quiz, &attr);
0
   quiz = shoes_native_to_s(quiz);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
- defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(quiz)]];
0
- NSTextField *input;
0
- if (RTEST(ATTR(attr, secret)))
0
- input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
- else
0
- input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
- [input setStringValue:@""];
0
- [alert setAccessoryView:input];
0
- if ([alert runModal] == NSOKButton)
0
- {
0
- answer = rb_str_new2([[input stringValue] UTF8String]);
0
- }
0
- RELEASE;
0
+ COCOA_DO({
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
+ defaultButton:@"OK" alternateButton:@"Cancel" otherButton:nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: RSTRING_PTR(quiz)]];
0
+ NSTextField *input;
0
+ if (RTEST(ATTR(attr, secret)))
0
+ input = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
+ else
0
+ input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)];
0
+ [input setStringValue:@""];
0
+ [alert setAccessoryView:input];
0
+ if ([alert runModal] == NSOKButton)
0
+ answer = rb_str_new2([[input stringValue] UTF8String]);
0
+ });
0
   return answer;
0
 }
0
 
0
 VALUE
0
 shoes_dialog_confirm(VALUE self, VALUE quiz)
0
 {
0
- INIT;
0
   char *msg;
0
   VALUE answer = Qnil;
0
- quiz = shoes_native_to_s(quiz);
0
- msg = RSTRING_PTR(quiz);
0
- NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
- defaultButton: @"OK" alternateButton: @"Cancel" otherButton:nil
0
- informativeTextWithFormat: [NSString stringWithUTF8String: msg]];
0
- answer = ([alert runModal] == NSOKButton ? Qtrue : Qfalse);
0
- RELEASE;
0
+ COCOA_DO({
0
+ quiz = shoes_native_to_s(quiz);
0
+ msg = RSTRING_PTR(quiz);
0
+ NSAlert *alert = [NSAlert alertWithMessageText: @"Shoes asks:"
0
+ defaultButton: @"OK" alternateButton: @"Cancel" otherButton:nil
0
+ informativeTextWithFormat: [NSString stringWithUTF8String: msg]];
0
+ answer = ([alert runModal] == NSOKButton ? Qtrue : Qfalse);
0
+ });
0
   return answer;
0
 }
0
 
0
@@ -1252,17 +1248,20 @@ shoes_dialog_color(VALUE self, VALUE title)
0
 static VALUE
0
 shoes_dialog_chooser(VALUE self, NSString *title, BOOL directories)
0
 {
0
- NSOpenPanel* openDlg = [NSOpenPanel openPanel];
0
- [openDlg setCanChooseFiles: !directories];
0
- [openDlg setCanChooseDirectories: directories];
0
- [openDlg setAllowsMultipleSelection: NO];
0
- if ( [openDlg runModalForDirectory: nil file: nil] == NSOKButton )
0
- {
0
- NSArray* files = [openDlg filenames];
0
- char *filename = [[files objectAtIndex: 0] UTF8String];
0
- return rb_str_new2(filename);
0
- }
0
- return Qnil;
0
+ VALUE path = Qnil;
0
+ COCOA_DO({
0
+ NSOpenPanel* openDlg = [NSOpenPanel openPanel];
0
+ [openDlg setCanChooseFiles: !directories];
0
+ [openDlg setCanChooseDirectories: directories];
0
+ [openDlg setAllowsMultipleSelection: NO];
0
+ if ( [openDlg runModalForDirectory: nil file: nil] == NSOKButton )
0
+ {
0
+ NSArray* files = [openDlg filenames];
0
+ char *filename = [[files objectAtIndex: 0] UTF8String];
0
+ path = rb_str_new2(filename);
0
+ }
0
+ });
0
+ return path;
0
 }
0
 
0
 VALUE
0
@@ -1274,12 +1273,15 @@ shoes_dialog_open(VALUE self)
0
 VALUE
0
 shoes_dialog_save(VALUE self)
0
 {
0
- NSSavePanel* saveDlg = [NSSavePanel savePanel];
0
- if ( [saveDlg runModalForDirectory:nil file:nil] == NSOKButton )
0
- {
0
- char *filename = [[saveDlg filename] UTF8String];
0
- return rb_str_new2(filename);
0
- }
0
+ VALUE path = Qnil;
0
+ COCOA_DO({
0
+ NSSavePanel* saveDlg = [NSSavePanel savePanel];
0
+ if ( [saveDlg runModalForDirectory:nil file:nil] == NSOKButton )
0
+ {
0
+ char *filename = [[saveDlg filename] UTF8String];
0
+ path = rb_str_new2(filename);
0
+ }
0
+ });
0
   return Qnil;
0
 }
0
 

Comments

    No one has commented yet.