Browse files

Add QuickLook support in tree view

This adds a QuickLook button that will allow you to directly view any file in
the tree view in QuickLook. This is really nice for PDF's and images. You can
select multiple files and even play a slideshow if you want.

Currently it does not remove temporary files it created. This means that they
will probably stay around until you reboot.
  • Loading branch information...
1 parent b62e92a commit 28e8bacb897227751849bd84ea35956ce6430ec5 @pieter committed Jun 16, 2008
Showing with 1,587 additions and 1,382 deletions.
  1. +3 −0 ApplicationController.m
  2. +85 −0 CWQuickLook.h
  3. +1,454 −1,381 English.lproj/MainMenu.xib
  4. +2 −0 GitX.xcodeproj/project.pbxproj
  5. +2 −0 PBDetailController.h
  6. +40 −1 PBDetailController.m
  7. +1 −0 PBGitTree.m
View
3 ApplicationController.m
@@ -14,6 +14,9 @@ @implementation ApplicationController
- (ApplicationController*) init
{
+ if([[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load])
+ NSLog(@"Quick Look loaded!");
+
// Find the current repository
char* a = getenv("PWD");
NSString* path;
View
85 CWQuickLook.h
@@ -0,0 +1,85 @@
+@interface QLPreviewPanel : NSPanel
++ (id)sharedPreviewPanel;
++ (id)_previewPanel;
++ (BOOL)isSharedPreviewPanelLoaded;
+- (id)initWithContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24 backing:(unsigned int)fp28 defer:(BOOL)fp32;
+- (id)initWithCoder:(id)fp8;
+- (void)dealloc;
+- (BOOL)isOpaque;
+- (BOOL)canBecomeKeyWindow;
+- (BOOL)canBecomeMainWindow;
+- (BOOL)shouldIgnorePanelFrameChanges;
+- (BOOL)isOpen;
+- (void)setFrame:(struct _NSRect)fp8 display:(BOOL)fp24 animate:(BOOL)fp28;
+- (id)_subEffectsForWindow:(id)fp8 itemFrame:(struct _NSRect)fp12 transitionWindow:(id *)fp28;
+- (id)_scaleEffectForItemFrame:(struct _NSRect)fp8 transitionWindow:(id *)fp24;
+- (void)_invertCurrentEffect;
+- (struct _NSRect)_currentItemFrame;
+- (void)setAutosizesAndCenters:(BOOL)fp8;
+- (BOOL)autosizesAndCenters;
+- (void)makeKeyAndOrderFront:(id)fp8;
+- (void)makeKeyAndOrderFrontWithEffect:(int)fp8;
+- (void)makeKeyAndGoFullscreenWithEffect:(int)fp8;
+- (void)makeKeyAndOrderFrontWithEffect:(int)fp8 canClose:(BOOL)fp12;
+- (void)_makeKeyAndOrderFrontWithEffect:(int)fp8 canClose:(BOOL)fp12 willOpen:(BOOL)fp16 toFullscreen:(BOOL)fp20;
+- (int)openingEffect;
+- (void)closePanel;
+- (void)close;
+- (void)closeWithEffect:(int)fp8;
+- (void)closeWithEffect:(int)fp8 canReopen:(BOOL)fp12;
+- (void)_closeWithEffect:(int)fp8 canReopen:(BOOL)fp12;
+- (void)windowEffectDidTerminate:(id)fp8;
+- (void)_close:(id)fp8;
+- (void)sendEvent:(id)fp8;
+- (void)selectNextItem;
+- (void)selectPreviousItem;
+- (void)setURLs:(id)fp8 currentIndex:(unsigned int)fp12 preservingDisplayState:(BOOL)fp16;
+- (void)setURLs:(id)fp8 preservingDisplayState:(BOOL)fp12;
+- (void)setURLs:(id)fp8;
+- (id)URLs;
+- (unsigned int)indexOfCurrentURL;
+- (void)setIndexOfCurrentURL:(unsigned int)fp8;
+- (void)setDelegate:(id)fp8;
+- (id)sharedPreviewView;
+- (void)setSharedPreviewView:(id)fp8;
+- (void)setCyclesSelection:(BOOL)fp8;
+- (BOOL)cyclesSelection;
+- (void)setShowsAddToiPhotoButton:(BOOL)fp8;
+- (BOOL)showsAddToiPhotoButton;
+- (void)setShowsiChatTheaterButton:(BOOL)fp8;
+- (BOOL)showsiChatTheaterButton;
+- (void)setShowsFullscreenButton:(BOOL)fp8;
+- (BOOL)showsFullscreenButton;
+- (void)setShowsIndexSheetButton:(BOOL)fp8;
+- (BOOL)showsIndexSheetButton;
+- (void)setAutostarts:(BOOL)fp8;
+- (BOOL)autostarts;
+- (void)setPlaysDuringPanelAnimation:(BOOL)fp8;
+- (BOOL)playsDuringPanelAnimation;
+- (void)setDeferredLoading:(BOOL)fp8;
+- (BOOL)deferredLoading;
+- (void)setEnableDragNDrop:(BOOL)fp8;
+- (BOOL)enableDragNDrop;
+- (void)start:(id)fp8;
+- (void)stop:(id)fp8;
+- (void)setShowsIndexSheet:(BOOL)fp8;
+- (BOOL)showsIndexSheet;
+- (void)setShareWithiChat:(BOOL)fp8;
+- (BOOL)shareWithiChat;
+- (void)setPlaysSlideShow:(BOOL)fp8;
+- (BOOL)playsSlideShow;
+- (void)setIsFullscreen:(BOOL)fp8;
+- (BOOL)isFullscreen;
+- (void)setMandatoryClient:(id)fp8;
+- (id)mandatoryClient;
+- (void)setForcedContentTypeUTI:(id)fp8;
+- (id)forcedContentTypeUTI;
+- (void)setDocumentURLs:(id)fp8;
+- (void)setDocumentURLs:(id)fp8 preservingDisplayState:(BOOL)fp12;
+- (void)setDocumentURLs:(id)fp8 itemFrame:(struct _NSRect)fp12;
+- (void)setURLs:(id)fp8 itemFrame:(struct _NSRect)fp12;
+- (void)setAutoSizeAndCenterOnScreen:(BOOL)fp8;
+- (void)setShowsAddToiPhoto:(BOOL)fp8;
+- (void)setShowsiChatTheater:(BOOL)fp8;
+- (void)setShowsFullscreen:(BOOL)fp8;
+@end
View
2,835 English.lproj/MainMenu.xib
1,454 additions, 1,381 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 GitX.xcodeproj/project.pbxproj
@@ -43,6 +43,7 @@
77C8280C06725ACE000B614F /* ApplicationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplicationController.m; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* GitX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GitX.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ F53EE3590E06BBA00022B925 /* CWQuickLook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CWQuickLook.h; sourceTree = "<group>"; };
F561727C0E056A11001DCD79 /* diff_style.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = diff_style.css; path = html/diff_style.css; sourceTree = "<group>"; };
F56173270E056ED2001DCD79 /* diffHighlighter.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = diffHighlighter.js; path = html/diffHighlighter.js; sourceTree = "<group>"; };
F56174550E058893001DCD79 /* PBGitTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitTree.h; sourceTree = "<group>"; };
@@ -202,6 +203,7 @@
F56524BA0E02D22D00F03B52 /* NSFileHandleExt.h */,
F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */,
F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */,
+ F53EE3590E06BBA00022B925 /* CWQuickLook.h */,
);
name = Aux;
sourceTree = "<group>";
View
2 PBDetailController.h
@@ -31,6 +31,8 @@
- (IBAction) setRawView: sender;
- (IBAction) setTreeView: sender;
+- (IBAction) toggleQuickView: sender;
- (IBAction) openSelectedFile: sender;
+- (void) updateQuicklook;
@end
View
41 PBDetailController.m
@@ -7,6 +7,9 @@
//
#import "PBDetailController.h"
+#import "CWQuickLook.h"
+
+#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
@implementation PBDetailController
@@ -19,7 +22,7 @@ @implementation PBDetailController
[fileBrowser setDoubleAction:@selector(openSelectedFile:)];
self.selectedTab = [NSNumber numberWithInt:0];
[commitController addObserver:self forKeyPath:@"selection" options:(NSKeyValueObservingOptionNew,NSKeyValueObservingOptionOld) context:@"commitChange"];
-
+ [treeController addObserver:self forKeyPath:@"selection" options:0 context:@"treeChange"];
return self;
}
@@ -58,6 +61,10 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
[self updateKeys];
return;
}
+ else if ([(NSString *)context isEqualToString: @"treeChange"]) {
+ [self updateQuicklook];
+ }
+
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@@ -83,5 +90,37 @@ - (IBAction) setTreeView: sender {
self.selectedTab = [NSNumber numberWithInt:2];
}
+- (IBAction) toggleQuickView: sender
+{
+ id panel = [QLPreviewPanel sharedPreviewPanel];
+ if ([panel isOpen]) {
+ [panel closePanel];
+ } else {
+ [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFrontWithEffect:1];
+ [self updateQuicklook];
+ }
+}
+
+- (void) updateQuicklook
+{
+ NSLog(@"Updating quicklook");
+ if (![[QLPreviewPanel sharedPreviewPanel] isOpen])
+ return;
+
+ NSArray* selectedFiles = [treeController selectedObjects];
+
+ if ([selectedFiles count] == 0)
+ return;
+
+ NSMutableArray* fileNames = [NSMutableArray array];
+ for (PBGitTree* tree in selectedFiles) {
+ NSString* s = [tree tmpFileNameForContents];
+ if (s)
+ [fileNames addObject:[NSURL fileURLWithPath: s]];
+ }
+
+ [[QLPreviewPanel sharedPreviewPanel] setURLs:fileNames currentIndex:0 preservingDisplayState:YES];
+
+}
@end
View
1 PBGitTree.m
@@ -64,6 +64,7 @@ - (NSString*) tmpFileNameForContents
{
if (!leaf)
return nil;
+ NSLog(@"Getting tmp file");
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
NSData* data = [handle readDataToEndOfFile];
return [PBEasyPipe writeData:data toTempFileWithName:path];

0 comments on commit 28e8bac

Please sign in to comment.