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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
#import "WindowController.h"
#import "ApplicationController.h"
#import "FileTableDelegate.h"
#import "GroupTableDelegate.h"
static NSString *
myLocalizedString(NSString *aString)
{
return NSLocalizedStringFromTable(aString, @"WindowElements", @"");
}
static void
logRect(NSString *desc, NSRect aRect)
{
[LiLog logAsDebug: @"%@, (%f, %f, %f, %f)", desc, aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height];
}
@implementation WindowController (WindowDelegate)
- (NSRect)windowWillUseStandardFrame: (NSWindow *)aWindow
defaultFrame: (NSRect)defaultFrame
{
FileTableDelegate *fileDelegate;
GroupTableDelegate *groupDelegate;
NSRect curGroupFrame, curFileFrame, windowFrame;
NSSize minGroupSize, minFileSize;
float newWidth, newHeight, splitterWidth, headerHeight;
[LiLog logAsDebug: @"[WindowController minSize]"];
[LiLog indentDebugLog];
groupDelegate = [theGroupList delegate];
fileDelegate = [theFileList delegate];
windowFrame = [aWindow frame];
logRect(@"Unadjusted window frame", windowFrame);
windowFrame = [NSWindow contentRectForFrameRect: [aWindow frame]
styleMask: [aWindow styleMask]];
logRect(@"Old window frame", windowFrame);
curFileFrame = [[theFileList superview] frame];
logRect(@"curFileFrame", curFileFrame);
curGroupFrame = [[theGroupList superview] frame];
logRect(@"curGroupFrame", curGroupFrame);
splitterWidth = windowFrame.size.width - (curFileFrame.size.width + curGroupFrame.size.width);
[LiLog logAsDebug: @"splitter width: %f", splitterWidth];
headerHeight = windowFrame.size.height - MAX(curFileFrame.size.height, curGroupFrame.size.height);
[LiLog logAsDebug: @"header height: %f, wf.height: %f, MAX(file,group).height: %f", headerHeight, windowFrame.size.height, MAX(curFileFrame.size.height, curGroupFrame.size.height)];
minGroupSize = [groupDelegate minSize];
[LiLog logAsDebug: @"minGroupSize: %f, %f", minGroupSize.width, minGroupSize.height];
minFileSize = [fileDelegate minSize];
[LiLog logAsDebug: @"minFileSize: %f, %f", minFileSize.width, minFileSize.height];
newWidth = minGroupSize.width + minFileSize.width + splitterWidth;
newHeight = MAX(minGroupSize.height, minFileSize.height) + headerHeight + 6.0;
[LiLog logAsDebug: @"newWidth, newHeight: %f, %f", newWidth, newHeight];
windowFrame.origin.y += windowFrame.size.height;
windowFrame.origin.y -= newHeight;
windowFrame.size = NSMakeSize(newWidth, newHeight);
windowFrame = [NSWindow frameRectForContentRect: windowFrame
styleMask: [aWindow styleMask]];
if ((windowFrame.origin.x + windowFrame.size.width) >
(defaultFrame.origin.x + defaultFrame.size.width)) {
[LiLog logAsDebug: @"Need to adjust width"];
if (windowFrame.size.width > defaultFrame.size.width) {
windowFrame.origin.x = defaultFrame.origin.x;
windowFrame.size.width = defaultFrame.size.width;
} else {
windowFrame.origin.x = defaultFrame.size.width - windowFrame.size.width;
}
}
if ((windowFrame.origin.y + windowFrame.size.height) >
(defaultFrame.origin.y + defaultFrame.size.height)) {
[LiLog logAsDebug: @"Need to adjust height"];
if (windowFrame.size.height > defaultFrame.size.height) {
windowFrame.origin.y = defaultFrame.origin.y;
windowFrame.size.height = defaultFrame.size.height;
} else {
windowFrame.origin.y = defaultFrame.size.height - windowFrame.size.height;
}
}
logRect(@"New window frame", windowFrame);
[LiLog unindentDebugLog];
return windowFrame;
}
- (void)windowDidBecomeKey: (NSNotification *)aNotificatin
{
[LiLog logAsDebug: @"[WindowController windowDidBecomeKey]"];
[[theMainWindow firstResponder] becomeFirstResponder];
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
FileTableDelegate *fileDelegate;
fileDelegate = [theFileList dataSource];
[fileDelegate saveSelectionOfTableView: theFileList];
[fileDelegate setSearchString:
[[[[aNotification object] stringValue] lowercaseString] retain]];
[fileDelegate redisplay];
[fileDelegate restoreSelectionToTableView: theFileList refresh: YES];
}
@end
@implementation WindowController
- (id)init
{
self = [super init];
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)setupToolbar
{
NSToolbar *toolbar;
toolbar = [[[NSToolbar alloc]
initWithIdentifier: @"mainToolbar"] autorelease];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
[theMainWindow setToolbar: toolbar];
}
- (void)awakeFromNib
{
[self setupToolbar];
}
@synthesize theInspectorWindow;
@synthesize theGroupList;
@synthesize theFileList;
@synthesize theSearchField;
@synthesize theMainWindow;
@end
@implementation WindowController (ToolbarDelegateCategory)
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:
NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
@"AddFilesItem",
@"RemoveFilesItem",
@"SearchItem",
@"InfoItem",
@"AddGroupItem",
@"RemoveGroupItem",
@"RevealInFinderItem",
nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:
@"AddGroupItem",
@"RemoveGroupItem",
NSToolbarSeparatorItemIdentifier,
@"AddFilesItem",
@"RemoveFilesItem",
@"InfoItem",
@"RevealInFinderItem",
NSToolbarFlexibleSpaceItemIdentifier,
@"SearchItem",
NSToolbarSeparatorItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
nil];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:
itemIdentifier];
if ([itemIdentifier isEqualToString: @"AddFilesItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarAddFileLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarAddFilePaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarAddFileToolTip")];
[item setImage: [NSImage imageNamed: @"AddFiles.tiff"]];
[item setTarget: self];
[item setAction: @selector(addToLibrary:)];
} else if ([itemIdentifier isEqualToString: @"RemoveFilesItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarRemoveFileLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarRemoveFilePaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarRemoveFileToolTip")];
[item setImage: [NSImage imageNamed: @"RemoveFiles.tiff"]];
[item setTarget: self];
[item setAction: @selector(removeFiles:)];
} else if ([itemIdentifier isEqualToString: @"SearchItem"]) {
NSRect frame;
frame = [theSearchField frame];
[item setLabel: myLocalizedString(@"LiToolbarSearchLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarSearchPaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarSearchToolTip")];
[item setView: theSearchField];
[item setMinSize: frame.size];
[item setMaxSize: frame.size];
} else if ([itemIdentifier isEqualToString: @"InfoItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarGetInfoLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarGetInfoPaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarGetInfoToolTip")];
[item setImage: [NSImage imageNamed: @"info (italic).tiff"]];
[item setTarget: self];
[item setAction: @selector(openInspector:)];
} else if ([itemIdentifier isEqualToString: @"AddGroupItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarAddGroupLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarAddGroupPaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarAddGroupToolTip")];
[item setImage: [NSImage imageNamed: @"AddGroup.tiff"]];
[item setTarget: self];
[item setAction: @selector(addGroup:)];
} else if ([itemIdentifier isEqualToString: @"RemoveGroupItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarRemoveGroupLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarRemoveGroupPaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarRemoveGroupToolTip")];
[item setImage: [NSImage imageNamed: @"RemoveGroup.tiff"]];
[item setTarget: self];
[item setAction: @selector(removeGroup:)];
} else if ([itemIdentifier isEqualToString: @"RevealInFinderItem"]) {
[item setLabel: myLocalizedString(@"LiToolbarRevealLabel")];
[item setPaletteLabel: myLocalizedString(@"LiToolbarRevealPaletteLabel")];
[item setToolTip: myLocalizedString(@"LiToolbarRevealToolTip")];
[item setImage: [NSImage imageNamed: @"reveal.tiff"]];
[item setTarget: self];
[item setAction: @selector(revealInFinder:)];
}
return [item autorelease];
}
- (BOOL)validateToolbarItem: (NSToolbarItem *)theItem
{
GroupTableDelegate *groupDelegate;
FileTableDelegate *fileDelegate;
groupDelegate = [theGroupList delegate];
fileDelegate = [theFileList delegate];
if ([theItem action] == @selector(addToLibrary:)) {
return [fileDelegate validateAction: @selector(addFiles:)];
} else if ([theItem action] == @selector(revealInFinder:)) {
return [fileDelegate validateAction: @selector(revealInFinder:)];
} else if ([theItem action] == @selector(removeFiles:)) {
return [fileDelegate validateAction: @selector(delete:)];
} else if ([theItem action] == @selector(addGroup:)) {
return [groupDelegate validateAction: @selector(addGroup:)];
} else if ([theItem action] == @selector(removeGroup:)) {
return [groupDelegate validateAction: @selector(delete:)];
}
return YES;
}
- (IBAction)addGroup:(id)sender
{
[[theGroupList delegate] addGroup: self];
}
- (IBAction)removeGroup:(id)sender
{
[theGroupList performSelector: @selector(delete:) withObject: sender];
}
- (IBAction)addToLibrary:(id)sender
{
[[theFileList delegate] addFiles: self];
}
- (IBAction)removeFiles:(id)sender
{
[theFileList performSelector: @selector(delete:) withObject: sender];
}
- (IBAction)openInspector:(id)sender
{
[[ApplicationController theApp] showInspectorWindow: self];
}
- (IBAction)revealInFinder:(id)sender
{
[[theFileList delegate] revealInFinder: self];
}
@end
|