2009-08-05 08:59:46 +00:00
/ *
2013-04-28 14:35:51 +00:00
Copyright 2013 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
* /
2012-08-30 20:08:21 +00:00
# import "ResultWindowBase.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
@ implementation ResultWindowBase
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 ] ] ;
2009-10-30 12:56:05 +00:00
[ self initResultColumns ] ;
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 ] ;
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-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 ) {
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
}
}
2012-07-29 15:16:04 +00:00
- ( void ) startDuplicateScan
2010-02-12 16:15:48 +00:00
{
2012-01-13 19:43:43 +00:00
if ( [ model resultsAreModified ] ) {
2012-08-01 20:34:12 +00:00
if ( [ Dialogs askYesNo : NSLocalizedString ( @ "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
}
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
- ( void ) jobInProgress : ( NSNotification * ) aNotification
{
2012-08-01 20:34:12 +00:00
[ Dialogs showMessage : NSLocalizedString ( @ "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