Develop and Download Open Source Software

Browse CVS Repository

Contents of /lupin/lupin/LupinBrowser/LPMainWindowController.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Wed Jul 13 05:07:50 2005 UTC (18 years, 9 months ago) by letter
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +3 -2 lines
change not to start progressive bar when inspective window is opened

1 /*
2 * Copyright (c) 2004-2005 The Lupin Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
8 * and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
11 * conditions and the following disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE LUPIN PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LUPIN PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21 * POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #import "LPMainWindowController.h"
25
26
27 @implementation LPMainWindowController
28
29 - (void)dealloc
30 {
31 if (lastSortIdentifier) [lastSortIdentifier release];
32 if (_iconDict) [_iconDict release];
33 if (_folderIcon) [_folderIcon release];
34 [super dealloc];
35 }
36
37 - (void)windowDidLoad
38 {
39 NSLog(@"windowDidLoad(LPMainWindowController)");
40 //NSLog([[self document] fileType]);
41 //if ([[[self document] fileType] isEqualToString:@"LupinCompressType"])
42 // [self setWindow:_progressPanel]; //! ���������������������������������������������������������������������
43 // ������������������������������������������������������������������
44 //���������������������������������������������������������������������������
45 //[_progressIndicator setHidden:NO];
46 //[_progressIndicator startAnimation:self];
47 if ([[[self document] fileType] isEqualToString:@"LupinUncompressType"]) {
48 //[[self document] uncompress:self];
49 } else {
50 _iconDict = [NSMutableDictionary dictionary];
51 [_iconDict retain];
52 // ���������������������������������������������������������������������������������������������������������������������������������������������������������������
53 _folderIcon = [[NSWorkspace sharedWorkspace] iconForFile:[[NSBundle mainBundle] resourcePath]];
54 [_folderIcon retain];
55 // ���������������������������������������������������������
56 [_fileOutlineView setAutoresizesOutlineColumn:NO];
57 NSBrowserCell* browserCell = [[[NSBrowserCell alloc] init] autorelease];
58 [browserCell setLeaf:YES];
59 [browserCell setWraps:YES];
60 [[_fileOutlineView tableColumnWithIdentifier:@"name"] setDataCell:browserCell];
61 }
62 }
63
64 - (void)loadDialogs
65 {
66 [NSBundle loadNibNamed:@"LPDialogs" owner:self];
67 }
68
69 - (void)archiveInfoDictDidBuild
70 {
71 [_progressIndicator stopAnimation:self];
72 [self refreshStatus];
73 [_fileOutlineView reloadData];
74 }
75
76 - (void)archiveDidUncompress
77 {
78 [_progressIndicator setDoubleValue:[_progressIndicator maxValue]];
79 [_progressIndicator stopAnimation:self];
80 [_progressIndicator display]; //! ������������������������������������������������������������
81 [self refreshStatus];
82 [_cancelButton setEnabled:YES];
83 [_cancelButton setTitle:NSLocalizedString(@"DialogFinished",nil)];
84 [_cancelButton setKeyEquivalent:@"\r"];
85 }
86
87 - (void)archiveWillUncompress
88 {
89 _processMode = LPProcessCompressMode;
90 [_progressIndicator setIndeterminate:NO];
91 [_progressIndicator setUsesThreadedAnimation:YES];
92 }
93
94 - (void)archiveDidCompress
95 {
96 [_progressIndicator setDoubleValue:[_progressIndicator maxValue]];
97 [_progressIndicator stopAnimation:self];
98 [_progressIndicator display]; //! ������������������������������������������������������������
99 [self refreshStatus];
100 [_cancelButton setEnabled:YES];
101 [_cancelButton setTitle:NSLocalizedString(@"DialogFinished",nil)];
102 [_cancelButton setKeyEquivalent:@"\r"];
103 }
104
105 - (void)archiveWillCompress
106 {
107 _processMode = LPProcessUncompressMode;
108 [_progressIndicator setIndeterminate:NO];
109 }
110
111 /*
112 - (void)changeWindowToProgressType
113 {
114 [self setWindow:_progressPanel];
115 }
116 */
117
118 #pragma mark -
119 #pragma mark OutlineView
120 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
121 {
122 [self refreshStatus];
123 }
124
125 - (void)outlineViewItemDidExpand:(NSNotification *)notification
126 {
127 [self refreshStatus];
128 }
129
130 - (void)outlineViewItemDidCollapse:(NSNotification *)notification
131 {
132 [self refreshStatus];
133 }
134
135 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
136 {
137 [item setExpanded:YES];
138 return YES;
139 }
140
141 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item
142 {
143 NSLog(@"shouldCollapseItem");
144 [item setExpanded:NO];
145 return YES;
146 }
147
148 - (id)outlineView:(NSOutlineView*)outlineView child:(int)index ofItem:(id)item
149 {
150 if (!item) {
151 item = [[self document] infoDict];
152 }
153 return [[item children] objectAtIndex:index];
154 }
155
156 - (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item
157 {
158 if (!item) {
159 item = [[self document] infoDict];
160 }
161 //return [item children] != nil;
162 //return [[item children] count] != 0;
163 return [item isDir];
164 }
165
166 - (int)outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(id)item
167 {
168 if (!item) {
169 item = [[self document] infoDict];
170 }
171 //NSLog(@"children count=%d",[[item children] count]);
172 return [[item children] count];
173 }
174
175 - (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)column byItem:(id)item
176 {
177 id identifier;
178 identifier = [column identifier];
179
180 NSString* str;
181
182 if ([identifier isEqualToString:@"name"]) {
183 NSImage* icon = [item icon];
184 if (!icon) {
185 if (![item isDir]) {
186 icon = [_iconDict objectForKey:[[item name] pathExtension]];
187 if (!icon) {
188 icon = [[NSWorkspace sharedWorkspace] iconForFileType:[[item name] pathExtension]];
189 [_iconDict setObject:icon forKey:[[item name] pathExtension]];
190 }
191 } else {
192 icon = _folderIcon;
193 }
194 }
195 [icon setSize:NSMakeSize(16, 16)];
196 [[column dataCell] setImage:icon];
197 str = [item name];
198 } else if ([identifier isEqualToString:@"modifieddate"]) {
199 str = [item convertModifiedDateWithWidth:[[_fileOutlineView tableColumnWithIdentifier:@"modifieddate"] width]];
200 //return [item objectForKey:@"modifieddate"]; //using NSDateFormatter in NSCell
201 } else if ([identifier isEqualToString:@"size"]) {
202 //NSDictionary *aLocale = [NSDictionary dictionaryWithObjectsAndKeys:
203 // @"NSPositiveCurrencyFormatString",NSPositiveCurrencyFormatString,nil];
204 //return [[item objectForKey:@"size"] descriptionWithLocale:aLocale];
205 str = [item convertSize];
206 } else if ([identifier isEqualToString:@"kind"]) {
207 str = [item kind];
208 } else {
209 str = nil;
210 }
211 if (!str) str = @"--";
212
213 //������������������������������������������
214 NSMutableParagraphStyle* style = [[[NSMutableParagraphStyle alloc] init] autorelease];
215 [style setLineBreakMode:NSLineBreakByTruncatingMiddle];
216 NSMutableAttributedString* attrString = [[[NSMutableAttributedString alloc] initWithString:str] autorelease];
217 [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0,[str length])];
218 return attrString;
219 }
220
221 /// 10.3���������������������������������
222 /*
223 - (void)outlineView:(NSOutlineView *)outlineView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn
224 {
225
226 }
227 */
228 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectTableColumn:(NSTableColumn *)tableColumn
229 {
230 if (lastSortIdentifier) {
231 if ([lastSortIdentifier isEqualToString:[tableColumn identifier]])
232 //������������������������������������������������������������������������������
233 sortUp = !sortUp;
234 else {
235 //������������������������������������������������������������
236 //������������������������������������������������������������������������
237 [outlineView setIndicatorImage:nil inTableColumn:[outlineView tableColumnWithIdentifier:lastSortIdentifier]];
238 [lastSortIdentifier release];
239 lastSortIdentifier = [NSString stringWithString:[tableColumn identifier]];
240 [lastSortIdentifier retain];
241 sortUp = YES;
242 }
243 } else {
244 //������������������������������������������������
245 lastSortIdentifier = [NSString stringWithString:[tableColumn identifier]];
246 [lastSortIdentifier retain];
247 sortUp = YES;
248 }
249 //���������������������������
250 [[[self document] infoDict] sortBy:lastSortIdentifier order:sortUp];
251 [outlineView setHighlightedTableColumn:tableColumn];
252 [outlineView setIndicatorImage:[NSImage imageNamed:sortUp ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"] inTableColumn:tableColumn];
253 [outlineView reloadData];
254 return NO;
255 }
256
257 #pragma mark -
258 #pragma mark Drag&Drop
259
260 //������������������������������������������������
261 -(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
262 {
263 [[self document] setSelectedArray:items];
264 [outlineView dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"txt"]
265 fromRect:NSMakeRect(0,0,0,0)
266 source:self //outlineView
267 slideBack:NO
268 event:[NSApp currentEvent]];
269
270 return YES;
271
272 //NSString* LPFilePboardType = @"LPFilePboardType";
273 //[pboard declareTypes:[NSArray arrayWithObjects:NSFilesPromisePboardType,nil] owner:self];
274 //[pboard setPropertyList:items forType:LPFilePboardType];
275 //[pboard setPropertyList:[NSArray arrayWithObject:@"html"] forType:NSFilesPromisePboardType];
276 //[self dragPromisedFilesOfTypes:fromRect:source:slideBack:event:];
277 //return YES;
278 }
279
280 - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
281 {
282 NSLog(@"namesOfPromisedFilesDroppedAtDestination");
283 //NSLog(@"number of item=%d,Extract at %@",[_selectedArray count],[dropDestination path]);
284 [[self document] archiveUncompress:[dropDestination path]];
285 //[self showProcessWindow]; //! ������������������������������
286 return [NSArray arrayWithObjects:@"",nil];
287 }
288
289 - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal
290 {
291 //NSLog(@"draggingSourceOperationMaskForLocal");
292 if (isLocal) return NSDragOperationNone;
293 else return NSDragOperationCopy;
294 }
295
296 #pragma mark -
297 #pragma mark Show Information
298
299 - (void)refreshStatus
300 {
301 //NSLog(@"refreshStatus");
302 if (_fileOutlineView) {
303 NSNumberFormatter* numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
304 [numberFormatter setFormat:@"###,###,###,###,###,##0"];
305 int numberOfSelectedRows = [_fileOutlineView numberOfSelectedRows];
306 if (numberOfSelectedRows > 0) {
307 unsigned long long totalSize = 0;
308 int i;
309 for (i=0;i<[_fileOutlineView numberOfRows];i++) {
310 if ([_fileOutlineView isRowSelected:i]) {
311 totalSize += [[(LPFile*)[_fileOutlineView itemAtRow:i] size] unsignedLongLongValue];
312 }
313 }
314 [_statusTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"StatusSelectedFormat", nil),[numberFormatter stringForObjectValue:[NSNumber numberWithUnsignedLongLong:totalSize]],numberOfSelectedRows,[_fileOutlineView numberOfRows]]];
315 } else {
316 NSString* totalNumOfChildrenString = [[[(LPDocument*)[self document] infoDict] totalNumOfChildren] stringValue];
317 NSString* totalSizeString = [numberFormatter stringForObjectValue:[[(LPDocument*)[self document] infoDict] totalSize]];
318 [_statusTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"StatusFormat", nil),totalNumOfChildrenString,totalSizeString]];
319 }
320 } else {
321 [_statusTextField setStringValue:NSLocalizedString(@"StatusJobFinished", nil)];
322 }
323 }
324
325 //���������������������������������������������������������������������������������������������������������������
326 - (void)progressUpdate
327 {
328 //NSLog(@"progressUpdate start");
329 NSString* formatString;
330 if (_processMode == LPProcessCompressMode)
331 formatString = NSLocalizedString(@"StatusUncompressingFormat", nil);
332 else // if (_processMode == LPProcessUncompressMode)
333 formatString = NSLocalizedString(@"StatusCompressingFormat", nil);
334 NSString* title = [NSString string];
335 NSNumber* perProgress = [[[self document] plugin] processInfo:&title];
336 [_statusTextField setStringValue:[NSString stringWithFormat:formatString,title]];
337 if (perProgress) {
338 NSLog(@"Progressbar=%d/%d",(int)[_progressIndicator doubleValue],(int)[_progressIndicator maxValue]);
339 [_progressIndicator setDoubleValue:[perProgress doubleValue]];
340 } else {
341 [_progressIndicator startAnimation:self];
342 }
343 //NSLog(@"progressUpdate end");
344 }
345
346 - (IBAction)stopProcess:(id)sender
347 {
348 [[self document] close];
349 }
350
351 - (IBAction)pauseProcess:(id)sender
352 {
353
354 }
355
356 #pragma mark -
357 #pragma mark Dialog
358
359 - (LPDialogResult)showChoiceAlert:(BOOL*)flag title:(NSString*)title defaultButton:(NSString*)defaultButton
360 alternateButton:(NSString*)alternateButton otherButton:(NSString*)otherButton
361 message:(NSString*)message
362 {
363 NSLog(@"showChoiceAlert");
364
365 if (!_choicePanel) [self loadDialogs];
366 if (title) [_choiceTitleTextField setStringValue:title];
367 if (defaultButton) [_choiceYesButton setTitle:defaultButton];
368 if (alternateButton) {
369 [_choiceNoButton setTitle:alternateButton];
370 [_choiceNoButton setHidden:NO];
371 } else [_choiceNoButton setHidden:YES];
372 if (otherButton) {
373 [_choiceCancelButton setTitle:otherButton];
374 [_choiceCancelButton setHidden:NO];
375 } else [_choiceCancelButton setHidden:YES];
376 if (message) [_choiceInfoTextField setStringValue:message];
377 [_choiceCheckButton setHidden:(flag) ? NO : YES];
378
379 [NSApp beginSheet:_choicePanel
380 modalForWindow:[self window]
381 modalDelegate:self
382 didEndSelector:@selector(didEndChoice)
383 contextInfo:nil];
384 LPDialogResult result = [NSApp runModalForWindow:_choicePanel];
385 if (flag) *flag = ([_choiceCheckButton state] == NSOnState) ? YES : NO;
386 [NSApp endSheet:_choicePanel]; //!���������������������������������������������������������������������������������������������������������
387 [_choicePanel orderOut:self];
388 return result;
389 }
390
391 - (IBAction)choiceYes:(id)sender
392 {
393 [NSApp stopModalWithCode:LPDialogYES];
394 }
395
396 - (IBAction)choiceNo:(id)sender
397 {
398 [NSApp stopModalWithCode:LPDialogNO];
399 }
400
401 - (IBAction)choiceCancel:(id)sender
402 {
403 [NSApp stopModalWithCode:LPDialogCancel];
404 }
405
406 - (void)didEndChoice
407 {
408 NSLog(@"didEndChoice");
409 [_choicePanel orderOut:self];
410 }
411
412 - (void)showErrorAlertWithErrorID:(LPError)error
413 {
414 NSString* title;
415 NSString* info;
416 switch (error) {
417 case LPErrorWarning:
418 title = NSLocalizedString(@"DialogErrorWarningTitle",nil);
419 info = NSLocalizedString(@"DialogErrorWarningInfo",nil);
420 break;
421 case LPErrorNotImplementMethod:
422 title = NSLocalizedString(@"DialogErrorNotImplementMethodTitle",nil);
423 info = NSLocalizedString(@"DialogErrorNotImplementMethodInfo",nil);
424 break;
425 case LPErrorBadArgument:
426 title = NSLocalizedString(@"ErrorBadArgumentTitle",nil);
427 info = NSLocalizedString(@"ErrorBadArgumentInfo",nil);
428 break;
429 case LPErrorNotExist:
430 title = NSLocalizedString(@"DialogErrorNotExistTitle",nil);
431 info = NSLocalizedString(@"DialogErrorNotExistInfo",nil);
432 break;
433 case LPErrorBrokenArchive:
434 title = NSLocalizedString(@"DialogErrorBrokenArchiveTitle",nil);
435 info = NSLocalizedString(@"DialogErrorBrokenArchiveInfo",nil);
436 break;
437 case LPErrorLockedArchive:
438 title = NSLocalizedString(@"DialogErrorLockedArchiveTitle",nil);
439 info = NSLocalizedString(@"DialogErrorLockedArchiveInfo",nil);
440 break;
441 case LPErrorNotSupportFormat:
442 title = NSLocalizedString(@"DialogErrorNotSupportFormatTitle",nil);
443 info = NSLocalizedString(@"DialogErrorNotSupportFormatInfo",nil);
444 break;
445 case LPErrorRequestPassword:
446 title = NSLocalizedString(@"DialogErrorRequestPasswordTitle",nil);
447 info = NSLocalizedString(@"DialogErrorRequestPasswordInfo",nil);
448 break;
449 case LPErrorBadPassword:
450 title = NSLocalizedString(@"DialogErrorBadPasswordTitle",nil);
451 info = NSLocalizedString(@"DialogErrorBadPasswordInfo",nil);
452 break;
453 case LPErrorFileOpening:
454 title = NSLocalizedString(@"DialogErrorFileOpeningTitle",nil);
455 info = NSLocalizedString(@"DialogErrorFileOpeningInfo",nil);
456 case LPErrorFileReading:
457 title = NSLocalizedString(@"DialogErrorFileReadingTitle",nil);
458 info = NSLocalizedString(@"DialogErrorFileReadingInfo",nil);
459 break;
460 case LPErrorFileWriting:
461 title = NSLocalizedString(@"DialogErrorFileWritingTitle",nil);
462 info = NSLocalizedString(@"DialogErrorFileWritingInfo",nil);
463 break;
464 case LPErrorFailureAllocateMemory:
465 title = NSLocalizedString(@"DialogErrorFailureAllocateMemoryTitle",nil);
466 info = NSLocalizedString(@"DialogErrorFailureAllocateMemoryInfo",nil);
467 break;
468 case LPErrorNoError:
469 title = NSLocalizedString(@"DialogErrorNoErrorTitle",nil);
470 info = NSLocalizedString(@"DialogErrorNoErrorInfo",nil);
471 break;
472 default:
473 title = NSLocalizedString(@"DialogErrorUnknownTitle",nil);
474 info = NSLocalizedString(@"DialogErrorUnknownInfo",nil);
475 }
476 [self showErrorAlert:title info:info];
477 }
478
479 - (void)showErrorAlert:(NSString*)title info:(NSString*)info
480 {
481 NSLog(@"showErrorAlert");
482 if (!_errorPanel) [self loadDialogs];
483 if (title) [_errorTitleTextField setStringValue:title];
484 if (info) [_errorInfoTextField setStringValue:info];
485 [NSApp beginSheet:_errorPanel
486 modalForWindow:[self window]
487 modalDelegate:self
488 didEndSelector:NULL
489 contextInfo:nil];
490 [NSApp runModalForWindow:_errorPanel];
491
492 [NSApp endSheet:_errorPanel];
493 [_errorPanel orderOut:self];
494 }
495
496 - (IBAction)errorAccept:(id)sender
497 {
498 [NSApp stopModal];
499 }
500
501 - (NSString*)askPassword
502 {
503 NSLog(@"askPassword");
504 if (!_passwordPanel) [self loadDialogs];
505 [NSApp beginSheet:_passwordPanel
506 modalForWindow:[self window]
507 modalDelegate:self
508 didEndSelector:NULL
509 contextInfo:nil];
510 int result = [NSApp runModalForWindow:_passwordPanel];
511 [NSApp endSheet:_passwordPanel]; //!���������������������������������������������������������������������������������������������������������
512 [_passwordPanel orderOut:self];
513 if (result == NSOKButton)
514 return [_passwordTextField stringValue];
515 else
516 return nil;
517 }
518
519 - (IBAction)passwordAccept:(id)sender
520 {
521 [NSApp stopModalWithCode:NSOKButton];
522 }
523
524 - (IBAction)passwordCancel:(id)sender
525 {
526 [NSApp stopModalWithCode:NSCancelButton];
527 }
528
529 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26