FROM : Oliver Cameron
DATE : Sun Dec 12 22:14:26 2004
Hi,
So, I've got basic data into my browser by doing this:
- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
{
return [snippetObject count];
}
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell
atRow:(int)row column:(int)column
{
[cell setStringValue:@"Hello"];
}
- (void)addSnippet:(id)sender
{
SnippetsObject *newObject = [[SnippetsObject alloc]
initWithFileTitled:@"Test" contents:@"Test" parent:snippetObject];
[snippetObject addSnippet:newObject];
[self reloadData];
}
This kinda works, but basically all it does is add an object to the
NSBrowser titled Hello, and basically, it adds an infinite number of
items exactly the same within the root Hello item.
A SnippetsObject is basically a NSObject subclass which just holds
details for each instance of it, like its title and contents.
snippetObject is basically like my root, I add every new SnippetsObject
to that. So basically, what I want, is that every parent should contain
all its children in a different column.
I'm confused as to how I would go about doing that.
Thanks,
Oliver
On 12 Dec 2004, at 20:59, Andreas Höschler wrote:
>
> On Sonntag, Dezember 12, 2004, at 09:38 Uhr, Oliver Cameron wrote:
>
>> I'm trying to make an app with a NSBrowser in the UI. And I am just
>> plain stumped as to how to make this work. Basically, at first I went
>> with a NSOutlineView, so I'm trying to migrate it over, as they sound
>> like or should use the same type of system.
>>
>> For example, in a NSTableView datasource, you set its data by
>> numberOfRows and objectValueForTableColumn. I noticed there was a
>> similar numberOfRows method for NSBrowser, and I fed it the same data
>> as the NSOutlineView. I noticed in the example of SimpleBrowser the
>> method willDisplayCell. I am guessing this is similar to the
>> objectValueForTableColumn, but I just don't *get* how it works at
>> all, how to set the data in the NSBrowser etc. Any simpler examples
>> than the AppKit example would really help.
>>
>>
>
> In the delegate implement stuff like
>
> - (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
> {
> if (sender == browser)
> {
> if (column == 0)
> {
> return [_classesDisplayGroup numberOfDisplayedObjects];
> }
> else
> {
> // NSString *path = [[sender pathToColumn:column]
> stringAfterRemovingFirstCharacter];
> NSArray *browserPath = [sender browserPathToColumn:column];
> // NSLog(@"browserPath %@", browserPath);
> int numberOfRows = [[self
> subclassesForBrowserPath:browserPath] count];
> // NSLog(@"numberOfRows %d", numberOfRows);
> return numberOfRows;
> }
> }
> else // Code Browser
> {
> if (column == 0)
> {
> return [_codeClassesDisplayGroup numberOfDisplayedObjects];
> }
> else
> {
> // return [_codeMethodDisplayGroup numberOfDisplayedObjects];
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:[sender
> selectedRowInColumn:0]];
> return [[codeClass sortedMethodsForModule:_module] count];
> }
> }
> }
>
> - (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell
> atRow:(int)row column:(int)column
> {
> if (sender == browser) // object model
> {
> SOClass *class;
> SOModule *module;
>
> if (column == 0)
> {
> class = [[_classesDisplayGroup displayedObjects]
> objectAtIndex:row];
> }
> else
> {
> NSArray *browserPath = [sender browserPathToColumn:column];
> class = [[self subclassesForBrowserPath:browserPath]
> objectAtIndex:row];
> }
> module = [class valueForKey:@"backTo_SOModule_classes"];
>
> NSColor *color = [[class module] color];
> NSDictionary *attributeDic = ((color) ? [NSDictionary
> dictionaryWithObject:color forKey:NSForegroundColorAttributeName] :
> nil);
> [cell setAttributedStringValue:[[[NSAttributedString alloc]
> initWithString:[class valueForKey:@"name"]
> attributes:attributeDic] autorelease]];
> [cell setLeaf:([[[class valueForKey:@"subclasses"]
> filteredArrayUsingQualifier:[FBQualifier
> classesQualifierForModule:_module]] count] == 0)];
> }
> else // code classes
> {
> if (column == 0)
> {
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:row];
> [cell setAttributedStringValue:[codeClass
> attributedNameString]];
> // [cell setLeaf:[[codeClass valueForKey:@"methods"] count] ==
> 0];
> [cell setLeaf:NO];
> }
> else
> {
> // SOCodeMethod *method = (SOCodeMethod
> *)[_codeMethodDisplayGroup displayedObjectAtIndex:row];
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:[sender
> selectedRowInColumn:0]];
> NSArray *methods = [codeClass sortedMethodsForModule:_module];
> SOCodeMethod *method = [methods objectAtIndex:row];
> [cell setAttributedStringValue:[method
> attributedSelectorString]];
> [cell setLeaf:YES];
> }
> }
> }
>
> - (BOOL)browser:(NSBrowser *)sender isColumnValid:(int)column
> {
> return NO;
> }
>
DATE : Sun Dec 12 22:14:26 2004
Hi,
So, I've got basic data into my browser by doing this:
- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
{
return [snippetObject count];
}
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell
atRow:(int)row column:(int)column
{
[cell setStringValue:@"Hello"];
}
- (void)addSnippet:(id)sender
{
SnippetsObject *newObject = [[SnippetsObject alloc]
initWithFileTitled:@"Test" contents:@"Test" parent:snippetObject];
[snippetObject addSnippet:newObject];
[self reloadData];
}
This kinda works, but basically all it does is add an object to the
NSBrowser titled Hello, and basically, it adds an infinite number of
items exactly the same within the root Hello item.
A SnippetsObject is basically a NSObject subclass which just holds
details for each instance of it, like its title and contents.
snippetObject is basically like my root, I add every new SnippetsObject
to that. So basically, what I want, is that every parent should contain
all its children in a different column.
I'm confused as to how I would go about doing that.
Thanks,
Oliver
On 12 Dec 2004, at 20:59, Andreas Höschler wrote:
>
> On Sonntag, Dezember 12, 2004, at 09:38 Uhr, Oliver Cameron wrote:
>
>> I'm trying to make an app with a NSBrowser in the UI. And I am just
>> plain stumped as to how to make this work. Basically, at first I went
>> with a NSOutlineView, so I'm trying to migrate it over, as they sound
>> like or should use the same type of system.
>>
>> For example, in a NSTableView datasource, you set its data by
>> numberOfRows and objectValueForTableColumn. I noticed there was a
>> similar numberOfRows method for NSBrowser, and I fed it the same data
>> as the NSOutlineView. I noticed in the example of SimpleBrowser the
>> method willDisplayCell. I am guessing this is similar to the
>> objectValueForTableColumn, but I just don't *get* how it works at
>> all, how to set the data in the NSBrowser etc. Any simpler examples
>> than the AppKit example would really help.
>>
>>
>
> In the delegate implement stuff like
>
> - (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
> {
> if (sender == browser)
> {
> if (column == 0)
> {
> return [_classesDisplayGroup numberOfDisplayedObjects];
> }
> else
> {
> // NSString *path = [[sender pathToColumn:column]
> stringAfterRemovingFirstCharacter];
> NSArray *browserPath = [sender browserPathToColumn:column];
> // NSLog(@"browserPath %@", browserPath);
> int numberOfRows = [[self
> subclassesForBrowserPath:browserPath] count];
> // NSLog(@"numberOfRows %d", numberOfRows);
> return numberOfRows;
> }
> }
> else // Code Browser
> {
> if (column == 0)
> {
> return [_codeClassesDisplayGroup numberOfDisplayedObjects];
> }
> else
> {
> // return [_codeMethodDisplayGroup numberOfDisplayedObjects];
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:[sender
> selectedRowInColumn:0]];
> return [[codeClass sortedMethodsForModule:_module] count];
> }
> }
> }
>
> - (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell
> atRow:(int)row column:(int)column
> {
> if (sender == browser) // object model
> {
> SOClass *class;
> SOModule *module;
>
> if (column == 0)
> {
> class = [[_classesDisplayGroup displayedObjects]
> objectAtIndex:row];
> }
> else
> {
> NSArray *browserPath = [sender browserPathToColumn:column];
> class = [[self subclassesForBrowserPath:browserPath]
> objectAtIndex:row];
> }
> module = [class valueForKey:@"backTo_SOModule_classes"];
>
> NSColor *color = [[class module] color];
> NSDictionary *attributeDic = ((color) ? [NSDictionary
> dictionaryWithObject:color forKey:NSForegroundColorAttributeName] :
> nil);
> [cell setAttributedStringValue:[[[NSAttributedString alloc]
> initWithString:[class valueForKey:@"name"]
> attributes:attributeDic] autorelease]];
> [cell setLeaf:([[[class valueForKey:@"subclasses"]
> filteredArrayUsingQualifier:[FBQualifier
> classesQualifierForModule:_module]] count] == 0)];
> }
> else // code classes
> {
> if (column == 0)
> {
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:row];
> [cell setAttributedStringValue:[codeClass
> attributedNameString]];
> // [cell setLeaf:[[codeClass valueForKey:@"methods"] count] ==
> 0];
> [cell setLeaf:NO];
> }
> else
> {
> // SOCodeMethod *method = (SOCodeMethod
> *)[_codeMethodDisplayGroup displayedObjectAtIndex:row];
> SOCodeClass *codeClass = (SOCodeClass
> *)[_codeClassesDisplayGroup displayedObjectAtIndex:[sender
> selectedRowInColumn:0]];
> NSArray *methods = [codeClass sortedMethodsForModule:_module];
> SOCodeMethod *method = [methods objectAtIndex:row];
> [cell setAttributedStringValue:[method
> attributedSelectorString]];
> [cell setLeaf:YES];
> }
> }
> }
>
> - (BOOL)browser:(NSBrowser *)sender isColumnValid:(int)column
> {
> return NO;
> }
>
| Related mails | Author | Date |
|---|---|---|
| Oliver Cameron | Dec 12, 21:38 | |
| Oliver Cameron | Dec 12, 22:14 | |
| Andreas Höschler | Dec 12, 22:55 |






Cocoa mail archive

