Permalink
Browse files

Add applescript to get and set color presets. Issue 4868

  • Loading branch information...
1 parent 88d0522 commit d7ecbf94f779d073aabfd47c98aeb3f4ee68b431 @gnachman committed Jan 2, 2017
View
@@ -537,6 +537,9 @@
<property name="text" description="The currently visible contents of the session." code="pcnt" type="text" access="r">
<cocoa key="text" />
</property>
+ <property name="color preset" code="Copr" type="text">
+ <cocoa key="colorPresetName" />
+ </property>
<property name="background color" code="Co00" type="RGB color">
<cocoa key="backgroundColor" />
</property>
@@ -28,5 +28,6 @@
@property(nonatomic, retain) NSColor *ansiBrightCyanColor;
@property(nonatomic, retain) NSColor *ansiBrightWhiteColor;
@property(nonatomic, readonly) NSString *profileName;
+@property(nonatomic, copy) NSString *colorPresetName;
@end
@@ -1,5 +1,6 @@
#import "PTYSession+Scripting.h"
#import "NSColor+iTerm.h"
+#import "ProfilesColorsPreferencesViewController.h"
#import "PTYTab.h"
#import "WindowControllerInterface.h"
@@ -468,4 +469,12 @@ - (NSString *)profileName {
return self.profile[KEY_NAME];
}
+- (NSString *)colorPresetName {
+ return [ProfilesColorsPreferencesViewController nameOfPresetUsedByProfile:self.profile];
+}
+
+- (void)setColorPresetName:(NSString *)colorPresetName {
+ [self setColorsFromPresetNamed:colorPresetName];
+}
+
@end
@@ -10,4 +10,5 @@
@interface ProfilesColorsPreferencesViewController : iTermProfilePreferencesBaseViewController
++ (NSString *)nameOfPresetUsedByProfile:(Profile *)profile;
@end
@@ -66,6 +66,40 @@ @implementation ProfilesColorsPreferencesViewController {
IBOutlet NSPopUpButton *_presetsPopupButton;
}
++ (NSArray<NSString *> *)presetNames {
+ NSArray<NSString *> *builtInNames = [[iTermColorPresets builtInColorPresets] allKeys];
+ NSArray<NSString *> *customNames = [[iTermColorPresets customColorPresets] allKeys];
+ return [builtInNames arrayByAddingObjectsFromArray:customNames];
+}
+
++ (iTermColorPreset *)presetWithName:(NSString *)name {
+ iTermColorPreset *dict = [[iTermColorPresets builtInColorPresets] objectForKey:name];
+ if (dict) {
+ return dict;
+ }
+ return [[iTermColorPresets customColorPresets] objectForKey:name];
+}
+
++ (NSString *)nameOfPresetUsedByProfile:(Profile *)profile {
+ for (NSString *presetName in [self presetNames]) {
+ iTermColorPreset *preset = [self presetWithName:presetName];
+ BOOL ok = YES;
+ for (NSString *colorName in [ProfileModel colorKeys]) {
+ iTermColorDictionary *presetColorDict = [preset iterm_presetColorWithName:colorName];
+ NSDictionary *profileColorDict = [iTermProfilePreferences objectForKey:colorName
+ inProfile:profile];
+ if (![presetColorDict isEqual:profileColorDict] && presetColorDict != profileColorDict) {
+ ok = NO;
+ break;
+ }
+ }
+ if (ok) {
+ return presetName;
+ }
+ }
+ return nil;
+}
+
- (void)awakeFromNib {
// Updates fields when a preset is loaded.
[[NSNotificationCenter defaultCenter] addObserver:self

0 comments on commit d7ecbf9

Please sign in to comment.