2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2010-01-01 20:11:34 +00:00
|
|
|
Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2010-09-30 10:17:41 +00:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
http://www.hardcoded.net/licenses/bsd_license
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "ProgressController.h"
|
2010-09-29 14:49:50 +00:00
|
|
|
#import "HSFairwareReminder.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#import "Utils.h"
|
|
|
|
#import "Consts.h"
|
2011-01-13 15:20:03 +00:00
|
|
|
#import "Dialogs.h"
|
2010-02-05 15:51:00 +00:00
|
|
|
#import <Sparkle/SUUpdater.h>
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@implementation AppDelegateBase
|
2011-01-13 15:20:03 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
_recentResults = [[HSRecentFiles alloc] initWithName:@"recentResults" menu:recentResultsMenu];
|
|
|
|
[_recentResults setDelegate:self];
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
- (PyDupeGuruBase *)py { return py; }
|
2010-02-05 16:05:00 +00:00
|
|
|
- (DirectoryPanel *)directoryPanel
|
|
|
|
{
|
|
|
|
if (!_directoryPanel)
|
|
|
|
_directoryPanel = [[DirectoryPanel alloc] initWithParentApp:self];
|
|
|
|
return _directoryPanel;
|
|
|
|
}
|
|
|
|
|
2010-02-05 16:15:45 +00:00
|
|
|
- (DetailsPanel *)detailsPanel
|
|
|
|
{
|
|
|
|
if (!_detailsPanel)
|
|
|
|
_detailsPanel = [[DetailsPanel alloc] initWithPy:py];
|
|
|
|
return _detailsPanel;
|
|
|
|
}
|
2009-10-30 14:40:17 +00:00
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (HSRecentFiles *)recentResults
|
2010-02-05 15:51:00 +00:00
|
|
|
{
|
2011-01-13 15:20:03 +00:00
|
|
|
return _recentResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)homepageURL
|
|
|
|
{
|
|
|
|
return @""; // Virtual
|
2010-02-05 15:51:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 12:00:44 +00:00
|
|
|
- (IBAction)showAboutBox:(id)sender
|
|
|
|
{
|
|
|
|
if (_aboutBox == nil) {
|
|
|
|
_aboutBox = [[HSAboutBox alloc] initWithApp:py];
|
|
|
|
}
|
|
|
|
[[_aboutBox window] makeKeyAndOrderFront:sender];
|
|
|
|
}
|
|
|
|
|
2011-01-12 16:30:57 +00:00
|
|
|
- (IBAction)openWebsite:(id)sender
|
|
|
|
{
|
2011-01-13 15:20:03 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[self homepageURL]]];
|
2011-01-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)openHelp:(id)sender
|
|
|
|
{
|
|
|
|
NSBundle *b = [NSBundle mainBundle];
|
|
|
|
NSString *p = [b pathForResource:@"index" ofType:@"html" inDirectory:@"help"];
|
|
|
|
NSURL *u = [NSURL fileURLWithPath:p];
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:u];
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (IBAction)toggleDirectories:(id)sender
|
|
|
|
{
|
|
|
|
[[self directoryPanel] toggleVisible:sender];
|
|
|
|
}
|
|
|
|
|
2009-10-30 14:40:17 +00:00
|
|
|
/* Delegate */
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
[[ProgressController mainProgressController] setWorker:py];
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
//Restore Columns
|
|
|
|
NSArray *columnsOrder = [ud arrayForKey:@"columnsOrder"];
|
|
|
|
NSDictionary *columnsWidth = [ud dictionaryForKey:@"columnsWidth"];
|
|
|
|
if ([columnsOrder count])
|
|
|
|
[result restoreColumnsPosition:columnsOrder widths:columnsWidth];
|
|
|
|
else
|
|
|
|
[result resetColumnsToDefault:nil];
|
2010-09-29 14:49:50 +00:00
|
|
|
[HSFairwareReminder showNagWithApp:[self py]];
|
2011-01-13 15:20:03 +00:00
|
|
|
[py loadSession];
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
2010-02-05 15:31:09 +00:00
|
|
|
|
|
|
|
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if (![[result window] isVisible])
|
|
|
|
[result showWindow:NSApp];
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
|
|
|
{
|
|
|
|
if ([py resultsAreModified]) {
|
|
|
|
NSString *msg = @"You have unsaved results, do you really want to quit?";
|
|
|
|
if ([Dialogs askYesNo:msg] == NSAlertSecondButtonReturn) { // NO
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NSTerminateNow;
|
|
|
|
}
|
|
|
|
|
2010-02-05 15:31:09 +00:00
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
[ud setObject: [result getColumnsOrder] forKey:@"columnsOrder"];
|
|
|
|
[ud setObject: [result getColumnsWidth] forKey:@"columnsWidth"];
|
|
|
|
NSInteger sc = [ud integerForKey:@"sessionCountSinceLastIgnorePurge"];
|
2011-01-13 15:20:03 +00:00
|
|
|
if (sc >= 10) {
|
2010-02-05 15:31:09 +00:00
|
|
|
sc = -1;
|
|
|
|
[py purgeIgnoreList];
|
|
|
|
}
|
|
|
|
sc++;
|
2011-01-13 15:20:03 +00:00
|
|
|
[py saveSession];
|
2010-02-05 15:31:09 +00:00
|
|
|
[ud setInteger:sc forKey:@"sessionCountSinceLastIgnorePurge"];
|
|
|
|
// NSApplication does not release nib instances objects, we must do it manually
|
|
|
|
// Well, it isn't needed because the memory is freed anyway (we are quitting the application
|
2011-01-13 15:20:03 +00:00
|
|
|
// But I need to release HSRecentFiles so it saves the user defaults
|
|
|
|
[_directoryPanel release];
|
|
|
|
[_recentResults release];
|
2010-02-05 15:31:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:20:03 +00:00
|
|
|
- (void)recentFileClicked:(NSString *)path
|
2010-02-05 15:51:00 +00:00
|
|
|
{
|
2011-01-13 15:20:03 +00:00
|
|
|
[py loadResultsFrom:path];
|
2010-02-05 15:51:00 +00:00
|
|
|
}
|
2009-06-01 09:55:11 +00:00
|
|
|
@end
|