@@ -68,6 +68,12 @@ +(void)setCurrentThemeName:(NSString*)name
6868 }
6969 }
7070
71+ if (!matched)
72+ {
73+ alert (@" theme missing" );
74+ return ;
75+ }
76+
7177 setXcodeTheme (matched);
7278}
7379
@@ -100,40 +106,96 @@ +(CGRect)projectRect
100106 return [Settings rectWithPrefix: @" project" ];
101107}
102108
103- +(NSString *)themeNameWithSuffix : (NSString *)suffix
109+ +(void )saveThemeWithName : (NSString *)name backgroundColor : (NSString *)backgroundColor highlightColor : (NSString *)highlightColor selectionColor : (NSString *)selectionColor defaultFont : (NSString *)defaultFont defaultColor : (NSString *)defaultColor commentFont : (NSString *)commentFont commentColor : (NSString *)commentColor preprocessorFont : (NSString *)preprocessorFont preprocessorColor : (NSString *)preprocessorColor classFont : (NSString *)classFont classColor : (NSString *)classColor functionFont : (NSString *)functionFont functionColor : (NSString *)functionColor keywordFont : (NSString *)keywordFont keywordColor : (NSString *)keywordColor stringFont : (NSString *)stringFont stringColor : (NSString *)stringColor numberFont : (NSString *)numberFont numberColor : (NSString *)numberColor
110+ {
111+ NSString * basePath=[getXcodeSystemThemesPath () stringByAppendingPathComponent: @" Default (Light).xccolortheme" ];
112+ NSData * baseData=[NSData dataWithContentsOfFile: basePath];
113+ if (!baseData)
114+ {
115+ alertAbort (@" base theme missing" );
116+ }
117+
118+ NSMutableDictionary * custom=[NSPropertyListSerialization propertyListWithData: baseData options: NSPropertyListMutableContainers format: nil error: nil ];
119+ if (!custom)
120+ {
121+ alertAbort (@" base theme broken" );
122+ }
123+
124+ custom[XcodeThemeBackgroundKey]=backgroundColor;
125+ custom[XcodeThemeHighlightKey]=highlightColor;
126+ custom[XcodeThemeSelectionKey]=selectionColor;
127+ custom[XcodeThemeCursorKey]=defaultColor;
128+ custom[XcodeThemeInvisiblesKey]=commentColor;
129+
130+ NSMutableDictionary * innerFonts=custom[XcodeThemeFontsKey];
131+ NSMutableDictionary * innerColors=custom[XcodeThemeColorsKey];
132+ for (NSString * key in innerColors.allKeys )
133+ {
134+ NSString * font=defaultFont;
135+ NSString * color=defaultColor;
136+
137+ if ([XcodeThemeCommentKeys containsObject: key])
138+ {
139+ font=commentFont;
140+ color=commentColor;
141+ }
142+ else if ([XcodeThemePreprocessorKeys containsObject: key])
143+ {
144+ font=preprocessorFont;
145+ color=preprocessorColor;
146+ }
147+ else if ([XcodeThemeClassKeys containsObject: key])
148+ {
149+ font=classFont;
150+ color=classColor;
151+ }
152+ else if ([XcodeThemeFunctionKeys containsObject: key])
153+ {
154+ font=functionFont;
155+ color=functionColor;
156+ }
157+ else if ([XcodeThemeKeywordKeys containsObject: key])
158+ {
159+ font=keywordFont;
160+ color=keywordColor;
161+ }
162+ else if ([XcodeThemeStringKeys containsObject: key])
163+ {
164+ font=stringFont;
165+ color=stringColor;
166+ }
167+ else if ([XcodeThemeNumberKeys containsObject: key])
168+ {
169+ font=numberFont;
170+ color=numberColor;
171+ }
172+
173+ innerFonts[key]=font;
174+ innerColors[key]=[color stringByAppendingString: @" 1" ];
175+ }
176+
177+ NSString * customPath=[getXcodeUserThemesPath () stringByAppendingPathComponent: [name stringByAppendingString: @" .xccolortheme" ]];
178+ [NSFileManager .defaultManager createDirectoryAtPath: customPath.stringByDeletingLastPathComponent withIntermediateDirectories: true attributes: nil error: nil ];
179+
180+ NSData * customData=[NSPropertyListSerialization dataWithPropertyList: custom format: NSPropertyListXMLFormat_v1_0 options: 0 error: nil ];
181+ if (![customData writeToFile: customPath atomically: true ])
182+ {
183+ alertAbort (@" theme write failed" );
184+ }
185+ }
186+
187+ +(NSString *)simpleThemeNameWithSuffix : (NSString *)suffix
104188{
105189 return [NSString stringWithFormat: @" %@ %@ " ,getAppName (),suffix];
106190}
107191
108- +(void )saveThemeWithSuffix : (NSString *)suffix background : (NSString *)backgroundColor highlight : (NSString *)highlightColor selection : (NSString *)selectionColor normal : (NSString *)normalColor meta : (NSString *)metaColor type : (NSString *)typeColor keyword : (NSString *)keywordColor string : (NSString *)stringColor number : (NSString *)numberColor
192+ +(void )saveSimpleThemeWithSuffix : (NSString *)suffix background : (NSString *)backgroundColor highlight : (NSString *)highlightColor selection : (NSString *)selectionColor normal : (NSString *)normalColor meta : (NSString *)metaColor type : (NSString *)typeColor keyword : (NSString *)keywordColor string : (NSString *)stringColor number : (NSString *)numberColor
109193{
110- ThemeMapping* theme=ThemeMapping.alloc .init .autorelease ;
111-
112194 NSString * regular=@" SFMono-Regular - 13.0" ;
113195 NSString * italic=@" SFMono-RegularItalic - 13.0" ;
114196 NSString * bold=@" SFMono-Bold - 13.0" ;
115197
116- theme.defaultFont =regular;
117- theme.defaultColor =normalColor;
118- theme.backgroundColor =backgroundColor;
119- theme.highlightColor =highlightColor;
120- theme.selectionColor =selectionColor;
121- theme.commentFont =italic;
122- theme.commentColor =metaColor;
123- theme.preprocessorFont =regular;
124- theme.preprocessorColor =metaColor;
125- theme.classFont =bold;
126- theme.classColor =typeColor;
127- theme.functionFont =regular;
128- theme.functionColor =typeColor;
129- theme.keywordFont =bold;
130- theme.keywordColor =keywordColor;
131- theme.stringFont =bold;
132- theme.stringColor =stringColor;
133- theme.numberFont =bold;
134- theme.numberColor =numberColor;
135-
136- [theme saveWithName: [Settings themeNameWithSuffix: suffix]];
198+ [Settings saveThemeWithName: [Settings simpleThemeNameWithSuffix: suffix] backgroundColor: backgroundColor highlightColor: highlightColor selectionColor: selectionColor defaultFont: regular defaultColor: normalColor commentFont: italic commentColor: metaColor preprocessorFont: regular preprocessorColor: metaColor classFont: bold classColor: typeColor functionFont: regular functionColor: typeColor keywordFont: bold keywordColor: keywordColor stringFont: bold stringColor: stringColor numberFont: bold numberColor: numberColor];
137199}
138200
139201+(void )reset
@@ -143,11 +205,13 @@ +(void)reset
143205 mapping.reset ;
144206 }
145207
146- [Settings saveThemeWithSuffix: @" Old" background: @" 1 0.9 1" highlight: @" 1 0.85 1" selection: @" 1 0.75 1" normal: @" 0.3 0.3 0.6" meta: @" 0.6 0.5 0.8" type: @" 0 0.5 0.4" keyword: @" 0.8 0 1" string: @" 0.85 0.5 0.8" number: @" 0.3 0.6 1" ];
147- [Settings saveThemeWithSuffix: @" Pink (Light)" background: @" 1 0.75 1" highlight: @" 1 0.7 1" selection: @" 1 0.6 1" normal: @" 0.3 0.2 0.5" meta: @" 0.5 0.4 0.7" type: @" 0.6 0.2 0.8" keyword: @" 0.7 0.2 0.6" string: @" 0.8 0.4 0.8" number: @" 0.5 0.3 0.9" ];
148- [Settings saveThemeWithSuffix: @" Pink (Dark)" background: @" 0.1 0 0.1" highlight: @" 0.15 0 0.15" selection: @" 0.25 0 0.25" normal: @" 0.5 0.4 0.5" meta: @" 0.3 0.2 0.3" type: @" 0.5 0.2 0.6" keyword: @" 0.5 0.1 0.3" string: @" 0.5 0.2 0.4" number: @" 0.3 0.2 0.5" ];
208+ [Settings saveSimpleThemeWithSuffix: @" Pink (Light)" background: @" 1 0.75 1" highlight: @" 1 0.7 1" selection: @" 1 0.6 1" normal: @" 0.3 0.2 0.5" meta: @" 0.5 0.4 0.7" type: @" 0.6 0.2 0.8" keyword: @" 0.7 0.2 0.5" string: @" 0.8 0.4 0.8" number: @" 0.5 0.4 0.9" ];
209+ [Settings saveSimpleThemeWithSuffix: @" Pink (Dark)" background: @" 0.15 0 0.15" highlight: @" 0.2 0 0.2" selection: @" 0.3 0 0.3" normal: @" 0.5 0.4 0.6" meta: @" 0.3 0.2 0.4" type: @" 0.5 0.2 0.7" keyword: @" 0.5 0.1 0.3" string: @" 0.5 0.2 0.5" number: @" 0.3 0.2 0.7" ];
210+
211+ [Settings saveSimpleThemeWithSuffix: @" Neutral (Light)" background: @" 1 1 1" highlight: @" 0.95 0.95 1" selection: @" 0.8 0.8 1" normal: @" 0.3 0.3 0.6" meta: @" 0.5 0.5 0.8" type: @" 0.6 0.1 1" keyword: @" 0.8 0.2 0.4" string: @" 0.9 0.4 0.9" number: @" 0.2 0.5 1" ];
212+ [Settings saveSimpleThemeWithSuffix: @" Neutral (Dark)" background: @" 0.1 0.1 0.1" highlight: @" 0.13 0.13 0.16" selection: @" 0.25 0.25 0.4" normal: @" 0.5 0.5 0.7" meta: @" 0.3 0.3 0.5" type: @" 0.5 0.3 0.7" keyword: @" 0.6 0.2 0.3" string: @" 0.6 0.3 0.6" number: @" 0.2 0.3 0.6" ];
149213
150- [Settings setCurrentThemeName: [Settings themeNameWithSuffix :@" Pink (Light)" ]];
214+ [Settings setCurrentThemeName: [Settings simpleThemeNameWithSuffix :@" Neutral (Light)" ]];
151215}
152216
153217@end
0 commit comments