mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-03-14 06:31:31 +00:00
* English.lproj/FindPanel.gorm: Added Find panel.
* PCMenuController.m: Added Find panel support. * TextFinder.[hm]: Added implementation of Find panel. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@25498 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7f177759cf
commit
e8e18614e8
22 changed files with 607 additions and 37 deletions
|
@ -1,3 +1,9 @@
|
|||
2007-09-24 Sergii Stoian <stoyan255@gmail.com>
|
||||
|
||||
* English.lproj/FindPanel.gorm: Added Find panel.
|
||||
* PCMenuController.m: Added Find panel support.
|
||||
* TextFinder.[hm]: Added implementation of Find panel.
|
||||
|
||||
2007-08-29 Sergii Stoian <stoyan255@gmail.com>
|
||||
|
||||
* Frameworks/PCFileManager.m:
|
||||
|
|
34
English.lproj/FindPanel.gorm/data.classes
Normal file
34
English.lproj/FindPanel.gorm/data.classes
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"## Comment" = "Do NOT change this file, Gorm maintains it";
|
||||
FirstResponder = {
|
||||
Actions = (
|
||||
"findNext:",
|
||||
"findNextAndOrderFindPanelOut:",
|
||||
"findPrevious:",
|
||||
"ignoreCase:",
|
||||
"replace:",
|
||||
"replaceAll:",
|
||||
"replaceAndFind:"
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
TextFinder = {
|
||||
Actions = (
|
||||
"findNext:",
|
||||
"findNextAndOrderFindPanelOut:",
|
||||
"findPrevious:",
|
||||
"replace:",
|
||||
"replaceAll:",
|
||||
"replaceAndFind:"
|
||||
);
|
||||
Outlets = (
|
||||
findNextButton,
|
||||
findTextField,
|
||||
ignoreCaseButton,
|
||||
replaceAllScopeMatrix,
|
||||
replaceTextField,
|
||||
statusField
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
}
|
BIN
English.lproj/FindPanel.gorm/data.info
Normal file
BIN
English.lproj/FindPanel.gorm/data.info
Normal file
Binary file not shown.
BIN
English.lproj/FindPanel.gorm/objects.gorm
Normal file
BIN
English.lproj/FindPanel.gorm/objects.gorm
Normal file
Binary file not shown.
BIN
English.lproj/Info.gorm/Info.tiff
Normal file
BIN
English.lproj/Info.gorm/Info.tiff
Normal file
Binary file not shown.
3
English.lproj/Info.gorm/data.classes
Normal file
3
English.lproj/Info.gorm/data.classes
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"## Comment" = "Do NOT change this file, Gorm maintains it";
|
||||
}
|
BIN
English.lproj/Info.gorm/data.info
Normal file
BIN
English.lproj/Info.gorm/data.info
Normal file
Binary file not shown.
BIN
English.lproj/Info.gorm/objects.gorm
Normal file
BIN
English.lproj/Info.gorm/objects.gorm
Normal file
Binary file not shown.
|
@ -1,5 +1,15 @@
|
|||
{
|
||||
"## Comment" = "Do NOT change this file, Gorm maintains it";
|
||||
FirstResponder = {
|
||||
Actions = (
|
||||
"findEnterSelection:",
|
||||
"findNext:",
|
||||
"findPrevious:",
|
||||
"findShowPanel:",
|
||||
"findJumpToSelection:"
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
PCAppController = {
|
||||
Actions = (
|
||||
);
|
||||
|
@ -44,7 +54,12 @@
|
|||
"loadedFilesSortByName:",
|
||||
"loadedFilesNextFile:",
|
||||
"loadedFilesPreviousFile:",
|
||||
"showLogPanel:"
|
||||
"showLogPanel:",
|
||||
"findEnterSelection:",
|
||||
"findNext:",
|
||||
"findPrevious:",
|
||||
"findShowPanel:",
|
||||
"findJumpToSelection:"
|
||||
);
|
||||
Outlets = (
|
||||
);
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -27,6 +27,7 @@
|
|||
#import <ProjectCenter/PCFileManager.h>
|
||||
#import <ProjectCenter/PCProjectManager.h>
|
||||
#import <ProjectCenter/PCBundleManager.h>
|
||||
|
||||
#import <ProjectCenter/PCProject.h>
|
||||
#import <ProjectCenter/PCProjectWindow.h>
|
||||
#import <ProjectCenter/PCProjectBrowser.h>
|
||||
|
@ -673,7 +674,8 @@ NSString *PCEditorDidResignActiveNotification =
|
|||
|
||||
- (void)editorDidClose:(NSNotification *)aNotif
|
||||
{
|
||||
id<CodeEditor> editor = [aNotif object];
|
||||
// id<CodeEditor> editor = [aNotif object];
|
||||
id editor = [aNotif object];
|
||||
|
||||
// It is not our editor
|
||||
if ([editor projectEditor] != self)
|
||||
|
|
|
@ -89,7 +89,9 @@ Modules/Parsers/ProjectCenter/ProjectCenter.parser
|
|||
# Localization
|
||||
#
|
||||
ProjectCenter_LOCALIZED_RESOURCE_FILES = \
|
||||
ProjectCenter.gorm
|
||||
ProjectCenter.gorm \
|
||||
Info.gorm \
|
||||
FindPanel.gorm
|
||||
|
||||
ProjectCenter_LANGUAGES = \
|
||||
English
|
||||
|
@ -110,6 +112,7 @@ ProjectCenter_OBJC_FILES = \
|
|||
PCAppController.m \
|
||||
PCInfoController.m \
|
||||
PCMenuController.m \
|
||||
TextFinder.m \
|
||||
ProjectCenter_main.m
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
|
Binary file not shown.
|
@ -48,6 +48,7 @@
|
|||
NSString *_categoryPath;
|
||||
NSWindow *_window;
|
||||
|
||||
|
||||
BOOL _isEdited;
|
||||
BOOL _isWindowed;
|
||||
BOOL _isExternal;
|
||||
|
@ -58,8 +59,6 @@
|
|||
// NSMutableArray *classNames;
|
||||
// NSMutableArray *methodNames;
|
||||
|
||||
IBOutlet NSMenu *menu;
|
||||
|
||||
NSFont *defaultFont;
|
||||
NSFont *highlightFont;
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#import "PCEditorView.h"
|
||||
//#import "CommandQueryPanel.h"
|
||||
//#import "LineQueryPanel.h"
|
||||
//#import "TextFinder.h"
|
||||
|
||||
@implementation PCEditor (UInterface)
|
||||
|
||||
|
@ -218,6 +217,7 @@
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
// --- Protocol
|
||||
- (void)setParser:(id)parser
|
||||
{
|
||||
// NSLog(@"RC aParser:%i parser:%i",
|
||||
|
@ -345,6 +345,7 @@
|
|||
|
||||
return self;
|
||||
}
|
||||
// --- Protocol End
|
||||
|
||||
- (void)externalEditorDidClose:(NSNotification *)aNotif
|
||||
{
|
||||
|
@ -365,10 +366,10 @@
|
|||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Accessory methods
|
||||
// ==== CodeEditor protocol
|
||||
// ===========================================================================
|
||||
|
||||
//--- CodeEditor protocol
|
||||
// --- Accessor methods
|
||||
|
||||
- (id)projectEditor
|
||||
{
|
||||
|
@ -508,16 +509,12 @@
|
|||
return items;
|
||||
}
|
||||
|
||||
- (NSMenu *)menu
|
||||
- (void)show
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
//--- protocol end
|
||||
|
||||
- (BOOL)isWindowed
|
||||
{
|
||||
return _isWindowed;
|
||||
if (_isWindowed)
|
||||
{
|
||||
[_window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setWindowed:(BOOL)yn
|
||||
|
@ -541,17 +538,12 @@
|
|||
_isWindowed = yn;
|
||||
}
|
||||
|
||||
- (void)show
|
||||
- (BOOL)isWindowed
|
||||
{
|
||||
if (_isWindowed)
|
||||
{
|
||||
[_window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
return _isWindowed;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Object managment
|
||||
// ===========================================================================
|
||||
// --- Object managment
|
||||
|
||||
- (BOOL)saveFileIfNeeded
|
||||
{
|
||||
|
|
|
@ -276,6 +276,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
|
|||
|
||||
- (unichar)firstCharOfNextLineForIndex:(int)index
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void)performIndentation
|
||||
|
@ -284,11 +285,11 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
|
|||
int location;
|
||||
int line_start;
|
||||
int offset;
|
||||
unichar c, fc, plfc, clfc;
|
||||
unichar c, plfc, clfc;
|
||||
NSRange wsRange;
|
||||
NSMutableString *indentString;
|
||||
int i;
|
||||
int point;
|
||||
// int point;
|
||||
|
||||
location = [self selectedRange].location;
|
||||
|
||||
|
@ -461,7 +462,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start)
|
|||
|
||||
- (void)drawRect:(NSRect)r
|
||||
{
|
||||
NSEnumerator *e;
|
||||
// NSEnumerator *e;
|
||||
NSRange drawnRange;
|
||||
|
||||
drawnRange = [[self layoutManager]
|
||||
|
|
|
@ -56,7 +56,13 @@
|
|||
|
||||
- (void)showInfoWindow:(id)sender
|
||||
{
|
||||
#if defined(GNUSTEP)
|
||||
if ([NSBundle loadNibNamed:@"Info" owner:self] == NO)
|
||||
{
|
||||
// PCLogError(self, @"error loading Menu NIB file!");
|
||||
return;
|
||||
}
|
||||
|
||||
/*#if defined(GNUSTEP)
|
||||
if (!infoWindow)
|
||||
{
|
||||
infoWindow = [[GSInfoPanel alloc] initWithDictionary:infoDict];
|
||||
|
@ -69,7 +75,7 @@
|
|||
NSRunAlertPanel(@"Info",
|
||||
@"OPENSTEP has no support for GSInfoPanel",
|
||||
@"OK",nil,nil,nil);
|
||||
#endif
|
||||
#endif*/
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include "PCMenuController.h"
|
||||
#include "PCInfoController.h"
|
||||
|
||||
#import "TextFinder.h"
|
||||
|
||||
@implementation PCMenuController
|
||||
|
||||
- (id)init
|
||||
|
@ -256,24 +258,33 @@
|
|||
@"OK",nil,nil);
|
||||
}
|
||||
|
||||
// Edit. PCProjectEditor have to provide this menu and functionality
|
||||
/*- (void)findShowPanel:(id)sender
|
||||
// Edit
|
||||
- (void)findShowPanel:(id)sender
|
||||
{
|
||||
[[PCTextFinder sharedFinder] showFindPanel:self];
|
||||
[[TextFinder sharedInstance] orderFrontFindPanel:self];
|
||||
}
|
||||
|
||||
- (void)findNext:(id)sender
|
||||
{
|
||||
[[PCTextFinder sharedFinder] findNext:self];
|
||||
[[TextFinder sharedInstance] findNext:self];
|
||||
}
|
||||
|
||||
- (void)findPrevious:(id)sender
|
||||
{
|
||||
[[PCTextFinder sharedFinder] findPrevious:self];
|
||||
}*/
|
||||
[[TextFinder sharedInstance] findPrevious:self];
|
||||
}
|
||||
|
||||
- (void)findJumpToSelection:(id)sender
|
||||
{
|
||||
[[TextFinder sharedInstance] jumpToSelection:self];
|
||||
}
|
||||
|
||||
- (void)findEnterSelection:(id)sender
|
||||
{
|
||||
[[TextFinder sharedInstance] enterSelection:self];
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
- (void)toggleToolbar:(id)sender
|
||||
{
|
||||
[[[projectManager rootActiveProject] projectWindow] toggleToolbar];
|
||||
|
|
64
TextFinder.h
Normal file
64
TextFinder.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#import <Foundation/NSObject.h>
|
||||
|
||||
#define Forward YES
|
||||
#define Backward NO
|
||||
|
||||
@interface TextFinder : NSObject
|
||||
{
|
||||
NSString *findString;
|
||||
id findTextField;
|
||||
id replaceTextField;
|
||||
id ignoreCaseButton;
|
||||
id findNextButton;
|
||||
id replaceAllScopeMatrix;
|
||||
id statusField;
|
||||
BOOL findStringChangedSinceLastPasteboardUpdate;
|
||||
BOOL lastFindWasSuccessful; /* A bit of a kludge */
|
||||
}
|
||||
|
||||
/* Common way to get a text finder. One instance of TextFinder per
|
||||
* app is good enough. */
|
||||
+ (id)sharedInstance;
|
||||
|
||||
/* Main method for external users; does a find in the first responder.
|
||||
* Selects found range or beeps. */
|
||||
- (BOOL)find:(BOOL)direction;
|
||||
|
||||
/* Loads UI lazily */
|
||||
- (NSPanel *)findPanel;
|
||||
|
||||
/* Gets the first responder and returns it if it's an NSTextView */
|
||||
- (NSTextView *)textObjectToSearchIn;
|
||||
|
||||
/* Get/set the current find string. Will update UI if UI is loaded */
|
||||
- (NSString *)findString;
|
||||
- (void)setFindString:(NSString *)string;
|
||||
|
||||
/* Misc internal methods */
|
||||
- (void)appDidActivate:(NSNotification *)notification;
|
||||
- (void)addWillDeactivate:(NSNotification *)notification;
|
||||
- (void)loadFindStringFromPasteboard;
|
||||
- (void)loadFindStringToPasteboard;
|
||||
|
||||
/* Methods sent from the find panel UI */
|
||||
- (void)findNext:(id)sender;
|
||||
- (void)findPrevious:(id)sender;
|
||||
- (void)enterSelection:(id)sender;
|
||||
- (void)jumpToSelection:(id)sender;
|
||||
- (void)findNextAndOrderFindPanelOut:(id)sender;
|
||||
- (void)replace:(id)sender;
|
||||
- (void)replaceAndFind:(id)sender;
|
||||
- (void)replaceAll:(id)sender;
|
||||
- (void)orderFrontFindPanel:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSString (NSStringTextFinding)
|
||||
|
||||
- (NSRange)findString:(NSString *)string
|
||||
selectedRange:(NSRange)selectedRange
|
||||
options:(unsigned)mask
|
||||
wrap:(BOOL)wrapFlag;
|
||||
|
||||
@end
|
||||
|
434
TextFinder.m
Normal file
434
TextFinder.m
Normal file
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
TextFinder.m
|
||||
Copyright (c) 1995-1996, NeXT Software, Inc.
|
||||
All rights reserved.
|
||||
Author: Ali Ozer
|
||||
|
||||
You may freely copy, distribute and reuse the code in this example.
|
||||
NeXT disclaims any warranty of any kind, expressed or implied,
|
||||
as to its fitness for any particular use.
|
||||
|
||||
Find and replace functionality with a minimal panel...
|
||||
|
||||
In addition to including this class and FindPanel.nib in your app, you
|
||||
probably need to hook up the following action methods in your document
|
||||
object (or whatever object is first responder) to call the appropriate
|
||||
methods in [TextFinder sharedInstance]:
|
||||
|
||||
orderFrontFindPanel:
|
||||
findNext:
|
||||
findPrevious:
|
||||
enterSelection: (calls setFindString:)
|
||||
|
||||
2/21/95 aozer Created for Edit II.
|
||||
2/24/95 aozer Find pasteboard support
|
||||
8/16/95 aozer Replace functionality
|
||||
10/4/95 aozer Status field update
|
||||
11/12/96 aozer Correctly send shouldChange... to the textview
|
||||
while doing a replace
|
||||
|
||||
*/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import "TextFinder.h"
|
||||
|
||||
@implementation TextFinder
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector (appDidActivate:)
|
||||
name:NSApplicationDidBecomeActiveNotification
|
||||
object:[NSApplication sharedApplication]];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector (addWillDeactivate:)
|
||||
name:NSApplicationWillResignActiveNotification
|
||||
object:[NSApplication sharedApplication]];
|
||||
|
||||
[self setFindString:@""];
|
||||
[self loadFindStringFromPasteboard];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)appDidActivate:(NSNotification *)notification
|
||||
{
|
||||
[self loadFindStringFromPasteboard];
|
||||
}
|
||||
|
||||
- (void)addWillDeactivate:(NSNotification *)notification
|
||||
{
|
||||
[self loadFindStringToPasteboard];
|
||||
}
|
||||
|
||||
- (void)loadFindStringFromPasteboard
|
||||
{
|
||||
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSFindPboard];
|
||||
|
||||
if ([[pasteboard types] containsObject:NSStringPboardType])
|
||||
{
|
||||
NSString *string = [pasteboard stringForType:NSStringPboardType];
|
||||
if (string && [string length])
|
||||
{
|
||||
[self setFindString:string];
|
||||
findStringChangedSinceLastPasteboardUpdate = NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)loadFindStringToPasteboard
|
||||
{
|
||||
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName: NSFindPboard];
|
||||
|
||||
if (findStringChangedSinceLastPasteboardUpdate)
|
||||
{
|
||||
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType]
|
||||
owner:nil];
|
||||
[pasteboard setString:[self findString] forType:NSStringPboardType];
|
||||
findStringChangedSinceLastPasteboardUpdate = NO;
|
||||
}
|
||||
}
|
||||
|
||||
static id sharedFindObject = nil;
|
||||
|
||||
+ (id)sharedInstance
|
||||
{
|
||||
if (!sharedFindObject)
|
||||
{
|
||||
sharedFindObject = [[self alloc] init];
|
||||
}
|
||||
return sharedFindObject;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[ignoreCaseButton setRefusesFirstResponder:YES];
|
||||
[findNextButton setRefusesFirstResponder:YES];
|
||||
[replaceAllScopeMatrix setRefusesFirstResponder:YES];
|
||||
[statusField setRefusesFirstResponder:YES];
|
||||
}
|
||||
|
||||
- (void)loadUI
|
||||
{
|
||||
if (!findTextField)
|
||||
{
|
||||
if (![NSBundle loadNibNamed:@"FindPanel" owner:self])
|
||||
{
|
||||
NSLog(@"Failed to load FindPanel.gorm");
|
||||
NSBeep();
|
||||
}
|
||||
if (self == sharedFindObject)
|
||||
{
|
||||
[[findTextField window] setFrameAutosaveName:@"Find"];
|
||||
}
|
||||
}
|
||||
[findTextField setStringValue:[self findString]];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (self != sharedFindObject)
|
||||
{
|
||||
[findString release];
|
||||
[super dealloc];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)findString
|
||||
{
|
||||
return findString;
|
||||
}
|
||||
|
||||
- (void)setFindString:(NSString *)string
|
||||
{
|
||||
if ([string isEqualToString:findString])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
[findString autorelease];
|
||||
findString = [string copy];
|
||||
|
||||
if (findTextField)
|
||||
{
|
||||
[findTextField setStringValue:string];
|
||||
[findTextField selectText:nil];
|
||||
}
|
||||
|
||||
findStringChangedSinceLastPasteboardUpdate = YES;
|
||||
}
|
||||
|
||||
- (NSTextView *)textObjectToSearchIn
|
||||
{
|
||||
id obj = [[NSApp mainWindow] firstResponder];
|
||||
|
||||
return (obj && [obj isKindOfClass:[NSTextView class]]) ? obj : nil;
|
||||
}
|
||||
|
||||
- (NSPanel *)findPanel
|
||||
{
|
||||
if (!findTextField)
|
||||
{
|
||||
[self loadUI];
|
||||
}
|
||||
|
||||
return (NSPanel *)[findTextField window];
|
||||
}
|
||||
|
||||
/*
|
||||
The primitive for finding; this ends up setting the status field (and
|
||||
beeping if necessary)...
|
||||
*/
|
||||
- (BOOL)find:(BOOL)direction
|
||||
{
|
||||
NSTextView *text = [self textObjectToSearchIn];
|
||||
|
||||
lastFindWasSuccessful = NO;
|
||||
|
||||
if (text)
|
||||
{
|
||||
NSString *textContents = [text string];
|
||||
unsigned int textLength;
|
||||
|
||||
if (textContents && (textLength = [textContents length]))
|
||||
{
|
||||
NSRange range;
|
||||
unsigned int options = 0;
|
||||
|
||||
if (direction == Backward)
|
||||
options |= NSBackwardsSearch;
|
||||
if ([ignoreCaseButton state])
|
||||
options |= NSCaseInsensitiveSearch;
|
||||
|
||||
range = [textContents findString:[self findString]
|
||||
selectedRange:[text selectedRange]
|
||||
options:options
|
||||
wrap:YES];
|
||||
if (range.length)
|
||||
{
|
||||
[text setSelectedRange:range];
|
||||
[text scrollRangeToVisible:range];
|
||||
lastFindWasSuccessful = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!lastFindWasSuccessful)
|
||||
{
|
||||
NSBeep ();
|
||||
[statusField setStringValue:@"Not found"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[statusField setStringValue:@""];
|
||||
}
|
||||
return lastFindWasSuccessful;
|
||||
}
|
||||
|
||||
- (void)orderFrontFindPanel:(id)sender
|
||||
{
|
||||
NSPanel *panel = [self findPanel];
|
||||
|
||||
[findTextField selectText:nil];
|
||||
[panel makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
/**** Action methods for gadgets in the find panel; these should all end up setting or clearing the status field ****/
|
||||
|
||||
- (void)findNextAndOrderFindPanelOut:(id)sender
|
||||
{
|
||||
[findNextButton performClick:nil];
|
||||
|
||||
if (lastFindWasSuccessful)
|
||||
{
|
||||
[[self findPanel] orderOut: sender];
|
||||
}
|
||||
else
|
||||
{
|
||||
[findTextField selectText:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)findNext:(id)sender
|
||||
{
|
||||
if (findTextField)
|
||||
{
|
||||
// findTextField should be set
|
||||
[self setFindString:[findTextField stringValue]];
|
||||
}
|
||||
|
||||
[self find:Forward];
|
||||
}
|
||||
|
||||
- (void)findPrevious:(id)sender
|
||||
{
|
||||
if (findTextField)
|
||||
{
|
||||
// findTextField should be set
|
||||
[self setFindString:[findTextField stringValue]];
|
||||
}
|
||||
|
||||
[self find:Backward];
|
||||
}
|
||||
|
||||
- (void)enterSelection:(id)sender
|
||||
{
|
||||
NSTextView *text = [self textObjectToSearchIn];
|
||||
NSRange range = [text selectedRange];
|
||||
NSString *string = [text string];
|
||||
|
||||
[self setFindString:[string substringWithRange:range]];
|
||||
}
|
||||
|
||||
- (void)jumpToSelection:(id)sender
|
||||
{
|
||||
NSTextView *text = [self textObjectToSearchIn];
|
||||
NSRange range = [text selectedRange];
|
||||
|
||||
[text scrollRangeToVisible:range];
|
||||
}
|
||||
|
||||
- (void)replace:(id)sender
|
||||
{
|
||||
NSTextView *text = [self textObjectToSearchIn];
|
||||
|
||||
if (!text)
|
||||
{
|
||||
NSBeep ();
|
||||
}
|
||||
else
|
||||
{
|
||||
[[text textStorage]
|
||||
replaceCharactersInRange:[text selectedRange]
|
||||
withString:[replaceTextField stringValue]];
|
||||
[text didChangeText];
|
||||
}
|
||||
|
||||
[statusField setStringValue:@""];
|
||||
}
|
||||
|
||||
- (void)replaceAndFind:(id)sender
|
||||
{
|
||||
[self replace:sender];
|
||||
[self findNext:sender];
|
||||
}
|
||||
|
||||
#define ReplaceAllScopeEntireFile 42
|
||||
#define ReplaceAllScopeSelection 43
|
||||
|
||||
- (void)replaceAll:(id)sender
|
||||
{
|
||||
NSTextView *text = [self textObjectToSearchIn];
|
||||
|
||||
if (!text)
|
||||
{
|
||||
NSBeep();
|
||||
}
|
||||
else
|
||||
{
|
||||
NSTextStorage *textStorage = [text textStorage];
|
||||
NSString *textContents = [text string];
|
||||
NSString *replaceString = [replaceTextField stringValue];
|
||||
BOOL entireFile = replaceAllScopeMatrix ? ([replaceAllScopeMatrix selectedTag] == ReplaceAllScopeEntireFile) : YES;
|
||||
NSRange replaceRange = entireFile ? NSMakeRange (0, [textStorage length]) : [text selectedRange];
|
||||
unsigned int options = NSBackwardsSearch | ([ignoreCaseButton state] ? NSCaseInsensitiveSearch : 0);
|
||||
unsigned int replaced = 0;
|
||||
|
||||
if (findTextField)
|
||||
{
|
||||
[self setFindString:[findTextField stringValue]];
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
NSRange foundRange = [textContents rangeOfString:[self findString]
|
||||
options:options
|
||||
range:replaceRange];
|
||||
|
||||
if (foundRange.length == 0)
|
||||
break;
|
||||
|
||||
if ([text shouldChangeTextInRange:foundRange
|
||||
replacementString:replaceString])
|
||||
{
|
||||
if (replaced == 0)
|
||||
[textStorage beginEditing];
|
||||
|
||||
replaced++;
|
||||
|
||||
[textStorage replaceCharactersInRange:foundRange
|
||||
withString:replaceString];
|
||||
replaceRange.length = foundRange.location - replaceRange.location;
|
||||
}
|
||||
}
|
||||
|
||||
if (replaced > 0)
|
||||
{ /* There was at least one replacement */
|
||||
|
||||
/* We need this to bracket the beginEditing */
|
||||
[textStorage endEditing];
|
||||
/* We need one of these to terminate the shouldChange...
|
||||
* methods we sent */
|
||||
[text didChangeText];
|
||||
[statusField setStringValue:[NSString stringWithFormat:@"%d replaced", replaced]];
|
||||
}
|
||||
else
|
||||
{ /* No replacements were done... */
|
||||
NSBeep();
|
||||
[statusField setStringValue:@"Not found"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSString (NSStringTextFinding)
|
||||
|
||||
- (NSRange)findString:(NSString *)string
|
||||
selectedRange:(NSRange)selectedRange
|
||||
options:(unsigned)options
|
||||
wrap:(BOOL)wrap
|
||||
{
|
||||
BOOL forwards = (options & NSBackwardsSearch) == 0;
|
||||
unsigned int length = [self length];
|
||||
NSRange searchRange, range;
|
||||
|
||||
if (forwards)
|
||||
{
|
||||
searchRange.location = NSMaxRange(selectedRange);
|
||||
searchRange.length = length - searchRange.location;
|
||||
range = [self rangeOfString:string options:options range:searchRange];
|
||||
|
||||
if ((range.length == 0) && wrap)
|
||||
{ // If not found look at the first part of the string
|
||||
searchRange.location = 0;
|
||||
searchRange.length = selectedRange.location;
|
||||
range = [self rangeOfString:string options:options range:searchRange];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
searchRange.location = 0;
|
||||
searchRange.length = selectedRange.location;
|
||||
range = [self rangeOfString:string options:options range:searchRange];
|
||||
|
||||
if ((range.length == 0) && wrap)
|
||||
{
|
||||
searchRange.location = NSMaxRange(selectedRange);
|
||||
searchRange.length = length - searchRange.location;
|
||||
range = [self rangeOfString:string options:options range:searchRange];
|
||||
}
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in a new issue