Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[nv_lastFindWasSuccessful:] get rid of isa poking for OBJC v1 and add…

… try/catch around KV access in case Apple changes NSTextFinder in the future.
  • Loading branch information...
commit 2ec9ad68314bea8cd9108dbbd4cce056fd511368 1 parent 3e339ce
Brian Bergstrand authored
Showing with 100 additions and 18 deletions.
  1. +97 −0 NSTextFinder.h
  2. +3 −18 NSTextFinder_LastFind.m
View
97 NSTextFinder.h
@@ -12,6 +12,33 @@ enum {LAST_FIND_UNKNOWN, LAST_FIND_NO, LAST_FIND_YES};
@interface NSTextFinder : NSObject
{
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+ //10.6
+ NSComboBox *findComboBox;
+ NSComboBox *replaceComboBox;
+ NSTextField *statusField;
+ NSButton *ignoreCaseButton;
+ NSButton *replaceAllButton;
+ NSButton *replaceButton;
+ NSButton *findNextButton;
+ NSButton *findPreviousButton;
+ NSButton *replaceAndFindButton;
+ NSButton *wrapAroundButton;
+ NSPopUpButton *matchPopUp;
+ NSTextView *fieldEditor;
+ NSString *findString;
+ BOOL lastFindWasSuccessful;
+ BOOL findStringChangedInUI;
+ BOOL findStringNeedsToBeRefreshedFromPB;
+ NSInteger lastChangeCount;
+ BOOL caseInsensitiveSearchDefault;
+ NSInteger substringMatchDefault;
+ NSMutableArray *recentFindStrings;
+ NSMutableArray *recentFindOptions;
+ NSMutableArray *recentReplaceStrings;
+ NSInteger numberOfRecentStrings;
+ #else
+ // 10.4
NSTextField *findTextField;
NSTextField *replaceTextField;
NSTextField *statusField;
@@ -29,6 +56,7 @@ enum {LAST_FIND_UNKNOWN, LAST_FIND_NO, LAST_FIND_YES};
BOOL lastFindWasSuccessful;
BOOL findStringChangedInUI;
BOOL findStringNeedsToBeRefreshedFromPB;
+ #endif
}
+ (id)sharedTextFinder;
@@ -65,3 +93,72 @@ enum {LAST_FIND_UNKNOWN, LAST_FIND_NO, LAST_FIND_YES};
- (int)nv_lastFindWasSuccessful;
@end
+
+// Dump from 10.6 x86_64
+#if 0
+@interface NSTextFinder : NSObject <NSWindowDelegate, NSComboBoxDelegate>
+{
+ NSComboBox *findComboBox;
+ NSComboBox *replaceComboBox;
+ NSTextField *statusField;
+ NSButton *ignoreCaseButton;
+ NSButton *replaceAllButton;
+ NSButton *replaceButton;
+ NSButton *findNextButton;
+ NSButton *findPreviousButton;
+ NSButton *replaceAndFindButton;
+ NSButton *wrapAroundButton;
+ NSPopUpButton *matchPopUp;
+ NSTextView *fieldEditor;
+ NSString *findString;
+ BOOL lastFindWasSuccessful;
+ BOOL findStringChangedInUI;
+ BOOL findStringNeedsToBeRefreshedFromPB;
+ long long lastChangeCount;
+ BOOL caseInsensitiveSearchDefault;
+ long long substringMatchDefault;
+ NSMutableArray *recentFindStrings;
+ NSMutableArray *recentFindOptions;
+ NSMutableArray *recentReplaceStrings;
+ long long numberOfRecentStrings;
+}
+
++ (id)sharedTextFinder;
+- (id)init;
+- (void)awakeFromNib;
+- (void)dealloc;
+- (id)windowWillReturnFieldEditor:(id)arg1 toObject:(id)arg2;
+- (BOOL)needToRefreshFromPasteboard;
+- (void)appDidActivate:(id)arg1;
+- (BOOL)loadFindStringFromPasteboard;
+- (void)loadFindStringToPasteboard;
+- (void)restoreDefaultSearchOptions;
+- (void)makeCurrentSearchOptionsDefault;
+- (void)setDefaultSearchOptions:(id)arg1;
+- (void)loadUI;
+- (void)controlTextDidChange:(id)arg1;
+- (void)addStringToRecentSearchStrings:(id)arg1;
+- (void)addStringToRecentReplaceStrings:(id)arg1;
+- (id)comboBox:(id)arg1 objectValueForItemAtIndex:(long long)arg2;
+- (long long)numberOfItemsInComboBox:(id)arg1;
+- (void)comboBoxSelectionDidChange:(id)arg1;
+- (id)findString;
+- (void)setFindString:(id)arg1 writeToPasteboard:(BOOL)arg2 updateUI:(BOOL)arg3;
+- (id)textObjectToSearchIn;
+- (id)findPanel:(BOOL)arg1;
+- (void)takeFindStringFromView:(id)arg1;
+- (unsigned long long)optionsFromPanel;
+- (BOOL)findInView:(id)arg1 forward:(BOOL)arg2;
+- (BOOL)replaceInView:(id)arg1;
+- (BOOL)replaceAndFindInView:(id)arg1;
+- (long long)replaceAllInView:(id)arg1 selectionOnly:(BOOL)arg2;
+- (BOOL)selectAllInView:(id)arg1 selectionOnly:(BOOL)arg2;
+- (void)orderFrontFindPanel:(id)arg1;
+- (void)findNextAndOrderFindPanelOut:(id)arg1;
+- (void)performFindPanelAction:(id)arg1;
+- (void)performFindPanelAction:(unsigned long long)arg1 forClient:(id)arg2;
+- (BOOL)validateFindPanelAction:(unsigned long long)arg1 forClient:(id)arg2;
+- (void)windowDidUpdate:(id)arg1;
+
+@end
+#endif
View
21 NSTextFinder_LastFind.m
@@ -5,33 +5,18 @@
* Created by Zachary Schneirov
*
*/
-#include <objc/objc-runtime.h>
#import "NSTextFinder.h"
@implementation NSTextFinder (LastFind)
- (int)nv_lastFindWasSuccessful {
- #if defined(OBJC2_UNAVAILABLE)
+ @try {
NSNumber *success = [self valueForKey:@"lastFindWasSuccessful"];
if (success)
return ([success boolValue] ? LAST_FIND_YES : LAST_FIND_NO);
- #else
- int i;
- Ivar ivar;
-
- //this might not work so well with Obj-C 2
- for (i = 0; i < isa->ivars->ivar_count; i++ ) {
- ivar = &isa->ivars->ivar_list[i];
- if (strcmp( ivar->ivar_name, "lastFindWasSuccessful") == 0) {
-
- BOOL *lastFind = ((BOOL*) self + ivar->ivar_offset);
-
- return *lastFind ? LAST_FIND_YES : LAST_FIND_NO;
- }
- }
- #endif
+ } @catch (NSException *e) {}
- NSLog(@"No lastFindWasSuccessful ivars found!");
+ NSLog(@"lastFindWasSuccessful ivar not found!");
return LAST_FIND_UNKNOWN;
}
Please sign in to comment.
Something went wrong with that request. Please try again.