Skip to content

Commit

Permalink
Add applescript to get and set color presets. Issue 4868
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Jan 2, 2017
1 parent 88d0522 commit d7ecbf9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions iTerm2.sdef
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions sources/PTYSession+Scripting.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions sources/PTYSession+Scripting.m
@@ -1,5 +1,6 @@
#import "PTYSession+Scripting.h"
#import "NSColor+iTerm.h"
#import "ProfilesColorsPreferencesViewController.h"
#import "PTYTab.h"
#import "WindowControllerInterface.h"

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions sources/ProfilesColorsPreferencesViewController.h
Expand Up @@ -10,4 +10,5 @@


@interface ProfilesColorsPreferencesViewController : iTermProfilePreferencesBaseViewController
+ (NSString *)nameOfPresetUsedByProfile:(Profile *)profile;
@end
34 changes: 34 additions & 0 deletions sources/ProfilesColorsPreferencesViewController.m
Expand Up @@ -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
Expand Down

0 comments on commit d7ecbf9

Please sign in to comment.