-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVNSelect.mm
181 lines (164 loc) · 5.29 KB
/
SVNSelect.mm
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#import "SVNSelect.h"
#import "SVNProgress.h"
#import "SVNLog.h"
#import "SVNProperties.h"
#import "SVNBlame.h"
#import "SVNEditor.h"
#import <Cocoa/Cocoa.h>
//------------------------------------------------------------------------------
// SVNSelect
//------------------------------------------------------------------------------
@implementation SVNSelect
@synthesize data;
@synthesize status;
@synthesize title;
-(id)initWithWindow:(NSWindow*)window {
if (self = [super initWithWindow:window]) {
data = [NSMutableArray new];
svn = new SVNcontext;
}
return self;
}
-(id)initWithTitle:(NSString*)init_title {
if (self = [self initWithWindowNibName:@"SVNSelect"]) {
self.title = init_title;
[self setShouldCascadeWindows:NO];
[self setWindowFrameAutosaveName:@"SVNSelect"];
[self setLogo];
}
return self;
}
-(void)dealloc {
[data release];
[super dealloc];
}
-(void)windowWillClose:(NSNotification*)notification {
[self release];
}
-(void)add:(id)value {
[self willChangeValueForKey:@"data"];
[self.data addObject:value];
[self didChangeValueForKey:@"data"];
}
-(IBAction)cancel_pressed:(id)sender {
[self close];
}
-(void)getFiles:(NSArray*)paths all:(bool)all {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
for (NSString *path in paths) {
if (svn_error_t *err = svn->GetStatus(self, path, SVNrevision::head(), svn_depth_infinity, all))
self.status = svn->GetErrorMessage(err);
}
});
}
-(NSArray*)getSelected {
int n = [data count];
NSMutableArray *selected = [NSMutableArray arrayWithCapacity:n];
for (NSDictionary *info in data) {
if ([[info valueForKey:@"selected"] boolValue])
[selected addObject:info];
}
return selected;
}
-(NSArray*)getSelectedPaths {
int n = [data count];
NSMutableArray *selected = [NSMutableArray arrayWithCapacity:n];
for (NSDictionary *info in data) {
if ([[info valueForKey:@"selected"] boolValue])
[selected addObject:((SVNClientStatus*)[info valueForKey:@"status"])->path];
}
return selected;
}
//------------------------------------------------------------------------------
// actions on paths
//------------------------------------------------------------------------------
-(SVNClientStatus*)get_selection {
NSDictionary *entry = [data objectAtIndex:[table clickedRow]];
return [entry valueForKey:@"status"];
}
-(NSString*)get_selected_path {
return [self get_selection]->path;
}
- (IBAction)compare:(id)sender {
NSString *local = [self get_selected_path];
NSString *repos = [NSTemporaryDirectory() stringByAppendingPathComponent:[local lastPathComponent]];
svn_client_info2_t *info;
svn_error_t *err = svn->GetInfo(local, SVNrevision::head(), &info);
if (!err) {
NSString *url = [NSString stringWithUTF8String:info->URL];
if (!(err = svn->GetFile(SVNstreamFILE([repos UTF8String]), url, SVNrevision::head()))) {
#if 0
NSString *command = [[NSUserDefaults standardUserDefaults] stringForKey:@"diff_command"];
[NSTask launchedTaskWithLaunchPath:command arguments:[NSArray arrayWithObjects:local, repos, nil]];
#else
[[SVNEditor new] diff:local base:repos];
#endif
}
return;
}
svn->LogErrorMessage(err);
}
- (IBAction)revert:(id)sender {
svn_error_t *err = svn->Revert(self, [NSArray arrayWithObject:[self get_selected_path]]);
if (!err) {
[data removeObjectAtIndex:[table clickedRow]];
}
}
- (IBAction)log:(id)sender {
[[[SVNLog alloc] init] svn_log:[NSArray arrayWithObject:[self get_selected_path]]];
}
- (IBAction)blame:(id)sender {
[[[SVNBlame alloc] init] svn_blame:[self get_selected_path] fromRevision:1 toRevision:SVNrevision::head()];
}
- (IBAction)open:(id)sender {
[[NSWorkspace sharedWorkspace] openFile:[self get_selected_path]];
}
- (IBAction)open_with:(id)sender {
NSString *fn = [self get_selected_path];
if (NSString *app = [sender representedObject]) {
[[NSWorkspace sharedWorkspace] openFile:fn withApplication:app];
} else {
[self chooseApplication:^(NSURL *app) {
[[NSWorkspace sharedWorkspace] openFile:fn withApplication:[app path]];
}];
}
}
- (IBAction)finder:(id)sender {
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:
[NSArray arrayWithObject: [NSURL fileURLWithPath: [self get_selected_path]]]
];
}
- (IBAction)show_props:(id)sender {
NSString *local = [self get_selected_path];
[[[SVNProperties alloc] init] svn_props:local];
}
- (IBAction)copy_paths:(id)sender {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObject:[self get_selected_path]]];
}
- (IBAction)copy_all:(id)sender {
SVNClientStatus *stat = [self get_selection];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObjects:
stat.path,
stat.lock,
stat.text_status,
stat.prop_status,
nil
]];
}
- (IBAction)copy_column:(id)sender {
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard clearContents];
[pboard writeObjects:[NSArray arrayWithObject:[self get_selected_path]]];
}
//------------------------------------------------------------------------------
// NSMenuDelegate
//------------------------------------------------------------------------------
- (void)menuNeedsUpdate:(NSMenu*)menu {
NSString *path = [self get_selected_path];
[[menu itemWithTitle:@"Open with"] setSubmenu:[self openWithFor:path]];
}
@end