libs-gui/Source/NSTextFinder.m

274 lines
7.2 KiB
Mathematica
Raw Permalink Normal View History

2020-08-02 10:22:16 +00:00
/* Implementation of class NSTextFinder
Copyright (C) 2020 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 02-08-2020
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
2020-08-02 14:59:56 +00:00
#import <Foundation/NSArray.h>
2020-08-04 10:32:19 +00:00
#import <Foundation/NSArchiver.h>
2020-08-02 14:59:56 +00:00
2020-08-02 10:22:16 +00:00
#import "AppKit/NSTextFinder.h"
#import "AppKit/NSTextView.h"
#import "AppKit/NSUserInterfaceValidation.h"
#import "GSTextFinder.h"
2020-08-02 10:22:16 +00:00
@implementation NSTextFinder
2020-08-04 10:32:19 +00:00
2020-08-04 11:25:10 +00:00
- (instancetype) init
{
self = [super init];
if (self != nil)
{
// initialize finder...
2020-08-09 12:49:20 +00:00
_finder = [[GSTextFinder alloc] init];
2020-08-04 11:25:10 +00:00
}
return self;
}
2020-08-02 14:59:56 +00:00
// Validating and performing
2020-08-21 17:37:22 +00:00
- (void) performFindPanelAction: (id)sender
2020-08-14 02:54:55 +00:00
{
2020-08-21 17:37:22 +00:00
[self performAction: [sender tag]];
2020-08-14 02:54:55 +00:00
}
2020-08-21 17:37:22 +00:00
- (void) performTextFinderAction: (id)sender
2020-08-14 02:54:55 +00:00
{
2020-08-21 17:37:22 +00:00
[self performFindPanelAction: sender];
2020-08-14 02:54:55 +00:00
}
- (NSInteger) tag
{
return _tag;
}
- (void) _mapOpToTag: (NSTextFinderAction)op
2020-08-02 14:59:56 +00:00
{
switch (op)
2020-08-04 11:04:21 +00:00
{
case NSTextFinderActionShowFindInterface:
_tag = NSFindPanelActionShowFindPanel;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionNextMatch:
_tag = NSFindPanelActionNext;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionPreviousMatch:
_tag = NSFindPanelActionPrevious;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionReplaceAll:
_tag = NSFindPanelActionReplaceAll;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionReplace:
_tag = NSFindPanelActionReplace;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionReplaceAndFind:
_tag = NSFindPanelActionReplaceAndFind;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionSetSearchString:
_tag = NSFindPanelActionSetFindString;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionReplaceAllInSelection:
_tag = NSFindPanelActionReplaceAllInSelection;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionSelectAll:
_tag = NSFindPanelActionSelectAll;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionSelectAllInSelection:
_tag = NSFindPanelActionSelectAllInSelection;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionHideFindInterface:
// unsupported;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionShowReplaceInterface:
// unsupported;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
case NSTextFinderActionHideReplaceInterface:
// unsupported;
2020-08-04 11:16:46 +00:00
break;
2020-08-04 11:04:21 +00:00
default:
2020-08-04 11:16:46 +00:00
NSLog(@"Unknown operation: %ld", op);
2020-08-04 11:04:21 +00:00
break;
}
2020-08-02 14:59:56 +00:00
}
- (void) performAction: (NSTextFinderAction)op
{
[self _mapOpToTag: op];
[_finder performFindPanelAction: self];
}
- (BOOL) validateUserInterfaceAction: (id<NSValidatedUserInterfaceItem>)item
{
SEL action = [item action];
if (sel_isEqual(action, @selector(performTextFinderAction:)) ||
sel_isEqual(action, @selector(performFindPanelAction:)))
{
return [self validateAction: [item tag]];
}
return YES;
}
2020-08-04 11:04:21 +00:00
- (BOOL) validateAction: (NSTextFinderAction)op
2020-08-02 14:59:56 +00:00
{
[self _mapOpToTag: op];
return [_finder validateFindPanelAction: self
withTextView: nil];
2020-08-02 14:59:56 +00:00
}
2023-11-17 15:53:43 +00:00
- (void)cancelFindIndicator
2020-08-02 14:59:56 +00:00
{
}
// Properties
- (id<NSTextFinderClient>) client
{
return _client;
2020-08-02 14:59:56 +00:00
}
- (void) setClient: (id<NSTextFinderClient>) client
{
_client = client;
2020-08-02 14:59:56 +00:00
}
- (id<NSTextFinderBarContainer>) findBarContainer
{
return _findBarContainer;
2020-08-02 14:59:56 +00:00
}
- (void) setFindBarContainer: (id<NSTextFinderBarContainer>) findBarContainer
{
_findBarContainer = findBarContainer;
2020-08-02 14:59:56 +00:00
}
2020-08-04 10:32:19 +00:00
- (BOOL) findIndicatorNeedsUpdate
2020-08-02 14:59:56 +00:00
{
2020-08-04 10:32:19 +00:00
return _findIndicatorNeedsUpdate;
2020-08-02 14:59:56 +00:00
}
- (void) setFindIndicatorNeedsUpdate: (BOOL)flag
{
2020-08-04 10:32:19 +00:00
_findIndicatorNeedsUpdate = flag;
2020-08-02 14:59:56 +00:00
}
- (BOOL) isIncrementalSearchingEnabled
{
2020-08-04 10:32:19 +00:00
return _incrementalSearchingEnabled;
2020-08-02 14:59:56 +00:00
}
- (void) setIncrementalSearchingEnabled: (BOOL)flag
{
2020-08-04 10:32:19 +00:00
_incrementalSearchingEnabled = flag;
2020-08-02 14:59:56 +00:00
}
- (BOOL) incrementalSearchingShouldDimContentView
{
2020-08-04 10:32:19 +00:00
return _incrementalSearchingShouldDimContentView;
2020-08-02 14:59:56 +00:00
}
- (void) setIncrementalSearchingShouldDimContentView: (BOOL)flag
{
2020-08-04 10:32:19 +00:00
_incrementalSearchingShouldDimContentView = flag;
2020-08-02 14:59:56 +00:00
}
- (NSArray *) incrementalMatchRanges
{
2020-08-04 10:32:19 +00:00
return _incrementalMatchRanges;
2020-08-02 14:59:56 +00:00
}
+ (void) drawIncrementalMatchHighlightInRect: (NSRect)rect
{
}
- (void) noteClientStringWillChange
{
2020-08-04 10:32:19 +00:00
// nothing...
2020-08-02 14:59:56 +00:00
}
// NSCoding...
- (instancetype) initWithCoder: (NSCoder *)coder
{
2020-08-04 10:32:19 +00:00
self = [super init];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
if ([coder containsValueForKey: @"NSFindIndicatorNeedsUpdate"])
{
_findIndicatorNeedsUpdate = [coder decodeBoolForKey: @"NSFindIndicatorNeedsUpdate"];
}
if ([coder containsValueForKey: @"NSIncrementalSearchingEnabled"])
{
_incrementalSearchingEnabled = [coder decodeBoolForKey: @"NSIncrementalSearchingEnabled"];
}
if ([coder containsValueForKey: @"NSIncrementalSearchingShouldDimContentView"])
{
_incrementalSearchingShouldDimContentView = [coder decodeBoolForKey: @"NSIncrementalSearchingShouldDimContentView"];
}
if ([coder containsValueForKey: @"NSIncrementalMatchRanges"])
{
ASSIGN(_incrementalMatchRanges, [coder decodeObjectForKey: @"NSIncrementalMatchRanges"]);
}
2020-08-04 11:25:10 +00:00
// initialize finder...
_finder = [GSTextFinder sharedTextFinder];
2020-08-04 10:32:19 +00:00
}
else
{
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_findIndicatorNeedsUpdate];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_incrementalSearchingEnabled];
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_incrementalSearchingShouldDimContentView];
ASSIGN(_incrementalMatchRanges, [coder decodeObject]);
}
}
return self;
2020-08-02 14:59:56 +00:00
}
- (void) encodeWithCoder: (NSCoder *)coder
{
if ([coder allowsKeyedCoding])
{
[coder encodeBool: _findIndicatorNeedsUpdate
forKey: @"NSFindIndicatorNeedsUpdate"];
[coder encodeBool: _incrementalSearchingEnabled
forKey: @"NSIncrementalSearchingEnabled"];
[coder encodeBool: _incrementalSearchingShouldDimContentView
forKey: @"NSIncrementalSearchingShouldDimContentView"];
[coder encodeObject: _incrementalMatchRanges
forKey: @"NSIncrementalMatchRanges"];
}
else
{
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_findIndicatorNeedsUpdate];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_incrementalSearchingEnabled];
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_incrementalSearchingShouldDimContentView];
[coder encodeObject: _incrementalMatchRanges];
}
2020-08-02 14:59:56 +00:00
}
2020-08-02 10:22:16 +00:00
@end