Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6958d0f39134f2c8774f30e867f9e17a88865aa2
Author: Amy <[email protected]>
Date:   Mon May 27 00:24:14 2024 -0400

    don't crash on high sierra

    - change from NSAppearanceNameDarkAqua to NSAppearanceNameVibrantDark which works on both HS and current
    - availability check NSApp.appearance and fallback to NSWindow.appearance (former prevents light flash opening dark windows, otherwise we could just use the latter everywhere)

commit 922149f6dca1449c3f2ef5aeb66699dbe583851c
Author: Amy <[email protected]>
Date:   Sun May 26 23:59:06 2024 -0400

    more visual tweaks

    - revert confusing windowing scheme
    - attempt to match xcode theme in window ui with some rather bad hacks
    - temporarily break high sierra support
  • Loading branch information
ASentientBot committed May 27, 2024
1 parent 8f81d78 commit b27c1b8
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 46 deletions.
6 changes: 0 additions & 6 deletions Delegate.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
@interface Delegate:NSObject<NSApplicationDelegate,NSUserInterfaceValidations>

@property(assign) BOOL nextWindowIsNotTab;
@property(assign) CGPoint lastCascadePoint;

-(BOOL)shouldMakeTab;

@end
23 changes: 1 addition & 22 deletions Delegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ -(void)applicationWillFinishLaunching:(NSNotification*)note
Settings.reset;
}

self.lastCascadePoint=CGPointMake(INT_MAX,INT_MAX);

contextMenuHook=[^()
{
NSMenu* menu=NSMenu.alloc.init.autorelease;
Expand All @@ -70,8 +68,7 @@ -(void)applicationWillFinishLaunching:(NSNotification*)note
[self addItemTitle:@"Quit" action:@"terminate:" key:@"q" to:titleMenu];

NSMenu* fileMenu=[self addMenuTitle:@"File" to:bar];
[self addItemTitle:@"New Window" action:@"amyNewWindow:" key:@"n" to:fileMenu];
[self addItemTitle:@"New Tab" action:@"amyNewTab:" key:@"n" mask:NSEventModifierFlagCommand|NSEventModifierFlagOption to:fileMenu];
[self addItemTitle:@"New" action:@"newDocument:" key:@"n" to:fileMenu];
[self addItemTitle:@"Open" action:@"openDocument:" key:@"o" to:fileMenu];
[self addSeparatorTo:fileMenu];
[self addItemTitle:@"Close" action:@"performClose:" key:@"w" to:fileMenu];
Expand Down Expand Up @@ -128,24 +125,6 @@ -(void)applicationWillFinishLaunching:(NSNotification*)note
NSApp.mainMenu=bar;
}

-(void)amyNewWindow:(NSMenuItem*)sender
{
self.nextWindowIsNotTab=true;
[NSDocumentController.sharedDocumentController newDocument:nil];
}

-(void)amyNewTab:(NSMenuItem*)sender
{
[NSDocumentController.sharedDocumentController newDocument:nil];
}

-(BOOL)shouldMakeTab
{
BOOL result=!self.nextWindowIsNotTab;
self.nextWindowIsNotTab=false;
return result;
}

-(void)amySelectTab:(NSMenuItem*)sender
{
NSArray<NSWindow*>* windows=NSApp.keyWindow.tabbedWindows;
Expand Down
15 changes: 12 additions & 3 deletions Settings.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,23 @@ +(NSString*)currentThemeName

+(void)setCurrentThemeName:(NSString*)name
{
XcodeTheme2* matched=nil;

for(XcodeTheme2* theme in getXcodeThemeManager().availablePreferenceSets)
{
if([theme.localizedName isEqual:name])
{
getXcodeThemeManager().currentPreferenceSet=theme;
matched=theme;
break;
}
}

getXcodeThemeManager().currentPreferenceSet=matched;

// TODO: hack to preserve when changing dark/light

[NSUserDefaults.standardUserDefaults setObject:matched.name forKey:XcodeLightThemeKey];
[NSUserDefaults.standardUserDefaults setObject:matched.name forKey:XcodeDarkThemeKey];
}

+(void)reset
Expand All @@ -82,13 +91,13 @@ +(void)setSampleTheme
ThemeMapping* theme=ThemeMapping.alloc.init.autorelease;

NSString* regular=@"SFMono-Regular - 13.0";
NSString* italic=@"SFMono-RegularItalic - 13.0";
NSString* italic=@"SFMono-LightItalic - 13.0";
NSString* bold=@"SFMono-Bold - 13.0";

theme.defaultFont=regular;
theme.defaultColor=@"0.3 0.3 0.6 1";

theme.backgroundColor=@"1 0.96 1 1";
theme.backgroundColor=@"1 0.95 1 1";
theme.highlightColor=@"1 0.9 1 1";
theme.selectionColor=@"1 0.8 1 1";

Expand Down
1 change: 1 addition & 0 deletions WindowController.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@interface WindowController:NSWindowController

@property(retain) XcodeViewController* xcodeViewController;

-(instancetype)initWithDocument:(Document*)document;

@end
95 changes: 80 additions & 15 deletions WindowController.m
Original file line number Diff line number Diff line change
@@ -1,35 +1,100 @@
NSColor* (*hackRealColor)(NSObject*,SEL,NSString*,NSBundle*)=NULL;
NSColor* hackFakeColor(NSObject* self,SEL sel,NSString* name,NSBundle* bundle)
{
if([name containsString:@"_NSTabBar"])
{
NSColor* base=getXcodeThemeManager().currentPreferenceSet.sourceTextCurrentLineHighlightColor;

if([@[@"_NSTabBarInactiveTabHoverColor",@"_NSTabBarNewTabButtonHoverColor"] containsObject:name])
{
return base;
}

if([@[@"_NSTabBarTabFillColorActiveWindow",@"_NSTabBarInactiveTabHoverColor",@"_NSTabBarNewTabButtonHoverColor"] containsObject:name])
{
// TODO: completely arbitrary

return [base colorWithAlphaComponent:0.5];
}

return NSColor.clearColor;
}

return hackRealColor(self,sel,name,bundle);
}

@implementation WindowController

+(void)initialize
{
swizzle(@"NSColor",@"colorNamed:bundle:",false,(IMP)hackFakeColor,(IMP*)&hackRealColor);

[NSNotificationCenter.defaultCenter addObserverForName:XcodeThemeChangedKey object:nil queue:nil usingBlock:^(NSNotification* note)
{
for(Document* document in NSDocumentController.sharedDocumentController.documents)
{
for(WindowController* controller in document.windowControllers)
{
controller.syncTheme;
}
}
}];
}

-(instancetype)initWithDocument:(Document*)document
{
self=super.init;

CGRect rect=CGRectMake(0,0,600,500);
NSWindowStyleMask style=NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskResizable|NSWindowStyleMaskMiniaturizable;
self.window=[NSWindow.alloc initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:false].autorelease;

// TODO: this now behaves exactly how i want, but it's very nonstandard

Delegate* delegate=(Delegate*)NSApp.delegate;
if(delegate.shouldMakeTab)
{
[self.window cascadeTopLeftFromPoint:CGPointMake(INT_MAX,INT_MAX)];

self.window.tabbingMode=NSWindowTabbingModePreferred;
self.window.frameAutosaveName=getAppName();
}
else
{
delegate.lastCascadePoint=[self.window cascadeTopLeftFromPoint:delegate.lastCascadePoint];
}
[self.window cascadeTopLeftFromPoint:CGPointMake(INT_MAX,INT_MAX)];
self.window.tabbingMode=NSWindowTabbingModePreferred;
self.window.frameAutosaveName=getAppName();
self.window.titlebarAppearsTransparent=true;

self.xcodeViewController=getXcodeViewController(document.xcodeDocument);
self.window.contentView=self.xcodeViewController.view;
self.window.contentView.clipsToBounds=true;
focusXcodeViewController(self.xcodeViewController);

self.syncTheme;

// TODO: make toggle-able? dependent on minimap?

self.xcodeViewController.mainScrollView.hasVerticalScroller=false;

return self;
}

-(void)syncTheme
{
dispatch_async(dispatch_get_main_queue(),^()
{
XcodeTheme2* theme=getXcodeThemeManager().currentPreferenceSet;

NSAppearance* appearance=[NSAppearance appearanceNamed:theme.hasLightBackground?NSAppearanceNameAqua:NSAppearanceNameVibrantDark];
if(@available(macOS 10.14,*))
{
NSApp.appearance=appearance;
}
else
{
self.window.appearance=appearance;
}

self.window.backgroundColor=theme.sourceTextBackgroundColor;

// TODO: hack to refresh the "new tab" button

if(self.window.isKeyWindow)
{
self.window.resignKeyWindow;
self.window.becomeKeyWindow;
}
});
}

-(void)dealloc
{
self.xcodeViewController=nil;
Expand Down
9 changes: 9 additions & 0 deletions Xcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ @interface XcodeViewController:NSViewController

-(instancetype)initWithNibName:(NSString*)nib bundle:(NSBundle*)bundle document:(NSDocument*)document;
-(void)selectDocumentLocations:(NSArray<XcodeDocumentLocation*>*)locations;
-(NSScrollView*)mainScrollView;

@end

Expand All @@ -47,10 +48,18 @@ +(instancetype)sharedPreferences;

@class XcodeThemeManager;

#define XcodeLightThemeKey @"XCFontAndColorCurrentTheme"
#define XcodeDarkThemeKey @"XCFontAndColorCurrentDarkTheme"
#define XcodeThemeChangedKey @"DVTFontAndColorSettingsChangedNotification"

@interface XcodeTheme2:NSObject

+(XcodeThemeManager*)preferenceSetsManager;
-(NSString*)localizedName;
-(NSString*)name;
-(BOOL)hasLightBackground;
-(NSColor*)sourceTextBackgroundColor;
-(NSColor*)sourceTextCurrentLineHighlightColor;

@end

Expand Down

0 comments on commit b27c1b8

Please sign in to comment.