probably to simple for the experienced cocoa writers
probably to simple for the experienced cocoa writers
- Subject: probably to simple for the experienced cocoa writers
- From: Jasper Touwen <email@hidden>
- Date: Tue, 25 Dec 2001 02:35:34 +0100
hai,
At this moment a'm really allowed to say: Merry Christmas(this prob.
depends on your local settings), so Merry Christmas.
I'm trying to learn some cocoa, so i'd started with the book 'Learning
cocoa', i got a bit bored so i try to build something for myself. The
easiest thing (i guesed, maybe wrong) is working with text.
To the point or question...
In my mainwindow of an document based document i've got a NSTextView and
a NSOutlineView. The outlineview has to use data and has to get updated
by the content of the textView...
This is what i tried to do.. I gave the outlineView it's own datasource.
It had to get the first base items from the NSDocumentClass ('ve
subclassed it). From the datasourceClass I tried to do this with:
itemArray = [ [NSDocumentController currentDocument] itemArray];
The problem is after stepping through the code... The datasourceObject
is initiated before the documentcontroller. So i would never find a
itemArray... At least this is what i think (with po
[NSDocumentController currentDocument] i receive <nil>). Maybe i have to
solve this totally different.
any idea?
Oh, from a newbie to a newbie and (if this is not a correct solution
please give a better advice):
A long time ago asked someone for a HTML editor(maybe you can update
you're ... There was an advice to look at the code of texshop..
Here's a variant to that code for highlighting braces etc...
==========================================================================
================
/*notification .. add a selection change notification if you want to
highlight also if move along a brace*/
- (BOOL)textView:(NSTextView *)aTextView
shouldChangeTextInRange:(NSRange)affectedCharRange
replacementString:(NSString *)replacementString{
NSRange foundRange;
NSDate *myDate;
BOOL found = NO;
// check for rightBrace... if there is: find the left one...
if ( [replacementString isEqualToString:@"]" ] ){
foundRange = [self findLeftPartCharacterInString:[aTextView
string] leftPartChar:@"[" rightPartChar:@"]"
inRange:NSMakeRange(0,affectedCharRange.location)];
if (foundRange.location != NSNotFound){
found=YES;
NSLog(@"something found somewhere at index:%d",
foundRange.location);
}
} else if ( [replacementString isEqualToString:@"}" ] ){
foundRange = [self findLeftPartCharacterInString:[aTextView
string] leftPartChar:@"{" rightPartChar:@"}"
inRange:NSMakeRange(0,affectedCharRange.location)];
if (foundRange.location != NSNotFound){
found=YES;
NSLog(@"something found somewhere at
index:%d", foundRange.location);
}
}
if (found) {
if (foundRange.location != NSNotFound){
[aTextView setSelectedRange:foundRange
affinity: NSSelectByCharacter stillSelecting: YES];
[aTextView display];
myDate = [NSDate date];
/* Koch: Jan 26, 2001: changed -0.15 to -0.075 to speed
things up <--- thank him for the base of the code, not me i just play
with it..*/
while ([myDate timeIntervalSinceNow] > - 0.075);
[aTextView setSelectedRange: affectedCharRange];
}
}
return YES;
}
- (NSRange)findLeftPartCharacterInString:(NSString *)searchString
leftPartChar:(NSString *)leftPart rightPartChar:(NSString *)rightPart
inRange:(NSRange)searchRange{
int counter, index; // not to smart.. index = 0[zero] means in the
find loop nothing found (better rename);
NSRange foundRange;
NSCharacterSet *charSet = [NSCharacterSet
characterSetWithCharactersInString: [leftPart
stringByAppendingString:rightPart] ];
counter = 1;
index = 1;
//just a backwardssearch...okay repeated if necessary...
while ( (counter != 0) && (index!=0) ) {
foundRange = [searchString rangeOfCharacterFromSet:charSet
options:(NSBackwardsSearch) range:searchRange];
if ( (index = foundRange.location) != NSNotFound) { // so i
found a left or right brace...
// if the counter receives zero the left one is found
if ( [[searchString substringWithRange:foundRange]
isEqualToString:rightPart ] ){
counter++;
} else {
counter--;
};
searchRange = NSMakeRange(0,index); // create a new
searchRange..
} else {
index = 0;
}
}
return foundRange;
}
==========================================================================
================
Sorry this mail got a bit long...
Sincerely Jasper, just peeking around a corner...