Skip to content
Browse files

adding workspace header and invoking native methods instead of replac…

…ing them entirely
  • Loading branch information...
1 parent fbd21e1 commit 0a6d75f348decf0549494a97612a33e025ee61bd @markhuot committed Jun 10, 2011
Showing with 142 additions and 19 deletions.
  1. +6 −0 ProjectPlus.xcodeproj/project.pbxproj
  2. +4 −0 src/MHOpenFiles.h
  3. +57 −7 src/MHOpenFiles.m
  4. +16 −0 src/MHOutlineView.h
  5. +43 −0 src/MHOutlineView.m
  6. +16 −12 src/ProjectTree.mm
View
6 ProjectPlus.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 0E4A151513A2C3E40096ACDE /* MHOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E4A151413A2C3E40096ACDE /* MHOutlineView.m */; };
0E70FE8D137F359E00804EB9 /* MHOpenFiles.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E70FE8C137F359E00804EB9 /* MHOpenFiles.m */; };
0E70FE8F137F35FE00804EB9 /* shadow.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 0E70FE8E137F35FE00804EB9 /* shadow.tiff */; };
0E70FE91137F3BB800804EB9 /* FossilIcons.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E70FE90137F3BB800804EB9 /* FossilIcons.mm */; };
@@ -71,6 +72,8 @@
/* Begin PBXFileReference section */
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
+ 0E4A151313A2C3E40096ACDE /* MHOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHOutlineView.h; sourceTree = "<group>"; };
+ 0E4A151413A2C3E40096ACDE /* MHOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHOutlineView.m; sourceTree = "<group>"; };
0E70FE8B137F359E00804EB9 /* MHOpenFiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHOpenFiles.h; sourceTree = "<group>"; };
0E70FE8C137F359E00804EB9 /* MHOpenFiles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHOpenFiles.m; sourceTree = "<group>"; };
0E70FE8E137F35FE00804EB9 /* shadow.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = shadow.tiff; sourceTree = "<group>"; };
@@ -225,6 +228,8 @@
915AD4D30ED9E6AD0017679A /* src */ = {
isa = PBXGroup;
children = (
+ 0E4A151313A2C3E40096ACDE /* MHOutlineView.h */,
+ 0E4A151413A2C3E40096ACDE /* MHOutlineView.m */,
0E70FE8B137F359E00804EB9 /* MHOpenFiles.h */,
0E70FE8C137F359E00804EB9 /* MHOpenFiles.m */,
915AD4DB0ED9E6AD0017679A /* scm */,
@@ -419,6 +424,7 @@
0E70FE8D137F359E00804EB9 /* MHOpenFiles.m in Sources */,
0E70FE91137F3BB800804EB9 /* FossilIcons.mm in Sources */,
0E8A934A138C20150044F2D2 /* MHDividerView.m in Sources */,
+ 0E4A151513A2C3E40096ACDE /* MHOutlineView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
4 src/MHOpenFiles.h
@@ -16,6 +16,8 @@
id tabView;
}
++ (MHOpenFiles *)sharedInstance;
+
+ (id)objectForTabs:(id)theTabs;
- (id)initForTabs:(id)theTabs;
@@ -31,4 +33,6 @@
- (void)resizeViews;
+- (void)selectFile:(NSString *)path;
+
@end
View
64 src/MHOpenFiles.m
@@ -10,8 +10,19 @@
@implementation MHOpenFiles
+static MHOpenFiles *sharedInstance;
static NSMutableArray *objectList = NULL;
++ (MHOpenFiles *)sharedInstance
+{
+ if (!sharedInstance)
+ {
+ sharedInstance = [MHOpenFiles new];
+ }
+
+ return sharedInstance;
+}
+
+ (id)objectForTabs:(id)theTabs
{
if (!objectList) {
@@ -29,6 +40,12 @@ + (id)objectForTabs:(id)theTabs
MHOpenFiles *obj = [[MHOpenFiles alloc] initForTabs:theTabs];
[objectList addObject:obj];
+
+ if (!sharedInstance)
+ {
+ sharedInstance = obj;
+ }
+
return obj;
}
@@ -46,6 +63,7 @@ - (id)initForTabs:(id)theTabs
- (void)setOutlineView:(NSOutlineView *)theOutlineView
{
outlineView = theOutlineView;
+ [outlineView setIndentationPerLevel:0.0];
[outlineView expandItem:[outlineView itemAtRow:0]];
}
@@ -83,21 +101,45 @@ - (void)removeFile:(NSString *)path
[self resizeViews];
}
+- (void)selectFile:(NSString *)path
+{
+ int len = [openFiles count];
+ int i = 0;
+ for (i; i<len; i++)
+ {
+ NSString *filePath = [openFiles objectAtIndex:i];
+ if ([path isEqualToString:filePath])
+ {
+ [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:(i+1)] byExtendingSelection:NO];
+ }
+ }
+}
+
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
- return [openFiles count];
+ return (item == nil) ? 1 : [openFiles count];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
- return NO;
+ return (item == @"WORKSPACE") ? YES : NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
- return (item == nil) ? [openFiles objectAtIndex:index] : nil;
+ return (item == nil) ? @"WORKSPACE" : [openFiles objectAtIndex:index];
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
+{
+ return (item == @"WORKSPACE") ? YES : NO;
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
+{
+ return (item == @"WORKSPACE") ? NO : YES;
}
@@ -109,9 +151,17 @@ - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTabl
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
- NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:item];
- [icon setSize:NSMakeSize(16.0, 16.0)];
- [cell setImage:icon];
+ if (item == @"WORKSPACE")
+ {
+ [cell setImage:nil];
+ }
+
+ else
+ {
+ NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:item];
+ [icon setSize:NSMakeSize(16.0, 16.0)];
+ [cell setImage:icon];
+ }
}
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
@@ -129,7 +179,7 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification
- (void)resizeViews
{
- float neededHeight = ([outlineView numberOfRows] * [outlineView rowHeight]) + (6.0 * [outlineView numberOfRows]);
+ float neededHeight = ([outlineView numberOfRows] * [outlineView rowHeight]) + (6.0 * [outlineView numberOfRows]) + 2.0;
NSView *openFilesCustomView = (NSView *)[[outlineView superview] superview];
NSView *drawerView = [openFilesCustomView superview];
View
16 src/MHOutlineView.h
@@ -0,0 +1,16 @@
+//
+// MHOutlineView.h
+// ProjectPlus
+//
+// Created by Mark Huot on 6/6/11.
+// Copyright 2011 Home. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface MHOutlineView : NSOutlineView {
+
+}
+
+@end
View
43 src/MHOutlineView.m
@@ -0,0 +1,43 @@
+//
+// MHOutlineView.m
+// ProjectPlus
+//
+// Created by Mark Huot on 6/6/11.
+// Copyright 2011 Home. All rights reserved.
+//
+
+#import "MHOutlineView.h"
+
+
+@implementation MHOutlineView
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ // Initialization code here.
+ }
+
+ return self;
+}
+
+- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row
+{
+ NSRect rc = [super frameOfCellAtColumn:column row:row];
+
+ if (row > 0)
+ {
+ CGFloat indent = 14.0; //[self indentationPerLevel];
+ rc.origin.x += indent;
+ rc.size.width -= indent;
+ }
+
+ return rc;
+}
+
+- (void)dealloc
+{
+ [super dealloc];
+}
+
+@end
View
28 src/ProjectTree.mm
@@ -1,6 +1,7 @@
#import "JRSwizzle.h"
#import "MHOpenFiles.h"
#import "MHDividerView.h"
+#import "MHOutlineView.h"
#define OakImageAndTextCell NSClassFromString(@"OakImageAndTextCell")
@interface ProjectTree : NSObject
@@ -39,8 +40,8 @@ - (void)ProjectTree_windowDidLoad
NSArray *rootItems = [self valueForKey:@"rootItems"];
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OakProjectWindowShowTabBarEnabled"];
- [[NSUserDefaults standardUserDefaults] synchronize];
+ //[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OakProjectWindowShowTabBarEnabled"];
+ //[[NSUserDefaults standardUserDefaults] synchronize];
/*NSDictionary *newRoot = [NSDictionary dictionaryWithObjectsAndKeys:
@"Files", @"displayName",
@@ -106,7 +107,7 @@ - (void)ProjectTree_windowDidLoad
[newScrollView setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
NSRect clipViewBounds = [[newScrollView contentView] bounds];
- NSOutlineView* openFiles = [[[NSOutlineView alloc] initWithFrame:clipViewBounds] autorelease];
+ MHOutlineView *openFiles = [[[MHOutlineView alloc] initWithFrame:clipViewBounds] autorelease];
[openFiles setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
[openFiles setRowHeight:14];
[openFiles setIntercellSpacing:NSMakeSize(3.0, 6.0)];
@@ -137,7 +138,7 @@ - (void)ProjectTree_windowDidLoad
// Add the divider
//
//
- NSView *dividerView = [[MHDividerView alloc] initWithFrame:NSMakeRect(-[drawer frame].size.width, 0, [drawer frame].size.width, 2.0)];
+ NSView *dividerView = [[MHDividerView alloc] initWithFrame:NSMakeRect(0, [drawer frame].size.height+2, [drawer frame].size.width, 2.0)];
[dividerView setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
[drawer addSubview:dividerView];
@@ -203,20 +204,25 @@ - (void)ProjectTree_outlineView:(id)outlineView willDisplayCell:(id)cell forTabl
- (void)ProjectTree_tabBarView:(id)arg1 didOpenTab:(id)tab
{
+ [self ProjectTree_tabBarView:arg1 didOpenTab:tab];
+
MHOpenFiles *openFilesClass = [MHOpenFiles objectForTabs:[self valueForKey:@"tabBarView"]];
[openFilesClass addFile:[tab identifier]];
-
- //NSLog(@"%@", [self valueForKey:@"showTabBarView"]?@"YES":@"NO");
- //[self valueForKey:@"tabBarView"];
}
- (void)ProjectTree_tabBarView:(id)arg1 didCloseTab:(id)tab
{
+ [self ProjectTree_tabBarView:arg1 didOpenTab:tab];
+
MHOpenFiles *openFilesClass = [MHOpenFiles objectForTabs:[self valueForKey:@"tabBarView"]];
[openFilesClass removeFile:[tab identifier]];
}
-// can't override this because important things happen that we don't want to have to recreate
-// - (void)ProjectTree_tabBarView:(id)arg1 didSelectTab:(id)arg2 { /* ... */ }
+- (void)ProjectTree_tabBarView:(id)arg1 didSelectTab:(id)arg2
+{
+ [self ProjectTree_tabBarView:arg1 didSelectTab:arg2];
+
+ [[MHOpenFiles sharedInstance] selectFile:[arg2 identifier]];
+}
@end
@@ -233,9 +239,7 @@ + (void)load
[NSClassFromString(@"OakProjectController") jr_swizzleMethod:@selector(outlineView:willDisplayCell:forTableColumn:item:) withMethod:@selector(ProjectTree_outlineView:willDisplayCell:forTableColumn:item:) error:NULL];
[NSClassFromString(@"OakProjectController") jr_swizzleMethod:@selector(tabBarView:didOpenTab:) withMethod:@selector(ProjectTree_tabBarView:didOpenTab:) error:NULL];
[NSClassFromString(@"OakProjectController") jr_swizzleMethod:@selector(tabBarView:didCloseTab:) withMethod:@selector(ProjectTree_tabBarView:didCloseTab:) error:NULL];
-
- // can't override this because important things happen that we don't want to have to recreate
- // [NSClassFromString(@"OakProjectController") jr_swizzleMethod:@selector(tabBarView:didSelectTab:) withMethod:@selector(ProjectTree_tabBarView:didSelectTab:) error:NULL];
+ [NSClassFromString(@"OakProjectController") jr_swizzleMethod:@selector(tabBarView:didSelectTab:) withMethod:@selector(ProjectTree_tabBarView:didSelectTab:) error:NULL];
}
+ (BOOL)preserveTreeState;

0 comments on commit 0a6d75f

Please sign in to comment.
Something went wrong with that request. Please try again.