Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #55. Use arrows to select column(s) #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Table Tool.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
5B338F741EF03D8000D40406 /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B338F731EF03D8000D40406 /* Constants.m */; };
AA58C3F91CFC4DC600106C66 /* TTFormatViewControllerAccessory.xib in Resources */ = {isa = PBXBuildFile; fileRef = AA58C3F81CFC4DC600106C66 /* TTFormatViewControllerAccessory.xib */; };
AAB016721D057426005E3F7A /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = AAB016711D057426005E3F7A /* Credits.rtf */; };
C7F5DC0A234BD37900892C4E /* TTTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = C7F5DC09234BD37900892C4E /* TTTableView.m */; };
E109B48B1B5E4598005B4959 /* CSVConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = E109B48A1B5E4598005B4959 /* CSVConfiguration.m */; };
E109B4921B623924005B4959 /* TTFormatViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E109B4901B623924005B4959 /* TTFormatViewController.m */; };
E109B4931B623924005B4959 /* TTFormatViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E109B4911B623924005B4959 /* TTFormatViewController.xib */; };
Expand Down Expand Up @@ -49,6 +50,8 @@
AA41D3431CF2E7CE00CB3E7D /* Table Tool-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Table Tool-Bridging-Header.h"; sourceTree = "<group>"; };
AA58C3F81CFC4DC600106C66 /* TTFormatViewControllerAccessory.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TTFormatViewControllerAccessory.xib; sourceTree = "<group>"; };
AAB016711D057426005E3F7A /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
C7F5DC08234BD37900892C4E /* TTTableView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TTTableView.h; sourceTree = "<group>"; };
C7F5DC09234BD37900892C4E /* TTTableView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TTTableView.m; sourceTree = "<group>"; };
E109B4891B5E4598005B4959 /* CSVConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSVConfiguration.h; sourceTree = "<group>"; };
E109B48A1B5E4598005B4959 /* CSVConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSVConfiguration.m; sourceTree = "<group>"; };
E109B48F1B623924005B4959 /* TTFormatViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTFormatViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -152,6 +155,8 @@
E1CEF8841B7097280083B957 /* CSVHeuristic.h */,
E1CEF8851B7097280083B957 /* CSVHeuristic.m */,
AA41D3431CF2E7CE00CB3E7D /* Table Tool-Bridging-Header.h */,
C7F5DC08234BD37900892C4E /* TTTableView.h */,
C7F5DC09234BD37900892C4E /* TTTableView.m */,
);
path = "Table Tool";
sourceTree = "<group>";
Expand Down Expand Up @@ -254,6 +259,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -308,6 +314,7 @@
E1CEF8861B7097280083B957 /* CSVHeuristic.m in Sources */,
E1CC84E41B4A5F2A00ED8314 /* main.m in Sources */,
E1CEF87F1B6A23860083B957 /* TTErrorViewController.m in Sources */,
C7F5DC0A234BD37900892C4E /* TTTableView.m in Sources */,
E109B48B1B5E4598005B4959 /* CSVConfiguration.m in Sources */,
E1CC84E21B4A5F2A00ED8314 /* AppDelegate.m in Sources */,
E109B4921B623924005B4959 /* TTFormatViewController.m in Sources */,
Expand Down
14 changes: 7 additions & 7 deletions Table Tool/Base.lproj/Document.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -27,11 +27,11 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" topStrut="YES"/>
<rect key="contentRect" x="100" y="421" width="837" height="523"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<rect key="screenRect" x="0.0" y="0.0" width="3840" height="2137"/>
<value key="minSize" type="size" width="94" height="200"/>
<view key="contentView" id="gIp-Ho-8D9">
<rect key="frame" x="0.0" y="0.0" width="837" height="523"/>
<autoresizingMask key="autoresizingMask"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<splitView dividerStyle="thin" translatesAutoresizingMaskIntoConstraints="NO" id="rW8-oV-UJz">
<rect key="frame" x="0.0" y="0.0" width="837" height="523"/>
Expand All @@ -46,7 +46,7 @@
<rect key="frame" x="0.0" y="0.0" width="837" height="523"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="none" columnSelection="YES" autosaveColumns="NO" headerView="81d-2U-CFl" id="bLT-tG-Zln">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="none" columnSelection="YES" autosaveColumns="NO" headerView="81d-2U-CFl" id="bLT-tG-Zln" customClass="TTTableView">
<rect key="frame" x="0.0" y="0.0" width="837" height="500"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="1" height="1"/>
Expand Down Expand Up @@ -75,11 +75,11 @@
</tableView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="OPb-Ko-dkb">
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="OPb-Ko-dkb">
<rect key="frame" x="1" y="119" width="223" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="IaR-Dt-c0F">
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="IaR-Dt-c0F">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down
9 changes: 8 additions & 1 deletion Table Tool/Document.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "CSVHeuristic.h"
#import "TTErrorViewController.h"
#import "ToolbarIcons.h"
#import "TTTableView.h"

@interface Document () {
NSCell *dataCell;
Expand Down Expand Up @@ -46,7 +47,7 @@ - (instancetype)init {
_maxColumnNumber = 1;
_csvConfig = [[CSVConfiguration alloc]init];
newFile = YES;
errorCode5 = @"Your are not allowed to save while the input format has an error. Configure the format manually, until no error occurs.";
errorCode5 = @"You are not allowed to save while the input format has an error. Configure the format manually, until no error occurs.";
_didSave = NO;

[self initValidPBoardTypes];
Expand Down Expand Up @@ -320,6 +321,12 @@ -(NSArray *)getColumnsOrder{
return columnsOrder.copy;
}

-(void)tableView:(NSTableView *)tableView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn {
if ([tableView isKindOfClass:[TTTableView class]]) {
[((TTTableView *)tableView) resetAnchor];
}
}

#pragma mark - tableViewDataSource (optional methods) - drag & drop

-(void)initValidPBoardTypes
Expand Down
19 changes: 19 additions & 0 deletions Table Tool/TTTableView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// TTTableView.h
// Table Tool
//
// Created by Rob Warner on 10/7/19.
// Copyright © 2019 Egger Apps. All rights reserved.
//

#import <Cocoa/Cocoa.h>

NS_ASSUME_NONNULL_BEGIN

@interface TTTableView : NSTableView<NSTableViewDelegate>

-(void)resetAnchor;

@end

NS_ASSUME_NONNULL_END
67 changes: 67 additions & 0 deletions Table Tool/TTTableView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// TTTableView.m
// Table Tool
//
// Created by Rob Warner on 10/7/19.
// Copyright © 2019 Egger Apps. All rights reserved.
//

#import <math.h>
#import "TTTableView.h"

const int NONE_SELECTED = -1;

@implementation TTTableView

NSInteger anchor = NONE_SELECTED;

- (void)keyDown:(NSEvent *)event {
unichar character = [[event characters] characterAtIndex:0];
if (character == NSLeftArrowFunctionKey || character == NSRightArrowFunctionKey) {
BOOL handled = (event.modifierFlags & NSShiftKeyMask) ?
[self selectMultipleColumns: character] :
[self selectSingleColumn: character];
if (handled) {
return;
}
}
[super keyDown:event];
}

- (BOOL)selectMultipleColumns:(unichar)character {
NSInteger selected = self.selectedColumn;
if (anchor == NONE_SELECTED) {
anchor = selected;
}

NSInteger newColumn = character == NSLeftArrowFunctionKey ? selected - 1 : selected + 1;
if (newColumn >= 0 && newColumn < self.numberOfColumns) {
if ((character == NSLeftArrowFunctionKey && newColumn >= anchor) || (character == NSRightArrowFunctionKey && newColumn <= anchor)) {
[self deselectColumn:selected];
}

[self selectColumnIndexes:[NSIndexSet indexSetWithIndex:newColumn] byExtendingSelection:YES];

return YES;
}

return NO;
}

- (BOOL)selectSingleColumn:(unichar)character {
[self resetAnchor];

NSInteger newColumn = character == NSLeftArrowFunctionKey ? self.selectedColumn - 1 : self.selectedColumn + 1;
if (newColumn >= 0 && newColumn < self.numberOfColumns) {
[self selectColumnIndexes:[NSIndexSet indexSetWithIndex:newColumn] byExtendingSelection:NO];
return YES;
}

return NO;
}

- (void)resetAnchor {
anchor = NONE_SELECTED;
}

@end