Skip to content

Commit a77d86d

Browse files
committed
MPWCursor → MPWArrayCursor, and hopefully make it useful; moved notifications from ui to base
1 parent adacf96 commit a77d86d

File tree

15 files changed

+196
-161
lines changed

15 files changed

+196
-161
lines changed

Classes/MPWFoundation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
#import <MPWFoundation/MPWStreamableReference.h>
138138
#import <MPWFoundation/MPWReferenceTemplate.h>
139139
#import <MPWFoundation/MPWTemplateMatchingStore.h>
140-
#import <MPWFoundation/MPWCursor.h>
140+
#import <MPWFoundation/MPWArrayCursor.h>
141141
#import <MPWFoundation/MPWInitStore.h>
142142
#import <MPWFoundation/MPWKeychainStore.h>
143143
#import <MPWFoundation/MPWObjectStore.h>

Classes/NSObject+MPWNotificationProtocol.h

+19
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,22 @@ NSString *notificatioNameFromProtocol(Protocol *aProtocol );
4747

4848
@end
4949
#endif
50+
51+
@protocol ModelDidChange<MPWNotificationProtocol>
52+
53+
-(void)modelDidChange:(NSNotification*)notification;
54+
55+
@end
56+
57+
@protocol SelectionDidChange<MPWNotificationProtocol>
58+
59+
-(void)selectionDidChange:(NSNotification*)notification;
60+
61+
@end
62+
63+
@protocol ValidationDidChange<MPWNotificationProtocol>
64+
65+
-(void)validationDidChange:(NSNotification*)notification;
66+
67+
@end
68+

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ libMPWFoundation_OBJC_FILES = \
125125
Streams.subproj/MPWRESTCopyStream.m \
126126
Streams.subproj/MPWCombinerStream.m \
127127
Streams.subproj/MPWMapFilter.m \
128-
Streams.subproj/MPWNotificationStream.m \
128+
Streams.subproj/MPWEventWriter.m \
129129
Streams.subproj/MPWPipeline.m \
130130
Streams.subproj/MPWScatterStream.m \
131131
Streams.subproj/MPWActionStreamAdapter.m \

MPWFoundation.xcodeproj/project.pbxproj

+16-16
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@
352352
1F783B17256B0E1100BE8654 /* SwiftValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F783B16256B0E1100BE8654 /* SwiftValueStore.swift */; };
353353
1F783B18256B0E1100BE8654 /* SwiftValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F783B16256B0E1100BE8654 /* SwiftValueStore.swift */; };
354354
1F783B19256B0E1100BE8654 /* SwiftValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F783B16256B0E1100BE8654 /* SwiftValueStore.swift */; };
355-
1F78CB262AE19E5800B6458E /* MPWCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
356-
1F78CB272AE19E5800B6458E /* MPWCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
357-
1F78CB282AE19E5800B6458E /* MPWCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
358-
1F78CB292AE19E5800B6458E /* MPWCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWCursor.m */; };
359-
1F78CB2A2AE19E5800B6458E /* MPWCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWCursor.m */; };
360-
1F78CB2B2AE19E5800B6458E /* MPWCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWCursor.m */; };
355+
1F78CB262AE19E5800B6458E /* MPWArrayCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWArrayCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
356+
1F78CB272AE19E5800B6458E /* MPWArrayCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWArrayCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
357+
1F78CB282AE19E5800B6458E /* MPWArrayCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F78CB242AE19E5800B6458E /* MPWArrayCursor.h */; settings = {ATTRIBUTES = (Public, ); }; };
358+
1F78CB292AE19E5800B6458E /* MPWArrayCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWArrayCursor.m */; };
359+
1F78CB2A2AE19E5800B6458E /* MPWArrayCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWArrayCursor.m */; };
360+
1F78CB2B2AE19E5800B6458E /* MPWArrayCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F78CB252AE19E5800B6458E /* MPWArrayCursor.m */; };
361361
1F7A22851B786F9000FF6C03 /* MPWPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 07DF193F006686DDC35ADD82 /* MPWPoint.m */; };
362362
1F7A22861B786F9000FF6C03 /* MPWRect.m in Sources */ = {isa = PBXBuildFile; fileRef = 07DF1940006686DDC35ADD82 /* MPWRect.m */; };
363363
1F7A22871B786F9200FF6C03 /* MPWPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 07DF193F006686DDC35ADD82 /* MPWPoint.m */; };
@@ -1594,8 +1594,8 @@
15941594
1F783B04256A73AE00BE8654 /* MPWPropertyStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPWPropertyStore.h; sourceTree = "<group>"; };
15951595
1F783B05256A73AE00BE8654 /* MPWPropertyStore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPWPropertyStore.m; sourceTree = "<group>"; };
15961596
1F783B16256B0E1100BE8654 /* SwiftValueStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftValueStore.swift; sourceTree = "<group>"; };
1597-
1F78CB242AE19E5800B6458E /* MPWCursor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPWCursor.h; sourceTree = "<group>"; };
1598-
1F78CB252AE19E5800B6458E /* MPWCursor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPWCursor.m; sourceTree = "<group>"; };
1597+
1F78CB242AE19E5800B6458E /* MPWArrayCursor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPWArrayCursor.h; sourceTree = "<group>"; };
1598+
1F78CB252AE19E5800B6458E /* MPWArrayCursor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPWArrayCursor.m; sourceTree = "<group>"; };
15991599
1F7FCD03264570E6008B6D1A /* NSRunLoopAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSRunLoopAdditions.h; sourceTree = "<group>"; };
16001600
1F7FCD04264570E6008B6D1A /* NSRunLoopAdditions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSRunLoopAdditions.m; sourceTree = "<group>"; };
16011601
1F7FCD0B264BBCA6008B6D1A /* MPWFileChangesStream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPWFileChangesStream.h; sourceTree = "<group>"; };
@@ -2716,8 +2716,8 @@
27162716
1F3F7F2E2A2F2B01000857B0 /* MPWPropertyPathStore.h */,
27172717
1FD6BCD62C577CDA009FEA38 /* MPWPropertyPathDefs.h */,
27182718
1F3F7F2F2A2F2B01000857B0 /* MPWPropertyPathStore.m */,
2719-
1F78CB242AE19E5800B6458E /* MPWCursor.h */,
2720-
1F78CB252AE19E5800B6458E /* MPWCursor.m */,
2719+
1F78CB242AE19E5800B6458E /* MPWArrayCursor.h */,
2720+
1F78CB252AE19E5800B6458E /* MPWArrayCursor.m */,
27212721
1FD7A6A12AE2BE2D0091F9E6 /* MPWAlias.h */,
27222722
1FD7A6A22AE2BE2D0091F9E6 /* MPWAlias.m */,
27232723
1F86798F2AE5454200849711 /* MPWArrayWithCursor.h */,
@@ -2912,7 +2912,7 @@
29122912
1FE37C11196976C500C9A378 /* MPWNamedData.h in Headers */,
29132913
1F8679922AE5454200849711 /* MPWArrayWithCursor.h in Headers */,
29142914
1FE37C401969773C00C9A378 /* MPWSubData.h in Headers */,
2915-
1F78CB272AE19E5800B6458E /* MPWCursor.h in Headers */,
2915+
1F78CB272AE19E5800B6458E /* MPWArrayCursor.h in Headers */,
29162916
1F3D01FF1D702902001A9732 /* MPWScatterStream.h in Headers */,
29172917
1FED48C4242634CC00AF2FAD /* MPWMAXParser_private.h in Headers */,
29182918
1FE37C0B196976C500C9A378 /* MPWFastInvocation.h in Headers */,
@@ -3115,7 +3115,7 @@
31153115
1FCF264F1CF3993C00AC64CE /* MPWRect.h in Headers */,
31163116
1FCF26411CF3993C00AC64CE /* MPWObject_fastrc.h in Headers */,
31173117
1FED48C5242634CC00AF2FAD /* MPWMAXParser_private.h in Headers */,
3118-
1F78CB282AE19E5800B6458E /* MPWCursor.h in Headers */,
3118+
1F78CB282AE19E5800B6458E /* MPWArrayCursor.h in Headers */,
31193119
1FCF25D71CF3983C00AC64CE /* MPWFoundationWatch.h in Headers */,
31203120
1FB561F92B3ED658009FC583 /* MPWEnsureNonNilStore.h in Headers */,
31213121
1FCF262B1CF3993C00AC64CE /* AccessorMacros.h in Headers */,
@@ -3350,7 +3350,7 @@
33503350
1F3F678F2085B452001B80D9 /* NSObject+MPWNotificationProtocol.h in Headers */,
33513351
1F1E09D5269DB9E700567AF6 /* MPWSQLColumnInfo.h in Headers */,
33523352
1FD64E5D158A181800D96811 /* MPWObject_fastrc.h in Headers */,
3353-
1F78CB262AE19E5800B6458E /* MPWCursor.h in Headers */,
3353+
1F78CB262AE19E5800B6458E /* MPWArrayCursor.h in Headers */,
33543354
);
33553355
runOnlyForDeploymentPostprocessing = 0;
33563356
};
@@ -3993,7 +3993,7 @@
39933993
1F8574AC2ACD8E1300283E7A /* MPWObjectStore.m in Sources */,
39943994
1FED48C7242634CC00AF2FAD /* MPWXmlElement.m in Sources */,
39953995
1F32EC972146AB710074C15A /* MPWQueue.m in Sources */,
3996-
1F78CB2A2AE19E5800B6458E /* MPWCursor.m in Sources */,
3996+
1F78CB2A2AE19E5800B6458E /* MPWArrayCursor.m in Sources */,
39973997
1F840DC6193F50AC00589595 /* NSNil.m in Sources */,
39983998
1F45AA9029F9912800FB1C4E /* MPWKeychainStore.m in Sources */,
39993999
1FEFBD2E2427F88E001E44B2 /* MPWMASONParser.m in Sources */,
@@ -4212,7 +4212,7 @@
42124212
1FCF26621CF39AD400AC64CE /* MPWFakedReturnMethodSignature.m in Sources */,
42134213
1F8679962AE5454200849711 /* MPWArrayWithCursor.m in Sources */,
42144214
1F1E09DA269DB9E700567AF6 /* MPWSQLColumnInfo.m in Sources */,
4215-
1F78CB2B2AE19E5800B6458E /* MPWCursor.m in Sources */,
4215+
1F78CB2B2AE19E5800B6458E /* MPWArrayCursor.m in Sources */,
42164216
1F6244CC2148557D00BB00C4 /* MPWMergingStore.m in Sources */,
42174217
1F1BEDB5213BE769004B4947 /* MPWFilter.m in Sources */,
42184218
1FCF25F41CF398F400AC64CE /* MPWRect.m in Sources */,
@@ -4348,7 +4348,7 @@
43484348
1F5336112A1D284600AA1754 /* MPWMarkdownTransformer.m in Sources */,
43494349
1FF8FE1409B49D0100652476 /* MPWNeXTPListWriter.m in Sources */,
43504350
1FF6590D24957007002371E9 /* MPWStreamQLite.m in Sources */,
4351-
1F78CB292AE19E5800B6458E /* MPWCursor.m in Sources */,
4351+
1F78CB292AE19E5800B6458E /* MPWArrayCursor.m in Sources */,
43524352
1FF8FE1509B49D0100652476 /* MPWFlattenStream.m in Sources */,
43534353
1F04A53B21D2E01500E19C3F /* MPWInterval.m in Sources */,
43544354
1FF8FE1609B49D0100652476 /* NSObjectFiltering.m in Sources */,

MPWFoundation.xcodeproj/xcuserdata/marcel.xcuserdatad/xcschemes/xcschememanagement.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<key>MPWFoundationUIKit.xcscheme_^#shared#^_</key>
7575
<dict>
7676
<key>orderHint</key>
77-
<integer>82</integer>
77+
<integer>78</integer>
7878
</dict>
7979
<key>ObjectiveSSH.xcscheme_^#shared#^_</key>
8080
<dict>

MPWFoundationUI/Classes/MPWTableView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@interface MPWTableView : NSTableView <NSTableViewDataSource,ModelDidChange,NSTableViewDelegate>
1515

1616
@property (nonatomic, strong, nullable) MPWReference *binding;
17-
@property (nonatomic, strong, nullable) MPWReference *cursorRef;
17+
@property (nonatomic, strong, nullable) MPWArrayCursor *cursor;
1818
@property (nonatomic, strong, nullable) NSArray* (^valueFilter)(id object);
1919
@property (nonatomic, weak, nullable) id <NSTableViewDelegate> mpwDelegate;
2020

MPWFoundationUI/Classes/MPWTableView.m

+7-8
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,13 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
241241

242242
- (void)tableViewSelectionDidChange:(NSNotification *)notification
243243
{
244-
if (self.cursorRef && self.binding) {
245-
MPWCursor *cursor=[MPWCursor cursorWithBinding:self.binding offset:[self selectedRow]];
246-
self.cursorRef.value = cursor;
247-
}
248-
if ( [self.items respondsToSelector:@selector(setOffset:)] ) {
249-
[self.items setOffset:[self selectedRow]];
250-
[@protocol(ModelDidChange) notify];
244+
if (self.cursor ) {
245+
self.cursor.offset = [self selectedRow];
251246
}
247+
// if ( [self.items respondsToSelector:@selector(setOffset:)] ) {
248+
// [self.items setOffset:[self selectedRow]];
249+
// [@protocol(ModelDidChange) notify];
250+
// }
252251
if ( [self.mpwDelegate respondsToSelector:@selector(tableViewSelectionDidChange:)] && self.mpwDelegate != self) {
253252
[self.mpwDelegate tableViewSelectionDidChange:notification];
254253
}
@@ -268,7 +267,7 @@ -(CGFloat)calculateHeightForRow:(NSUInteger)row usingColumn:(NSString *)columnNa
268267
[c nsrect:NSMakeRect(0, 0, [[self tableColumnWithIdentifier:columnName] width], 100000 )];
269268
}];
270269
CGRect r = [[self context] boundingRectForText:value inPath:path];
271-
return r.size.height+10;
270+
return r.size.height+12;
272271
}
273272

274273
@end

MPWFoundationUI/Classes/ModelDidChangeNotification.h

-12
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,4 @@
1010

1111
#import <MPWFoundation/MPWFoundation.h>
1212

13-
@protocol ModelDidChange<MPWNotificationProtocol>
14-
15-
-(void)modelDidChange:(NSNotification*)notification;
16-
17-
@end
18-
19-
@protocol ValidationDidChange<MPWNotificationProtocol>
20-
21-
-(void)validationDidChange:(NSNotification*)notification;
22-
23-
@end
24-
2513
#endif /* ModelDidChangeNotification_h */

Stores.subproj/MPWArrayCursor.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// MPWArrayCursor.h
3+
// MPWFoundation
4+
//
5+
// Created by Marcel Weiher on 19.10.23.
6+
//
7+
8+
#import <MPWFoundation/MPWFoundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface MPWArrayCursor : NSObject <MPWReferencing>
13+
14+
-initWithArray:anArray;
15+
16+
@property (nonatomic, assign) long offset;
17+
18+
19+
20+
@end
21+
22+
NS_ASSUME_NONNULL_END

Stores.subproj/MPWArrayCursor.m

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//
2+
// MPWArrayCursor.m
3+
// MPWFoundation
4+
//
5+
// Created by Marcel Weiher on 19.10.23.
6+
//
7+
8+
#import "MPWArrayCursor.h"
9+
10+
@interface MPWArrayCursor()
11+
12+
@property (nonatomic, strong) NSMutableArray *base;
13+
14+
15+
@end
16+
17+
@implementation MPWArrayCursor
18+
19+
+(instancetype)cursorWithArray:(NSMutableArray*)newarray
20+
{
21+
return [[[self alloc] initWithArray:newarray] autorelease];
22+
}
23+
24+
-(instancetype)initWithArray:(NSMutableArray*)newarray
25+
{
26+
self=[super init];
27+
self.base = newarray;
28+
self.offset=0;
29+
return self;
30+
}
31+
32+
-(id)value
33+
{
34+
return [self.base objectAtIndex:self.offset];
35+
}
36+
37+
-(void)setValue:newValue
38+
{
39+
[self.base replaceObjectAtIndex:self.offset withObject:newValue];
40+
}
41+
42+
-(instancetype)copyWithZone:(NSZone*)aZone
43+
{
44+
return [[[self class] allocWithZone:aZone] initWithArray:self.base];
45+
}
46+
47+
48+
-(void)dealloc
49+
{
50+
[_base release];
51+
[super dealloc];
52+
}
53+
54+
- (NSURL *)URL {
55+
return nil;
56+
}
57+
58+
- (id<MPWStorage>)asScheme {
59+
return nil;
60+
}
61+
62+
- (NSArray *)children {
63+
return self.base;
64+
}
65+
66+
- (void)delete {
67+
[self.base removeObjectAtIndex:self.offset];
68+
}
69+
70+
- (BOOL)hasChildren {
71+
return YES;
72+
}
73+
74+
- (instancetype)initWithIdentifer:(id)anIdentifier inStore:(id)aStore {
75+
return nil;
76+
}
77+
78+
+ (instancetype)referenceWithIdentifier:(id)anIdentifier inStore:(id)aStore {
79+
return nil;
80+
}
81+
82+
@end
83+
84+
85+
#import <MPWFoundation/DebugMacros.h>
86+
87+
@implementation MPWArrayCursor(testing)
88+
89+
+(void)testCanGetValueAtTheInitialisedOffset
90+
{
91+
NSArray *testArray=@[ @"a", @"b"];
92+
MPWArrayCursor *cursor1=[self cursorWithArray:testArray];
93+
IDEXPECT( [cursor1 value], @"a", @"offset 0");
94+
cursor1.offset=1;
95+
IDEXPECT( [cursor1 value], @"b", @"offset 1");
96+
}
97+
98+
+(void)testCanSetValueAtTheInitialisedOffset
99+
{
100+
NSMutableArray *testArray=[[@[ @"a", @"b"] mutableCopy] autorelease];
101+
MPWArrayCursor *cursor1=[self cursorWithArray:testArray];
102+
IDEXPECT( [cursor1 value], @"a", @"offset 0");
103+
cursor1.value = @"new value";
104+
IDEXPECT( [testArray firstObject], @"new value", @"did set");
105+
}
106+
107+
+(NSArray*)testSelectors
108+
{
109+
return @[
110+
@"testCanGetValueAtTheInitialisedOffset",
111+
@"testCanSetValueAtTheInitialisedOffset",
112+
];
113+
}
114+
115+
@end

Stores.subproj/MPWCursor.h

-24
This file was deleted.

0 commit comments

Comments
 (0)