-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Expose theme through variable. Add python binding for it.
- Loading branch information
Showing
7 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// NSUserDefaults+iTerm.h | ||
// iTerm2SharedARC | ||
// | ||
// Created by George Nachman on 9/19/18. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSUserDefaults (iTerm) | ||
|
||
- (void)it_addObserverForKey:(NSString *)key | ||
block:(void (^)(id newValue))block; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// NSUserDefaults+iTerm.m | ||
// iTerm2SharedARC | ||
// | ||
// Created by George Nachman on 9/19/18. | ||
// | ||
|
||
#import "NSUserDefaults+iTerm.h" | ||
#import "NSDictionary+iTerm.h" | ||
|
||
static char iTermUserDefaultsKVOKey; | ||
typedef void (^iTermUserDefaultsBlock)(id); | ||
|
||
@implementation NSUserDefaults (iTerm) | ||
|
||
static NSMutableDictionary<NSString *, NSMutableArray<iTermUserDefaultsBlock> *> *iTermUserDefaultsObserverBlocks(void) { | ||
static NSMutableDictionary<NSString *, NSMutableArray<iTermUserDefaultsBlock> *> *blocks; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
blocks = [NSMutableDictionary dictionary]; | ||
}); | ||
return blocks; | ||
} | ||
|
||
- (void)it_addObserverForKey:(NSString *)key | ||
block:(void (^)(id newValue))block { | ||
[iTermUserDefaultsObserverBlocks() it_addObject:block toMutableArrayForKey:key]; | ||
[[NSUserDefaults standardUserDefaults] addObserver:self | ||
forKeyPath:key | ||
options:NSKeyValueObservingOptionNew | ||
context:(void *)&iTermUserDefaultsKVOKey]; | ||
} | ||
|
||
// This is called when user defaults are changed anywhere. | ||
- (void)observeValueForKeyPath:(NSString *)keyPath | ||
ofObject:(id)object | ||
change:(NSDictionary *)change | ||
context:(void *)context { | ||
if (context == &iTermUserDefaultsKVOKey) { | ||
NSMutableDictionary<NSString *, NSMutableArray<iTermUserDefaultsBlock> *> *blocks = | ||
iTermUserDefaultsObserverBlocks(); | ||
NSMutableArray<iTermUserDefaultsBlock> *array = blocks[keyPath]; | ||
id newValue = change[NSKeyValueChangeNewKey]; | ||
for (iTermUserDefaultsBlock block in array) { | ||
block(newValue); | ||
} | ||
} else { | ||
[super observeValueForKeyPath:keyPath | ||
ofObject:object | ||
change:change | ||
context:context]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters