mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 17:52:42 +00:00
Update loading mechanism and add new proxy class for tree node
This commit is contained in:
parent
f7afc331eb
commit
3dfcdf6570
6 changed files with 158 additions and 30 deletions
|
@ -303,6 +303,7 @@ NSWindowController.m \
|
|||
NSWorkspace.m \
|
||||
GSAnimator.m \
|
||||
GSAutocompleteWindow.m \
|
||||
GSControllerTreeProxy.m \
|
||||
GSDisplayServer.m \
|
||||
GSHelpManagerPanel.m \
|
||||
GSInfoPanel.m \
|
||||
|
|
52
Source/GSControllerTreeProxy.h
Normal file
52
Source/GSControllerTreeProxy.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Definition of class GSControllerTreeProxy
|
||||
Copyright (C) 2024 Free Software Foundation, Inc.
|
||||
|
||||
By: Gregory John Casamento
|
||||
Date: 24-06-2024
|
||||
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSControllerTreeProxy_h_GNUSTEP_GUI_INCLUDE
|
||||
#define _GSControllerTreeProxy_h_GNUSTEP_GUI_INCLUDE
|
||||
|
||||
#import "AppKit/NSTreeNode.h"
|
||||
|
||||
@class NSTreeController;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@interface GSControllerTreeProxy : NSTreeNode
|
||||
{
|
||||
NSTreeController *_controller;
|
||||
}
|
||||
|
||||
- (instancetype) initWithRepresentedObject: (id)representedObject
|
||||
withController: (id)controller;
|
||||
- (NSUInteger) count;
|
||||
|
||||
@end
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GSControllerTreeProxy_h_GNUSTEP_GUI_INCLUDE */
|
||||
|
61
Source/GSControllerTreeProxy.m
Normal file
61
Source/GSControllerTreeProxy.m
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* Implementation of class GSControllerTreeProxy
|
||||
Copyright (C) 2024 Free Software Foundation, Inc.
|
||||
|
||||
By: Gregory John Casamento
|
||||
Date: 24-06-2024
|
||||
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#import "AppKit/NSTreeController.h"
|
||||
|
||||
#import "GSControllerTreeProxy.h"
|
||||
#import "GSBindingHelpers.h"
|
||||
|
||||
@implementation GSControllerTreeProxy
|
||||
|
||||
- (instancetype) initWithRepresentedObject: (id)representedObject
|
||||
withController: (id)controller
|
||||
{
|
||||
self = [super initWithRepresentedObject: representedObject];
|
||||
if (self != nil)
|
||||
{
|
||||
ASSIGN(_controller, controller);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSUInteger) count
|
||||
{
|
||||
NSDictionary *ro = [self representedObject];
|
||||
NSArray *children = [ro objectForKey: @"children"];
|
||||
|
||||
return [children count];
|
||||
}
|
||||
|
||||
- (id) value
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1834,7 +1834,7 @@ Also returns the child index relative to this parent. */
|
|||
|
||||
// If we have content binding the data source is used only
|
||||
// like a delegate
|
||||
GSKeyValueBinding *theBinding = [GSKeyValueBinding getBinding: NSContentBinding
|
||||
GSKeyValueBinding *theBinding = [GSKeyValueBinding getBinding: NSValueBinding
|
||||
forObject: tb];
|
||||
if (theBinding != nil)
|
||||
{
|
||||
|
@ -1982,7 +1982,7 @@ Also returns the child index relative to this parent. */
|
|||
- (void) _loadDictionaryStartingWith: (id) startitem
|
||||
atLevel: (NSInteger) level
|
||||
{
|
||||
GSKeyValueBinding *theBinding;
|
||||
GSKeyValueBinding *theBinding = nil;
|
||||
NSInteger num = 0;
|
||||
NSInteger i = 0;
|
||||
id sitem = (startitem == nil) ? (id)[NSNull null] : (id)startitem;
|
||||
|
@ -1992,50 +1992,52 @@ Also returns the child index relative to this parent. */
|
|||
forObject: self];
|
||||
if (theBinding != nil)
|
||||
{
|
||||
id observedObject = [theBinding observedObject];
|
||||
NSTreeController *tc = (NSTreeController *)observedObject;
|
||||
NSArray *children = nil;
|
||||
// NSString *leafKeyPath = [tc leafKeyPath];
|
||||
|
||||
/* Implement logic to build the internal data structure here using
|
||||
* bindings...
|
||||
*/
|
||||
id observedObject = [theBinding observedObject];
|
||||
|
||||
|
||||
if ([observedObject isKindOfClass: [NSTreeController class]])
|
||||
{
|
||||
NSTreeController *tc = (NSTreeController *)observedObject;
|
||||
NSString *leafKeyPath = [tc leafKeyPath];
|
||||
NSString *childrenKeyPath = [tc childrenKeyPath];
|
||||
NSString *countKeyPath = [tc countKeyPath];
|
||||
|
||||
// NSLog(@"leafKeyPath = %@", leafKeyPath);
|
||||
// NSLog(@"childrenKeyPath = %@", childrenKeyPath);
|
||||
// NSLog(@"countKeyPath = %@", countKeyPath);
|
||||
|
||||
if (startitem == nil)
|
||||
{
|
||||
NSArray *items = (NSArray *)[theBinding destinationValue];
|
||||
NSLog(@"items = %@", items);
|
||||
NSTreeNode *node = (NSTreeNode *)[theBinding destinationValue];
|
||||
NSDictionary *representedObject = [node representedObject];
|
||||
|
||||
num = [items count];
|
||||
children = [representedObject objectForKey: @"children"];
|
||||
num = [children count];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *childrenKeyPath = [tc childrenKeyPath];
|
||||
NSString *countKeyPath = [tc countKeyPath];
|
||||
NSNumber *n = [sitem valueForKeyPath: countKeyPath];
|
||||
|
||||
num = [n integerValue];
|
||||
children = [sitem valueForKeyPath: childrenKeyPath];
|
||||
}
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
anarray = [NSMutableArray array];
|
||||
anarray = [NSMutableArray arrayWithCapacity: num];
|
||||
NSMapInsert(_itemDict, sitem, anarray);
|
||||
}
|
||||
|
||||
NSMapInsert(_levelOfItems, sitem, [NSNumber numberWithInteger: level]);
|
||||
|
||||
/*
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
id anitem = [_dataSource outlineView: self
|
||||
child: i
|
||||
ofItem: startitem];
|
||||
|
||||
id anitem = [children objectAtIndex: i];
|
||||
|
||||
NSLog(@"anitem = %@, level = %d", anitem, level);
|
||||
[anarray addObject: anitem];
|
||||
[self _loadDictionaryStartingWith: anitem
|
||||
atLevel: level + 1];
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2057,7 +2059,7 @@ Also returns the child index relative to this parent. */
|
|||
|
||||
if (num > 0)
|
||||
{
|
||||
anarray = [NSMutableArray array];
|
||||
anarray = [NSMutableArray arrayWithCapacity: num];
|
||||
NSMapInsert(_itemDict, sitem, anarray);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#import <Foundation/NSArchiver.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSIndexPath.h>
|
||||
#import <Foundation/NSKeyedArchiver.h>
|
||||
#import <Foundation/NSKeyValueObserving.h>
|
||||
|
@ -41,6 +42,7 @@
|
|||
|
||||
#import "GSBindingHelpers.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
#import "GSControllerTreeProxy.h"
|
||||
|
||||
@implementation NSTreeController
|
||||
|
||||
|
@ -48,7 +50,7 @@
|
|||
{
|
||||
if (self == [NSTreeController class])
|
||||
{
|
||||
// [self exposeBinding: NSContentArrayBinding];
|
||||
[self exposeBinding: NSContentArrayBinding];
|
||||
[self exposeBinding: NSContentBinding];
|
||||
[self setKeys: [NSArray arrayWithObjects: NSContentBinding, NSContentObjectBinding, nil]
|
||||
triggerChangeNotificationsForDependentKey: @"arrangedObjects"];
|
||||
|
@ -177,13 +179,17 @@
|
|||
|
||||
- (void) rearrangeObjects
|
||||
{
|
||||
NSLog(@"---- rearrangeObjects");
|
||||
[self willChangeValueForKey: @"arrangedObjects"];
|
||||
DESTROY(_arranged_objects);
|
||||
NSLog(@"-- _content = %@", _content);
|
||||
_arranged_objects = [[GSObservableArray alloc]
|
||||
initWithArray: [self arrangeObjects: _content]];
|
||||
NSLog(@"-- _arranged_objects = %@", _arranged_objects);
|
||||
|
||||
if ([_content isKindOfClass: [NSArray class]])
|
||||
{
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObject: _content
|
||||
forKey: @"children"];
|
||||
_arranged_objects = [[GSControllerTreeProxy alloc] initWithRepresentedObject: dictionary
|
||||
withController: self];
|
||||
}
|
||||
|
||||
[self didChangeValueForKey: @"arrangedObjects"];
|
||||
}
|
||||
|
||||
|
|
|
@ -248,4 +248,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (NSString *) description
|
||||
{
|
||||
return [NSString stringWithFormat: @"<%@> _representedObject = %@, _childNode = %@, _parentNode = %@",
|
||||
[super description], _representedObject, _childNodes, _parentNode];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue