Skip to content
This repository
Newer
Older
100644 183 lines (150 sloc) 6.067 kb
79e9ba9f »
2008-06-14 Add a detailed HTML view
1 //
2 // PBWebGitController.m
3 // GitTest
4 //
5 // Created by Pieter de Bie on 14-06-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
9 #import "PBWebHistoryController.h"
0363eea4 »
2009-09-17 HistoryView: don't load in commit information in a separate thread an…
10 #import "PBGitDefaults.h"
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
11 #import "PBGitSHA.h"
79e9ba9f »
2008-06-14 Add a detailed HTML view
12
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
13 @implementation PBWebHistoryController
79e9ba9f »
2008-06-14 Add a detailed HTML view
14
15 @synthesize diff;
16
17 - (void) awakeFromNib
18 {
bd097b0e »
2008-10-21 HTML: Restructure html folder
19 startFile = @"history";
415ee91b »
2008-12-01 WebHistoryView: Add a link to display changed images
20 repository = historyController.repository;
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
21 [super awakeFromNib];
708c08a2 »
2008-09-19 First part of splitting views
22 [historyController addObserver:self forKeyPath:@"webCommit" options:0 context:@"ChangedCommit"];
79e9ba9f »
2008-06-14 Add a detailed HTML view
23 }
24
53d92fb7 »
2010-07-03 Cleanup the views when the repository window closes and stop memory l…
25 - (void)closeView
26 {
27 [[self script] setValue:nil forKey:@"commit"];
28 [historyController removeObserver:self forKeyPath:@"webCommit"];
29
30 [super closeView];
31 }
32
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
33 - (void) didLoad
79e9ba9f »
2008-06-14 Add a detailed HTML view
34 {
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
35 currentSha = nil;
708c08a2 »
2008-09-19 First part of splitting views
36 [self changeContentTo: historyController.webCommit];
79e9ba9f »
2008-06-14 Add a detailed HTML view
37 }
38
6dcefe5b »
2009-05-01 Fix many gcc 4.2 compiler warnings
39 - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
79e9ba9f »
2008-06-14 Add a detailed HTML view
40 {
6dcefe5b »
2009-05-01 Fix many gcc 4.2 compiler warnings
41 if ([(NSString *)context isEqualToString: @"ChangedCommit"])
708c08a2 »
2008-09-19 First part of splitting views
42 [self changeContentTo: historyController.webCommit];
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
43 else
79e9ba9f »
2008-06-14 Add a detailed HTML view
44 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
45 }
46
2e4ea6ed »
2008-06-15 Load commit list in a separate thread
47 - (void) changeContentTo: (PBGitCommit *) content
79e9ba9f »
2008-06-14 Add a detailed HTML view
48 {
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
49 if (content == nil || !finishedLoading)
6ba944b2 »
2008-06-16 Implement a DetailsController
50 return;
51
887cf21b »
2008-09-19 Also reload refs in the webview
52 // The sha is the same, but refs may have changed.. reload it lazy
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
53 if ([currentSha isEqual:[content sha]])
887cf21b »
2008-09-19 Also reload refs in the webview
54 {
b7645ec9 »
2008-10-31 PBWebHistoryController: show the commit diff async
55 [[self script] callWebScriptMethod:@"reload" withArguments: nil];
2e4ea6ed »
2008-06-15 Load commit list in a separate thread
56 return;
887cf21b »
2008-09-19 Also reload refs in the webview
57 }
58
b7645ec9 »
2008-10-31 PBWebHistoryController: show the commit diff async
59 NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil];
2b0c2b20 »
2010-03-05 Retry loadCommit() script when it fails
60 id scriptResult = [[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments];
61 if (!scriptResult) {
62 // the web view is not really ready for scripting???
63 [self performSelector:_cmd withObject:content afterDelay:0.05];
64 return;
65 }
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
66 currentSha = [content sha];
0363eea4 »
2009-09-17 HistoryView: don't load in commit information in a separate thread an…
67
68 // Now we load the extended details. We used to do this in a separate thread,
69 // but this caused some funny behaviour because NSTask's and NSThread's don't really
70 // like each other. Instead, just do it async.
71
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
72 NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", [currentSha string], nil];
0363eea4 »
2009-09-17 HistoryView: don't load in commit information in a separate thread an…
73 if (![PBGitDefaults showWhitespaceDifferences])
74 [taskArguments insertObject:@"-w" atIndex:1];
75
76 NSFileHandle *handle = [repository handleForArguments:taskArguments];
77 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
78 // Remove notification, in case we have another one running
693a23d5 »
2010-06-20 Bugfix: don't remove all notifications from the web history controller
79 [nc removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
0363eea4 »
2009-09-17 HistoryView: don't load in commit information in a separate thread an…
80 [nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
81 [handle readToEndOfFileInBackgroundAndNotify];
82 }
83
84 - (void)commitDetailsLoaded:(NSNotification *)notification
85 {
693a23d5 »
2010-06-20 Bugfix: don't remove all notifications from the web history controller
86 [[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
87
0363eea4 »
2009-09-17 HistoryView: don't load in commit information in a separate thread an…
88 NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
89 if (!data)
90 return;
91
92 NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
93 if (!details)
94 details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
95
96 if (!details)
97 return;
98
99 [[view windowScriptObject] callWebScriptMethod:@"loadCommitDetails" withArguments:[NSArray arrayWithObject:details]];
79e9ba9f »
2008-06-14 Add a detailed HTML view
100 }
f4a81e21 »
2008-06-15 Make the link to previous parents work
101
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
102 - (void)selectCommit:(NSString *)sha
f4a81e21 »
2008-06-15 Make the link to previous parents work
103 {
c17215e5 »
2010-07-03 Create wrapper class around git_oid and use it
104 [historyController selectCommit:[PBGitSHA shaWithString:sha]];
f4a81e21 »
2008-06-15 Make the link to previous parents work
105 }
106
c3c4f98c »
2008-09-12 Allow hunk navigation by using j/k keys
107 - (void) sendKey: (NSString*) key
108 {
109 id script = [view windowScriptObject];
110 [script callWebScriptMethod:@"handleKeyFromCocoa" withArguments: [NSArray arrayWithObject:key]];
111 }
112
f48d0022 »
2008-09-19 Allow copy and pasting of web source by pressing 'c'
113 - (void) copySource
114 {
b257f009 »
2008-09-24 Fix compiler warnings
115 NSString *source = [(DOMHTMLElement *)[[[view mainFrame] DOMDocument] documentElement] outerHTML];
f48d0022 »
2008-09-19 Allow copy and pasting of web source by pressing 'c'
116 NSPasteboard *a =[NSPasteboard generalPasteboard];
117 [a declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
118 [a setString:source forType: NSStringPboardType];
119 }
120
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
121 - (NSArray *) webView:(WebView *)sender
122 contextMenuItemsForElement:(NSDictionary *)element
123 defaultMenuItems:(NSArray *)defaultMenuItems
124 {
f8270f38 »
2008-09-19 Add framework to support removing refs
125 DOMNode *node = [element valueForKey:@"WebElementDOMNode"];
126
c9609f22 »
2009-06-16 WebHistoryController: Refactor menu search to be recursive
127 while (node) {
128 // Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref.
129 if ([[node className] hasPrefix:@"refs "]) {
130 NSString *selectedRefString = [[[node childNodes] item:0] textContent];
131 for (PBGitRef *ref in historyController.webCommit.refs)
132 {
133 if ([[ref shortName] isEqualToString:selectedRefString])
ff5f3f79 »
2010-02-02 Add methods dealing with menus needed for future features.
134 return [contextMenuDelegate menuItemsForRef:ref];
c9609f22 »
2009-06-16 WebHistoryController: Refactor menu search to be recursive
135 }
136 NSLog(@"Could not find selected ref!");
137 return defaultMenuItems;
138 }
a002e331 »
2009-06-16 WebHistoryView: Also use the tree context menu
139 if ([node hasAttributes] && [[node attributes] getNamedItem:@"representedFile"])
140 return [historyController menuItemsForPaths:[NSArray arrayWithObject:[[[node attributes] getNamedItem:@"representedFile"] value]]];
9e8002a9 »
2010-06-27 Only allow the "Copy Image" menu item for images
141 else if ([[node class] isEqual:[DOMHTMLImageElement class]]) {
142 // Copy Image is the only menu item that makes sense here since we don't need
143 // to download the image or open it in a new window (besides with the
144 // current implementation these two entries can crash GitX anyway)
145 for (NSMenuItem *item in defaultMenuItems)
146 if ([item tag] == WebMenuItemTagCopyImageToClipboard)
147 return [NSArray arrayWithObject:item];
148 return nil;
149 }
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
150
c9609f22 »
2009-06-16 WebHistoryController: Refactor menu search to be recursive
151 node = [node parentNode];
e02ee523 »
2008-11-01 WebHistoryController: Move ref deletion to RefController
152 }
153
154 return defaultMenuItems;
f8270f38 »
2008-09-19 Add framework to support removing refs
155 }
188d13f2 »
2008-09-26 WebGitController: Add a policy to open links in browser
156
40e97262 »
2008-10-08 WebControllers: Refactor to use common code
157
158 // Open external links in the default browser
188d13f2 »
2008-09-26 WebGitController: Add a policy to open links in browser
159 - (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
160 request:(NSURLRequest *)request
161 newFrameName:(NSString *)frameName
162 decisionListener:(id < WebPolicyDecisionListener >)listener
163 {
164 [[NSWorkspace sharedWorkspace] openURL:[request URL]];
165 }
166
b4bcc58b »
2008-10-14 CommitView/Gistie: Use github.user and github.login
167 - getConfig:(NSString *)config
168 {
169 return [historyController valueForKeyPath:[@"repository.config." stringByAppendingString:config]];
170 }
171
53d92fb7 »
2010-07-03 Cleanup the views when the repository window closes and stop memory l…
172 - (void)finalize
3dd63854 »
2008-11-26 Fix memory leaks
173 {
174 [super finalize];
175 }
176
31d2e1ad »
2008-12-28 Have history view react to configuration changes.
177 - (void) preferencesChanged
178 {
179 [[self script] callWebScriptMethod:@"enableFeatures" withArguments:nil];
180 }
181
79e9ba9f »
2008-06-14 Add a detailed HTML view
182 @end
Something went wrong with that request. Please try again.