mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 15:00:38 +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>
|
2002-06-12 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
* Source/GSServicesManager.m (-rebuildServicesMenu): Disable auto-
|
* Source/GSServicesManager.m (-rebuildServicesMenu): Disable auto-
|
||||||
|
|
|
@ -173,7 +173,7 @@ static NSImage *unexpandable = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self _collectItemsStartingWith: anitem
|
[self _collectItemsStartingWith: anitem
|
||||||
into: allChildren];
|
into: allChildren];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,39 +318,24 @@ static NSImage *unexpandable = nil;
|
||||||
object: self
|
object: self
|
||||||
userInfo: infoDict];
|
userInfo: infoDict];
|
||||||
|
|
||||||
|
// recursively find all children and call this method to open them.
|
||||||
if(collapseChildren) // collapse all
|
if(collapseChildren) // collapse all
|
||||||
{
|
{
|
||||||
|
NSMutableArray *allChildren = nil;
|
||||||
int numchild = 0;
|
int numchild = 0;
|
||||||
int index = 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];
|
numchild = [allChildren count];
|
||||||
|
|
||||||
for(index = 0;index < numchild;index++)
|
for(index = 0;index < numchild;index++)
|
||||||
{
|
{
|
||||||
id child = [allChildren objectAtIndex: index];
|
id child = [allChildren objectAtIndex: index];
|
||||||
|
|
||||||
if([self isExpandable: child] &&
|
if([self isExpandable: child])
|
||||||
[self isItemExpanded: child])
|
|
||||||
{
|
{
|
||||||
NSMutableDictionary *childDict = [NSDictionary dictionary];
|
[self collapseItem: child collapseChildren: collapseChildren];
|
||||||
[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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,60 +358,51 @@ static NSImage *unexpandable = nil;
|
||||||
canExpand = [_delegate outlineView: self shouldExpandItem: item];
|
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];
|
// if it is not already expanded and it can be expanded, then expand
|
||||||
|
if(![self isItemExpanded: item] && canExpand)
|
||||||
[infoDict setObject: item forKey: @"NSObject"];
|
{
|
||||||
|
NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
|
||||||
// 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
|
[infoDict setObject: item forKey: @"NSObject"];
|
||||||
// actual object.
|
|
||||||
[self _openItem: item];
|
// Send out the notification to let observers know that this is about
|
||||||
|
// to occur.
|
||||||
// Send out the notification to let observers know that this has
|
[nc postNotificationName: NSOutlineViewItemWillExpandNotification
|
||||||
// occured.
|
object: self
|
||||||
[nc postNotificationName: NSOutlineViewItemDidExpandNotification
|
userInfo: infoDict];
|
||||||
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
|
if(expandChildren) // expand all
|
||||||
{
|
{
|
||||||
NSMutableArray *allChildren = nil;
|
NSMutableArray *allChildren = nil;
|
||||||
int numchild = 0;
|
int numchild = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
id sitem = (item == nil)?[NSNull null]:item;
|
||||||
|
|
||||||
[self _collectItemsStartingWith: item into: allChildren];
|
allChildren = NSMapGet(_itemDict, sitem);
|
||||||
numchild = [allChildren count];
|
numchild = [allChildren count];
|
||||||
|
|
||||||
for(index = 0;index < numchild;index++)
|
for(index = 0;index < numchild;index++)
|
||||||
{
|
{
|
||||||
id child = [allChildren objectAtIndex: index];
|
id child = [allChildren objectAtIndex: index];
|
||||||
|
|
||||||
if([self isExpandable: child] &&
|
if([self isExpandable: child])
|
||||||
![self isItemExpanded: child])
|
|
||||||
{
|
{
|
||||||
NSMutableDictionary *childDict = [NSMutableDictionary dictionary];
|
[self expandItem: child expandChildren: expandChildren];
|
||||||
|
|
||||||
[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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -714,31 +690,20 @@ static NSImage *unexpandable = nil;
|
||||||
|
|
||||||
- (void) setDataSource: (id)anObject
|
- (void) setDataSource: (id)anObject
|
||||||
{
|
{
|
||||||
NSArray *requiredMethods =
|
#define CHECK_REQUIRED_METHOD(selector_name) \
|
||||||
[NSArray arrayWithObjects: @"outlineView:child:ofItem:",
|
if (![anObject respondsToSelector: @selector(##selector_name)]) \
|
||||||
@"outlineView:isItemExpandable:",
|
[NSException raise: NSInternalInconsistencyException \
|
||||||
@"outlineView:numberOfChildrenOfItem:",
|
format: @"data source does not respond to ##selector_name"]
|
||||||
@"outlineView:objectValueForTableColumn:byItem:",
|
|
||||||
nil];
|
CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
|
||||||
NSEnumerator *en = [requiredMethods objectEnumerator];
|
CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
|
||||||
NSString *selectorName = nil;
|
CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
|
||||||
|
CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
|
||||||
|
|
||||||
// Is the data source editable?
|
// Is the data source editable?
|
||||||
_dataSource_editable = [anObject respondsToSelector:
|
_dataSource_editable = [anObject respondsToSelector:
|
||||||
@selector(outlineView:setObjectValue:forTableColumn:byItem:)];
|
@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 */
|
/* We do *not* retain the dataSource, it's like a delegate */
|
||||||
_dataSource = anObject;
|
_dataSource = anObject;
|
||||||
[self tile];
|
[self tile];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue