-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDemonstrationController.m
92 lines (71 loc) · 3.08 KB
/
DemonstrationController.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
//
// DemonstrationController.m
// JournlerCore
//
// Created by Philip Dow on 7/17/09.
// Copyright 2009 Lead Developer, Journler Software. All rights reserved.
//
#import "DemonstrationController.h"
@implementation DemonstrationController
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
// set up the shared journal
mJournal = [[JournlerJournal alloc] init];
[mJournal setOwner:self];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// add journler's preferences to the user default's search list
static NSString *kJournlerBundleIdentifier = @"com.phildow.journler";
[[NSUserDefaults standardUserDefaults] addSuiteNamed:kJournlerBundleIdentifier];
}
- (IBAction) startIt:(id)sender
{
[self loadJournal];
}
#pragma mark ~
- (void) loadJournal
{
NSInteger jError = 0;
JournalLoadFlag loadResult;
// get the location from Journler's preferences
NSString *journalLocation = [[[NSUserDefaults standardUserDefaults] stringForKey:@"Default Journal Location"] stringByStandardizingPath];
[self updateTextView:journalLocation];
// this demonstration does not check for password protection
// this demonstration does not perform error checking
// - the loadResult broadly describes any problems that may have occurred while loading
// - the jError more specifically indicates what may have gone wrong
// - see <JournlerCore/JournlerJournal.h> for more information about possible results
// - future demonstrations will include the complete load code
loadResult = [mJournal loadFromPath:journalLocation error:&jError];
if ( jError ) {
[self updateTextView:@"\nGot an error loading journal. The Journal has been released from memory.\n"];
[mJournal release];
mJournal = nil;
}
else {
NSUInteger numberOfFolders = [[mJournal collections] count];
NSUInteger numberOfRootFolders = [[mJournal rootFolders] count];
NSUInteger numberOfEntries = [[mJournal entries] count];
NSUInteger numberOfResources = [[mJournal resources] count];
NSString *infoString = [NSString stringWithFormat:@"\nJournal Successfuly Loaded!!\nTotal Folders: %i\nTotal Root Folders: %i\nTotal Entries: %i\nTotal Resources: %i\n",
numberOfFolders, numberOfRootFolders, numberOfEntries, numberOfResources];
[self updateTextView:infoString];
// at this point you have complete read and write access to a user's journal
// you can set up bindings or look at the entries, collections (folders), rootFolders and resources
// by accessor methods.
// writing to the journal does require a bit more effort, as changes must be saved
// future editions of this demonstration code will include more detailed examples
// of reading from and writing to the journal.
// if you just can't wait to get started, email [email protected] and maybe I can help you out.
}
}
- (void) updateTextView:(NSString*)text
{
[[textView textStorage] beginEditing];
[[textView textStorage] appendAttributedString:
[[[NSAttributedString alloc] initWithString:
[NSString stringWithFormat:@"\n%@\n",text]] autorelease]];
[[textView textStorage] endEditing];
}
@end