mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-08 09:50:41 +00:00
Added fix to 1) make NSOutlineView faster using Maps and 2) eliminate the need for items to implement NSCopying which is not correct behavior. GJC
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13284 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
48ee386dc3
commit
040cf48e73
3 changed files with 64 additions and 56 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2002-04-01 Gregory Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
|
* Source/NSOutlineView.m
|
||||||
|
Replaced dictionaries w/ NSMapTable. NSDictionary required
|
||||||
|
items of the NSOutlineView to implement the NSCopying protocol
|
||||||
|
which is incorrect.
|
||||||
|
* Headers/gnustep/gui/NSOutlineView.h
|
||||||
|
Replaced dictionaries in class declaration.
|
||||||
|
|
||||||
2002-03-31 Fred Kiefer <FredKiefer@gmx.de>
|
2002-03-31 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/Window.m
|
* Source/Window.m
|
||||||
|
|
|
@ -30,16 +30,17 @@
|
||||||
#define _GNUstep_H_NSOutlineView
|
#define _GNUstep_H_NSOutlineView
|
||||||
|
|
||||||
#include <AppKit/NSTableView.h>
|
#include <AppKit/NSTableView.h>
|
||||||
|
#include <Foundation/NSMapTable.h>
|
||||||
|
|
||||||
@class NSMutableArray;
|
@class NSMutableArray;
|
||||||
@class NSString;
|
@class NSString;
|
||||||
|
|
||||||
@interface NSOutlineView : NSTableView
|
@interface NSOutlineView : NSTableView
|
||||||
{
|
{
|
||||||
NSMutableDictionary *_itemDict;
|
NSMapTable *_itemDict;
|
||||||
NSMutableArray *_items;
|
NSMutableArray *_items;
|
||||||
NSMutableArray *_expandedItems;
|
NSMutableArray *_expandedItems;
|
||||||
NSMutableDictionary *_levelOfItems;
|
NSMapTable *_levelOfItems;
|
||||||
BOOL _autoResizesOutlineColumn;
|
BOOL _autoResizesOutlineColumn;
|
||||||
BOOL _indentationMarkerFollowsCell;
|
BOOL _indentationMarkerFollowsCell;
|
||||||
BOOL _autosaveExpandedItems;
|
BOOL _autosaveExpandedItems;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#import <AppKit/PSOperators.h>
|
#import <AppKit/PSOperators.h>
|
||||||
#import <AppKit/NSCachedImageRep.h>
|
#import <AppKit/NSCachedImageRep.h>
|
||||||
#import <Foundation/NSArray.h>
|
#import <Foundation/NSArray.h>
|
||||||
|
#import <Foundation/NSMapTable.h>
|
||||||
|
|
||||||
static NSNotificationCenter *nc = nil;
|
static NSNotificationCenter *nc = nil;
|
||||||
static const int current_version = 1;
|
static const int current_version = 1;
|
||||||
|
@ -117,16 +118,19 @@ static NSImage *unexpandable = nil;
|
||||||
_autosaveExpandedItems = NO;
|
_autosaveExpandedItems = NO;
|
||||||
_indentationPerLevel = 0.0;
|
_indentationPerLevel = 0.0;
|
||||||
_outlineTableColumn = nil;
|
_outlineTableColumn = nil;
|
||||||
_itemDict = [NSMutableDictionary dictionary];
|
_itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
_items = [NSMutableArray array];
|
_items = [NSMutableArray array];
|
||||||
_expandedItems = [NSMutableArray array];
|
_expandedItems = [NSMutableArray array];
|
||||||
_levelOfItems = [NSMutableDictionary dictionary];
|
_levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
|
|
||||||
|
|
||||||
// Retain items
|
// Retain items
|
||||||
RETAIN(_items);
|
RETAIN(_items);
|
||||||
RETAIN(_expandedItems);
|
RETAIN(_expandedItems);
|
||||||
RETAIN(_itemDict);
|
|
||||||
RETAIN(_levelOfItems);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -147,15 +151,14 @@ static NSImage *unexpandable = nil;
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
id sitem = startitem;
|
id object = nil;
|
||||||
|
|
||||||
if(sitem == nil)
|
object = NSMapGet(_itemDict, startitem);
|
||||||
sitem = [NSNull null];
|
num = [object count];
|
||||||
|
|
||||||
num = [[_itemDict objectForKey: sitem] count];
|
|
||||||
for(i = 0; i < num; i++)
|
for(i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
id anitem = [[_itemDict objectForKey: sitem] objectAtIndex: i];
|
id obj = NSMapGet(_itemDict, startitem);
|
||||||
|
id anitem = [obj objectAtIndex: i];
|
||||||
|
|
||||||
// Only collect the children if the item is expanded
|
// Only collect the children if the item is expanded
|
||||||
if([self isItemExpanded: startitem])
|
if([self isItemExpanded: startitem])
|
||||||
|
@ -174,29 +177,22 @@ static NSImage *unexpandable = nil;
|
||||||
int num = [_dataSource outlineView: self
|
int num = [_dataSource outlineView: self
|
||||||
numberOfChildrenOfItem: startitem];
|
numberOfChildrenOfItem: startitem];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
id sitem = startitem;
|
id sitem = (startitem == nil)?[NSNull null]:startitem;
|
||||||
|
|
||||||
if(num > 0)
|
if(num > 0)
|
||||||
{
|
{
|
||||||
if(sitem == nil)
|
NSMapInsert(_itemDict, sitem, [NSMutableArray array]);
|
||||||
{
|
|
||||||
sitem = [NSNull null];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[_itemDict setObject: [NSMutableArray array]
|
NSMapInsert(_levelOfItems, sitem, [NSNumber numberWithInt: level]);
|
||||||
forKey: sitem];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[_levelOfItems setObject: [NSNumber numberWithInt: level]
|
|
||||||
forKey: sitem];
|
|
||||||
|
|
||||||
for(i = 0; i < num; i++)
|
for(i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
id anitem = [_dataSource outlineView: self
|
id anitem = [_dataSource outlineView: self
|
||||||
child: i
|
child: i
|
||||||
ofItem: startitem];
|
ofItem: startitem];
|
||||||
id anarray = [_itemDict objectForKey: sitem];
|
|
||||||
|
id anarray = NSMapGet(_itemDict, sitem);
|
||||||
|
|
||||||
[anarray addObject: anitem];
|
[anarray addObject: anitem];
|
||||||
[self _loadDictionaryStartingWith: anitem
|
[self _loadDictionaryStartingWith: anitem
|
||||||
|
@ -233,13 +229,11 @@ static NSImage *unexpandable = nil;
|
||||||
int numchildren = 0;
|
int numchildren = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int insertionPoint = 0;
|
int insertionPoint = 0;
|
||||||
id sitem = item;
|
id object = nil;
|
||||||
|
id sitem = (item == nil)?[NSNull null]:item;
|
||||||
|
|
||||||
if(item == nil)
|
object = NSMapGet(_itemDict, sitem);
|
||||||
sitem = [NSNull null];
|
numchildren = [object count];
|
||||||
|
|
||||||
numchildren = [[_itemDict objectForKey: sitem] count];
|
|
||||||
// NSLog(@"item: %@ children: %d", sitem, numchildren);
|
|
||||||
|
|
||||||
// open the item...
|
// open the item...
|
||||||
if(item != nil)
|
if(item != nil)
|
||||||
|
@ -260,7 +254,8 @@ static NSImage *unexpandable = nil;
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
for(i=numchildren-1; i >= 0; i--)
|
for(i=numchildren-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
id child = [[_itemDict objectForKey: sitem] objectAtIndex: i];
|
id obj = NSMapGet(_itemDict, sitem);
|
||||||
|
id child = [obj objectAtIndex: i];
|
||||||
|
|
||||||
// Add all of the children...
|
// Add all of the children...
|
||||||
if([self isItemExpanded: child])
|
if([self isItemExpanded: child])
|
||||||
|
@ -466,7 +461,8 @@ static NSImage *unexpandable = nil;
|
||||||
{
|
{
|
||||||
if(item != nil)
|
if(item != nil)
|
||||||
{
|
{
|
||||||
return [[_levelOfItems objectForKey: item] intValue];
|
id object = NSMapGet(_levelOfItems, item);
|
||||||
|
return [object intValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -486,7 +482,7 @@ static NSImage *unexpandable = nil;
|
||||||
childIndex: (int *)index
|
childIndex: (int *)index
|
||||||
ofParent: (id)parent
|
ofParent: (id)parent
|
||||||
{
|
{
|
||||||
NSArray *allKeys = [_itemDict allKeys];
|
NSArray *allKeys = NSAllMapTableKeys(_itemDict);
|
||||||
BOOL hasChildren = NO;
|
BOOL hasChildren = NO;
|
||||||
NSEnumerator *en = [allKeys objectEnumerator];
|
NSEnumerator *en = [allKeys objectEnumerator];
|
||||||
id object = nil;
|
id object = nil;
|
||||||
|
@ -502,7 +498,7 @@ static NSImage *unexpandable = nil;
|
||||||
|
|
||||||
while((object = [en nextObject]))
|
while((object = [en nextObject]))
|
||||||
{
|
{
|
||||||
NSArray *childArray = [_itemDict objectForKey: object];
|
NSArray *childArray = NSMapGet(_itemDict, object);
|
||||||
|
|
||||||
if((*index = [childArray indexOfObject: item]) != NSNotFound)
|
if((*index = [childArray indexOfObject: item]) != NSNotFound)
|
||||||
{
|
{
|
||||||
|
@ -521,14 +517,12 @@ static NSImage *unexpandable = nil;
|
||||||
|
|
||||||
- (void)reloadItem: (id)item reloadChildren: (BOOL)reloadChildren
|
- (void)reloadItem: (id)item reloadChildren: (BOOL)reloadChildren
|
||||||
{
|
{
|
||||||
id object = item;
|
|
||||||
id parent = nil;
|
id parent = nil;
|
||||||
id dsobj = nil;
|
id dsobj = nil;
|
||||||
BOOL haschildren = NO;
|
BOOL haschildren = NO;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
id obj = nil;
|
||||||
if(object == nil)
|
id object = (item == nil)?([NSNull null]):item;
|
||||||
object = [NSNull null];
|
|
||||||
|
|
||||||
// find the item
|
// find the item
|
||||||
haschildren = [self _findItem: object
|
haschildren = [self _findItem: object
|
||||||
|
@ -539,15 +533,14 @@ static NSImage *unexpandable = nil;
|
||||||
child: index
|
child: index
|
||||||
ofItem: parent];
|
ofItem: parent];
|
||||||
|
|
||||||
[[_itemDict objectForKey: parent] removeObject: item];
|
obj = NSMapGet(_itemDict, parent);
|
||||||
[[_itemDict objectForKey: parent] insertObject: dsobj atIndex: index];
|
[obj removeObject: item];
|
||||||
|
[obj insertObject: dsobj atIndex: index];
|
||||||
|
|
||||||
if(reloadChildren && haschildren) // expand all
|
if(reloadChildren && haschildren) // expand all
|
||||||
{
|
{
|
||||||
NSMutableDictionary *allChildren = [NSMutableDictionary dictionary];
|
[self _loadDictionaryStartingWith: object
|
||||||
[self _loadDictionaryStartingWith: item
|
atLevel: [self levelForItem: object]];
|
||||||
atLevel: [self levelForItem: item]];
|
|
||||||
[_itemDict addEntriesFromDictionary: allChildren];
|
|
||||||
|
|
||||||
// release the old array
|
// release the old array
|
||||||
if(_items != nil)
|
if(_items != nil)
|
||||||
|
@ -722,20 +715,24 @@ static NSImage *unexpandable = nil;
|
||||||
RELEASE(_items);
|
RELEASE(_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_itemDict != nil)
|
if(_itemDict != NULL)
|
||||||
{
|
{
|
||||||
RELEASE(_itemDict);
|
NSFreeMapTable(_itemDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_levelOfItems != nil)
|
if(_levelOfItems != NULL)
|
||||||
{
|
{
|
||||||
RELEASE(_levelOfItems);
|
NSFreeMapTable(_levelOfItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new empty one
|
// create a new empty one
|
||||||
_items = RETAIN([NSMutableArray array]);
|
_items = RETAIN([NSMutableArray array]);
|
||||||
_itemDict = RETAIN([NSMutableDictionary dictionary]);
|
_itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
_levelOfItems = RETAIN([NSMutableDictionary dictionary]);
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
|
_levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
|
|
||||||
// reload all the open items...
|
// reload all the open items...
|
||||||
[self _loadDictionaryStartingWith: nil
|
[self _loadDictionaryStartingWith: nil
|
||||||
|
@ -794,16 +791,17 @@ static NSImage *unexpandable = nil;
|
||||||
[aDecoder decodeValueOfObjCType: @encode(float) at: &_indentationPerLevel];
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_indentationPerLevel];
|
||||||
_outlineTableColumn = [aDecoder decodeObject];
|
_outlineTableColumn = [aDecoder decodeObject];
|
||||||
|
|
||||||
_itemDict = [NSMutableDictionary dictionary];
|
_itemDict = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
_items = [NSMutableArray array];
|
_items = [NSMutableArray array];
|
||||||
_expandedItems = [NSMutableArray array];
|
_expandedItems = [NSMutableArray array];
|
||||||
_levelOfItems = [NSMutableDictionary dictionary];
|
_levelOfItems = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||||
|
NSObjectMapValueCallBacks,
|
||||||
|
64);
|
||||||
// Retain items
|
// Retain items
|
||||||
RETAIN(_items);
|
RETAIN(_items);
|
||||||
RETAIN(_expandedItems);
|
RETAIN(_expandedItems);
|
||||||
RETAIN(_itemDict);
|
|
||||||
RETAIN(_levelOfItems);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue