Definition of NSWorkspace, NSNotificationCenter, and NSRunningApplication#101
Definition of NSWorkspace, NSNotificationCenter, and NSRunningApplication#101agg23 wants to merge 9 commits intoryanmcgrath:trunkfrom
Conversation
| @@ -1,3 +1,5 @@ | |||
| // TODO: This should be moved elsewhere | |||
There was a problem hiding this comment.
I don't really understand why this trait is under notification_center. It also isn't very obvious how this should be used, except for the examples.
There was a problem hiding this comment.
Yeah, this is... ancient and really just dates back to when an early version of this was used in subatomic. It can def be moved.
| pub fn keys(&self) -> Vec<String> { | ||
| let keys = NSArray::retain(unsafe { msg_send![self.0, allKeys] }); | ||
| keys.iter().map(|s| NSString::retain(s).to_string()).collect() | ||
| } | ||
|
|
||
| /// Converts the dictionary into a hashmap, passing each item through a transform function. | ||
| /// | ||
| /// **NOTE:** This only works with string keys | ||
| pub fn into_hashmap<T, F>(&self, item_transform: F) -> HashMap<String, T> | ||
| where | ||
| F: Fn(&String, id) -> T, | ||
| { | ||
| let mut map = HashMap::new(); | ||
|
|
||
| let keys = self.keys(); | ||
|
|
||
| for key in keys { | ||
| let item_id = self.get(&key); | ||
|
|
||
| if let Some(item_id) = item_id { | ||
| let item = item_transform(&key, item_id); | ||
|
|
||
| map.insert(key, item); | ||
| } else { | ||
| // TODO: Should there be an assertion here for runtime failure? | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| map | ||
| } |
There was a problem hiding this comment.
I hate these being string specific, but I'm not sure how else to keep this API usable
There was a problem hiding this comment.
This is fine to use String keys for now, to be honest - better to be out and working with potential improvements/revamps later, especially since while I'm fine with these pieces being more open, they're still mostly an internal aspect.
I think you're probably on the right train of thought re: having an assertion here.
|
So I'm musing about juggling pull requests here - I definitely do want these in cacao, however I think the |
|
(Also: |
|
That's perfectly fine. I think most of this becomes unnecessary with |
Got a little carried away going down the rabbit hole of getting some notifications and
NSWorkspacemethods working. I believe this PR should cover the majority of usecases, though there are some uncommon methods that I did not implement (I left comments marking what is missing).Retainabletrait - Allows for a common way to buildretaindefinitions and allows for theretain_nullableconnivence method, which will be needed more and more as more nullable instance properties are implementedNSMutableDictionarymethods to be more complete. AddsIteratorsupport - Note that the untyped nature of Objective-C collections makes dictionaries particularly difficult. Several methods assumeNSStringkeysstrummacros for generatingNSStringconstants from enums, like what is used forNotificationName- I don't imagine there will be many other locations outside ofNSNotificationwhere this macro is used, but I think it's hugely helpful in this case.NSWorkspace,NSNotificationCenter,NSRunningApplication, andNSNotification- These are all interconnected and rely on each other, hence the expanding scope of this PR. Addresses Bindings for NSWorkspace #24I know there's a lot of stuff here, so take your time. I'm sure there's many things to complain about.