2010-09-24 13:48:59 +00:00
|
|
|
/*
|
2011-04-12 08:04:01 +00:00
|
|
|
Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
2010-09-24 13:48:59 +00:00
|
|
|
|
2010-09-30 10:17:41 +00:00
|
|
|
This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2010-09-24 13:48:59 +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
|
2010-09-24 13:48:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "ResultTable.h"
|
|
|
|
#import "Dialogs.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "Consts.h"
|
2011-09-22 19:59:11 +00:00
|
|
|
#import "HSQuicklook.h"
|
|
|
|
|
|
|
|
@interface HSTable (private)
|
|
|
|
- (void)setPySelection;
|
|
|
|
- (void)setViewSelection;
|
|
|
|
@end
|
2010-09-24 13:48:59 +00:00
|
|
|
|
|
|
|
@implementation ResultTable
|
2011-11-27 17:47:00 +00:00
|
|
|
- (id)initWithPy:(id)aPy view:(NSTableView *)aTableView
|
2010-09-24 13:48:59 +00:00
|
|
|
{
|
2011-11-27 17:47:00 +00:00
|
|
|
self = [super initWithPy:aPy view:aTableView];
|
2011-11-27 18:10:35 +00:00
|
|
|
_deltaColumns = [[NSSet setWithArray:[[self py] deltaColumns]] retain];
|
2010-09-24 13:48:59 +00:00
|
|
|
[self connect];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[self disconnect];
|
|
|
|
[_deltaColumns release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PyResultTable *)py
|
|
|
|
{
|
|
|
|
return (PyResultTable *)py;
|
|
|
|
}
|
|
|
|
|
2011-09-22 19:59:11 +00:00
|
|
|
/* Private */
|
|
|
|
- (void)updateQuicklookIfNeeded
|
|
|
|
{
|
|
|
|
if ([[QLPreviewPanel sharedPreviewPanel] dataSource] == self) {
|
|
|
|
[[QLPreviewPanel sharedPreviewPanel] reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPySelection
|
|
|
|
{
|
|
|
|
[super setPySelection];
|
|
|
|
[self updateQuicklookIfNeeded];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setViewSelection
|
|
|
|
{
|
|
|
|
[super setViewSelection];
|
|
|
|
[self updateQuicklookIfNeeded];
|
|
|
|
}
|
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
/* Public */
|
|
|
|
- (BOOL)powerMarkerMode
|
|
|
|
{
|
|
|
|
return [[self py] powerMarkerMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPowerMarkerMode:(BOOL)aPowerMarkerMode
|
|
|
|
{
|
|
|
|
[[self py] setPowerMarkerMode:aPowerMarkerMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)deltaValuesMode
|
|
|
|
{
|
|
|
|
return [[self py] deltaValuesMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDeltaValuesMode:(BOOL)aDeltaValuesMode
|
|
|
|
{
|
|
|
|
[[self py] setDeltaValuesMode:aDeltaValuesMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)selectedDupeCount
|
|
|
|
{
|
|
|
|
return [[self py] selectedDupeCount];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeSelected
|
|
|
|
{
|
|
|
|
NSInteger selectedDupeCount = [self selectedDupeCount];
|
|
|
|
if (!selectedDupeCount)
|
|
|
|
return;
|
2011-11-04 17:10:11 +00:00
|
|
|
NSString *msgFmt = TR(@"You are about to remove %d files from results. Continue?");
|
2011-01-18 14:35:14 +00:00
|
|
|
NSString *msg = [NSString stringWithFormat:msgFmt,selectedDupeCount];
|
2010-09-24 13:48:59 +00:00
|
|
|
if ([Dialogs askYesNo:msg] == NSAlertSecondButtonReturn) // NO
|
|
|
|
return;
|
|
|
|
[[self py] removeSelected];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Datasource */
|
|
|
|
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger)row
|
|
|
|
{
|
|
|
|
NSString *identifier = [column identifier];
|
|
|
|
if ([identifier isEqual:@"marked"]) {
|
|
|
|
return [[self py] valueForColumn:@"marked" row:row];
|
|
|
|
}
|
2011-11-26 15:55:14 +00:00
|
|
|
return [[self py] valueForRow:row column:identifier];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)column row:(NSInteger)row
|
|
|
|
{
|
|
|
|
NSString *identifier = [column identifier];
|
|
|
|
if ([identifier isEqual:@"marked"]) {
|
|
|
|
[[self py] setValue:object forColumn:identifier row:row];
|
|
|
|
}
|
2011-11-26 15:55:14 +00:00
|
|
|
else if ([identifier isEqual:@"name"]) {
|
|
|
|
NSString *oldName = [[self py] valueForRow:row column:identifier];
|
2010-09-24 13:48:59 +00:00
|
|
|
NSString *newName = object;
|
|
|
|
if (![newName isEqual:oldName]) {
|
|
|
|
BOOL renamed = [[self py] renameSelected:newName];
|
|
|
|
if (!renamed) {
|
2011-11-04 17:10:11 +00:00
|
|
|
[Dialogs showMessage:[NSString stringWithFormat:TR(@"The name '%@' already exists."), newName]];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
[tableView setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delegate */
|
|
|
|
- (void)tableView:(NSTableView *)aTableView didClickTableColumn:(NSTableColumn *)tableColumn
|
|
|
|
{
|
|
|
|
if ([[tableView sortDescriptors] count] < 1)
|
|
|
|
return;
|
|
|
|
NSSortDescriptor *sd = [[tableView sortDescriptors] objectAtIndex:0];
|
2011-11-27 17:47:00 +00:00
|
|
|
[[self py] sortBy:[sd key] ascending:[sd ascending]];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)column row:(NSInteger)row
|
2011-04-22 09:07:54 +00:00
|
|
|
{
|
|
|
|
BOOL isSelected = [tableView isRowSelected:row];
|
2010-09-24 13:48:59 +00:00
|
|
|
BOOL isMarkable = n2b([[self py] valueForColumn:@"markable" row:row]);
|
|
|
|
if ([[column identifier] isEqual:@"marked"]) {
|
|
|
|
[cell setEnabled:isMarkable];
|
|
|
|
// Low-tech solution, for indentation, but it works...
|
|
|
|
NSCellImagePosition pos = isMarkable ? NSImageRight : NSImageLeft;
|
|
|
|
[cell setImagePosition:pos];
|
|
|
|
}
|
|
|
|
if ([cell isKindOfClass:[NSTextFieldCell class]]) {
|
2011-04-22 09:07:54 +00:00
|
|
|
NSColor *color = [NSColor textColor];
|
|
|
|
if (isSelected) {
|
|
|
|
color = [NSColor selectedTextColor];
|
|
|
|
}
|
|
|
|
else if (isMarkable) {
|
2010-09-24 13:48:59 +00:00
|
|
|
if ([self deltaValuesMode]) {
|
2011-11-27 17:54:58 +00:00
|
|
|
if ([_deltaColumns containsObject:[column identifier]]) {
|
2011-04-22 09:07:54 +00:00
|
|
|
color = [NSColor orangeColor];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-05 07:54:52 +00:00
|
|
|
else {
|
2011-04-22 09:07:54 +00:00
|
|
|
color = [NSColor blueColor];
|
2010-10-05 07:54:52 +00:00
|
|
|
}
|
2011-04-22 09:07:54 +00:00
|
|
|
[(NSTextFieldCell *)cell setTextColor:color];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableViewHadDeletePressed:(NSTableView *)tableView
|
|
|
|
{
|
|
|
|
[self removeSelected];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableViewHadSpacePressed:(NSTableView *)tableView
|
|
|
|
{
|
|
|
|
[[self py] markSelected];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-09-22 19:59:11 +00:00
|
|
|
/* Quicklook */
|
|
|
|
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
|
|
|
|
{
|
|
|
|
return [[[self py] selectedRows] count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index
|
|
|
|
{
|
|
|
|
NSArray *selectedRows = [[self py] selectedRows];
|
|
|
|
NSInteger absIndex = n2i([selectedRows objectAtIndex:index]);
|
|
|
|
NSString *path = [[self py] pathAtIndex:absIndex];
|
|
|
|
return [[HSQLPreviewItem alloc] initWithUrl:[NSURL fileURLWithPath:path] title:path];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)previewPanel:(QLPreviewPanel *)panel handleEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
// redirect all key down events to the table view
|
|
|
|
if ([event type] == NSKeyDown) {
|
|
|
|
[[self view] keyDown:event];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
/* Python --> Cocoa */
|
|
|
|
- (void)invalidateMarkings
|
|
|
|
{
|
|
|
|
[tableView setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
@end
|