-
Notifications
You must be signed in to change notification settings - Fork 1
/
TWAppController.m
132 lines (107 loc) · 3.87 KB
/
TWAppController.m
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
/*
Copyright (C) 2013 Quentin Mathe
Author: Quentin Mathe <[email protected]>
Date: April 2013
License: Modified BSD (see COPYING)
*/
#import "TWAppController.h"
#import "TWLayoutItemFactory.h"
#import "TWTextTreeDocumentTemplate.h"
@implementation TWAppController
@synthesize currentPresentationTitle;
- (void) dealloc
{
DESTROY(itemFactory);
DESTROY(mainUndoTrack);
DESTROY(currentPresentationTitle);
[super dealloc];
}
- (id) init
{
self = [super initWithNibName: nil bundle: nil];
ASSIGN(itemFactory, [TWLayoutItemFactory factory]);
openedGroups = [[NSMutableSet alloc] init];
return self;
}
- (void) setUpMenus
{
[[ETApp mainMenu] addItem: [ETApp documentMenuItem]];
[[ETApp mainMenu] addItem: [ETApp editMenuItem]];
[[ETApp mainMenu] addItem: [ETApp viewMenuItem]];
[[[[ETApp viewMenuItem] submenu] itemWithTitle: _(@"List")] setState: NSOnState];
ASSIGN(currentPresentationTitle, _(@"List"));
}
- (void) setUpUndoTrack
{
ETUUID *trackUUID = [[NSUserDefaults standardUserDefaults] UUIDForKey: @"TWMainUndoTrackUUID"];
if (trackUUID == nil)
{
trackUUID = [ETUUID UUID];
[[NSUserDefaults standardUserDefaults] setUUID: trackUUID
forKey: @"TWMainUndoTrackUUID"];
}
mainUndoTrack = [[COCustomTrack alloc] initWithUUID: trackUUID
editingContext: [COEditingContext currentContext]];
/* For pushing revisions on the track */
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(didMakeLocalCommit:)
name: COEditingContextDidChangeNotification
object: [COEditingContext currentContext]];
}
- (void) setUpEditingContext
{
//[[NSFileManager defaultManager]
// removeFileAtPath: [@"~/TestObjectStore" stringByExpandingTildeInPath] handler: nil];
COEditingContext *ctxt = [COEditingContext contextWithURL:
[NSURL fileURLWithPath: [@"~/TestObjectStore.sqlite" stringByExpandingTildeInPath]]];
[COEditingContext setCurrentContext: ctxt];
}
- (void) registerTemplates
{
ETUTI *mainType =
[ETUTI registerTypeWithString: @"org.etoile-project.compound-document"
description: _(@"Etoile Compound or Composite Document Format")
supertypeStrings: A(@"public.composite-content")
typeTags: [NSDictionary dictionary]];
ETLayoutItemGroup *item = [itemFactory editorWithRepresentedObject: [[ETTextTree new] autorelease]
editingContext: [COEditingContext currentContext]];
ETItemTemplate *template = [TWTextTreeDocumentTemplate templateWithItem: item
objectClass: [ETTextTree class]];
[self setTemplate: template forType: mainType];
/* Set the type of the documented to be created by default with 'New' in the menu */
[self setCurrentObjectType: mainType];
}
- (void) presentInitialUI
{
[[itemFactory windowGroup] setController: self];
[self newDocument: nil];
}
- (void) applicationDidFinishLaunching: (NSNotification *)notif
{
[self setUpMenus];
[self setUpEditingContext];
[self setUpUndoTrack];
[self registerTemplates];
[self presentInitialUI];
}
- (void) didMakeLocalCommit: (NSNotification *)notif
{
ETUUID *storeUUID = [[[COEditingContext currentContext] store] UUID];
ETAssert([[[[notif object] store] UUID] isEqual: storeUUID]);
[mainUndoTrack addRevisions: [[notif userInfo] objectForKey: kCORevisionsKey]];
}
- (IBAction) undo: (id)sender
{
[mainUndoTrack undo];
}
- (IBAction) redo: (id)sender
{
[mainUndoTrack redo];
}
- (IBAction) browseUndoHistory: (id)sender
{
ETLayoutItemGroup *browser = [[ETLayoutItemFactory factory]
historyBrowserWithRepresentedObject: mainUndoTrack title: nil];
[[[ETLayoutItemFactory factory] windowGroup] addItem: browser];
}
@end