Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 183 lines (150 sloc) 6.067 kb
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
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
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
9 #import "PBWebHistoryController.h"
0363eea Pieter de Bie HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
10 #import "PBGitDefaults.h"
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
11 #import "PBGitSHA.h"
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
12
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
13 @implementation PBWebHistoryController
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
14
15 @synthesize diff;
16
17 - (void) awakeFromNib
18 {
bd097b0 Pieter de Bie HTML: Restructure html folder
pieter authored
19 startFile = @"history";
415ee91 Pieter de Bie WebHistoryView: Add a link to display changed images
pieter authored
20 repository = historyController.repository;
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
21 [super awakeFromNib];
708c08a Pieter de Bie First part of splitting views
pieter authored
22 [historyController addObserver:self forKeyPath:@"webCommit" options:0 context:@"ChangedCommit"];
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
23 }
24
53d92fb Nathan Kinsinger Cleanup the views when the repository window closes and stop memory leak...
authored
25 - (void)closeView
26 {
27 [[self script] setValue:nil forKey:@"commit"];
28 [historyController removeObserver:self forKeyPath:@"webCommit"];
29
30 [super closeView];
31 }
32
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
33 - (void) didLoad
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
34 {
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
35 currentSha = nil;
708c08a Pieter de Bie First part of splitting views
pieter authored
36 [self changeContentTo: historyController.webCommit];
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
37 }
38
6dcefe5 Benjamin Kramer Fix many gcc 4.2 compiler warnings
d0k authored
39 - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
40 {
6dcefe5 Benjamin Kramer Fix many gcc 4.2 compiler warnings
d0k authored
41 if ([(NSString *)context isEqualToString: @"ChangedCommit"])
708c08a Pieter de Bie First part of splitting views
pieter authored
42 [self changeContentTo: historyController.webCommit];
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
43 else
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
44 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
45 }
46
2e4ea6e Pieter de Bie Load commit list in a separate thread
pieter authored
47 - (void) changeContentTo: (PBGitCommit *) content
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
48 {
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
49 if (content == nil || !finishedLoading)
6ba944b Pieter de Bie Implement a DetailsController
pieter authored
50 return;
51
887cf21 Pieter de Bie Also reload refs in the webview
pieter authored
52 // The sha is the same, but refs may have changed.. reload it lazy
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
53 if ([currentSha isEqual:[content sha]])
887cf21 Pieter de Bie Also reload refs in the webview
pieter authored
54 {
b7645ec Pieter de Bie PBWebHistoryController: show the commit diff async
pieter authored
55 [[self script] callWebScriptMethod:@"reload" withArguments: nil];
2e4ea6e Pieter de Bie Load commit list in a separate thread
pieter authored
56 return;
887cf21 Pieter de Bie Also reload refs in the webview
pieter authored
57 }
58
b7645ec Pieter de Bie PBWebHistoryController: show the commit diff async
pieter authored
59 NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil];
2b0c2b2 Nathan Kinsinger Retry loadCommit() script when it fails
authored
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 }
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
66 currentSha = [content sha];
0363eea Pieter de Bie HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
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
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
72 NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", [currentSha string], nil];
0363eea Pieter de Bie HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
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
693a23d Nathan Kinsinger Bugfix: don't remove all notifications from the web history controller
authored
79 [nc removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
0363eea Pieter de Bie HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
80 [nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
81 [handle readToEndOfFileInBackgroundAndNotify];
82 }
83
84 - (void)commitDetailsLoaded:(NSNotification *)notification
85 {
693a23d Nathan Kinsinger Bugfix: don't remove all notifications from the web history controller
authored
86 [[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
87
0363eea Pieter de Bie HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
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]];
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
100 }
f4a81e2 Pieter de Bie Make the link to previous parents work
pieter authored
101
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
102 - (void)selectCommit:(NSString *)sha
f4a81e2 Pieter de Bie Make the link to previous parents work
pieter authored
103 {
c17215e Nathan Kinsinger Create wrapper class around git_oid and use it
authored
104 [historyController selectCommit:[PBGitSHA shaWithString:sha]];
f4a81e2 Pieter de Bie Make the link to previous parents work
pieter authored
105 }
106
c3c4f98 Pieter de Bie Allow hunk navigation by using j/k keys
pieter authored
107 - (void) sendKey: (NSString*) key
108 {
109 id script = [view windowScriptObject];
110 [script callWebScriptMethod:@"handleKeyFromCocoa" withArguments: [NSArray arrayWithObject:key]];
111 }
112
f48d002 Pieter de Bie Allow copy and pasting of web source by pressing 'c'
pieter authored
113 - (void) copySource
114 {
b257f00 Pieter de Bie Fix compiler warnings
pieter authored
115 NSString *source = [(DOMHTMLElement *)[[[view mainFrame] DOMDocument] documentElement] outerHTML];
f48d002 Pieter de Bie Allow copy and pasting of web source by pressing 'c'
pieter authored
116 NSPasteboard *a =[NSPasteboard generalPasteboard];
117 [a declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
118 [a setString:source forType: NSStringPboardType];
119 }
120
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
121 - (NSArray *) webView:(WebView *)sender
122 contextMenuItemsForElement:(NSDictionary *)element
123 defaultMenuItems:(NSArray *)defaultMenuItems
124 {
f8270f3 Pieter de Bie Add framework to support removing refs
pieter authored
125 DOMNode *node = [element valueForKey:@"WebElementDOMNode"];
126
c9609f2 Pieter de Bie WebHistoryController: Refactor menu search to be recursive
pieter authored
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])
ff5f3f7 Nathan Kinsinger Add methods dealing with menus needed for future features.
authored
134 return [contextMenuDelegate menuItemsForRef:ref];
c9609f2 Pieter de Bie WebHistoryController: Refactor menu search to be recursive
pieter authored
135 }
136 NSLog(@"Could not find selected ref!");
137 return defaultMenuItems;
138 }
a002e33 Pieter de Bie WebHistoryView: Also use the tree context menu
pieter authored
139 if ([node hasAttributes] && [[node attributes] getNamedItem:@"representedFile"])
140 return [historyController menuItemsForPaths:[NSArray arrayWithObject:[[[node attributes] getNamedItem:@"representedFile"] value]]];
9e8002a Nathan Kinsinger Only allow the "Copy Image" menu item for images
authored
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 }
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
150
c9609f2 Pieter de Bie WebHistoryController: Refactor menu search to be recursive
pieter authored
151 node = [node parentNode];
e02ee52 Pieter de Bie WebHistoryController: Move ref deletion to RefController
pieter authored
152 }
153
154 return defaultMenuItems;
f8270f3 Pieter de Bie Add framework to support removing refs
pieter authored
155 }
188d13f Pieter de Bie WebGitController: Add a policy to open links in browser
pieter authored
156
40e9726 Pieter de Bie WebControllers: Refactor to use common code
pieter authored
157
158 // Open external links in the default browser
188d13f Pieter de Bie WebGitController: Add a policy to open links in browser
pieter authored
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
b4bcc58 Pieter de Bie CommitView/Gistie: Use github.user and github.login
pieter authored
167 - getConfig:(NSString *)config
168 {
169 return [historyController valueForKeyPath:[@"repository.config." stringByAppendingString:config]];
170 }
171
53d92fb Nathan Kinsinger Cleanup the views when the repository window closes and stop memory leak...
authored
172 - (void)finalize
3dd6385 Pieter de Bie Fix memory leaks
pieter authored
173 {
174 [super finalize];
175 }
176
31d2e1a Daniel Lundqvist Have history view react to configuration changes.
dlundqvist authored
177 - (void) preferencesChanged
178 {
179 [[self script] callWebScriptMethod:@"enableFeatures" withArguments:nil];
180 }
181
79e9ba9 Pieter de Bie Add a detailed HTML view
pieter authored
182 @end
Something went wrong with that request. Please try again.