2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2012-03-15 18:28:40 +00:00
|
|
|
Copyright 2012 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 "ResultWindow.h"
|
|
|
|
#import "Dialogs.h"
|
|
|
|
#import "ProgressController.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "Consts.h"
|
2011-09-13 20:31:25 +00:00
|
|
|
#import "PrioritizeDialog.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@implementation ResultWindowBase
|
2011-01-14 12:56:50 +00:00
|
|
|
- (id)initWithParentApp:(AppDelegateBase *)aApp;
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
2011-01-14 12:56:50 +00:00
|
|
|
self = [super initWithWindowNibName:@"ResultWindow"];
|
|
|
|
app = aApp;
|
2012-01-13 19:43:43 +00:00
|
|
|
model = [app model];
|
|
|
|
[[self window] setTitle:fmt(@"%@ Results", [model appName])];
|
2011-01-14 12:56:50 +00:00
|
|
|
columnsMenu = [app columnsMenu];
|
2010-09-24 14:01:38 +00:00
|
|
|
/* Put a cute iTunes-like bottom bar */
|
|
|
|
[[self window] setContentBorderThickness:28 forEdge:NSMinYEdge];
|
2012-01-13 20:25:34 +00:00
|
|
|
table = [[ResultTable alloc] initWithPyRef:[model resultTable] view:matches];
|
|
|
|
statsLabel = [[StatsLabel alloc] initWithPyRef:[model statsLabel] view:stats];
|
|
|
|
problemDialog = [[ProblemDialog alloc] initWithPyRef:[model problemDialog]];
|
2009-10-30 12:56:05 +00:00
|
|
|
[self initResultColumns];
|
|
|
|
[self fillColumnsMenu];
|
2010-02-09 13:50:27 +00:00
|
|
|
[matches setTarget:self];
|
2010-02-09 13:55:51 +00:00
|
|
|
[matches setDoubleAction:@selector(openClicked:)];
|
2012-03-20 19:43:47 +00:00
|
|
|
[self adjustUIToLocalization];
|
2010-02-09 13:50:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobStarted:) name:JobStarted object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobInProgress:) name:JobInProgress object:nil];
|
2011-01-14 12:56:50 +00:00
|
|
|
return self;
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 12:56:05 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2010-09-24 13:48:59 +00:00
|
|
|
[table release];
|
2010-04-12 10:21:01 +00:00
|
|
|
[statsLabel release];
|
|
|
|
[problemDialog release];
|
2009-10-30 12:56:05 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-01-15 10:38:59 +00:00
|
|
|
/* Virtual */
|
|
|
|
- (void)initResultColumns
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setScanOptions
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:48:47 +00:00
|
|
|
/* Helpers */
|
2009-10-30 12:56:05 +00:00
|
|
|
- (void)fillColumnsMenu
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
NSArray *menuItems = [[[table columns] model] menuItems];
|
2011-11-26 15:55:14 +00:00
|
|
|
for (NSInteger i=0; i < [menuItems count]; i++) {
|
|
|
|
NSArray *pair = [menuItems objectAtIndex:i];
|
|
|
|
NSString *display = [pair objectAtIndex:0];
|
|
|
|
BOOL marked = n2b([pair objectAtIndex:1]);
|
|
|
|
NSMenuItem *mi = [columnsMenu addItemWithTitle:display action:@selector(toggleColumn:) keyEquivalent:@""];
|
2009-10-30 12:56:05 +00:00
|
|
|
[mi setTarget:self];
|
2011-11-26 15:55:14 +00:00
|
|
|
[mi setState:marked ? NSOnState : NSOffState];
|
|
|
|
[mi setTag:i];
|
2009-10-30 12:56:05 +00:00
|
|
|
}
|
|
|
|
[columnsMenu addItem:[NSMenuItem separatorItem]];
|
2011-01-18 14:35:14 +00:00
|
|
|
NSMenuItem *mi = [columnsMenu addItemWithTitle:TR(@"Reset to Default")
|
|
|
|
action:@selector(resetColumnsToDefault:) keyEquivalent:@""];
|
2009-10-30 12:56:05 +00:00
|
|
|
[mi setTarget:self];
|
|
|
|
}
|
|
|
|
|
2010-09-25 13:37:18 +00:00
|
|
|
- (void)sendMarkedToTrash:(BOOL)hardlinkDeleted
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
2012-01-13 19:43:43 +00:00
|
|
|
[model setRemoveEmptyFolders:n2b([ud objectForKey:@"removeEmptyFolders"])];
|
2010-09-25 13:37:18 +00:00
|
|
|
if (hardlinkDeleted) {
|
2012-01-13 19:43:43 +00:00
|
|
|
[model hardlinkMarked];
|
2010-09-25 13:37:18 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 19:43:43 +00:00
|
|
|
[model deleteMarked];
|
2010-09-25 13:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 12:51:00 +00:00
|
|
|
- (void)updateOptionSegments
|
|
|
|
{
|
2011-01-14 12:56:50 +00:00
|
|
|
[optionsSwitch setSelected:[[app detailsPanel] isVisible] forSegment:0];
|
2011-01-13 12:51:00 +00:00
|
|
|
[optionsSwitch setSelected:[table powerMarkerMode] forSegment:1];
|
|
|
|
[optionsSwitch setSelected:[table deltaValuesMode] forSegment:2];
|
|
|
|
}
|
|
|
|
|
2012-03-09 18:47:28 +00:00
|
|
|
- (void)showProblemDialog
|
|
|
|
{
|
|
|
|
[problemDialog showWindow:self];
|
|
|
|
}
|
|
|
|
|
2012-03-20 19:43:47 +00:00
|
|
|
- (void)adjustUIToLocalization
|
|
|
|
{
|
|
|
|
NSString *lang = [[NSBundle preferredLocalizationsFromArray:[[NSBundle mainBundle] localizations]] objectAtIndex:0];
|
|
|
|
NSInteger seg1delta = 0;
|
|
|
|
NSInteger seg2delta = 0;
|
|
|
|
if ([lang isEqual:@"ru"]) {
|
|
|
|
seg2delta = 20;
|
|
|
|
}
|
|
|
|
else if ([lang isEqual:@"uk"]) {
|
|
|
|
seg2delta = 20;
|
|
|
|
}
|
|
|
|
else if ([lang isEqual:@"hy"]) {
|
|
|
|
seg1delta = 20;
|
|
|
|
}
|
|
|
|
if (seg1delta || seg2delta) {
|
|
|
|
[optionsSwitch setWidth:[optionsSwitch widthForSegment:0]+seg1delta forSegment:0];
|
|
|
|
[optionsSwitch setWidth:[optionsSwitch widthForSegment:1]+seg2delta forSegment:1];
|
|
|
|
NSSize s = [optionsToolbarItem maxSize];
|
|
|
|
s.width += seg1delta + seg2delta;
|
|
|
|
[optionsToolbarItem setMaxSize:s];
|
|
|
|
[optionsToolbarItem setMinSize:s];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
/* Actions */
|
2011-01-13 12:51:00 +00:00
|
|
|
- (IBAction)changeOptions:(id)sender
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
2011-01-13 12:51:00 +00:00
|
|
|
NSInteger seg = [optionsSwitch selectedSegment];
|
|
|
|
if (seg == 0) {
|
|
|
|
[self toggleDetailsPanel:sender];
|
|
|
|
}
|
|
|
|
else if (seg == 1) {
|
|
|
|
[self togglePowerMarker:sender];
|
|
|
|
}
|
|
|
|
else if (seg == 2) {
|
|
|
|
[self toggleDelta:sender];
|
|
|
|
}
|
2009-06-16 08:04:23 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
- (IBAction)copyMarked:(id)sender
|
|
|
|
{
|
2012-03-10 19:32:56 +00:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
[model setRemoveEmptyFolders:n2b([ud objectForKey:@"removeEmptyFolders"])];
|
|
|
|
[model setCopyMoveDestType:n2i([ud objectForKey:@"recreatePathType"])];
|
|
|
|
[model copyMarked];
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)deleteMarked:(id)sender
|
|
|
|
{
|
2010-09-25 13:37:18 +00:00
|
|
|
[self sendMarkedToTrash:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)hardlinkMarked:(id)sender
|
|
|
|
{
|
|
|
|
[self sendMarkedToTrash:YES];
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 14:05:00 +00:00
|
|
|
- (IBAction)exportToXHTML:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
NSString *exported = [model exportToXHTML];
|
2009-09-01 14:05:00 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] openFile:exported];
|
|
|
|
}
|
|
|
|
|
2010-02-06 10:40:10 +00:00
|
|
|
- (IBAction)filter:(id)sender
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
2012-01-13 19:43:43 +00:00
|
|
|
[model setEscapeFilterRegexp:!n2b([ud objectForKey:@"useRegexpFilter"])];
|
|
|
|
[model applyFilter:[filterField stringValue]];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)ignoreSelected:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model addSelectedToIgnoreList];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2010-04-12 15:43:24 +00:00
|
|
|
- (IBAction)invokeCustomCommand:(id)sender
|
|
|
|
{
|
2012-03-10 15:58:08 +00:00
|
|
|
[model invokeCustomCommand];
|
2010-04-12 15:43:24 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 10:40:10 +00:00
|
|
|
- (IBAction)markAll:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markAll];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)markInvert:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markInvert];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)markNone:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markNone];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)markSelected:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model toggleSelectedMark];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
- (IBAction)moveMarked:(id)sender
|
|
|
|
{
|
2012-03-10 19:32:56 +00:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
[model setRemoveEmptyFolders:n2b([ud objectForKey:@"removeEmptyFolders"])];
|
|
|
|
[model setCopyMoveDestType:n2i([ud objectForKey:@"recreatePathType"])];
|
|
|
|
[model moveMarked];
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2010-02-09 13:55:51 +00:00
|
|
|
- (IBAction)openClicked:(id)sender
|
|
|
|
{
|
|
|
|
if ([matches clickedRow] < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[matches selectRowIndexes:[NSIndexSet indexSetWithIndex:[matches clickedRow]] byExtendingSelection:NO];
|
2012-01-13 19:43:43 +00:00
|
|
|
[model openSelected];
|
2010-02-09 13:55:51 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 10:40:10 +00:00
|
|
|
- (IBAction)openSelected:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model openSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)removeMarked:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model removeMarked];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)removeSelected:(id)sender
|
|
|
|
{
|
2012-03-10 15:58:08 +00:00
|
|
|
[model removeSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)renameSelected:(id)sender
|
|
|
|
{
|
|
|
|
NSInteger col = [matches columnWithIdentifier:@"0"];
|
|
|
|
NSInteger row = [matches selectedRow];
|
|
|
|
[matches editColumn:col row:row withEvent:[NSApp currentEvent] select:YES];
|
|
|
|
}
|
|
|
|
|
2011-09-13 20:31:25 +00:00
|
|
|
- (IBAction)reprioritizeResults:(id)sender
|
|
|
|
{
|
2012-01-15 22:24:30 +00:00
|
|
|
PrioritizeDialog *dlg = [[PrioritizeDialog alloc] initWithApp:model];
|
2011-09-13 22:19:46 +00:00
|
|
|
NSInteger result = [NSApp runModalForWindow:[dlg window]];
|
|
|
|
if (result == NSRunStoppedResponse) {
|
2012-01-13 20:25:34 +00:00
|
|
|
[[dlg model] performReprioritization];
|
2011-09-13 22:19:46 +00:00
|
|
|
}
|
|
|
|
[dlg release];
|
|
|
|
[[self window] makeKeyAndOrderFront:nil];
|
2011-09-13 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 14:40:17 +00:00
|
|
|
- (IBAction)resetColumnsToDefault:(id)sender
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[[table columns] model] resetToDefaults];
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 10:40:10 +00:00
|
|
|
- (IBAction)revealSelected:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model revealSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 11:06:18 +00:00
|
|
|
- (IBAction)saveResults:(id)sender
|
|
|
|
{
|
|
|
|
NSSavePanel *sp = [NSSavePanel savePanel];
|
|
|
|
[sp setCanCreateDirectories:YES];
|
|
|
|
[sp setAllowedFileTypes:[NSArray arrayWithObject:@"dupeguru"]];
|
2011-11-04 17:10:11 +00:00
|
|
|
[sp setTitle:TR(@"Select a file to save your results to")];
|
2010-08-13 11:06:18 +00:00
|
|
|
if ([sp runModal] == NSOKButton) {
|
2012-01-13 19:43:43 +00:00
|
|
|
[model saveResultsAs:[sp filename]];
|
2011-01-14 12:56:50 +00:00
|
|
|
[[app recentResults] addFile:[sp filename]];
|
2010-08-13 11:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 16:15:48 +00:00
|
|
|
- (IBAction)startDuplicateScan:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
if ([model resultsAreModified]) {
|
2011-11-04 17:10:11 +00:00
|
|
|
if ([Dialogs askYesNo:TR(@"You have unsaved results, do you really want to continue?")] == NSAlertSecondButtonReturn) // NO
|
2011-01-15 10:38:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
[self setScanOptions];
|
2012-01-13 19:43:43 +00:00
|
|
|
[model doScan];
|
2010-02-12 16:15:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-14 14:48:47 +00:00
|
|
|
- (IBAction)switchSelected:(id)sender
|
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model makeSelectedReference];
|
2009-06-14 14:48:47 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 12:56:05 +00:00
|
|
|
- (IBAction)toggleColumn:(id)sender
|
|
|
|
{
|
|
|
|
NSMenuItem *mi = sender;
|
2012-01-13 16:49:34 +00:00
|
|
|
BOOL checked = [[[table columns] model] toggleMenuItem:[mi tag]];
|
2011-11-26 15:55:14 +00:00
|
|
|
[mi setState:checked ? NSOnState : NSOffState];
|
2009-10-30 12:56:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 12:51:00 +00:00
|
|
|
- (IBAction)toggleDetailsPanel:(id)sender
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2011-01-14 12:56:50 +00:00
|
|
|
[[app detailsPanel] toggleVisibility];
|
2011-01-13 12:51:00 +00:00
|
|
|
[self updateOptionSegments];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 12:51:00 +00:00
|
|
|
- (IBAction)toggleDelta:(id)sender
|
2009-11-02 15:16:34 +00:00
|
|
|
{
|
2011-01-13 12:51:00 +00:00
|
|
|
[table setDeltaValuesMode:![table deltaValuesMode]];
|
|
|
|
[self updateOptionSegments];
|
2009-11-02 15:16:34 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 08:04:23 +00:00
|
|
|
- (IBAction)togglePowerMarker:(id)sender
|
|
|
|
{
|
2011-01-13 12:51:00 +00:00
|
|
|
[table setPowerMarkerMode:![table powerMarkerMode]];
|
|
|
|
[self updateOptionSegments];
|
2009-06-16 08:04:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 19:59:11 +00:00
|
|
|
- (IBAction)toggleQuicklookPanel:(id)sender
|
|
|
|
{
|
|
|
|
if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]) {
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] orderOut:nil];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Quicklook */
|
|
|
|
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel;
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)beginPreviewPanelControl:(QLPreviewPanel *)panel
|
|
|
|
{
|
|
|
|
// This document is now responsible of the preview panel
|
|
|
|
// It is allowed to set the delegate, data source and refresh panel.
|
|
|
|
previewPanel = [panel retain];
|
|
|
|
panel.delegate = table;
|
|
|
|
panel.dataSource = table;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)endPreviewPanelControl:(QLPreviewPanel *)panel
|
|
|
|
{
|
|
|
|
// This document loses its responsisibility on the preview panel
|
|
|
|
// Until the next call to -beginPreviewPanelControl: it must not
|
|
|
|
// change the panel's delegate, data source or refresh it.
|
|
|
|
[previewPanel release];
|
|
|
|
previewPanel = nil;
|
|
|
|
}
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
- (void)jobInProgress:(NSNotification *)aNotification
|
|
|
|
{
|
2011-11-04 17:10:11 +00:00
|
|
|
[Dialogs showMessage:TR(@"A previous action is still hanging in there. You can't start a new one yet. Wait a few seconds, then try again.")];
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)jobStarted:(NSNotification *)aNotification
|
|
|
|
{
|
2011-01-14 14:34:10 +00:00
|
|
|
[[self window] makeKeyAndOrderFront:nil];
|
2009-06-01 09:55:11 +00:00
|
|
|
NSDictionary *ui = [aNotification userInfo];
|
|
|
|
NSString *desc = [ui valueForKey:@"desc"];
|
|
|
|
[[ProgressController mainProgressController] setJobDesc:desc];
|
|
|
|
NSString *jobid = [ui valueForKey:@"jobid"];
|
|
|
|
[[ProgressController mainProgressController] setJobId:jobid];
|
|
|
|
[[ProgressController mainProgressController] showSheetForParent:[self window]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
|
|
|
{
|
|
|
|
return ![[ProgressController mainProgressController] isShown];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
|
|
|
{
|
|
|
|
return ![[ProgressController mainProgressController] isShown];
|
|
|
|
}
|
|
|
|
@end
|