Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Outline view now shows generic list of repo file system
- Loading branch information
Justin Palmer
committed
Oct 2, 2008
1 parent
0c47f4a
commit 8f0f09f
Showing
8 changed files
with
598 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// GNFileSystemItem.h | ||
// | ||
// Based on code examples in NSOutlineView documentation. | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface GNFileSystemItem : NSObject | ||
{ | ||
NSString *relativePath; | ||
GNFileSystemItem *parent; | ||
NSMutableArray *children; | ||
NSImage *image; | ||
} | ||
|
||
+ (GNFileSystemItem *)rootItem; | ||
+ (NSString *)repoRoot; | ||
- (int)numberOfChildren;// Returns -1 for leaf nodes | ||
- (GNFileSystemItem *)childAtIndex:(int)n;// Invalid to call on leaf nodes | ||
- (NSString *)fullPath; | ||
- (NSString *)relativePath; | ||
- (void)setRelativePath:(NSString *)aString; | ||
- (NSImage*)icon; | ||
- (BOOL)isLeafNode; | ||
- (NSDictionary*)attributes; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// | ||
// GNFileSystemItem.m | ||
// | ||
// Based on code examples in NSOutlineView documentation. | ||
|
||
#import "GNFileSystemItem.h" | ||
|
||
|
||
@implementation GNFileSystemItem | ||
|
||
static GNFileSystemItem *rootItem = nil; | ||
#define IsALeafNode ((id)-1) | ||
|
||
- (id)initWithPath:(NSString *)path parent:(GNFileSystemItem *)obj | ||
{ | ||
if (self = [super init]) | ||
{ | ||
relativePath = [[path lastPathComponent] copy]; | ||
parent = obj; | ||
} | ||
return self; | ||
} | ||
|
||
|
||
+ (GNFileSystemItem *)rootItem | ||
{ | ||
if (rootItem == nil) | ||
{ | ||
rootItem = [[GNFileSystemItem alloc] initWithPath:[GNFileSystemItem repoRoot] parent:nil]; | ||
} | ||
return rootItem; | ||
} | ||
|
||
+ (NSString *)repoRoot { | ||
return [[[NSApplication sharedApplication] delegate] repository_location]; | ||
} | ||
|
||
// - (NSString *)ignoredByGit:(NSString *)fileItem | ||
// { | ||
// NSString *ret = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/env" arguments: | ||
// [NSArray arrayWithObjects:@"git", @"status", fileItem, nil]]; | ||
// NSLog(@"%s RET: %@", _cmd, ret); | ||
// return ret; | ||
// } | ||
|
||
// Creates, caches, and returns the array of children | ||
// Loads children incrementally | ||
- (NSArray *)children | ||
{ | ||
if (children == NULL) | ||
{ | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSString *fullPath = [self fullPath]; | ||
BOOL isDir, valid = [fileManager fileExistsAtPath:fullPath isDirectory:&isDir]; | ||
|
||
if (valid && isDir) | ||
{ | ||
NSArray *array = [fileManager directoryContentsAtPath:fullPath]; | ||
int numChildren = [array count]; | ||
children = [[NSMutableArray alloc] initWithCapacity:numChildren]; | ||
for (NSString *sourceFile in array) | ||
{ | ||
if([[sourceFile lastPathComponent] hasPrefix:@"."]) { | ||
continue; | ||
} | ||
|
||
// if([self ignoredByGit:sourceFile]) { | ||
// continue; | ||
// } | ||
|
||
GNFileSystemItem *newChild = [[GNFileSystemItem alloc] initWithPath:sourceFile parent:self]; | ||
[children addObject:newChild]; | ||
[newChild release]; | ||
} | ||
} | ||
else | ||
{ | ||
children = IsALeafNode; | ||
} | ||
} | ||
return children; | ||
} | ||
|
||
|
||
- (NSImage*)icon | ||
{ | ||
if (image == nil) | ||
{ | ||
image = [[[NSWorkspace sharedWorkspace] iconForFile: [self fullPath]] retain]; | ||
} | ||
|
||
return image; | ||
} | ||
|
||
|
||
- (NSDictionary*)attributes | ||
{ | ||
return [NSDictionary dictionaryWithDictionary: [[NSFileManager defaultManager] fileAttributesAtPath: [self fullPath] traverseLink: YES]]; | ||
} | ||
|
||
|
||
- (NSString *)relativePath | ||
{ | ||
return relativePath; | ||
} | ||
|
||
|
||
- (void)setRelativePath:(NSString *)aString | ||
{ | ||
if (aString != relativePath) | ||
{ | ||
[relativePath release]; | ||
[relativePath = aString copy]; | ||
} | ||
} | ||
|
||
|
||
- (NSString *)fullPath | ||
{ | ||
// If no parent, return our own relative path | ||
if (parent == nil) { | ||
return [GNFileSystemItem repoRoot]; | ||
} | ||
// recurse up the hierarchy, prepending each parent’s path | ||
return [[parent fullPath] stringByAppendingPathComponent:relativePath]; | ||
} | ||
|
||
|
||
- (GNFileSystemItem *)childAtIndex:(int)n | ||
{ | ||
return [[self children] objectAtIndex:n]; | ||
} | ||
|
||
|
||
- (BOOL)isLeafNode | ||
{ | ||
return [self children] == IsALeafNode; | ||
} | ||
|
||
- (int)numberOfChildren | ||
{ | ||
id tmp = [self children]; | ||
return (tmp == IsALeafNode) ? (-1) : [tmp count]; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[image release]; | ||
if (children != IsALeafNode) [children release]; | ||
[relativePath release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface GNTreeDataSource : NSObject | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#import "GNTreeDataSource.h" | ||
#import "GNFileSystemItem.h" | ||
|
||
@implementation GNTreeDataSource | ||
|
||
// Data Source methods | ||
|
||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { | ||
return (item == nil) ? 1 : [item numberOfChildren]; | ||
} | ||
|
||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { | ||
return (item == nil) ? YES : ([item numberOfChildren] != -1); | ||
} | ||
|
||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { | ||
return (item == nil) ? [GNFileSystemItem rootItem] : [(GNFileSystemItem *)item childAtIndex:index]; | ||
} | ||
|
||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { | ||
return (item == nil) ? @"/" : (id)[item relativePath]; | ||
} | ||
|
||
// Delegate methods | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# TreeController.rb | ||
# GitNub | ||
# | ||
# Created by Justin Palmer on 9/30/08. | ||
# Copyright (c) 2008 ENTP <http://hoth.entp.com>. All rights reserved. | ||
# | ||
|
||
require 'osx/cocoa' | ||
OSX.ns_import 'GNFileSystemItem' | ||
OSX.ns_import 'GNTreeDataSource' | ||
|
||
|
||
class TreeController < OSX::NSObject | ||
ib_outlet :tree_outline | ||
ib_outlet :file_canvas | ||
|
||
def awakeFromNib | ||
#@tree_outline.setDelegate(self) | ||
end | ||
end |