-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoubleViewController.m
184 lines (145 loc) · 4.21 KB
/
DoubleViewController.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
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
181
182
183
184
//
// DoubleViewController.m
// lutrin
//
// Created by Shigeru Hagiwara on 2012/12/30.
//
//
#import "DoubleViewController.h"
#import "LutrinWindowController.h"
@interface DoubleViewController (Util)
- (NSString *)makeTitle:(NSURL *)leftUrl right:(NSURL *)rightUrl;
@end
@implementation DoubleViewController
@synthesize rightImageView;
@synthesize rightImageProperties;
@synthesize leftToRight;
- (id)initWithWindowController:(LutrinWindowController *)_windowController
{
self = [super initWithWindowController:_windowController
nibName:@"DoubleViewController"];
if (self) {
leftToRight = TRUE;
}
return self;
}
- (void)dealloc
{
[rightImageProperties release];
[super dealloc];
}
- (NSURL *)nextFileUrl
{
NSUInteger index = [self getFileIndex];
index += 1;
if (index >= self.fileList.count) {
return [self transparentImage];
} else {
NSURL *url = (NSURL *)[self.fileList objectAtIndex:index];
if (url == nil)
url = [self transparentImage];
return url;
}
}
- (NSString *)makeTitle:(NSURL *)leftUrl right:(NSURL *)rightUrl
{
NSString *leftName = [leftUrl lastPathComponent];
if ([leftUrl isEqual:[self transparentImage]])
leftName = @"";
NSString *rightName = [rightUrl lastPathComponent];
if ([rightUrl isEqual:[self transparentImage]])
rightName = @"";
NSString *title = [NSString stringWithFormat:@"%@ | %@ (%ld/%ld)",
leftName, rightName,
([self getFileIndex] + 1), self.fileList.count];
return title;
}
- (void)clearImageView
{
[super clearImageView];
[self loadImageTo:self.rightImageView URL:[self transparentImage]
properties:&rightImageProperties];
}
- (void)openImageURL:(NSURL *)url
{
self.currentFile = url;
if (url == nil) {
[self loadImageTo:self.imageView URL:[self transparentImage]
properties:&imageProperties];
[self loadImageTo:self.rightImageView URL:[self transparentImage]
properties:&rightImageProperties];
[self.windowController setWindowTitle:@"no image"];
return;
}
NSURL *leftUrl = nil;
NSURL *rightUrl = nil;
if (leftToRight) {
if ([self getFileIndex] == 0) {
leftUrl = [self transparentImage];
rightUrl = url;
} else {
leftUrl = url;
rightUrl = [self nextFileUrl];
}
} else {
if ([self getFileIndex] == 0) {
leftUrl = url;
rightUrl = [self transparentImage];
} else {
leftUrl = [self nextFileUrl];
rightUrl = url;
}
}
[self loadImageTo:self.imageView URL:leftUrl properties:&imageProperties];
[self loadImageTo:self.rightImageView URL:rightUrl properties:&rightImageProperties];
[self.windowController setWindowTitle:[self makeTitle:leftUrl right:rightUrl]];
}
- (void)windowDidResize:(NSNotification *)notification
{
[self.imageView zoomImageToFit:self];
[self.rightImageView zoomImageToFit:self];
}
- (IBAction)nextFile: (id)sender
{
if (self.fileList.count == 0) return;
NSUInteger index = [self getFileIndex];
index += (index == 0) ? 1 : 2;
if (index >= self.fileList.count)
index = self.fileList.count - 1;
NSURL *url = (NSURL *)[self.fileList objectAtIndex:index];
if (url)
[self openImageURL:url];
}
- (IBAction)prevFile: (id)sender
{
if (self.fileList.count == 0) return;
NSUInteger index = [self getFileIndex];
if (index == 0 || index == 1)
index = 0;
else
index -= 2;
NSURL *url = (NSURL *)[self.fileList objectAtIndex:index];
if (url)
[self openImageURL:url];
}
- (IBAction)zoomActualSize: (id)sender
{
[super zoomActualSize:sender];
[self.rightImageView zoomImageToActualSize:sender];
}
- (IBAction)zoomFitToWindow: (id)sender
{
[super zoomFitToWindow:sender];
[self.rightImageView zoomImageToFit:sender];
}
- (IBAction)zoomIn: (id)sender
{
[super zoomIn:sender];
[self.rightImageView zoomIn:sender];
}
- (IBAction)zoomOut: (id)sender
{
[super zoomOut:sender];
[self.rightImageView zoomOut:sender];
}
@end