This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMarkdownDocument.m
More file actions
95 lines (79 loc) · 2.63 KB
/
MarkdownDocument.m
File metadata and controls
95 lines (79 loc) · 2.63 KB
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
//
// MyDocument.m
// MarkEdit
//
// Created by bodhi on 31/03/10.
// Copyright 2010 Apple Inc. All rights reserved.
//
#import "MarkdownDocument.h"
#import "OgreKit/OgreKit.h"
@implementation MarkdownDocument
@synthesize string;
- (id)init
{
self = [super init];
if (self) {
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
if (self.string != nil) {
mdDelegate.baseURL = [self fileURL];
[[textView textStorage] setAttributedString:self.string];
}
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
return [[[textView string] stringByReplacingOccurrencesOfString:mdDelegate.attachmentChar withString:@""] dataUsingEncoding:NSUTF8StringEncoding];
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (content != nil) {
self.string = [[NSMutableAttributedString alloc] initWithString:content];
[[textView textStorage] setAttributedString: self.string];
[content release];
return YES;
} else {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
return NO;
}
}
- (void)makeTextLarger:(id)sender {
[mdDelegate makeTextLarger:[textView textStorage]];
}
- (void)makeTextSmaller:(id)sender {
[mdDelegate makeTextSmaller:[textView textStorage]];
}
- (void)makeTextStandardSize:(id)sender {
[mdDelegate resetTextSize:[textView textStorage]];
}
- (void)reload:(id)sender {
NSLog(@"reparsing");
[mdDelegate markupString:[textView textStorage]];
}
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
originalRange = [mdDelegate visibleRange];
[mdDelegate setWidth:frameSize.width];
return frameSize;
}
- (void)windowDidResize:(NSNotification *)notification {
[mdDelegate recenterOn:originalRange];
}
- (void)windowWillExitFullScreen:(NSNotification *)notification {
originalRange = [mdDelegate visibleRange];
}
- (void)windowDidExitFullScreen:(NSNotification *)notification {
[mdDelegate setWidth:[[notification object] frame].size.width];
[mdDelegate recenterOn:originalRange];
}
@end