mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Allow double click to open file
This commit is contained in:
+2002
-1940
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,8 @@
|
||||
@interface PBDetailController : NSObject {
|
||||
IBOutlet NSNumber* selectedTab;
|
||||
IBOutlet NSArrayController* commitController;
|
||||
IBOutlet NSTreeController* treeController;
|
||||
IBOutlet NSOutlineView* fileBrowser;
|
||||
|
||||
PBGitTree* gitTree;
|
||||
PBGitCommit* webCommit;
|
||||
@@ -29,4 +31,6 @@
|
||||
- (IBAction) setRawView: sender;
|
||||
- (IBAction) setTreeView: sender;
|
||||
|
||||
- (IBAction) openSelectedFile: sender;
|
||||
|
||||
@end
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
- awakeFromNib
|
||||
{
|
||||
[fileBrowser setTarget:self];
|
||||
[fileBrowser setDoubleAction:@selector(openSelectedFile:)];
|
||||
self.selectedTab = [NSNumber numberWithInt:0];
|
||||
[commitController addObserver:self forKeyPath:@"selection" options:(NSKeyValueObservingOptionNew,NSKeyValueObservingOptionOld) context:@"commitChange"];
|
||||
|
||||
@@ -61,6 +63,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction) openSelectedFile: sender
|
||||
{
|
||||
NSArray* selectedFiles = [treeController selectedObjects];
|
||||
if ([selectedFiles count] == 0)
|
||||
return;
|
||||
PBGitTree* tree = [selectedFiles objectAtIndex:0];
|
||||
NSString* name = [tree tmpFileNameForContents];
|
||||
[[NSWorkspace sharedWorkspace] openTempFile:name];
|
||||
}
|
||||
|
||||
- (IBAction) setDetailedView: sender {
|
||||
self.selectedTab = [NSNumber numberWithInt:0];
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@
|
||||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args;
|
||||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir;
|
||||
|
||||
+ (NSString*) writeData:(NSData*) data toTempFileWithName: (NSString *) fileName;
|
||||
@end
|
||||
|
||||
@@ -50,4 +50,16 @@
|
||||
{
|
||||
return [self outputForCommand:cmd withArgs:args inDir:nil];
|
||||
}
|
||||
|
||||
+ (NSString*) writeData:(NSData*) data toTempFileWithName: (NSString *) fileName
|
||||
{
|
||||
NSString* newName = [NSString stringWithFormat: @"%@/XXXXXX%@", NSTemporaryDirectory(), fileName];
|
||||
char *template = (char*) [newName fileSystemRepresentation];
|
||||
int fd = mkstemps(template, [fileName length]);
|
||||
NSFileHandle* handle = [[NSFileHandle alloc] initWithFileDescriptor:fd];
|
||||
[handle writeData: data];
|
||||
[handle closeFile];
|
||||
return [NSString stringWithUTF8String:template];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
+ (PBGitTree*) rootForCommit: (id) commit;
|
||||
+ (PBGitTree*) treeForTree: (PBGitTree*) tree andPath: (NSString*) path;
|
||||
|
||||
- (NSString*) tmpFileNameForContents;
|
||||
|
||||
@property(copy) NSString* sha;
|
||||
@property(copy) NSString* path;
|
||||
@property(assign) BOOL leaf;
|
||||
|
||||
+10
@@ -9,6 +9,7 @@
|
||||
#import "PBGitTree.h"
|
||||
#import "PBGitCommit.h"
|
||||
#import "NSFileHandleExt.h"
|
||||
#import "PBEasyPipe.h"
|
||||
|
||||
@implementation PBGitTree
|
||||
|
||||
@@ -59,6 +60,15 @@
|
||||
return string;
|
||||
}
|
||||
|
||||
- (NSString*) tmpFileNameForContents
|
||||
{
|
||||
if (!leaf)
|
||||
return nil;
|
||||
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
NSData* data = [handle readDataToEndOfFile];
|
||||
return [PBEasyPipe writeData:data toTempFileWithName:path];
|
||||
}
|
||||
|
||||
- (NSArray*) children
|
||||
{
|
||||
if (children != nil)
|
||||
|
||||
Reference in New Issue
Block a user