!ß66: Add an iVar to track the search mode before/after quicklooking #724

Merged
merged 9 commits into from Mar 20, 2012
@@ -119,10 +119,13 @@ - (void)sendEvent:(NSEvent *)theEvent {
[QSModifierKeyEvent checkForModifierEvent:theEvent];
break;
}
- if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isInFullScreenMode]) {
+ if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
if ([theEvent type] == NSKeyDown) {
- if ([[theEvent charactersIgnoringModifiers] isEqual:@"y"] && ([theEvent modifierFlags] & (NSCommandKeyMask | NSAlternateKeyMask))) {
- [[self mainWindow] sendEvent:theEvent];
+ // Close the Quicksilver window when ⌘⌥Y is pressed in full screen, or the spacebar or ESC key is pressed (send event to QSSearchObjectView:keyDown)
+ QLPreviewPanel *quicklookPanel = [QLPreviewPanel sharedPreviewPanel];
+ NSString *key = [theEvent charactersIgnoringModifiers];
+ if (([quicklookPanel isInFullScreenMode] && [key isEqualToString:@"y"] && ([theEvent modifierFlags] & (NSCommandKeyMask | NSAlternateKeyMask))) || [key isEqualToString:@" "] || [theEvent keyCode] == 53) {
+ [(QSSearchObjectView *)[quicklookPanel delegate] closePreviewPanel];
return;
}
}
@@ -181,13 +181,13 @@ - (void)willHideMainWindow:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"InterfaceDeactivated" object:self];
[[self window] makeFirstResponder:nil];
}
-}
-
-- (void)hideMainWindowWithEffect:(id)effect {
// Close the Quicklook panel if the QS window closes
if([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
- [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
+ [(QSSearchObjectView *)[[QLPreviewPanel sharedPreviewPanel] delegate] closePreviewPanel];
}
+}
+
+- (void)hideMainWindowWithEffect:(id)effect {
[self willHideMainWindow:nil];
[self setHiding:YES];
if (effect && [[NSUserDefaults standardUserDefaults] boolForKey:kUseEffects])
@@ -465,6 +465,10 @@ - (BOOL)windowShouldClose:(id)sender {
- (void)windowDidResignMain:(NSNotification *)aNotification {}
- (void)windowDidResignKey:(NSNotification *)aNotification {
+ // Close the Quicklook panel if the QS window closes
+ if([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
+ return;
+ }
if ([aNotification object] == [self window]) {
if (hidingWindow) return;
if ([hideTimer isValid]) {
@@ -59,7 +59,7 @@ typedef enum QSSearchMode {
NSFont *textCellFont; // for text entry mode
NSColor *textCellFontColor; // for text entry mode
QLPreviewPanel* previewPanel;
-
+ QSSearchMode savedSearchMode;
@public
QSResultController *resultController;
@@ -206,7 +206,12 @@ typedef enum QSSearchMode {
@result YES if the object is a file or URL object, otherwise NO
*/
- (BOOL)canQuicklookCurrentObject;
-
+/*!
+ @closePreviewPanel
+ @abstract Method to close the preview panel
+ @discussion Closes the preview panel, returning Quicksilver to the state it was in before the panel was open
+ */
+- (void)closePreviewPanel;
- (IBAction)togglePreviewPanel:(id)previewPanel;
- (IBAction)togglePreviewPanelFullScreen:(id)previewPanel;
@end
@@ -1047,15 +1047,8 @@ - (BOOL)resignFirstResponder {
// This method deals with all keydowns. Some very interesting things could be done by manipulating this method
- (void)keyDown:(NSEvent *)theEvent {
- // Send events to the preview panel if it's open
- if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
- // space key
- if(![self handleBoundKey:theEvent]) {
- [previewPanel keyDown:theEvent];
- }
- return;
- }
- [NSThread setThreadPriority:1.0];
+
+ [NSThread setThreadPriority:1.0];
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval delay = [theEvent timestamp] -lastTime;
//if (VERBOSE) NSLog(@"KeyD: %@\r%@", [theEvent characters] , theEvent);
@@ -1369,6 +1362,7 @@ - (void)insertSpace:(id)sender {
[self moveLeft:sender];
else
[self moveRight:sender];
+ break;
case 6: // Show Quicklook window
[self togglePreviewPanel:nil];
break;
@@ -1843,7 +1837,7 @@ - (void)browse:(int)direction {
@implementation QSSearchObjectView (Quicklook)
--(BOOL)canQuicklookCurrentObject {
+- (BOOL)canQuicklookCurrentObject {
id object = [self objectValue];
// resolve ranked objects
if ([object isKindOfClass:[QSRankedObject class]]) {
@@ -1855,17 +1849,24 @@ -(BOOL)canQuicklookCurrentObject {
}
if ([object validPaths] || [[object primaryType] isEqualToString:QSURLType]) {
quicklookObject = [object retain];
+ savedSearchMode = searchMode;
return YES;
}
return NO;
}
+- (void)closePreviewPanel {
+ [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
+ [quicklookObject release];
+ quicklookObject = nil;
+ searchMode = savedSearchMode;
+}
+
+
- (IBAction)togglePreviewPanel:(id)previewPanel
{
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
- [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
- [quicklookObject release];
- quicklookObject = nil;
+ [self closePreviewPanel];
} else {
if ([self canQuicklookCurrentObject]) {
[NSApp activateIgnoringOtherApps:YES];
@@ -1882,9 +1883,7 @@ - (IBAction)togglePreviewPanel:(id)previewPanel
- (IBAction)togglePreviewPanelFullScreen:(id)previewPanel
{
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isInFullScreenMode]) {
- [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
- [quicklookObject release];
- quicklookObject = nil;
+ [self closePreviewPanel];
} else {
if ([self canQuicklookCurrentObject]) {
[NSApp activateIgnoringOtherApps:YES];
@@ -1912,8 +1911,7 @@ - (void)beginPreviewPanelControl:(QLPreviewPanel *)panel
[panel setDelegate:self];
[panel setDataSource:self];
// Put the panel just above Quicksilver's window
- [previewPanel setLevel:([[self window] level] + 1)];
-// [panel setFloatingPanel:YES];
+ [previewPanel setLevel:([[self window] level] + 2)];
}
- (void)endPreviewPanelControl:(QLPreviewPanel *)panel
@@ -1929,10 +1927,14 @@ - (void)endPreviewPanelControl:(QLPreviewPanel *)panel
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
{
+ /* Put the panel just above Quicksilver's window
+ Note: 10.6 seems to revert the panel level set in beginPreviewPanelControl above.
+ This 'hack' is required for 10.6 support only (10.7+ is OK) */
+ [previewPanel setLevel:([[self window] level] + 2)];
if (quicklookObject) {
return [quicklookObject count];
}
- return nil;
+ return 0;
}
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index
@@ -1947,12 +1949,12 @@ - (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
- (BOOL)previewPanel:(QLPreviewPanel *)panel handleEvent:(NSEvent *)event
{
- if (![event type] == NSKeyDown) {
+ if ([event type] != NSKeyDown) {
return NO;
}
NSString *key = [event charactersIgnoringModifiers];
NSUInteger eventModifierFlags = [event modifierFlags];
- if ([key isEqual:@"y"] && eventModifierFlags & NSCommandKeyMask) {
+ if ([key isEqual:@"y"] && eventModifierFlags & NSCommandKeyMask) {
if (eventModifierFlags & NSAlternateKeyMask) {
// Cmd + Optn + Y shortcut (full screen)
[self togglePreviewPanelFullScreen:nil];
@@ -1962,14 +1964,19 @@ - (BOOL)previewPanel:(QLPreviewPanel *)panel handleEvent:(NSEvent *)event
}
return YES;
}
- // Allow the defualt action to be executed (if CMD+ENTR or ENTR is pressed)
+ // Allow the default action to be executed (if CMD+ENTR or ENTR is pressed)
if ([key isEqualToString:@"\r"] && (eventModifierFlags & NSCommandKeyMask || ((eventModifierFlags & NSDeviceIndependentModifierFlagsMask) == 0))) {
if (eventModifierFlags & NSCommandKeyMask) {
[self insertNewline:nil];
} else {
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
- [[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
+ [self closePreviewPanel];
+ return YES;
+ }
+
+ // trap the 'delete' key from being pressed
+ if ([key length] && [key characterAtIndex:0] == NSDeleteCharacter ) {
return YES;
}
return NO;
@@ -1313,7 +1313,7 @@
E18001C307B2BBB800010DB0 /* AppKitPrivate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AppKitPrivate.h; sourceTree = "<group>"; };
E18001C507B2BBB800010DB0 /* main.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
E18001C807B2BBB800010DB0 /* QSApp.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = QSApp.h; sourceTree = "<group>"; };
- E18001C907B2BBB800010DB0 /* QSApp.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = QSApp.m; sourceTree = "<group>"; };
+ E18001C907B2BBB800010DB0 /* QSApp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QSApp.m; sourceTree = "<group>"; };
E18001D007B2BBB800010DB0 /* QSCatalogPrefPane.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = QSCatalogPrefPane.h; sourceTree = "<group>"; };
E18001D107B2BBB800010DB0 /* QSCatalogPrefPane.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = QSCatalogPrefPane.m; sourceTree = "<group>"; };
E18001D407B2BBB800010DB0 /* QSController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = QSController.h; sourceTree = "<group>"; };