mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-29 19:57:39 +00:00
Fixed some minor bugs in NSOutlineView and made delegate checking more efficient by using a macro.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13892 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
414d38ddd8
commit
9799537f92
2 changed files with 55 additions and 80 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2002-06-15 Gregory John Casamento <greg_casamerto@yahoo.com>
|
||||
|
||||
* Source/NSOutlineView.m a number of improvements:
|
||||
-setDelegate now uses the CHECK_REQUIRED macro to check
|
||||
for required methods instead of iterating over a list of strings.
|
||||
-expandItem:expandChildren: corrected bug which prevented the method
|
||||
from working correctly when expandChildren is YES.
|
||||
-collapseItem:collapseChildren: corrected bug which prevented the
|
||||
method from working correctly when expandChildren is YES.
|
||||
|
||||
2002-06-12 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Source/GSServicesManager.m (-rebuildServicesMenu): Disable auto-
|
||||
|
|
|
@ -173,7 +173,7 @@ static NSImage *unexpandable = nil;
|
|||
}
|
||||
|
||||
[self _collectItemsStartingWith: anitem
|
||||
into: allChildren];
|
||||
into: allChildren];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,39 +318,24 @@ static NSImage *unexpandable = nil;
|
|||
object: self
|
||||
userInfo: infoDict];
|
||||
|
||||
|
||||
// recursively find all children and call this method to open them.
|
||||
if(collapseChildren) // collapse all
|
||||
{
|
||||
NSMutableArray *allChildren = nil;
|
||||
int numchild = 0;
|
||||
int index = 0;
|
||||
NSMutableArray *allChildren = [NSMutableArray array];
|
||||
id sitem = (item == nil)?[NSNull null]:item;
|
||||
|
||||
[self _collectItemsStartingWith: item into: allChildren];
|
||||
allChildren = NSMapGet(_itemDict, sitem);
|
||||
numchild = [allChildren count];
|
||||
|
||||
for(index = 0;index < numchild;index++)
|
||||
{
|
||||
id child = [allChildren objectAtIndex: index];
|
||||
|
||||
if([self isExpandable: child] &&
|
||||
[self isItemExpanded: child])
|
||||
if([self isExpandable: child])
|
||||
{
|
||||
NSMutableDictionary *childDict = [NSDictionary dictionary];
|
||||
[childDict setObject: child forKey: @"NSObject"];
|
||||
|
||||
// Send out the notification to let observers know
|
||||
// that this is about to occur.
|
||||
[nc postNotificationName: NSOutlineViewItemWillCollapseNotification
|
||||
object: self
|
||||
userInfo: childDict];
|
||||
|
||||
[self _closeItem: child];
|
||||
|
||||
// Send out the notification to let observers know that
|
||||
// this is about to occur.
|
||||
[nc postNotificationName: NSOutlineViewItemDidCollapseNotification
|
||||
object: self
|
||||
userInfo: childDict];
|
||||
[self collapseItem: child collapseChildren: collapseChildren];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,60 +358,51 @@ static NSImage *unexpandable = nil;
|
|||
canExpand = [_delegate outlineView: self shouldExpandItem: item];
|
||||
}
|
||||
|
||||
if([self isExpandable: item] && ![self isItemExpanded: item] && canExpand)
|
||||
// if the item is expandable
|
||||
if([self isExpandable: item])
|
||||
{
|
||||
NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
|
||||
|
||||
[infoDict setObject: item forKey: @"NSObject"];
|
||||
|
||||
// Send out the notification to let observers know that this is about
|
||||
// to occur.
|
||||
[nc postNotificationName: NSOutlineViewItemWillExpandNotification
|
||||
object: self
|
||||
userInfo: infoDict];
|
||||
// if it is not already expanded and it can be expanded, then expand
|
||||
if(![self isItemExpanded: item] && canExpand)
|
||||
{
|
||||
NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
|
||||
|
||||
// insert the root element, if necessary otherwise insert the
|
||||
// actual object.
|
||||
[self _openItem: item];
|
||||
|
||||
// Send out the notification to let observers know that this has
|
||||
// occured.
|
||||
[nc postNotificationName: NSOutlineViewItemDidExpandNotification
|
||||
object: self
|
||||
userInfo: infoDict];
|
||||
[infoDict setObject: item forKey: @"NSObject"];
|
||||
|
||||
// Send out the notification to let observers know that this is about
|
||||
// to occur.
|
||||
[nc postNotificationName: NSOutlineViewItemWillExpandNotification
|
||||
object: self
|
||||
userInfo: infoDict];
|
||||
|
||||
// insert the root element, if necessary otherwise insert the
|
||||
// actual object.
|
||||
[self _openItem: item];
|
||||
|
||||
// Send out the notification to let observers know that this has
|
||||
// occured.
|
||||
[nc postNotificationName: NSOutlineViewItemDidExpandNotification
|
||||
object: self
|
||||
userInfo: infoDict];
|
||||
}
|
||||
|
||||
// recursively find all children and call this method to open them.
|
||||
if(expandChildren) // expand all
|
||||
{
|
||||
NSMutableArray *allChildren = nil;
|
||||
int numchild = 0;
|
||||
int index = 0;
|
||||
id sitem = (item == nil)?[NSNull null]:item;
|
||||
|
||||
[self _collectItemsStartingWith: item into: allChildren];
|
||||
allChildren = NSMapGet(_itemDict, sitem);
|
||||
numchild = [allChildren count];
|
||||
|
||||
for(index = 0;index < numchild;index++)
|
||||
{
|
||||
id child = [allChildren objectAtIndex: index];
|
||||
|
||||
if([self isExpandable: child] &&
|
||||
![self isItemExpanded: child])
|
||||
if([self isExpandable: child])
|
||||
{
|
||||
NSMutableDictionary *childDict = [NSMutableDictionary dictionary];
|
||||
|
||||
[childDict setObject: child forKey: @"NSObject"];
|
||||
// Send out the notification to let observers know that this has
|
||||
// occured.
|
||||
[nc postNotificationName: NSOutlineViewItemWillExpandNotification
|
||||
object: self
|
||||
userInfo: childDict];
|
||||
|
||||
[self _openItem: child];
|
||||
|
||||
// Send out the notification to let observers know that this has
|
||||
// occured.
|
||||
[nc postNotificationName: NSOutlineViewItemDidExpandNotification
|
||||
object: self
|
||||
userInfo: childDict];
|
||||
[self expandItem: child expandChildren: expandChildren];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -714,31 +690,20 @@ static NSImage *unexpandable = nil;
|
|||
|
||||
- (void) setDataSource: (id)anObject
|
||||
{
|
||||
NSArray *requiredMethods =
|
||||
[NSArray arrayWithObjects: @"outlineView:child:ofItem:",
|
||||
@"outlineView:isItemExpandable:",
|
||||
@"outlineView:numberOfChildrenOfItem:",
|
||||
@"outlineView:objectValueForTableColumn:byItem:",
|
||||
nil];
|
||||
NSEnumerator *en = [requiredMethods objectEnumerator];
|
||||
NSString *selectorName = nil;
|
||||
#define CHECK_REQUIRED_METHOD(selector_name) \
|
||||
if (![anObject respondsToSelector: @selector(##selector_name)]) \
|
||||
[NSException raise: NSInternalInconsistencyException \
|
||||
format: @"data source does not respond to ##selector_name"]
|
||||
|
||||
CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
|
||||
CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
|
||||
CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
|
||||
CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
|
||||
|
||||
// Is the data source editable?
|
||||
_dataSource_editable = [anObject respondsToSelector:
|
||||
@selector(outlineView:setObjectValue:forTableColumn:byItem:)];
|
||||
|
||||
while((selectorName = [en nextObject]) != nil)
|
||||
{
|
||||
SEL sel = NSSelectorFromString(selectorName);
|
||||
if ([anObject respondsToSelector: sel] == NO)
|
||||
{
|
||||
[NSException
|
||||
raise: NSInternalInconsistencyException
|
||||
format: @"Data Source doesn't respond to %@",
|
||||
selectorName];
|
||||
}
|
||||
}
|
||||
|
||||
/* We do *not* retain the dataSource, it's like a delegate */
|
||||
_dataSource = anObject;
|
||||
[self tile];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue