-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawerLogView.m
133 lines (99 loc) · 3.47 KB
/
DrawerLogView.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
//----------------------------------------------------------------------------------------
// DrawerLogView.m -
//
// Copyright © Chris, 2007 - 2010. All rights reserved.
//----------------------------------------------------------------------------------------
#import "DrawerLogView.h"
#import "MySvn.h"
#import "NSString+MyAdditions.h"
#import "CommonUtils.h"
@implementation DrawerLogView
- (id) initWithFrame: (NSRect) frame
{
if (self = [super initWithFrame: frame])
{
if ([NSBundle loadNibNamed: @"DrawerLogView" owner: self])
{
[_view setFrame: [self bounds]];
[self addSubview: _view];
}
}
return self;
}
//----------------------------------------------------------------------------------------
// - document : A MyRepository or a MyWorkingCopy instance
- (id) document { return fDocument; }
- (void) setDocument: (id) aDocument
{
Assert(fDocument == nil);
fDocument = [aDocument retain];
}
//----------------------------------------------------------------------------------------
- (void) setup: (NSDocument*) document
forWindow: (NSWindow*) window
{
[self setDocument: document];
[fDocument addObserver: self forKeyPath: @"displayedTaskObj.newStdout"
options: NSKeyValueObservingOptionNew context: NULL];
[fDocument addObserver: self forKeyPath: @"displayedTaskObj.newStderr"
options: NSKeyValueObservingOptionNew context: NULL];
[[NSNotificationCenter defaultCenter]
addObserver: self selector: @selector(unload)
name: NSWindowWillCloseNotification object: window];
}
//----------------------------------------------------------------------------------------
- (void) unload
{
[fDocument removeObserver: self forKeyPath: @"displayedTaskObj.newStdout"];
[fDocument removeObserver: self forKeyPath: @"displayedTaskObj.newStderr"];
[[NSNotificationCenter defaultCenter] removeObserver: self];
const id docProxy = documentProxy;
documentProxy = nil;
const id view = _view;
_view = nil;
// objects that are bound to the file owner retain it
// we need to unbind them
[docProxy unbind: @"contentObject"];
// the owner has to release its top level nib objects
[docProxy release];
[view release];
[fDocument release];
fDocument = nil;
}
//----------------------------------------------------------------------------------------
- (void) observeValueForKeyPath: (NSString*) keyPath
ofObject: (id) object
change: (NSDictionary*) change
context: (void*) context
{
#pragma unused(object, change, context)
NSDictionary *taskObj = [fDocument valueForKey: @"displayedTaskObj"];
if ( taskObj != nil )
{
if ( taskObj != currentTaskObj )
{
[[logTextView textStorage] setAttributedString: [taskObj objectForKey: @"combinedLog"]];
currentTaskObj = taskObj;
}
if ( [keyPath isEqualToString: @"displayedTaskObj.newStdout"] )
{
[logTextView appendString: [taskObj objectForKey: @"newStdout"] isErrorStyle: NO];
}
else
{
[logTextView appendString: [taskObj objectForKey: @"newStderr"] isErrorStyle: YES];
}
}
else
[logTextView setString: @""];
}
//----------------------------------------------------------------------------------------
- (IBAction) stopDisplayedTask: (id) sender
{
#pragma unused(sender)
id taskObj = [fDocument valueForKey: @"displayedTaskObj"];
if (taskObj)
[MySvn killTask: taskObj force: AltOrShiftPressed()];
}
//----------------------------------------------------------------------------------------
@end // DrawerLogView