Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Improved coding convention inconsistencies and setup defaults for new…
Browse files Browse the repository at this point in the history
… color preferences
  • Loading branch information
soffes committed May 28, 2011
1 parent 862cbd2 commit 0904405
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 107 deletions.
13 changes: 13 additions & 0 deletions Classes/MDMissingDrawer.m
Expand Up @@ -64,6 +64,19 @@ + (MDSplitView *)makeSplitViewWithMainView:(NSView *)contentView sideView:(NSVie
- (id)initWithPlugInController:(id<TMPlugInController>)aController {
if (self = [super init]) {
MDLog(@"initializing 'MissingDrawer' plugin");

// Setup defaults
NSColor *activeColor = [NSColor colorWithCalibratedRed:0.867f green:0.894f blue:0.918f alpha:1.0f];
NSColor *idleColor = [NSColor colorWithCalibratedRed:0.929f green:0.929f blue:0.929f alpha:1.0f];
NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSKeyedArchiver archivedDataWithRootObject:activeColor], kMDSidebarBackgroundColorActiveKey,
[NSKeyedArchiver archivedDataWithRootObject:idleColor], kMDSidebarBackgroundColorIdleKey,
nil];

[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:defaults];
[defaults release];

[self _injectPluginMethods];
[[[NSApp mainWindow] windowController] MD_splitWindowIfNeeded];
[self _installMenuItems];
Expand Down
38 changes: 29 additions & 9 deletions Classes/MDPreferenceController.h
Expand Up @@ -2,22 +2,42 @@
// MDPreferenceController.h
// MissingDrawer
//
// Created by Mads Hartmann Jensen on 12/9/10.
// Copyright 2010 Sidewayscoding. All rights reserved.
// Copyright (c) The MissingDrawer authors.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

#import <Cocoa/Cocoa.h>


@interface MDPreferenceController : NSObject {

NSWindowController* preferenceWindowController;
IBOutlet NSView* preferencesView;
IBOutlet NSView *preferencesView;

@private

NSWindowController *_preferenceWindowController;

}

+ (MDPreferenceController*)instance;
+ (MDPreferenceController *)instance;

@property(retain, readonly) NSView* preferencesView;
@property(retain, readonly) NSView *preferencesView;

@end
38 changes: 28 additions & 10 deletions Classes/MDPreferenceController.m
Expand Up @@ -2,8 +2,28 @@
// MDPreferenceController.m
// MissingDrawer
//
// Created by Mads Hartmann Jensen on 12/9/10.
// Copyright 2010 Sidewayscoding. All rights reserved.
// Copyright (c) The MissingDrawer authors.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

#import "MDPreferenceController.h"
Expand All @@ -15,25 +35,23 @@ @implementation MDPreferenceController

static MDPreferenceController *sharedInstance = nil;

+ (MDPreferenceController*)instance
{
@synchronized(self) {
+ (MDPreferenceController *)instance {
@synchronized (self) {
if (sharedInstance == nil) {
[[self alloc] init];
}
}
return sharedInstance;
}

-(id)init
{
if (self = [super init]) {
- (id)init {
if ((self = [super init])) {
sharedInstance = self;

// Load the preference NIB
NSString* nibPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Preferences" ofType:@"nib"];
preferenceWindowController = [[NSWindowController alloc] initWithWindowNibPath:nibPath owner:self];
[preferenceWindowController showWindow:self];
_preferenceWindowController = [[NSWindowController alloc] initWithWindowNibPath:nibPath owner:self];
[_preferenceWindowController showWindow:self];

}
return self;
Expand Down
4 changes: 2 additions & 2 deletions Classes/MDResizer.m
Expand Up @@ -30,13 +30,13 @@

@implementation MDResizer

- (void) mouseDown:(NSEvent *)theEvent {
- (void)mouseDown:(NSEvent *)theEvent {
MDLog(@"mouseDown in sliderImage");
[[[self superview] superview] mouseDown:theEvent];
}


- (void) mouseDragged:(NSEvent *)theEvent {
- (void)mouseDragged:(NSEvent *)theEvent {
MDLog(@"mouseDragged in sliderImage");
[[[self superview] superview] mouseDragged:theEvent];
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/MDSettings.h
Expand Up @@ -35,6 +35,8 @@ extern NSString *const kMD_SideView_namedColors;
extern NSString *const kMD_TerminalLauncherAppName;

@interface MDSettings : NSObject {

@private
BOOL _showSideViewOnLeft;
NSRect _sideViewLayout;
NSRect _mainViewLayout;
Expand Down
4 changes: 3 additions & 1 deletion Classes/MDSidebarBorderView.h
Expand Up @@ -28,7 +28,9 @@

@interface MDSidebarBorderView : NSView {

id<NSObject> projectFileOutlineView;
@private

id<NSObject> _projectFileOutlineView;
}

// Class Methods
Expand Down
12 changes: 6 additions & 6 deletions Classes/MDSidebarBorderView.m
Expand Up @@ -116,7 +116,7 @@ - (void)addToSuperview:(NSView*)superview {
[btns addObject:aView];
} else if ([aView isKindOfClass:[NSScrollView class]]) {
outlineView = (NSScrollView *)aView;
projectFileOutlineView = [[outlineView contentView] documentView];
_projectFileOutlineView = [[outlineView contentView] documentView];
}
}

Expand Down Expand Up @@ -227,16 +227,16 @@ - (void)addToSuperview:(NSView*)superview {

- (void)terminalButtonPressed:(id)sender {
NSArray *selectedItems = nil;
if (projectFileOutlineView &&
[projectFileOutlineView respondsToSelector:@selector(selectedItems)]) {
selectedItems = [projectFileOutlineView performSelector:@selector(selectedItems)];
if (_projectFileOutlineView &&
[_projectFileOutlineView respondsToSelector:@selector(selectedItems)]) {
selectedItems = [_projectFileOutlineView performSelector:@selector(selectedItems)];
if (!selectedItems || ![selectedItems isKindOfClass:[NSArray class]] || [selectedItems count] == 0) {
selectedItems = [NSArray arrayWithObject:[(NSOutlineView *)projectFileOutlineView itemAtRow:0]];
selectedItems = [NSArray arrayWithObject:[(NSOutlineView *)_projectFileOutlineView itemAtRow:0]];
}
}

for (NSDictionary *item in selectedItems) {
MDLog(@"[projectFileOutlineView selectedItems]: %@", item);
MDLog(@"[_projectFileOutlineView selectedItems]: %@", item);
NSString *path = [item objectForKey:@"sourceDirectory"];
if (!path) {
path = [[item objectForKey:@"filename"] stringByDeletingLastPathComponent];
Expand Down
9 changes: 6 additions & 3 deletions Classes/MDSplitView.h
Expand Up @@ -27,12 +27,15 @@
//

@interface MDSplitView : NSSplitView <NSSplitViewDelegate> {

IBOutlet id resizeSlider;

@private

NSView *_sideView;
NSView *_mainView;

IBOutlet id resizeSlider;
BOOL inResizeMode;

BOOL _inResizeMode;
}

@property (readonly) NSView *sideView;
Expand Down
20 changes: 10 additions & 10 deletions Classes/MDSplitView.m
Expand Up @@ -50,7 +50,7 @@ - (void)dealloc {

#pragma mark NSSplitView

- (void) drawDividerInRect:(NSRect)aRect {
- (void)drawDividerInRect:(NSRect)aRect {
[[NSColor colorWithDeviceWhite:0.625 alpha:1] setFill];
[NSBezierPath fillRect:aRect];
}
Expand Down Expand Up @@ -88,7 +88,7 @@ - (id)initWithFrame:(NSRect)frame mainView:(NSView *)aMainView sideView:(NSView

#pragma mark -

- (void) focusSideView {
- (void)focusSideView {
if([_sideView acceptsFirstResponder]){
[_sideView becomeFirstResponder];
} else {
Expand Down Expand Up @@ -171,12 +171,12 @@ - (void)restoreLayout {

#pragma mark NSSplitView Delegate

- (BOOL) splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview {
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview {
return NO;
}


- (CGFloat) splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset {
- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset {
if ([[self subviews] objectAtIndex:offset] == self.sideView) {
return MIN_SIDEVIEW_WIDTH;
} else {
Expand All @@ -186,7 +186,7 @@ - (CGFloat) splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)prop
}


- (CGFloat) splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset {
- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset {
if ([[self subviews] objectAtIndex:offset] == self.sideView) {
return MAX_SIDEVIEW_WIDTH;
} else {
Expand All @@ -195,7 +195,7 @@ - (CGFloat) splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)prop
}


- (void) splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize {
- (void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize {
MDLog();

[self setDividerStyle:NSSplitViewDividerStyleThin];
Expand Down Expand Up @@ -246,22 +246,22 @@ - (void)mouseDown:(NSEvent *)theEvent {
NSPoint clickLocation = [theEvent locationInWindow];
NSView *clickReceiver = [self hitTest:clickLocation];
if ([clickReceiver isKindOfClass:[MDResizer class]]) {
inResizeMode = YES;
_inResizeMode = YES;
} else {
inResizeMode = NO;
_inResizeMode = NO;
[super mouseDown:theEvent];
}
}

- (void)mouseUp:(NSEvent *)theEvent {
MDLog();
inResizeMode = NO;
_inResizeMode = NO;
}

- (void)mouseDragged:(NSEvent *)theEvent {
MDLog();

if (inResizeMode == NO) {
if (_inResizeMode == NO) {
[super mouseDragged:theEvent];
return;
}
Expand Down
3 changes: 3 additions & 0 deletions Classes/NSWindowController+MDAdditions.h
Expand Up @@ -26,6 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

extern NSString *const kMDSidebarBackgroundColorActiveKey;
extern NSString *const kMDSidebarBackgroundColorIdleKey;

@interface NSWindowController (MDAdditions)

- (void)MD_splitWindowIfNeeded;
Expand Down
28 changes: 18 additions & 10 deletions Classes/NSWindowController+MDAdditions.m
Expand Up @@ -31,6 +31,9 @@
#import "MDSplitView.h"
#import "MDSidebarBorderView.h"

NSString *const kMDSidebarBackgroundColorActiveKey = @"MDSidebarBackgroundColorActive";
NSString *const kMDSidebarBackgroundColorIdleKey = @"MDSidebarBackgroundColorIdle";

@implementation NSWindowController (MDAdditions)

- (void)MD_splitWindowIfNeeded {
Expand Down Expand Up @@ -71,28 +74,33 @@ - (NSOutlineView *)MD_outlineView {
}


- (void) MD_windowDidBecomeMain:(NSNotification *)notification {

NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
[bindingOptions setObject:NSUnarchiveFromDataTransformerName
forKey:@"NSValueTransformerName"];
- (void)MD_windowDidBecomeMain:(NSNotification *)notification {
NSDictionary *bindingOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
NSUnarchiveFromDataTransformerName, @"NSValueTransformerName", nil];
NSString *keyPath = [[NSString alloc] initWithFormat:@"values.%@", kMDSidebarBackgroundColorActiveKey];

[[self MD_outlineView] bind:@"backgroundColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.MDSideViewBgColorNew"
withKeyPath:keyPath
options:bindingOptions];

[bindingOptions release];
[keyPath release];
}


- (void) MD_windowDidResignMain:(NSNotification *)notification {
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
[bindingOptions setObject:NSUnarchiveFromDataTransformerName
forKey:@"NSValueTransformerName"];
- (void)MD_windowDidResignMain:(NSNotification *)notification {
NSDictionary *bindingOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
NSUnarchiveFromDataTransformerName, @"NSValueTransformerName", nil];
NSString *keyPath = [[NSString alloc] initWithFormat:@"values.%@", kMDSidebarBackgroundColorIdleKey];

[[self MD_outlineView] bind:@"backgroundColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.MDSideViewBgColorIdle"
options:bindingOptions];

[bindingOptions release];
[keyPath release];
}

@end
8 changes: 4 additions & 4 deletions Classes/NSWindowController+MDMethodReplacements.m
Expand Up @@ -35,7 +35,7 @@

@implementation NSWindowController (MDMethodReplacements)

- (void) MD_repl_windowDidLoad {
- (void)MD_repl_windowDidLoad {
MDLog();

// call original
Expand All @@ -48,7 +48,7 @@ - (void) MD_repl_windowDidLoad {
}


- (void) MD_repl_windowWillClose:(NSNotification*)notification {
- (void)MD_repl_windowWillClose:(NSNotification*)notification {
MDLog();

NSWindow *window = [notification object];
Expand All @@ -66,7 +66,7 @@ - (void) MD_repl_windowWillClose:(NSNotification*)notification {
}


- (void) MD_repl_openProjectDrawer:(id)sender {
- (void)MD_repl_openProjectDrawer:(id)sender {
MDLog();

NSWindow *window = [(NSWindowController*)self window];
Expand Down Expand Up @@ -95,7 +95,7 @@ - (void) MD_repl_openProjectDrawer:(id)sender {
}


- (void) MD_repl_revealInProject:(id)sender {
- (void)MD_repl_revealInProject:(id)sender {
MDLog();
[self MD_repl_revealInProject:sender];
[self MD_repl_revealInProject:sender]; //TODO: twice?
Expand Down

0 comments on commit 0904405

Please sign in to comment.