2009-08-05 08:59:46 +00:00
|
|
|
/*
|
2015-01-03 21:30:57 +00:00
|
|
|
Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
|
2015-01-03 21:33:16 +00:00
|
|
|
This software is licensed under the "GPLv3" 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
|
2015-01-03 21:33:16 +00:00
|
|
|
http://www.gnu.org/licenses/gpl-3.0.html
|
2009-08-05 08:59:46 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-05 01:18:14 +00:00
|
|
|
#import "ResultWindow.h"
|
2012-07-26 16:18:39 +00:00
|
|
|
#import "ResultWindow_UI.h"
|
2009-06-01 09:55:11 +00:00
|
|
|
#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
|
|
|
|
2016-06-05 01:18:14 +00:00
|
|
|
@implementation ResultWindow
|
2012-07-26 16:18:39 +00:00
|
|
|
|
|
|
|
@synthesize optionsSwitch;
|
|
|
|
@synthesize optionsToolbarItem;
|
|
|
|
@synthesize matches;
|
|
|
|
@synthesize stats;
|
|
|
|
@synthesize filterField;
|
|
|
|
|
2011-01-14 12:56:50 +00:00
|
|
|
- (id)initWithParentApp:(AppDelegateBase *)aApp;
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
2012-07-26 16:18:39 +00:00
|
|
|
self = [super initWithWindow:nil];
|
2011-01-14 12:56:50 +00:00
|
|
|
app = aApp;
|
2012-01-13 19:43:43 +00:00
|
|
|
model = [app model];
|
2012-07-26 16:18:39 +00:00
|
|
|
[self setWindow:createResultWindow_UI(self)];
|
2012-08-30 20:08:21 +00:00
|
|
|
[[self window] setTitle:fmt(NSLocalizedString(@"%@ Results", @""), [model appName])];
|
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]];
|
2012-05-30 16:10:56 +00:00
|
|
|
deletionOptions = [[DeletionOptions alloc] initWithPyRef:[model deletionOptions]];
|
2016-06-05 01:18:14 +00:00
|
|
|
[aApp initResultColumns:table];
|
2012-07-31 14:42:39 +00:00
|
|
|
[[table columns] setColumnsAsReadOnly];
|
2009-10-30 12:56:05 +00:00
|
|
|
[self fillColumnsMenu];
|
2010-02-09 13:50:27 +00:00
|
|
|
[matches setTarget:self];
|
2012-07-29 15:16:04 +00:00
|
|
|
[matches setDoubleAction:@selector(openClicked)];
|
2012-03-20 19:43:47 +00:00
|
|
|
[self adjustUIToLocalization];
|
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];
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:48:47 +00:00
|
|
|
/* Helpers */
|
2009-10-30 12:56:05 +00:00
|
|
|
- (void)fillColumnsMenu
|
|
|
|
{
|
2012-07-31 14:35:19 +00:00
|
|
|
[[app columnsMenu] removeAllItems];
|
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]);
|
2012-07-27 22:30:34 +00:00
|
|
|
NSMenuItem *mi = [[app 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
|
|
|
}
|
2012-07-27 22:30:34 +00:00
|
|
|
[[app columnsMenu] addItem:[NSMenuItem separatorItem]];
|
2012-08-01 20:34:12 +00:00
|
|
|
NSMenuItem *mi = [[app columnsMenu] addItemWithTitle:NSLocalizedString(@"Reset to Default", @"")
|
2012-07-29 15:16:04 +00:00
|
|
|
action:@selector(resetColumnsToDefault) keyEquivalent:@""];
|
2009-10-30 12:56:05 +00:00
|
|
|
[mi setTarget:self];
|
|
|
|
}
|
|
|
|
|
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 */
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)changeOptions
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
2011-01-13 12:51:00 +00:00
|
|
|
NSInteger seg = [optionsSwitch selectedSegment];
|
|
|
|
if (seg == 0) {
|
2012-07-29 15:16:04 +00:00
|
|
|
[self toggleDetailsPanel];
|
2011-01-13 12:51:00 +00:00
|
|
|
}
|
|
|
|
else if (seg == 1) {
|
2012-07-29 15:16:04 +00:00
|
|
|
[self togglePowerMarker];
|
2011-01-13 12:51:00 +00:00
|
|
|
}
|
|
|
|
else if (seg == 2) {
|
2012-07-29 15:16:04 +00:00
|
|
|
[self toggleDelta];
|
2011-01-13 12:51:00 +00:00
|
|
|
}
|
2009-06-16 08:04:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)copyMarked
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)trashMarked
|
2010-09-25 13:37:18 +00:00
|
|
|
{
|
2012-05-30 16:10:56 +00:00
|
|
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
[model setRemoveEmptyFolders:n2b([ud objectForKey:@"removeEmptyFolders"])];
|
|
|
|
[model deleteMarked];
|
2009-06-01 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)filter
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)focusOnFilterField
|
2012-06-01 14:00:05 +00:00
|
|
|
{
|
|
|
|
[[self window] makeFirstResponder:filterField];
|
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)ignoreSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model addSelectedToIgnoreList];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)invokeCustomCommand
|
2010-04-12 15:43:24 +00:00
|
|
|
{
|
2012-03-10 15:58:08 +00:00
|
|
|
[model invokeCustomCommand];
|
2010-04-12 15:43:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)markAll
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markAll];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)markInvert
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markInvert];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)markNone
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model markNone];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)markSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model toggleSelectedMark];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)moveMarked
|
2009-06-01 09:55:11 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)openClicked
|
2010-02-09 13:55:51 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)openSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model openSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)removeMarked
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model removeMarked];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)removeSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-03-10 15:58:08 +00:00
|
|
|
[model removeSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)renameSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-07-31 14:42:39 +00:00
|
|
|
NSInteger col = [matches columnWithIdentifier:@"name"];
|
2010-02-06 10:40:10 +00:00
|
|
|
NSInteger row = [matches selectedRow];
|
|
|
|
[matches editColumn:col row:row withEvent:[NSApp currentEvent] select:YES];
|
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)reprioritizeResults
|
2011-09-13 20:31:25 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)resetColumnsToDefault
|
2009-10-30 14:40:17 +00:00
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[[table columns] model] resetToDefaults];
|
2012-07-31 14:35:19 +00:00
|
|
|
[self fillColumnsMenu];
|
2009-10-30 14:40:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)revealSelected
|
2010-02-06 10:40:10 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model revealSelected];
|
2010-02-06 10:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)saveResults
|
2010-08-13 11:06:18 +00:00
|
|
|
{
|
|
|
|
NSSavePanel *sp = [NSSavePanel savePanel];
|
|
|
|
[sp setCanCreateDirectories:YES];
|
|
|
|
[sp setAllowedFileTypes:[NSArray arrayWithObject:@"dupeguru"]];
|
2012-08-01 20:34:12 +00:00
|
|
|
[sp setTitle:NSLocalizedString(@"Select a file to save your results to", @"")];
|
2010-08-13 11:06:18 +00:00
|
|
|
if ([sp runModal] == NSOKButton) {
|
2013-11-10 17:41:10 +00:00
|
|
|
[model saveResultsAs:[[sp URL] path]];
|
|
|
|
[[app recentResults] addFile:[[sp URL] path]];
|
2010-08-13 11:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)switchSelected
|
2009-06-14 14:48:47 +00:00
|
|
|
{
|
2012-01-13 19:43:43 +00:00
|
|
|
[model makeSelectedReference];
|
2009-06-14 14:48:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)toggleColumn:(id)sender
|
2009-10-30 12:56:05 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)toggleDetailsPanel
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)toggleDelta
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)togglePowerMarker
|
2009-06-16 08:04:23 +00:00
|
|
|
{
|
2011-01-13 12:51:00 +00:00
|
|
|
[table setPowerMarkerMode:![table powerMarkerMode]];
|
|
|
|
[self updateOptionSegments];
|
2009-06-16 08:04:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-29 15:16:04 +00:00
|
|
|
- (void)toggleQuicklookPanel
|
2011-09-22 19:59:11 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
|
|
|
{
|
|
|
|
return ![[ProgressController mainProgressController] isShown];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
|
|
|
{
|
2013-11-24 15:12:47 +00:00
|
|
|
if ([item action] == @selector(markAll)) {
|
|
|
|
[item setTitle:NSLocalizedString(@"Mark All", @"")];
|
|
|
|
}
|
2009-06-01 09:55:11 +00:00
|
|
|
return ![[ProgressController mainProgressController] isShown];
|
|
|
|
}
|
|
|
|
@end
|