Skip to content

Commit

Permalink
Duplicating theme now works and new docs properly init to theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Marrin committed Nov 3, 2011
1 parent 68e407d commit e3f91f2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Strawberry/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ DAMAGE.
@property(readwrite, assign) NSStringEncoding encoding;
@property(readwrite, copy) NSURL* url;

- (void)updateTextView;

@end
14 changes: 3 additions & 11 deletions Strawberry/Document.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

@implementation Document

@synthesize content, encoding, url;
@synthesize encoding, url, content;

- (id)init
{
Expand All @@ -65,20 +65,16 @@ - (void)updateTextView

NSAttributedString* string = [[ThemeController sharedController] highlightCode:content withSuffix:[url pathExtension]];
if (!string)
return;
string = [[[NSAttributedString alloc] init] autorelease];;

NSTextView* textView = ((WindowController*) [[self windowControllers] objectAtIndex:0]).textView;
[textView.textStorage setAttributedString:string];
[textView setFont:[ThemeController sharedController].font];
[textView setBackgroundColor:[[ThemeController sharedController] colorForGeneralType:@"background"]];
}

- (void)themeChanged:(NSNotification*) notification
{
if (![[self windowControllers] count])
return;

NSTextView* textView = ((WindowController*) [[self windowControllers] objectAtIndex:0]).textView;
[textView setBackgroundColor:[[ThemeController sharedController] colorForGeneralType:@"background"]];
[self updateTextView];
}

Expand All @@ -87,8 +83,6 @@ - (void)makeWindowControllers
// FIXME: For now just make a DocumentWindowController. Later on we need to deal with ProjectWindowControllers
DocumentWindowController* controller = [[DocumentWindowController alloc] initWithWindowNibName:@"Document"];
[self addWindowController:controller];
[self updateTextView];
[self themeChanged:nil];
}

- (void)windowControllerDidLoadNib:(NSWindowController *)controller
Expand All @@ -98,8 +92,6 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)controller
// FIXME: For now assume a single WindowController
if (self.content)
[self updateTextView];

[super windowControllerDidLoadNib:controller];
}

+ (BOOL)autosavesInPlace
Expand Down
6 changes: 6 additions & 0 deletions Strawberry/DocumentWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ - (void) textDidChange: (NSNotification *) notification
((Document*) [self document]).content = [[m_textView textStorage] string];
}

- (void)windowDidLoad
{
[super windowDidLoad];
[((Document*) [self document]) updateTextView];
}

@end
8 changes: 6 additions & 2 deletions Strawberry/PrefThemesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ - (IBAction)changeCaretColor:(id)sender
}

- (IBAction)duplicateTheme:(id)sender
{
{
m_duplicateThemeName.stringValue = @"";
[NSApp beginSheet:m_duplicateSheet modalForWindow:[m_view window] modalDelegate:self
didEndSelector:@selector(didEndDuplicateSheet:returnCode:contextInfo:) contextInfo:nil];
}
Expand All @@ -142,8 +143,11 @@ - (IBAction)duplicateThemeCancel:(id)sender
- (void)didEndDuplicateSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[m_duplicateSheet orderOut:self];
if (returnCode)
if (returnCode) {
[[ThemeController sharedController] duplicateCurrentTheme:m_duplicateThemeName.stringValue];
[self populateThemeMenu];
[self showCurrentTheme];
}
}

- (IBAction)deleteTheme:(id)sender
Expand Down
4 changes: 3 additions & 1 deletion Strawberry/ThemeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ - (NSDictionary*)currentSyntaxTypes
+ (ThemeController*)sharedController
{
static ThemeController* controller;
if (!controller)
if (!controller) {
controller = [[ThemeController alloc] init];
[[NSNotificationCenter defaultCenter] postNotificationName:NotifyThemeChanged object:nil];
}
return controller;
}

Expand Down

0 comments on commit e3f91f2

Please sign in to comment.