cocoafile 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ab0f5351dcf534a52248f4d84b4fc33440aea751b9cd4ed0bce4595b46ffc2d
4
- data.tar.gz: 22f20578bd99048cd74c837015fcb1bcca844d09b4891d85a7f549e2efb14895
3
+ metadata.gz: e19e0b889d1901951c25e1e6d12ad3fbb177091b28cfd52293b4d023369820a0
4
+ data.tar.gz: eda391282ad5c71d4807e240fee73fc83bfca0438fdcd49fba62ee428326c8ac
5
5
  SHA512:
6
- metadata.gz: 75b1b404425bfa53b244f3fa0108cde48b3bd2c9a0e402c05c41f87fb159a96d461c5a6befd3863b9ef3376ee9a10c37aef58e37d2a090e7b61a20b1ef490c93
7
- data.tar.gz: f7bd96ef7d01e61ed0d5645425d09e1700296b52ad15a904df28db456b1e5d4c8c87af7850e2061074401f8e68fd80c9ee5b3a201bddd20131894de07b678747
6
+ metadata.gz: 55a58dfce9a2872e9febc0dcaf3d2691b2fe37a088fd627da0c3cf6301e10bd320aaa8080aaf879d0481c2b7abbbdbe81b482ea6d110f23a01e2c225d43d8aac
7
+ data.tar.gz: ee86404f0f54693f4f3f86becfc995de79f1d549a469e44676aba3782d15ccad0c33ca0e1ea9963a8eef6359eaced1e692e6a44ab238657e02643d3546164891
@@ -4,36 +4,41 @@
4
4
  VALUE rb_mCocoafile;
5
5
  VALUE rb_mFile;
6
6
 
7
- VALUE choose_file(VALUE self);
7
+ VALUE choose_file(VALUE self, VALUE rb_ext);
8
8
 
9
9
  RUBY_FUNC_EXPORTED void
10
10
  Init_cocoafile(void)
11
11
  {
12
12
  rb_mCocoafile = rb_define_module("Cocoafile");
13
13
  rb_mFile = rb_define_class_under(rb_mCocoafile, "File", rb_cObject);
14
- rb_define_method(rb_mFile, "choose_file", choose_file, 0);
14
+ rb_define_method(rb_mFile, "choose_file", choose_file, 1);
15
15
  }
16
16
 
17
- VALUE choose_file(VALUE self) {
18
- rb_iv_set(self, "@var", rb_hash_new());
19
-
17
+ VALUE choose_file(VALUE self, VALUE rb_ext) {
18
+ // Convert Ruby string to NSString
19
+ Check_Type(rb_ext, T_STRING);
20
+ const char *ext_cstr = StringValueCStr(rb_ext);
21
+ NSString *ext = [NSString stringWithUTF8String:ext_cstr];
20
22
  NSOpenPanel *panel = [NSOpenPanel openPanel];
21
23
 
22
- // Create a UTType for your custom file extension
23
- UTType *lumioseType = [UTType typeWithFilenameExtension:@"lumiose"];
24
-
24
+ UTType *lumioseType = [UTType typeWithFilenameExtension:ext];
25
25
  panel.allowedContentTypes = @[lumioseType];
26
26
  panel.canChooseFiles = YES;
27
27
  panel.canChooseDirectories = NO;
28
28
  panel.allowsMultipleSelection = NO;
29
29
  panel.prompt = @"Open";
30
30
 
31
- [panel beginWithCompletionHandler:^(NSModalResponse result) {
32
- if (result == NSModalResponseOK) {
33
- NSURL *selectedFile = panel.URL;
34
- NSLog(@"Selected .lumiose file: %@", selectedFile.path);
35
- // Load your project file here
36
- }
37
- }];
38
- return self;
31
+ // Run synchronously
32
+ NSInteger result = [panel runModal];
33
+
34
+ if (result == NSModalResponseOK) {
35
+ NSURL *selectedFile = panel.URL;
36
+ NSString *path = selectedFile.path;
37
+
38
+ // Convert NSString → Ruby String
39
+ return rb_str_new_cstr([path UTF8String]);
40
+ }
41
+
42
+ // User cancelled: return nil
43
+ return Qnil;
39
44
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cocoafile
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoafile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Jeff