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
|
|
|
|
- (id)initWithPyParent:(id)aPyParent view:(NSTableView *)aTableView
|
|
|
|
{
|
|
|
|
self = [super initWithPyClassName:@"PyResultTable" pyParent:aPyParent view:aTableView];
|
|
|
|
[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];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDeltaColumns:(NSIndexSet *)aDeltaColumns
|
|
|
|
{
|
|
|
|
[_deltaColumns release];
|
|
|
|
_deltaColumns = [aDeltaColumns retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
NSInteger columnId = [identifier integerValue];
|
|
|
|
return [[self py] valueForRow:row column:columnId];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
else if ([identifier isEqual:@"0"]) {
|
|
|
|
NSString *oldName = [[self py] valueForRow:row column:0];
|
|
|
|
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];
|
|
|
|
[[self py] sortBy:[[sd key] integerValue] ascending:[sd ascending]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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]) {
|
|
|
|
NSInteger i = [[column identifier] integerValue];
|
|
|
|
if ([_deltaColumns containsIndex:i]) {
|
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
|