2010-09-24 13:48:59 +00:00
|
|
|
/*
|
2015-01-03 21:30:57 +00:00
|
|
|
Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2010-09-24 13:48:59 +00:00
|
|
|
|
2015-01-03 21:33:16 +00:00
|
|
|
This software is licensed under the "GPLv3" 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
|
2015-01-03 21:33:16 +00:00
|
|
|
http://www.gnu.org/licenses/gpl-3.0.html
|
2010-09-24 13:48:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "ResultTable.h"
|
|
|
|
#import "Dialogs.h"
|
|
|
|
#import "Utils.h"
|
2011-09-22 19:59:11 +00:00
|
|
|
#import "HSQuicklook.h"
|
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
@interface HSTable (private)
|
2011-09-22 19:59:11 +00:00
|
|
|
- (void)setPySelection;
|
|
|
|
- (void)setViewSelection;
|
|
|
|
@end
|
2010-09-24 13:48:59 +00:00
|
|
|
|
|
|
|
@implementation ResultTable
|
2012-01-13 20:25:34 +00:00
|
|
|
- (id)initWithPyRef:(PyObject *)aPyRef view:(NSTableView *)aTableView
|
2012-01-13 16:49:34 +00:00
|
|
|
{
|
2012-01-15 23:07:32 +00:00
|
|
|
self = [super initWithPyRef:aPyRef wrapperClass:[PyResultTable class] callbackClassName:@"ResultTableView" view:aTableView];
|
2010-09-24 13:48:59 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-01-13 16:49:34 +00:00
|
|
|
- (PyResultTable *)model
|
2010-09-24 13:48:59 +00:00
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
return (PyResultTable *)model;
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
return [[self model] powerMarkerMode];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPowerMarkerMode:(BOOL)aPowerMarkerMode
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self model] setPowerMarkerMode:aPowerMarkerMode];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)deltaValuesMode
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
return [[self model] deltaValuesMode];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDeltaValuesMode:(BOOL)aDeltaValuesMode
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self model] setDeltaValuesMode:aDeltaValuesMode];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Datasource */
|
|
|
|
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)column row:(NSInteger)row
|
|
|
|
{
|
|
|
|
NSString *identifier = [column identifier];
|
|
|
|
if ([identifier isEqual:@"marked"]) {
|
2012-01-13 16:49:34 +00:00
|
|
|
return [[self model] valueForColumn:@"marked" row:row];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
2012-01-13 16:49:34 +00:00
|
|
|
return [[self model] 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"]) {
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self model] setValue:object forColumn:identifier row:row];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
2011-11-26 15:55:14 +00:00
|
|
|
else if ([identifier isEqual:@"name"]) {
|
2012-01-13 16:49:34 +00:00
|
|
|
NSString *oldName = [[self model] valueForRow:row column:identifier];
|
2010-09-24 13:48:59 +00:00
|
|
|
NSString *newName = object;
|
|
|
|
if (![newName isEqual:oldName]) {
|
2012-01-13 16:49:34 +00:00
|
|
|
BOOL renamed = [[self model] renameSelected:newName];
|
2010-09-24 13:48:59 +00:00
|
|
|
if (!renamed) {
|
2012-08-01 20:34:12 +00:00
|
|
|
[Dialogs showMessage:[NSString stringWithFormat:NSLocalizedString(@"The name '%@' already exists.", @""), newName]];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self view] setNeedsDisplay:YES];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delegate */
|
|
|
|
- (void)tableView:(NSTableView *)aTableView didClickTableColumn:(NSTableColumn *)tableColumn
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
if ([[[self view] sortDescriptors] count] < 1)
|
2010-09-24 13:48:59 +00:00
|
|
|
return;
|
2012-01-13 16:49:34 +00:00
|
|
|
NSSortDescriptor *sd = [[[self view] sortDescriptors] objectAtIndex:0];
|
|
|
|
[[self model] 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
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
BOOL isSelected = [[self view] isRowSelected:row];
|
|
|
|
BOOL isMarkable = n2b([[self model] valueForColumn:@"markable" row:row]);
|
2010-09-24 13:48:59 +00:00
|
|
|
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) {
|
2013-07-28 21:45:23 +00:00
|
|
|
if ([[self model] isDeltaAtRow:row column:[column identifier]]) {
|
|
|
|
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
|
|
|
|
{
|
2012-03-10 15:58:08 +00:00
|
|
|
[[self model] removeSelected];
|
2010-09-24 13:48:59 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableViewHadSpacePressed:(NSTableView *)tableView
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self model] markSelected];
|
2010-09-24 13:48:59 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-09-22 19:59:11 +00:00
|
|
|
/* Quicklook */
|
|
|
|
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
return [[[self model] selectedRows] count];
|
2011-09-22 19:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
NSArray *selectedRows = [[self model] selectedRows];
|
2011-09-22 19:59:11 +00:00
|
|
|
NSInteger absIndex = n2i([selectedRows objectAtIndex:index]);
|
2012-01-13 16:49:34 +00:00
|
|
|
NSString *path = [[self model] pathAtIndex:absIndex];
|
2011-09-22 19:59:11 +00:00
|
|
|
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
|
|
|
|
{
|
2012-01-13 16:49:34 +00:00
|
|
|
[[self view] setNeedsDisplay:YES];
|
2010-09-24 13:48:59 +00:00
|
|
|
}
|
|
|
|
@end
|