mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
Fixed NSOutlineView to use incremental loading as Mac OS X does.
You can now use an outline view to browse a big tree structure e.g. a filesystem. Previously in such a case, NSOutlineView was attempting to traverse the entire directory structure on -reloadData. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31429 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2d8b12abfa
commit
d864f4cbb6
2 changed files with 44 additions and 8 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2010-09-27 Quentin Mathe <quentin.mathe@gmail.com>
|
||||
|
||||
Fixed NSOutlineView to use incremental loading as Mac OS X does.
|
||||
You can now use an outline view to browse a big tree structure e.g. a
|
||||
filesystem. Previously in such a case, NSOutlineView was attempting to
|
||||
traverse the entire directory structure on -reloadData.
|
||||
* Source/NSOutlineView.m
|
||||
(-reloadData:): Removed a redundant _loadDictionaryStartingWith:atLevel:
|
||||
call, _openItem: now does it.
|
||||
(-_loadDictionaryStartingWith:atLevel:): Modified to load the children only
|
||||
if the item is expanded.
|
||||
(_openItem:): Modified to call _loadDictionaryStartingWith:atLevel: when
|
||||
the item children are not loaded.
|
||||
|
||||
2010-09-25 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/NSFontManager.m (-orderFrontFontPanel:): Add method to
|
||||
|
|
|
@ -718,8 +718,6 @@ static NSImage *unexpandable = nil;
|
|||
64);
|
||||
|
||||
// reload all the open items...
|
||||
[self _loadDictionaryStartingWith: nil
|
||||
atLevel: -1];
|
||||
[self _openItem: nil];
|
||||
[super reloadData];
|
||||
}
|
||||
|
@ -1911,6 +1909,20 @@ Also returns the child index relative to this parent. */
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL) _isItemLoaded: (id)item
|
||||
{
|
||||
id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
|
||||
id object = NSMapGet(_itemDict, sitem);
|
||||
|
||||
// NOTE: We could store the loaded items in a map to ensure we only load
|
||||
// the children of item when it gets expanded for the first time. This would
|
||||
// allow to write: return (NSMapGet(_loadedItemDict, sitem) != nil);
|
||||
// The last line isn't truly correct because it implies an item without
|
||||
// children will get incorrectly reloaded automatically on each
|
||||
// expand/collapse.
|
||||
return ([object count] != 0);
|
||||
}
|
||||
|
||||
- (void) _loadDictionaryStartingWith: (id) startitem
|
||||
atLevel: (int) level
|
||||
{
|
||||
|
@ -1919,12 +1931,16 @@ Also returns the child index relative to this parent. */
|
|||
id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
|
||||
NSMutableArray *anarray = nil;
|
||||
|
||||
/* Check to see if item is expandable before getting the number of
|
||||
* items. For macos compatibility the topmost item (startitem==nil)
|
||||
/* Check to see if item is expandable and expanded before getting the number
|
||||
* of items. For macos compatibility the topmost item (startitem==nil)
|
||||
* is always considered expandable and must not be checked.
|
||||
* We must load the item only if expanded, otherwise an outline view is not
|
||||
* usable with a big tree structure. For example, an outline view to browse
|
||||
* file system would try to traverse every file/directory on -reloadData.
|
||||
*/
|
||||
if (startitem == nil
|
||||
if ((startitem == nil
|
||||
|| [_dataSource outlineView: self isItemExpandable: startitem])
|
||||
&& [self isItemExpanded: startitem])
|
||||
{
|
||||
num = [_dataSource outlineView: self
|
||||
numberOfChildrenOfItem: startitem];
|
||||
|
@ -1980,15 +1996,21 @@ Also returns the child index relative to this parent. */
|
|||
id object;
|
||||
id sitem = (item == nil) ? (id)[NSNull null] : (id)item;
|
||||
|
||||
object = NSMapGet(_itemDict, sitem);
|
||||
numChildren = numDescendants = [object count];
|
||||
|
||||
// open the item...
|
||||
if (item != nil)
|
||||
{
|
||||
[_expandedItems addObject: item];
|
||||
}
|
||||
|
||||
// Load the children of the item if needed
|
||||
if ([self _isItemLoaded: item] == NO)
|
||||
{
|
||||
[self _loadDictionaryStartingWith: item atLevel: [self levelForItem: item]];
|
||||
}
|
||||
|
||||
object = NSMapGet(_itemDict, sitem);
|
||||
numChildren = numDescendants = [object count];
|
||||
|
||||
insertionPoint = [_items indexOfObject: item];
|
||||
if (insertionPoint == NSNotFound)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue