Revision: 2837
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2837&view=rev
Author:   hofman
Date:     2007-09-05 10:33:18 -0700 (Wed, 05 Sep 2007)

Log Message:
-----------
Use a notification to stop type-select when the first responder or the key 
window changes.

Modified Paths:
--------------
    trunk/SKOutlineView.m
    trunk/SKPDFView.m
    trunk/SKTableView.m
    trunk/SKTypeSelectHelper.m

Modified: trunk/SKOutlineView.m
===================================================================
--- trunk/SKOutlineView.m       2007-09-05 16:50:17 UTC (rev 2836)
+++ trunk/SKOutlineView.m       2007-09-05 17:33:18 UTC (rev 2837)
@@ -103,13 +103,6 @@
         [super keyDown:theEvent];
 }
 
-- (BOOL)resignFirstResponder {
-    BOOL shouldResign = [super resignFirstResponder];
-    if (shouldResign)
-        [typeSelectHelper stopSearch];
-    return shouldResign;
-}
-
 - (void)scrollToBeginningOfDocument:(id)sender {
     if ([self numberOfRows])
         [self scrollRowToVisible:0];

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-09-05 16:50:17 UTC (rev 2836)
+++ trunk/SKPDFView.m   2007-09-05 17:33:18 UTC (rev 2837)
@@ -1441,13 +1441,6 @@
     [[NSSpellChecker sharedSpellChecker] ignoreWord:[[sender selectedCell] 
stringValue] inSpellDocumentWithTag:spellingTag];
 }
 
-- (BOOL)resignFirstResponder {
-    BOOL shouldResign = [super resignFirstResponder];
-    if (shouldResign)
-        [typeSelectHelper stopSearch];
-    return shouldResign;
-}
-
 #pragma mark Tracking mousemoved fix
 
 - (void)setFrame:(NSRect)frame {

Modified: trunk/SKTableView.m
===================================================================
--- trunk/SKTableView.m 2007-09-05 16:50:17 UTC (rev 2836)
+++ trunk/SKTableView.m 2007-09-05 17:33:18 UTC (rev 2837)
@@ -83,13 +83,6 @@
         [super keyDown:theEvent];
 }
 
-- (BOOL)resignFirstResponder {
-    BOOL shouldResign = [super resignFirstResponder];
-    if (shouldResign)
-        [typeSelectHelper stopSearch];
-    return shouldResign;
-}
-
 - (void)scrollToBeginningOfDocument:(id)sender {
     if ([self numberOfRows])
         [self scrollRowToVisible:0];

Modified: trunk/SKTypeSelectHelper.m
===================================================================
--- trunk/SKTypeSelectHelper.m  2007-09-05 16:50:17 UTC (rev 2836)
+++ trunk/SKTypeSelectHelper.m  2007-09-05 17:33:18 UTC (rev 2837)
@@ -37,13 +37,19 @@
  */
 
 #import "SKTypeSelectHelper.h"
+#import "OBUtilities.h"
 
+static NSString *SKWindowDidChangeFirstResponderNotification = 
@"SKWindowDidChangeFirstResponderNotification";
+
 #define REPEAT_CHARACTER '/'
 
[EMAIL PROTECTED] NSString (BDSKTypeAheadHelperExtensions)
[EMAIL PROTECTED] NSString (SKTypeAheadHelperExtensions)
 - (BOOL)containsStringStartingAtWord:(NSString *)string options:(int)mask 
range:(NSRange)range;
 @end
 
[EMAIL PROTECTED] NSWindow (SKTypeAheadHelperExtensions)
[EMAIL PROTECTED]
+
 #pragma mark -
 
 @interface SKTypeSelectHelper (SKPrivate)
@@ -52,8 +58,8 @@
 - (void)searchWithStickyMatch:(BOOL)allowUpdate;
 - (void)stopTimer;
 - (void)startTimerForSelector:(SEL)selector;
-- (void)typeSelectSearchTimeout:(NSTimer *)aTimer;
-- (void)typeSelectCleanTimeout:(NSTimer *)aTimer;
+- (void)typeSelectSearchTimeout:(id)sender;
+- (void)typeSelectCleanTimeout:(id)sender;
 - (unsigned int)indexOfMatchedItemAfterIndex:(unsigned int)selectedIndex;
 @end
 
@@ -72,6 +78,7 @@
 }
 
 - (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     [self stopTimer];
     [searchString release];
     [searchCache release];
@@ -142,8 +149,11 @@
 - (void)processKeyDownEvent:(NSEvent *)keyEvent {
     NSText *fieldEditor = [[NSApp keyWindow] fieldEditor:YES forObject:self];
     
-    if (processing == NO)
+    if (processing == NO) {
+        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(typeSelectCleanTimeout:) 
name:SKWindowDidChangeFirstResponderNotification object:[NSApp keyWindow]];
+        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(typeSelectCleanTimeout:) 
name:NSWindowDidResignKeyNotification object:[NSApp keyWindow]];
         [fieldEditor setString:@""];
+    }
     
     // Append the new character to the search string
     [fieldEditor interpretKeyEvents:[NSArray arrayWithObject:keyEvent]];
@@ -196,6 +206,7 @@
             continue;
         if ([self isProcessing] && [[NSCharacterSet controlCharacterSet] 
characterIsMember:character])
             continue;
+        return NO;
     }
     return YES;
 }
@@ -244,15 +255,16 @@
     [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
 }
 
-- (void)typeSelectSearchTimeout:(NSTimer *)aTimer {
+- (void)typeSelectSearchTimeout:(id)sender {
     if (matchesImmediately == NO)
         [self searchWithStickyMatch:NO];
-    [self typeSelectCleanTimeout:aTimer];
+    [self typeSelectCleanTimeout:sender];
 }
 
-- (void)typeSelectCleanTimeout:(NSTimer *)aTimer {
+- (void)typeSelectCleanTimeout:(id)sender {
     if ([dataSource 
respondsToSelector:@selector(typeSelectHelper:updateSearchString:)])
         [dataSource typeSelectHelper:self updateSearchString:nil];
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
     [self stopTimer];
     processing = NO;
 }
@@ -328,7 +340,7 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] NSString (BDSKTypeAheadHelperExtensions)
[EMAIL PROTECTED] NSString (SKTypeAheadHelperExtensions)
 
 - (BOOL)containsStringStartingAtWord:(NSString *)string options:(int)mask 
range:(NSRange)range {
     unsigned int stringLength = [string length];
@@ -354,3 +366,23 @@
 }
 
 @end
+
+#pragma mark -
+
[EMAIL PROTECTED] NSWindow (SKTypeAheadHelperExtensions)
+
+static BOOL (*originalMakeFirstResponder)(id, SEL, id) = NULL;
+
++ (void)load {
+    originalMakeFirstResponder = 
(typeof(originalMakeFirstResponder))OBReplaceMethodImplementationWithSelector(self,
 @selector(makeFirstResponder:), @selector(replacementMakeFirstResponder:));
+}
+
+- (BOOL)replacementMakeFirstResponder:(NSResponder *)aResponder {
+    id oldFirstResponder = [self firstResponder];
+    BOOL success = originalMakeFirstResponder(self, _cmd, aResponder);
+    if (oldFirstResponder != [self firstResponder])
+        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKWindowDidChangeFirstResponderNotification object:self];
+    return success;
+}
+
[EMAIL PROTECTED]


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to