Skip to content

Commit 26ac5ac

Browse files
committed
Squashed commit of the following:
commit 38b6b6f9c9f84d3ed00a2ef1e3d49d07096b398b Author: Amy <[email protected]> Date: Mon Jun 24 05:23:29 2024 -0400 update themes delete old, add neutral, default to neutral commit 2d8bda1132da77ef69bf980ce95603913bc09d83 Author: Amy <[email protected]> Date: Mon Jun 24 04:34:50 2024 -0400 don't assume stable document order im sure this was fine but it wasn't actually guaranteed commit 59ac3f934ebad0b4d8d5b93128d410ab9037df20 Author: Amy <[email protected]> Date: Mon Jun 24 04:30:27 2024 -0400 simplify transient documents revert most of previous commit because im dumb and there's a much easier way to do this commit 4c985ab9b19853b0d6f4a017b47e61d6a9263286 Author: Amy <[email protected]> Date: Mon Jun 24 04:20:58 2024 -0400 add transient document logic commit 2f271f63ca6c7ed9b7c55c7ccc57f27edf25bcd0 Author: Amy <[email protected]> Date: Mon Jun 24 04:19:50 2024 -0400 simplify sticky header hack we can directly hook the container rather than traversing to it from the subview commit 09f3c851d43a6560faf6c5d0d28d1799e23e197f Author: Amy <[email protected]> Date: Mon Jun 24 04:19:19 2024 -0400 squish ThemeMapping into Settings no reason to have a distinct class. also, guess what, tweak the colors
1 parent 0969e33 commit 26ac5ac

File tree

7 files changed

+122
-171
lines changed

7 files changed

+122
-171
lines changed

Delegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ -(void)addSeparatorTo:(NSMenu*)menu
4444
-(void)applicationWillFinishLaunching:(NSNotification*)note
4545
{
4646
BOOL firstRun=![NSUserDefaults.standardUserDefaults boolForKey:@"launched"];
47-
[NSUserDefaults.standardUserDefaults setBool:true forKey:@"launched"];
4847
if(firstRun)
4948
{
49+
[NSUserDefaults.standardUserDefaults setBool:true forKey:@"launched"];
5050
Settings.reset;
5151
}
5252

Document.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
@implementation Document
22

3+
+(void)closeTransientIfNeeded
4+
{
5+
NSArray<Document*>* documents=NSDocumentController.sharedDocumentController.documents;
6+
if(documents.count!=2)
7+
{
8+
return;
9+
}
10+
11+
for(Document* document in documents)
12+
{
13+
if(document.fileURL||document.documentEdited)
14+
{
15+
continue;
16+
}
17+
18+
[document.windowControllers.firstObject.window performClose:nil];
19+
}
20+
}
21+
322
-(void)makeWindowControllers
423
{
24+
if(self.fileURL)
25+
{
26+
Document.closeTransientIfNeeded;
27+
}
28+
529
[self addWindowController:WindowController.alloc.init.autorelease];
630
[self loadWithURL:self.fileURL type:self.fileType];
731
}
@@ -42,7 +66,6 @@ -(BOOL)writeSafelyToURL:(NSURL*)url ofType:(NSString*)type forSaveOperation:(NSS
4266
if(!self.fileURL)
4367
{
4468
// TODO: a tiny bit weird. maybe we can skip this by moving a bit "later" in the save process.
45-
// also, we should be able to do TextEdit-style "transient" untitled documents now
4669

4770
NSString* newType=[NSDocumentController.sharedDocumentController typeForContentsOfURL:url error:nil];
4871
[self loadWithURL:url type:newType];

Settings.m

Lines changed: 93 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

ThemeMapping.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

ThemeMapping.m

Lines changed: 0 additions & 108 deletions
This file was deleted.

WindowController.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ void hackFakeHeaderLayout(NSView* self,SEL sel)
3535
{
3636
hackRealHeaderLayout(self,sel);
3737

38-
NSView* container=self.superview.superview;
39-
container.subviews[0].hidden=true;
40-
container.layer.backgroundColor=getXcodeTheme().sourceTextBackgroundColor.CGColor;
38+
self.subviews.firstObject.hidden=true;
39+
self.layer.backgroundColor=getXcodeTheme().sourceTextBackgroundColor.CGColor;
4140
}
4241

4342
@implementation WindowController
@@ -52,9 +51,9 @@ +(void)initialize
5251

5352
// TODO: uhh
5453

55-
if(NSClassFromString(@"_TtC12SourceEditor16StickyHeaderView"))
54+
if(NSClassFromString(@"_TtC12SourceEditor21StickyHeaderStackView"))
5655
{
57-
swizzle(@"_TtC12SourceEditor16StickyHeaderView",@"layout",true,(IMP)hackFakeHeaderLayout,(IMP*)&hackRealHeaderLayout);
56+
swizzle(@"_TtC12SourceEditor21StickyHeaderStackView",@"layout",true,(IMP)hackFakeHeaderLayout,(IMP*)&hackRealHeaderLayout);
5857

5958
swizzle(@"NSColor",@"shadowWithLevel:",true,(IMP)hackFakeShadow,NULL);
6059
swizzle(@"NSColor",@"highlightWithLevel:",true,(IMP)hackFakeShadow,NULL);

main.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
#import "Xcode.m"
99

1010
#import "SettingsMapping.h"
11-
#import "ThemeMapping.h"
1211
#import "Settings.h"
1312
#import "Document.h"
1413
#import "WindowController.h"
1514
#import "Delegate.h"
1615

1716
#import "SettingsMapping.m"
18-
#import "ThemeMapping.m"
1917
#import "Settings.m"
2018
#import "Document.m"
2119
#import "WindowController.m"

0 commit comments

Comments
 (0)