Permalink
Browse files

Merging mads379 master

  • Loading branch information...
shell committed Mar 3, 2011
1 parent dce5d29 commit b9b9e76571afd183412beafc08b797bf44bd9f4e
@@ -31,7 +31,8 @@
@class MDSplitView;
@interface MDMissingDrawer : NSObject {
}
// Class Methods
View
@@ -44,9 +44,9 @@ void swapInstanceMethods(Class cls, SEL originalSel, SEL newSel) {
@interface MDMissingDrawer (PrivateMethods)
- (void)_injectPluginMethods;
- (void)_installMenuItems;
- (void)_injectPreferenceMethods;
@end
@implementation MDMissingDrawer
#pragma mark Class Methods
@@ -67,7 +67,8 @@ - (id)initWithPlugInController:(id<TMPlugInController>)aController {
[self _injectPluginMethods];
[[[NSApp mainWindow] windowController] MD_splitWindowIfNeeded];
[self _installMenuItems];
}
[self _injectPreferenceMethods];
}
return self;
}
@@ -123,4 +124,17 @@ - (void)_injectPluginMethods {
swapInstanceMethods(oakProjectController, @selector(revealInProject:), @selector(MD_repl_revealInProject:));
}
- (void)_injectPreferenceMethods {
MDLog("swapping OakPreferencesManager methods");
Class oakPreferenceController = NSClassFromString(@"OakPreferencesManager");
swapInstanceMethods(oakPreferenceController, @selector(toolbarAllowedItemIdentifiers:), @selector(MD_toolbarAllowedItemIdentifiers:));
swapInstanceMethods(oakPreferenceController, @selector(toolbarDefaultItemIdentifiers:), @selector(MD_toolbarDefaultItemIdentifiers:));
swapInstanceMethods(oakPreferenceController, @selector(toolbarSelectableItemIdentifiers:), @selector(MD_toolbarSelectableItemIdentifiers:));
swapInstanceMethods(oakPreferenceController, @selector(selectToolbarItem:), @selector(MD_selectToolbarItem:));
swapInstanceMethods(oakPreferenceController, @selector(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:),
@selector(MD_toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:));
}
@end
@@ -0,0 +1,23 @@
//
// MDPreferenceController.h
// MissingDrawer
//
// Created by Mads Hartmann Jensen on 12/9/10.
// Copyright 2010 Sidewayscoding. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MDPreferenceController : NSObject {
NSWindowController* preferenceWindowController;
IBOutlet NSView* preferencesView;
}
+ (MDPreferenceController*)instance;
@property(retain, readonly) NSView* preferencesView;
@end
@@ -0,0 +1,44 @@
//
// MDPreferenceController.m
// MissingDrawer
//
// Created by Mads Hartmann Jensen on 12/9/10.
// Copyright 2010 Sidewayscoding. All rights reserved.
//
#import "MDPreferenceController.h"
@implementation MDPreferenceController
@synthesize preferencesView;
static MDPreferenceController *sharedInstance = nil;
+ (MDPreferenceController*)instance
{
@synchronized(self) {
if (sharedInstance == nil) {
[[self alloc] init];
}
}
return sharedInstance;
}
-(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];
}
return self;
}
@end
View
@@ -33,8 +33,6 @@
NSString *const kMD_SideView_Frame = @"MDSideViewFrame";
NSString *const kMD_MainView_Frame = @"MDMainViewFrame";
NSString *const kMD_SideView_IsLeft = @"MDSideViewLeft";
NSString *const kMD_SideView_bgColor = @"MDSideViewBgColor";
NSString *const kMD_SideView_bgColorInactive = @"MDSideViewBgColorInactive";
NSString *const kMD_SideView_namedColors = @"MDSideViewNamedColors";
NSString *const kMD_TerminalLauncherAppName = @"TerminalLauncherAppName";
NSString *const kMD_OpenTerminalInTab = @"OpenTerminalInTab";
@@ -103,21 +101,10 @@ - (id) init {
self.sideViewLayout = NSRectFromString([defaults objectForKey:kMD_SideView_Frame]);
self.mainViewLayout = NSRectFromString([defaults objectForKey:kMD_MainView_Frame]);
self.showSideViewOnLeft = [defaults boolForKey:kMD_SideView_IsLeft];
self.bgColor = NSColorFromRGBString([defaults objectForKey:kMD_SideView_bgColor]);
self.bgColorInactive = NSColorFromRGBString([defaults objectForKey:kMD_SideView_bgColorInactive]);
self.terminalLauncherAppName = [defaults objectForKey:kMD_TerminalLauncherAppName];
self.openTerminalInTab = [defaults objectForKey:kMD_OpenTerminalInTab];
// reset colors to bundledDefaults if something ain't right
if (!self.bgColor || !self.bgColorInactive) {
if (!self.bgColor) {
self.bgColor = NSColorFromRGBString([bundledDefaultSettings objectForKey:kMD_SideView_bgColor]);
}
if (!self.bgColorInactive) {
self.bgColorInactive = NSColorFromRGBString([bundledDefaultSettings objectForKey:kMD_SideView_bgColorInactive]);
}
[self save];
}
[bundledDefaultSettings release];
NSString *menuTitle = self.showSideViewOnLeft ? @"Show on the Right" : @"Show on the Left";
@@ -153,8 +140,6 @@ - (void)save {
[defaults setObject:NSStringFromRect(self.sideViewLayout) forKey:kMD_SideView_Frame];
[defaults setObject:NSStringFromRect(self.mainViewLayout) forKey:kMD_MainView_Frame];
[defaults setBool:self.showSideViewOnLeft forKey:kMD_SideView_IsLeft];
[defaults setObject:NSColorToRGBString(self.bgColor) forKey:kMD_SideView_bgColor];
[defaults setObject:NSColorToRGBString(self.bgColorInactive) forKey:kMD_SideView_bgColorInactive];
[defaults synchronize];
}
@@ -274,11 +274,7 @@ - (void)terminalButtonPressed:(id)sender {
if ([appName caseInsensitiveCompare:@"iTerm"] == NSOrderedSame) {
appleScriptCommand = [NSString stringWithFormat:@"tell application \"iTerm\"\n\tactivate\n\ttell the first terminal\n\t\tlaunch session \"Default session\"\n\t\ttell the last session\n\t\t\twrite text \"cd \\\"%@\\\"\"\n\t\tend tell\n\tend tell\nend tell", path];
} else if ([appName caseInsensitiveCompare:@"Terminal"] == NSOrderedSame) {
if (openTerminalInTab) {
appleScriptCommand = [NSString stringWithFormat:@"activate application \"Terminal\"\n\ttell application \"System Events\"\n\tkeystroke \"t\" using {command down}\n\tend tell\n\ttell application \"Terminal\"\n\trepeat with win in windows\n\ttry\n\tif get frontmost of win is true then\n\tdo script \"cd \\\"%@\\\"; clear\" in (selected tab of win)\n\tend if\n\tend try\n\tend repeat\n\tend tell", path];
} else {
appleScriptCommand = [NSString stringWithFormat:@"tell application \"Terminal\"\n\tdo script \"cd \\\"%@\\\"\"\n\tactivate\nend tell", path];
}
appleScriptCommand = [NSString stringWithFormat:@"activate application \"Terminal\"\n\ttell application \"System Events\"\n\tkeystroke \"t\" using {command down}\n\tend tell\n\ttell application \"Terminal\"\n\trepeat with win in windows\n\ttry\n\tif get frontmost of win is true then\n\tdo script \"cd \\\"%@\\\"; clear\" in (selected tab of win)\n\tend if\n\tend try\n\tend repeat\n\tend tell", path];
} else {
return;
}
@@ -73,12 +73,27 @@ - (NSOutlineView *)MD_outlineView {
- (void) MD_windowDidBecomeMain:(NSNotification *)notification {
[[self MD_outlineView] setBackgroundColor:[NSColor colorWithCalibratedRed:0.871 green:0.894 blue:0.918 alpha:1.0]];
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
[bindingOptions setObject:NSUnarchiveFromDataTransformerName
forKey:@"NSValueTransformerName"];
[[self MD_outlineView] bind:@"backgroundColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.MDSideViewBgColorNew"
options:bindingOptions];
}
- (void) MD_windowDidResignMain:(NSNotification *)notification {
[[self MD_outlineView] setBackgroundColor:[NSColor colorWithCalibratedWhite:0.929 alpha:1.0]];
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
[bindingOptions setObject:NSUnarchiveFromDataTransformerName
forKey:@"NSValueTransformerName"];
[[self MD_outlineView] bind:@"backgroundColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.MDSideViewBgColorIdle"
options:bindingOptions];
}
@end
@@ -0,0 +1,19 @@
// This reuses a lot of code from Julian Eberius's Textmate-Minimap ( http://github.com/JulianEberius/Textmate-Minimap )
#import <Cocoa/Cocoa.h>
@interface NSWindowController (MD_Preferences)
- (NSArray*)MD_toolbarAllowedItemIdentifiers:(id)sender;
- (NSArray*)MD_toolbarDefaultItemIdentifiers:(id)sender;
- (NSArray*)MD_toolbarSelectableItemIdentifiers:(id)sender;
- (NSToolbarItem*)MD_toolbar:(NSToolbar*)toolbar
itemForItemIdentifier:(NSString*)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag;
- (void)MD_selectToolbarItem:(id)item;
@end
@@ -0,0 +1,74 @@
// This reuses a lot of code from Ciarán Walsh's ProjectPlus ( http://ciaranwal.sh/2008/08/05/textmate-plug-in-projectplus )
// Source: git://github.com/ciaran/projectplus.git
#import "NSWindowController+Preferences.h"
#import "MDMissingDrawer.h"
#import "MDPreferenceController.h"
float ToolbarHeightForWindow(NSWindow *window)
{
NSToolbar *toolbar;
float toolbarHeight = 0.0;
NSRect windowFrame;
toolbar = [window toolbar];
if(toolbar && [toolbar isVisible])
{
windowFrame = [NSWindow contentRectForFrameRect:[window frame] styleMask:[window styleMask]];
toolbarHeight = NSHeight(windowFrame) - NSHeight([[window contentView] frame]);
}
return toolbarHeight;
}
static NSString* MD_PREFERENCES_LABEL = @"Missing Drawer";
@implementation NSWindowController (MD_Preferences)
- (NSArray*)MD_toolbarAllowedItemIdentifiers:(id)sender
{
return [[self MD_toolbarAllowedItemIdentifiers:sender] arrayByAddingObject:MD_PREFERENCES_LABEL];
}
- (NSArray*)MD_toolbarDefaultItemIdentifiers:(id)sender
{
return [[self MD_toolbarDefaultItemIdentifiers:sender] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:MD_PREFERENCES_LABEL,nil]];
}
- (NSArray*)MD_toolbarSelectableItemIdentifiers:(id)sender
{
return [[self MD_toolbarSelectableItemIdentifiers:sender] arrayByAddingObject:MD_PREFERENCES_LABEL];
}
- (NSToolbarItem*)MD_toolbar:(NSToolbar*)toolbar
itemForItemIdentifier:(NSString*)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *item = [self MD_toolbar:toolbar itemForItemIdentifier:itemIdentifier willBeInsertedIntoToolbar:flag];
// if([itemIdentifier isEqualToString:MD_PREFERENCES_LABEL])
// At some point add a picture here
return item;
}
- (void)MD_selectToolbarItem:(id)item
{
if ([[item label] isEqualToString:MD_PREFERENCES_LABEL]) {
if ([[self valueForKey:@"selectedToolbarItem"] isEqualToString:[item label]]) return;
[[self window] setTitle:[item label]];
[self setValue:[item label] forKey:@"selectedToolbarItem"];
NSSize prefsSize = [[[MDPreferenceController instance] preferencesView] frame].size;
NSRect frame = [[self window] frame];
prefsSize.width = [[self window] contentMinSize].width;
[[self window] setContentView:[[MDPreferenceController instance] preferencesView]];
float newHeight = prefsSize.height + ToolbarHeightForWindow([self window]) + 22;
frame.origin.y += frame.size.height - newHeight;
frame.size.height = newHeight;
frame.size.width = prefsSize.width;
[[self window] setFrame:frame display:YES animate:YES];
} else {
[self MD_selectToolbarItem:item];
}
}
@end
Oops, something went wrong.

0 comments on commit b9b9e76

Please sign in to comment.