Permalink
Browse files

Improved coding convention inconsistencies and setup defaults for new…

… color preferences
  • Loading branch information...
soffes committed May 28, 2011
1 parent 862cbd2 commit 0904405ca398cd53f893d10ec151ee1b40c56e29
View
@@ -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];
@@ -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
@@ -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"
@@ -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;
View
@@ -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];
}
View
@@ -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;
@@ -28,7 +28,9 @@
@interface MDSidebarBorderView : NSView {
id<NSObject> projectFileOutlineView;
@private
id<NSObject> _projectFileOutlineView;
}
// Class Methods
@@ -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];
}
}
@@ -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];
View
@@ -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;
View
@@ -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];
}
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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];
@@ -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;
}
@@ -26,6 +26,9 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
extern NSString *const kMDSidebarBackgroundColorActiveKey;
extern NSString *const kMDSidebarBackgroundColorIdleKey;
@interface NSWindowController (MDAdditions)
- (void)MD_splitWindowIfNeeded;
@@ -31,6 +31,9 @@
#import "MDSplitView.h"
#import "MDSidebarBorderView.h"
NSString *const kMDSidebarBackgroundColorActiveKey = @"MDSidebarBackgroundColorActive";
NSString *const kMDSidebarBackgroundColorIdleKey = @"MDSidebarBackgroundColorIdle";
@implementation NSWindowController (MDAdditions)
- (void)MD_splitWindowIfNeeded {
@@ -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
@@ -35,7 +35,7 @@
@implementation NSWindowController (MDMethodReplacements)
- (void) MD_repl_windowDidLoad {
- (void)MD_repl_windowDidLoad {
MDLog();
// call original
@@ -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];
@@ -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];
@@ -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?
Oops, something went wrong.

0 comments on commit 0904405

Please sign in to comment.