This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COUndoController.h
187 lines (154 loc) · 6.35 KB
/
COUndoController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#import <Foundation/Foundation.h>
#import <EtoileFoundation/ETUUID.h>
#import "COSQLiteStore.h"
NSString *kCOIsUndo;
NSString *kCOSelector;
NSString *kCOUndoSelector;
NSString *kCOPersistentRootUUID;
NSString *kCOBranchUUID;
NSString *kCONewMetadata;
NSString *kCOOldMetadata;
NSString *kCOOldBranch;
NSString *kCONewBranch;
NSString *kCOOldCurrentRev;
NSString *kCONewCurrentRev;
NSString *kCOOldHeadRev;
NSString *kCONewHeadRev;
NSString *kCOOldTailRev;
NSString *kCONewTailRev;
@interface COStoreStructureEdit : NSObject
//{
// BOOL isUndo_;
// SEL selector_;
// SEL undoSelector_;
//
// COUUID *persistentRootUUID;
// COUUID *branchUUID;
//
// NSDictionary *newMetadata;
// NSDictionary *oldMetadata;
//
// COUUID *oldBranch;
// COUUID *newBranch;
//
// CORevisionID *oldCurrentRev;
// CORevisionID *newCurrentRev;
// CORevisionID *oldHeadRev;
// CORevisionID *newHeadRev;
// CORevisionID *oldTailRev;
// CORevisionID *newTailRev;
//
//}
+ (COStoreStructureEdit *)undoCreatePersistentRoot: (ETUUID*)aUUID;
@end
@implementation COStoreStructureEdit
- (NSDictionary *) inverseFromMetadata: (NSDictionary *)metadata
{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary: metadata];
[dict setObject: [NSNumber numberWithBool: ![[metadata objectForKey: kCOIsUndo] boolValue]]
forKey: kCOIsUndo];
return dict;
}
- (void) performEditFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
SEL selector = [[metadata objectForKey: kCOIsUndo] boolValue] ?
NSSelectorFromString([metadata objectForKey: kCOUndoSelector]) :
NSSelectorFromString([metadata objectForKey: kCOSelector]);
[self performSelector: selector
withObject: metadata
withObject: aStore];
}
- (BOOL)setMainBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMainBranch: [metadata objectForKey: kCONewBranch]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoSetMainBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMainBranch: [metadata objectForKey: kCOOldBranch]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)setCurrentBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setCurrentBranch: [metadata objectForKey: kCONewBranch]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoSetCurrentBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setCurrentBranch: [metadata objectForKey: kCOOldBranch]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)setRevisionsFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setCurrentRevision: [metadata objectForKey: kCONewCurrentRev]
headRevision: [metadata objectForKey: kCONewHeadRev]
tailRevision: [metadata objectForKey: kCONewTailRev]
forBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoSetRevisionsFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setCurrentRevision: [metadata objectForKey: kCOOldCurrentRev]
headRevision: [metadata objectForKey: kCOOldHeadRev]
tailRevision: [metadata objectForKey: kCOOldTailRev]
forBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)setPersistentRootMetadataFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMetadata: [metadata objectForKey: kCONewMetadata]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoSetPersistentRootMetadataFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMetadata: [metadata objectForKey: kCOOldMetadata]
forPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)setBranchMetadataFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMetadata: [metadata objectForKey: kCONewMetadata]
forBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoSetBranchMetadataFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore setMetadata: [metadata objectForKey: kCOOldMetadata]
forBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)deletePersistentRootFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore deletePersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoDeletePersistentRootFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore undeletePersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)deleteBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore deleteBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
- (BOOL)undoDeleteBranchFromMetadata: (NSDictionary *)metadata
store: (COSQLiteStore *)aStore
{
return [aStore undeleteBranch: [metadata objectForKey: kCOBranchUUID]
ofPersistentRoot: [metadata objectForKey: kCOPersistentRootUUID]];
}
@end
@interface COUndoController : NSObject
@end