aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-02-07 20:20:41 +0000
committerstuconnolly <stuart02@gmail.com>2011-02-07 20:20:41 +0000
commit2e31a4ad75b8e47a4feacadd567fbfab65eeede9 (patch)
treed224d2cda8463ca7645443944002e9f639909929
parentc9338aee82e9b42a07e93625c3235977c3dbf1b4 (diff)
downloadsequelpro-2e31a4ad75b8e47a4feacadd567fbfab65eeede9.tar.gz
sequelpro-2e31a4ad75b8e47a4feacadd567fbfab65eeede9.tar.bz2
sequelpro-2e31a4ad75b8e47a4feacadd567fbfab65eeede9.zip
Bring outline view branch up to date with trunk (r3179:r3187).
-rw-r--r--Interfaces/English.lproj/DataMigrationDialog.xib60
-rw-r--r--Source/NoodleLineNumberView.h49
-rw-r--r--Source/NoodleLineNumberView.m483
-rw-r--r--Source/SPDatabaseDocument.m1
-rw-r--r--Source/SPDatabaseViewController.m6
-rw-r--r--Source/SPFieldMapperController.h2
-rw-r--r--Source/SPFieldMapperController.m111
-rw-r--r--Source/SPTextView.m55
8 files changed, 451 insertions, 316 deletions
diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib
index e5a56ef5..1a7c25b6 100644
--- a/Interfaces/English.lproj/DataMigrationDialog.xib
+++ b/Interfaces/English.lproj/DataMigrationDialog.xib
@@ -2,17 +2,17 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">10F569</string>
+ <string key="IBDocument.SystemVersion">10J567</string>
<string key="IBDocument.InterfaceBuilderVersion">788</string>
- <string key="IBDocument.AppKitVersion">1038.29</string>
- <string key="IBDocument.HIToolboxVersion">461.00</string>
+ <string key="IBDocument.AppKitVersion">1038.35</string>
+ <string key="IBDocument.HIToolboxVersion">462.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">788</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="516"/>
+ <integer value="11"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -51,7 +51,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{522, 348}</string>
<object class="NSView" key="NSWindowView" id="78582513">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1532,6 +1532,7 @@
</object>
</object>
<string key="NSFrameSize">{522, 348}</string>
+ <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1280, 778}}</string>
<string key="NSMinSize">{522, 370}</string>
@@ -1568,12 +1569,14 @@
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{311, 111}</string>
<reference key="NSSuperview" ref="153719181"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTableHeaderView" key="NSHeaderView" id="293135471">
<reference key="NSNextResponder" ref="236935166"/>
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{311, 17}</string>
<reference key="NSSuperview" ref="236935166"/>
+ <reference key="NSWindow"/>
<reference key="NSTableView" ref="666379639"/>
</object>
<object class="_NSCornerView" key="NSCornerView" id="535120964">
@@ -1581,6 +1584,7 @@
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{224, 0}, {16, 17}}</string>
<reference key="NSSuperview" ref="466562755"/>
+ <reference key="NSWindow"/>
</object>
<object class="NSMutableArray" key="NSTableColumns">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1700,6 +1704,7 @@
</object>
<string key="NSFrame">{{1, 17}, {311, 111}}</string>
<reference key="NSSuperview" ref="466562755"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="666379639"/>
<reference key="NSDocView" ref="666379639"/>
<reference key="NSBGColor" ref="518286732"/>
@@ -1710,6 +1715,7 @@
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{-100, -100}, {15, 102}}</string>
<reference key="NSSuperview" ref="466562755"/>
+ <reference key="NSWindow"/>
<reference key="NSTarget" ref="466562755"/>
<string key="NSAction">_doScroller:</string>
<double key="NSPercent">0.99065423011779785</double>
@@ -1719,6 +1725,7 @@
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{-100, -100}, {238, 15}}</string>
<reference key="NSSuperview" ref="466562755"/>
+ <reference key="NSWindow"/>
<int key="NSsFlags">1</int>
<reference key="NSTarget" ref="466562755"/>
<string key="NSAction">_doScroller:</string>
@@ -1734,6 +1741,7 @@
</object>
<string key="NSFrame">{{1, 0}, {311, 17}}</string>
<reference key="NSSuperview" ref="466562755"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="293135471"/>
<reference key="NSDocView" ref="293135471"/>
<reference key="NSBGColor" ref="518286732"/>
@@ -1743,6 +1751,7 @@
</object>
<string key="NSFrame">{{-1, 71}, {313, 129}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="153719181"/>
<int key="NSsFlags">530</int>
<reference key="NSVScroller" ref="818055239"/>
@@ -1757,6 +1766,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{17, 42}, {22, 22}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="1062542413">
<int key="NSCellFlags">-2080244224</int>
@@ -1781,6 +1791,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{38, 42}, {22, 22}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="87720389">
<int key="NSCellFlags">-2080244224</int>
@@ -1805,6 +1816,7 @@
<int key="NSvFlags">289</int>
<string key="NSFrame">{{216, 13}, {80, 28}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="360762154">
@@ -1826,6 +1838,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{18, 17}, {197, 18}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="574058264">
<int key="NSCellFlags">-2080244224</int>
@@ -1848,6 +1861,7 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{70, 42}, {105, 22}}</string>
<reference key="NSSuperview" ref="803374494"/>
+ <reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
<object class="NSPopUpButtonCell" key="NSCell" id="514571508">
<int key="NSCellFlags">-2076049856</int>
@@ -1943,6 +1957,7 @@
</object>
<string key="NSFrameSize">{311, 210}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1280, 1002}}</string>
<string key="NSMinSize">{311, 208}</string>
@@ -3015,6 +3030,14 @@
</object>
<int key="connectionID">520</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">gobackButton</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="148795893"/>
+ </object>
+ <int key="connectionID">521</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -4527,10 +4550,10 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{457, 83}, {522, 348}}</string>
+ <string>{{343, 83}, {522, 348}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="YES"/>
- <string>{{457, 83}, {522, 348}}</string>
+ <string>{{343, 83}, {522, 348}}</string>
<integer value="1"/>
<string>{{387, 725}, {432, 282}}</string>
<boolean value="NO"/>
@@ -4907,7 +4930,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">520</int>
+ <int key="maxID">521</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -7741,8 +7764,10 @@
<string>closeInfoSheet:</string>
<string>closeSheet:</string>
<string>goBackToFileChooser:</string>
+ <string>goBackToFileChooserFromPathControl:</string>
<string>insertNULLValue:</string>
<string>insertPulldownValue:</string>
+ <string>insertRecentGlobalValue:</string>
<string>newTable:</string>
<string>newTableInfo:</string>
<string>openAdvancedSheet:</string>
@@ -7774,6 +7799,8 @@
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
@@ -7792,8 +7819,10 @@
<string>closeInfoSheet:</string>
<string>closeSheet:</string>
<string>goBackToFileChooser:</string>
+ <string>goBackToFileChooserFromPathControl:</string>
<string>insertNULLValue:</string>
<string>insertPulldownValue:</string>
+ <string>insertRecentGlobalValue:</string>
<string>newTable:</string>
<string>newTableInfo:</string>
<string>openAdvancedSheet:</string>
@@ -7853,6 +7882,10 @@
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
+ <string key="name">goBackToFileChooserFromPathControl:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
<string key="name">insertNULLValue:</string>
<string key="candidateClassName">id</string>
</object>
@@ -7861,6 +7894,10 @@
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
+ <string key="name">insertRecentGlobalValue:</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBActionInfo">
<string key="name">newTable:</string>
<string key="candidateClassName">id</string>
</object>
@@ -7915,6 +7952,7 @@
<string>fileSourcePath</string>
<string>globalValuesSheet</string>
<string>globalValuesTableView</string>
+ <string>gobackButton</string>
<string>highPriorityCheckBox</string>
<string>ignoreCheckBox</string>
<string>ignoreUpdateCheckBox</string>
@@ -7979,6 +8017,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
<string>NSPopUpButton</string>
<string>NSButton</string>
<string>NSPopUpButton</string>
@@ -8034,6 +8073,7 @@
<string>fileSourcePath</string>
<string>globalValuesSheet</string>
<string>globalValuesTableView</string>
+ <string>gobackButton</string>
<string>highPriorityCheckBox</string>
<string>ignoreCheckBox</string>
<string>ignoreUpdateCheckBox</string>
@@ -8156,6 +8196,10 @@
<string key="candidateClassName">NSTableView</string>
</object>
<object class="IBToOneOutletInfo">
+ <string key="name">gobackButton</string>
+ <string key="candidateClassName">id</string>
+ </object>
+ <object class="IBToOneOutletInfo">
<string key="name">highPriorityCheckBox</string>
<string key="candidateClassName">id</string>
</object>
diff --git a/Source/NoodleLineNumberView.h b/Source/NoodleLineNumberView.h
index 45f33c00..1d600720 100644
--- a/Source/NoodleLineNumberView.h
+++ b/Source/NoodleLineNumberView.h
@@ -29,37 +29,42 @@
#import <Cocoa/Cocoa.h>
-@class NoodleLineNumberMarker;
-
@interface NoodleLineNumberView : NSRulerView
{
- // Array of character indices for the beginning of each line
- NSMutableArray *lineIndices;
- NSFont *font;
- NSColor *textColor;
- NSColor *alternateTextColor;
- NSColor *backgroundColor;
- // Add support for selection by clicking/dragging
- NSUInteger dragSelectionStartLine;
-}
+ // Array of character indices for the beginning of each line
+ NSMutableArray *lineIndices;
-- (id)initWithScrollView:(NSScrollView *)aScrollView;
+ NSFont *font;
+ NSColor *textColor;
+ NSColor *alternateTextColor;
+ NSColor *backgroundColor;
+ CGFloat maxWidthOfGlyph;
+ CGFloat maxWidthOfGlyph1;
+ CGFloat maxWidthOfGlyph2;
+ CGFloat maxWidthOfGlyph3;
+ CGFloat maxWidthOfGlyph4;
+ CGFloat maxWidthOfGlyph5;
+ CGFloat maxWidthOfGlyph6;
+ CGFloat maxWidthOfGlyph7;
+ CGFloat maxWidthOfGlyph8;
+ NSDictionary *textAttributes;
-- (void)setFont:(NSFont *)aFont;
-- (NSFont *)font;
+ // Add support for selection by clicking/dragging
+ NSUInteger dragSelectionStartLine;
-- (void)setTextColor:(NSColor *)color;
-- (NSColor *)textColor;
+}
-- (void)setAlternateTextColor:(NSColor *)color;
-- (NSColor *)alternateTextColor;
+@property(retain) NSColor *alternateTextColor;
+@property(retain) NSColor *backgroundColor;
-- (void)setBackgroundColor:(NSColor *)color;
-- (NSColor *)backgroundColor;
+- (NSFont*)font;
+- (void)setFont:(NSFont*)aFont;
+- (NSColor*)textColor;
+- (void)setTextColor:(NSColor*)color;
+- (id)initWithScrollView:(NSScrollView *)aScrollView;
- (NSUInteger)lineNumberForLocation:(CGFloat)location;
-
-- (NSUInteger)lineNumberForCharacterIndex:(NSUInteger)index inText:(NSString *)text;
+- (NSUInteger)lineNumberForCharacterIndex:(NSUInteger)index;
@end
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m
index 3df2b423..ebca542d 100644
--- a/Source/NoodleLineNumberView.m
+++ b/Source/NoodleLineNumberView.m
@@ -28,32 +28,58 @@
//
// This version of the NoodleLineNumberView for Sequel Pro removes marker
-// functionality and adds selection by clicking on the ruler.
+// functionality and adds selection by clicking on the ruler. Furthermore
+// the code was optimized.
#import "NoodleLineNumberView.h"
#include <tgmath.h>
-#define DEFAULT_THICKNESS 22.0
-#define RULER_MARGIN 5.0
+#pragma mark NSCoding methods
+
+#define NOODLE_FONT_CODING_KEY @"font"
+#define NOODLE_TEXT_COLOR_CODING_KEY @"textColor"
+#define NOODLE_ALT_TEXT_COLOR_CODING_KEY @"alternateTextColor"
+#define NOODLE_BACKGROUND_COLOR_CODING_KEY @"backgroundColor"
+
+#pragma mark -
+
+#define DEFAULT_THICKNESS 22.0
+#define RULER_MARGIN 5.0
+#define RULER_MARGIN2 RULER_MARGIN * 2
+
+typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
+
+#pragma mark -
@interface NoodleLineNumberView (Private)
- (NSMutableArray *)lineIndices;
- (void)invalidateLineIndices;
- (void)calculateLines;
-- (NSDictionary *)textAttributes;
+- (void)updateGutterThicknessConstants;
@end
@implementation NoodleLineNumberView
+@synthesize alternateTextColor;
+@synthesize backgroundColor;
+
- (id)initWithScrollView:(NSScrollView *)aScrollView
{
+
if ((self = [super initWithScrollView:aScrollView orientation:NSVerticalRuler]) != nil)
{
[self setClientView:[aScrollView documentView]];
+ [self setAlternateTextColor:[NSColor whiteColor]];
lineIndices = nil;
+ textAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
+ [self font], NSFontAttributeName,
+ [self textColor], NSForegroundColorAttributeName,
+ nil] retain];
+ maxWidthOfGlyph = [[NSString stringWithString:@"8"] sizeWithAttributes:textAttributes].width;
+ [self updateGutterThicknessConstants];
}
return self;
@@ -69,27 +95,36 @@
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (lineIndices) [lineIndices release];
- [font release];
-
+ if (textAttributes) [textAttributes release];
+ if (font) [font release];
+ if (textColor) [textColor release];
[super dealloc];
}
+#pragma mark -
+
- (void)setFont:(NSFont *)aFont
{
if (font != aFont)
{
[font autorelease];
font = [aFont retain];
+ if (textAttributes) [textAttributes release];
+ textAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
+ font, NSFontAttributeName,
+ [self textColor], NSForegroundColorAttributeName,
+ nil] retain];
+ maxWidthOfGlyph = [[NSString stringWithString:@"8"] sizeWithAttributes:textAttributes].width;
+ [self updateGutterThicknessConstants];
}
}
- (NSFont *)font
{
if (font == nil)
- {
return [NSFont labelFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
- }
- return font;
+
+ return font;
}
- (void)setTextColor:(NSColor *)color
@@ -98,101 +133,68 @@
{
[textColor autorelease];
textColor = [color retain];
+ if (textAttributes) [textAttributes release];
+ textAttributes = [[NSDictionary dictionaryWithObjectsAndKeys:
+ [self font], NSFontAttributeName,
+ textColor, NSForegroundColorAttributeName,
+ nil] retain];
+ maxWidthOfGlyph = [[NSString stringWithString:@"8"] sizeWithAttributes:textAttributes].width;
+ [self updateGutterThicknessConstants];
}
}
- (NSColor *)textColor
{
if (textColor == nil)
- {
return [NSColor colorWithCalibratedWhite:0.42 alpha:1.0];
- }
- return textColor;
-}
-
-- (void)setAlternateTextColor:(NSColor *)color
-{
- if (alternateTextColor != color)
- {
- [alternateTextColor autorelease];
- alternateTextColor = [color retain];
- }
-}
-
-- (NSColor *)alternateTextColor
-{
- if (alternateTextColor == nil)
- {
- return [NSColor whiteColor];
- }
- return alternateTextColor;
-}
-
-- (void)setBackgroundColor:(NSColor *)color
-{
- if (backgroundColor != color)
- {
- [backgroundColor autorelease];
- backgroundColor = [color retain];
- }
-}
-- (NSColor *)backgroundColor
-{
- return backgroundColor;
+ return textColor;
}
- (void)setClientView:(NSView *)aView
{
- id oldClientView;
-
- oldClientView = [self clientView];
+ id oldClientView = [self clientView];
if ((oldClientView != aView) && [oldClientView isKindOfClass:[NSTextView class]])
- {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSTextStorageDidProcessEditingNotification object:[(NSTextView *)oldClientView textStorage]];
- }
+
[super setClientView:aView];
+
if ((aView != nil) && [aView isKindOfClass:[NSTextView class]])
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSTextStorageDidProcessEditingNotification object:[(NSTextView *)aView textStorage]];
-
[self invalidateLineIndices];
}
}
-- (NSMutableArray *)lineIndices
-{
- if (lineIndices == nil)
- {
- [self calculateLines];
- }
- return lineIndices;
-}
-
-- (void)invalidateLineIndices
-{
- if (lineIndices) [lineIndices release], lineIndices = nil;
-}
+#pragma mark -
- (void)textDidChange:(NSNotification *)notification
{
- // Invalidate the line indices. They will be recalculated and recached on demand.
- [self invalidateLineIndices];
+
+ if(![self clientView]) return;
+
+ NSUInteger editMask = [[(NSTextView *)[self clientView] textStorage] editedMask];
+
+ // Invalidate the line indices only if text view was changed in length but not if the font was changed.
+ // They will be recalculated and recached on demand.
+ if(editMask != 1)
+ [self invalidateLineIndices];
[self setNeedsDisplay:YES];
+
}
- (NSUInteger)lineNumberForLocation:(CGFloat)location
{
- NSUInteger line, count, index, rectCount, i;
- NSRectArray rects;
- NSRect visibleRect;
- NSLayoutManager *layoutManager;
- NSTextContainer *container;
- NSRange nullRange;
- NSArray *lines;
- id view;
+ NSUInteger line, count, rectCount, i;
+ NSRectArray rects;
+ NSRect visibleRect;
+ NSLayoutManager *layoutManager;
+ NSTextContainer *container;
+ NSRange nullRange;
+ NSArray *lines;
+ id view;
view = [self clientView];
visibleRect = [[[self scrollView] contentView] bounds];
@@ -216,148 +218,83 @@
// It doesn't show up in the glyphs so would not be accounted for.
range.length++;
- for (line = [self lineNumberForCharacterIndex:range.location inText:@""]; line < count; line++)
- {
+ // Cache loop methods for speed
+ SEL lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
+ IMP lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
- index = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue];
+ for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
+ {
- rects = [layoutManager rectArrayForCharacterRange:NSMakeRange(index, 0)
+ rects = [layoutManager rectArrayForCharacterRange:NSMakeRange([NSArrayObjectAtIndex(lines, line) unsignedIntegerValue], 0)
withinSelectedCharacterRange:nullRange
inTextContainer:container
rectCount:&rectCount];
- for (i = 0; i < rectCount; i++)
- if ((location >= NSMinY(rects[i])) && (location < NSMaxY(rects[i])))
- return line + 1;
+ if(!rectCount) return NSNotFound;
+
+ if ((location >= NSMinY(rects[0])) && (location < NSMaxY(rects[0])))
+ return line + 1;
}
}
return NSNotFound;
}
-- (void)calculateLines
+- (NSUInteger)lineNumberForCharacterIndex:(NSUInteger)index
{
- id view = [self clientView];
-
- if ([view isKindOfClass:[NSTextView class]])
- {
- NSUInteger index, stringLength, lineEnd, contentEnd;
- NSString *text;
- CGFloat oldThickness, newThickness;
-
- text = [view string];
- stringLength = [text length];
-
- // Switch off line numbering if text larger than 6MB
- // for performance reasons.
- // TODO improve performance maybe via threading
- if(stringLength>6000000)
- return;
+ NSUInteger left, right, mid, lineStart;
+ NSMutableArray *lines;
- if (lineIndices) [lineIndices release], lineIndices = nil;
- lineIndices = [[NSMutableArray alloc] initWithCapacity:1];
-
- index = 0;
+ lines = [self lineIndices];
- do
- {
- [lineIndices addObject:[NSNumber numberWithUnsignedInteger:index]];
- index = NSMaxRange([text lineRangeForRange:NSMakeRange(index, 0)]);
- }
- while (index < stringLength);
+ // Binary search
+ left = 0;
+ right = [lines count];
- // Check if text ends with a new line.
- [text getLineStart:NULL end:&lineEnd contentsEnd:&contentEnd forRange:NSMakeRange([[lineIndices lastObject] unsignedIntegerValue], 0)];
- if (contentEnd < lineEnd)
- {
- [lineIndices addObject:[NSNumber numberWithUnsignedInteger:index]];
- }
+ while ((right - left) > 1)
+ {
- oldThickness = [self ruleThickness];
- newThickness = [self requiredThickness];
- if (fabs(oldThickness - newThickness) > 1)
- {
- NSInvocation *invocation;
+ mid = (right + left) >> 1;
+ lineStart = [NSArrayObjectAtIndex(lines, mid) unsignedIntegerValue];
- // Not a good idea to resize the view during calculations (which can happen during
- // display). Do a delayed perform (using NSInvocation since arg is a float).
- invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(setRuleThickness:)]];
- [invocation setSelector:@selector(setRuleThickness:)];
- [invocation setTarget:self];
- [invocation setArgument:&newThickness atIndex:2];
+ if (index < lineStart)
+ right = mid;
+ else if (index > lineStart)
+ left = mid;
+ else
+ return mid;
- [invocation performSelector:@selector(invoke) withObject:nil afterDelay:0.0];
- }
}
-}
-
-- (NSUInteger)lineNumberForCharacterIndex:(NSUInteger)index inText:(NSString *)text
-{
- NSUInteger left, right, mid, lineStart;
- NSMutableArray *lines;
-
- lines = [self lineIndices];
-
- // Binary search
- left = 0;
- right = [lines count];
-
- while ((right - left) > 1)
- {
- mid = (right + left) / 2;
- lineStart = [NSArrayObjectAtIndex(lines, mid) unsignedIntegerValue];
-
- if (index < lineStart)
- {
- right = mid;
- }
- else if (index > lineStart)
- {
- left = mid;
- }
- else
- {
- return mid;
- }
- }
- return left;
-}
-
-- (NSDictionary *)textAttributes
-{
- return [NSDictionary dictionaryWithObjectsAndKeys:
- [self font], NSFontAttributeName,
- [self textColor], NSForegroundColorAttributeName,
- nil];
+ return left;
}
- (CGFloat)requiredThickness
{
NSUInteger lineCount = [[self lineIndices] count];
if(lineCount < 10)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"8"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph1;
else if(lineCount < 100)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"88"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph2;
else if(lineCount < 1000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph3;
else if(lineCount < 10000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"8888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph4;
else if(lineCount < 100000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"88888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph5;
else if(lineCount < 1000000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"888888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph6;
else if(lineCount < 10000000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"8888888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph7;
else if(lineCount < 100000000)
- return ceil(MAX(DEFAULT_THICKNESS, [[NSString stringWithString:@"88888888"] sizeWithAttributes:[self textAttributes]].width + RULER_MARGIN * 2));
+ return maxWidthOfGlyph8;
else
return 100;
}
- (void)drawHashMarksAndLabelsInRect:(NSRect)aRect
{
- id view;
- NSRect bounds;
+ id view;
+ NSRect bounds;
bounds = [self bounds];
@@ -374,45 +311,45 @@
if ([view isKindOfClass:[NSTextView class]])
{
- NSLayoutManager *layoutManager;
- NSTextContainer *container;
- NSRect visibleRect;
- NSRange range, glyphRange, nullRange;
- NSString *text, *labelText;
- NSUInteger rectCount, index, line, count;
- NSRectArray rects;
- CGFloat ypos, yinset;
- NSDictionary *textAttributes;
- NSSize stringSize;
- NSArray *lines;
-
- layoutManager = [view layoutManager];
- container = [view textContainer];
- text = [view string];
- nullRange = NSMakeRange(NSNotFound, 0);
-
- yinset = [view textContainerInset].height;
- visibleRect = [[[self scrollView] contentView] bounds];
-
- textAttributes = [self textAttributes];
-
- lines = [self lineIndices];
+ NSLayoutManager *layoutManager;
+ NSTextContainer *container;
+ NSRect visibleRect;
+ NSRange range, nullRange;
+ NSString *labelText;
+ NSUInteger rectCount, index, line, count;
+ NSRectArray rects;
+ CGFloat ypos, yinset;
+ NSSize stringSize;
+ NSArray *lines;
+
+ layoutManager = [view layoutManager];
+ container = [view textContainer];
+ nullRange = NSMakeRange(NSNotFound, 0);
+
+ yinset = [view textContainerInset].height;
+ visibleRect = [[[self scrollView] contentView] bounds];
+
+ lines = [self lineIndices];
// Find the characters that are currently visible
- glyphRange = [layoutManager glyphRangeForBoundingRect:visibleRect inTextContainer:container];
- range = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
+ range = [layoutManager characterRangeForGlyphRange:[layoutManager glyphRangeForBoundingRect:visibleRect inTextContainer:container] actualGlyphRange:NULL];
// Fudge the range a tad in case there is an extra new line at end.
// It doesn't show up in the glyphs so would not be accounted for.
range.length++;
count = [lines count];
-
- CGFloat boundsRULERMargin2 = NSWidth(bounds) - RULER_MARGIN * 2.0;
+
+ CGFloat boundsRULERMargin2 = NSWidth(bounds) - RULER_MARGIN2;
CGFloat boundsWidthRULER = NSWidth(bounds) - RULER_MARGIN;
CGFloat yinsetMinY = yinset - NSMinY(visibleRect);
+ CGFloat rectHeight;
- for (line = [self lineNumberForCharacterIndex:range.location inText:text]; line < count; line++)
+ // Cache loop methods for speed
+ SEL lineNumberForCharacterIndexSel = @selector(lineNumberForCharacterIndex:);
+ IMP lineNumberForCharacterIndexIMP = [self methodForSelector:lineNumberForCharacterIndexSel];
+
+ for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
{
index = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue];
@@ -433,35 +370,35 @@
stringSize = [labelText sizeWithAttributes:textAttributes];
+ rectHeight = NSHeight(rects[0]);
// Draw string flush right, centered vertically within the line
[labelText drawInRect:
NSMakeRect(boundsWidthRULER - stringSize.width,
- yinsetMinY + NSMinY(rects[0]) + ((NSHeight(rects[0]) - stringSize.height) / 2.0),
- boundsRULERMargin2, NSHeight(rects[0]))
+ yinsetMinY + NSMinY(rects[0]) + ((NSInteger)(rectHeight - stringSize.height) >> 1),
+ boundsRULERMargin2, rectHeight)
withAttributes:textAttributes];
}
}
+
if (index > NSMaxRange(range))
- {
break;
- }
+
}
}
}
- (void)mouseDown:(NSEvent *)theEvent
{
- NSPoint location;
- NSUInteger line;
- NSTextView *view;
-
- if (![[self clientView] isKindOfClass:[NSTextView class]]) return;
+
+ NSUInteger line;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]]) return;
view = (NSTextView *)[self clientView];
-
- location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
- line = [self lineNumberForLocation:location.y];
+
+ line = [self lineNumberForLocation:[self convertPoint:[theEvent locationInWindow] fromView:nil].y];
dragSelectionStartLine = line;
-
+
if (line != NSNotFound)
{
NSUInteger selectionStart, selectionEnd;
@@ -479,15 +416,14 @@
- (void)mouseDragged:(NSEvent *)theEvent
{
- NSPoint location;
- NSUInteger line, startLine, endLine;
- NSTextView *view;
-
- if (![[self clientView] isKindOfClass:[NSTextView class]] || dragSelectionStartLine == NSNotFound) return;
+
+ NSUInteger line, startLine, endLine;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]] || dragSelectionStartLine == NSNotFound) return;
view = (NSTextView *)[self clientView];
-
- location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
- line = [self lineNumberForLocation:location.y];
+
+ line = [self lineNumberForLocation:[self convertPoint:[theEvent locationInWindow] fromView:nil].y];
if (line != NSNotFound)
{
@@ -509,16 +445,11 @@
}
[view setSelectedRange:NSMakeRange(selectionStart, selectionEnd - selectionStart)];
}
-
+
[view autoscroll:theEvent];
}
-#pragma mark NSCoding methods
-
-#define NOODLE_FONT_CODING_KEY @"font"
-#define NOODLE_TEXT_COLOR_CODING_KEY @"textColor"
-#define NOODLE_ALT_TEXT_COLOR_CODING_KEY @"alternateTextColor"
-#define NOODLE_BACKGROUND_COLOR_CODING_KEY @"backgroundColor"
+#pragma mark -
- (id)initWithCoder:(NSCoder *)decoder
{
@@ -562,4 +493,94 @@
}
}
+#pragma mark -
+#pragma mark PrivateAPI
+
+- (NSMutableArray *)lineIndices
+{
+
+ if (lineIndices == nil)
+ [self calculateLines];
+
+ return lineIndices;
+
+}
+
+- (void)invalidateLineIndices
+{
+
+ if (lineIndices) [lineIndices release], lineIndices = nil;
+
+}
+
+- (void)calculateLines
+{
+ id view = [self clientView];
+
+ if ([view isKindOfClass:[NSTextView class]])
+ {
+ NSUInteger index, stringLength, lineEnd, contentEnd;
+ NSString *textString;
+ CGFloat newThickness;
+
+ textString = [view string];
+ stringLength = [textString length];
+
+ // Switch off line numbering if text larger than 6MB
+ // for performance reasons.
+ // TODO improve performance maybe via threading
+ if(stringLength>6000000)
+ return;
+
+ if (lineIndices) [lineIndices release], lineIndices = nil;
+ // Init lineIndices with text length / 16 + 1
+ lineIndices = [[NSMutableArray alloc] initWithCapacity:((NSUInteger)stringLength>>4)+1];
+
+ index = 0;
+
+ // Cache loop methods for speed
+ SEL lineRangeForRangeSel = @selector(lineRangeForRange:);
+ SEL addObjectSel = @selector(addObject:);
+ RangeOfLineIMP rangeOfLineIMP = (RangeOfLineIMP)[textString methodForSelector:lineRangeForRangeSel];
+ IMP addObjectIMP = [lineIndices methodForSelector:addObjectSel];
+
+ do
+ {
+ (void*)(*addObjectIMP)(lineIndices, addObjectSel, [NSNumber numberWithUnsignedInteger:index]);
+ index = NSMaxRange((*rangeOfLineIMP)(textString, lineRangeForRangeSel, NSMakeRange(index, 0)));
+ }
+ while (index < stringLength);
+
+ // Check if text ends with a new line.
+ [textString getLineStart:NULL end:&lineEnd contentsEnd:&contentEnd forRange:NSMakeRange([[lineIndices lastObject] unsignedIntegerValue], 0)];
+ if (contentEnd < lineEnd)
+ (void*)(*addObjectIMP)(lineIndices, addObjectSel, [NSNumber numberWithUnsignedInteger:index]);
+
+ newThickness = [self requiredThickness];
+ if (fabs([self ruleThickness] - newThickness) > 1)
+ {
+ // Not a good idea to resize the view during calculations (which can happen during
+ // display). Do a delayed perform (using NSInvocation since arg is a float).
+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(setRuleThickness:)]];
+ [invocation setSelector:@selector(setRuleThickness:)];
+ [invocation setTarget:self];
+ [invocation setArgument:&newThickness atIndex:2];
+
+ [invocation performSelector:@selector(invoke) withObject:nil afterDelay:0.0];
+ }
+ }
+}
+
+- (void)updateGutterThicknessConstants
+{
+ maxWidthOfGlyph1 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph + RULER_MARGIN2));
+ maxWidthOfGlyph2 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 2 + RULER_MARGIN2));
+ maxWidthOfGlyph3 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 3 + RULER_MARGIN2));
+ maxWidthOfGlyph4 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 4 + RULER_MARGIN2));
+ maxWidthOfGlyph5 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 5 + RULER_MARGIN2));
+ maxWidthOfGlyph6 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 6 + RULER_MARGIN2));
+ maxWidthOfGlyph7 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 7 + RULER_MARGIN2));
+ maxWidthOfGlyph8 = ceil(MAX(DEFAULT_THICKNESS, maxWidthOfGlyph * 8 + RULER_MARGIN2));
+}
+
@end
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 1d4b4fc6..4bc82a21 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -3795,7 +3795,6 @@
// Add the progress window to this window
[self centerTaskWindow];
- [taskProgressWindow orderFront:self];
[parentWindow addChildWindow:taskProgressWindow ordered:NSWindowAbove];
}
diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m
index a7867c53..03153230 100644
--- a/Source/SPDatabaseViewController.m
+++ b/Source/SPDatabaseViewController.m
@@ -426,6 +426,12 @@
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
+ // Cache table information on the working thread
+ if (selectedTableType == SPTableTypeView)
+ [tableDataInstance updateInformationForCurrentView];
+ else
+ [tableDataInstance updateInformationForCurrentTable];
+
// Notify listeners of the table change now that the state is fully set up.
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h
index 8a70df90..813a3b3e 100644
--- a/Source/SPFieldMapperController.h
+++ b/Source/SPFieldMapperController.h
@@ -76,6 +76,7 @@
IBOutlet id highPriorityCheckBox;
IBOutlet id skipexistingRowsCheckBox;
IBOutlet SPTextView *onupdateTextView;
+ IBOutlet id gobackButton;
IBOutlet id advancedButton;
@@ -171,6 +172,7 @@
- (IBAction)openAdvancedSheet:(id)sender;
- (IBAction)closeSheet:(id)sender;
- (IBAction)goBackToFileChooser:(id)sender;
+- (IBAction)goBackToFileChooserFromPathControl:(id)sender;
- (IBAction)addGlobalValue:(id)sender;
- (IBAction)removeGlobalValue:(id)sender;
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index e70a7c25..b77ca98e 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -29,6 +29,7 @@
#import "SPTextView.h"
#import "SPTableView.h"
#import "SPCategoryAdditions.h"
+#import "RegexKitLite.h"
#define SP_NUMBER_OF_RECORDS_STRING NSLocalizedString(@"%ld of %@%lu records", @"Label showing the index of the selected CSV row")
@@ -120,7 +121,7 @@ static const NSString *SPTableViewSqlColumnID = @"sql";
[pc setURL:[NSURL fileURLWithPath:sourcePath]];
if([pc pathComponentCells])
[fileSourcePath setPathComponentCells:[pc pathComponentCells]];
- [fileSourcePath setDoubleAction:@selector(goBackToFileChooser:)];
+ [fileSourcePath setDoubleAction:@selector(goBackToFileChooserFromPathControl:)];
[onupdateTextView setDelegate:theDelegate];
windowMinWidth = [[self window] minSize].width;
@@ -700,15 +701,24 @@ static const NSString *SPTableViewSqlColumnID = @"sql";
if(possibleImports < 1) return;
+ // Set all operators to doNotImport
+ [fieldMappingOperatorArray removeAllObjects];
+ for(i=0; i < [fieldMappingTableColumnNames count]; i++)
+ [fieldMappingOperatorArray addObject:doNotImport];
+
switch([[alignByPopup selectedItem] tag]) {
case 0: // file order
- for(i=0; i<possibleImports; i++)
+ for(i=0; i<possibleImports; i++) {
[fieldMappingArray replaceObjectAtIndex:i withObject:[NSNumber numberWithInteger:i]];
+ [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doImport];
+ }
break;
case 1: // reversed file order
possibleImports--;
- for(i=possibleImports; i>=0; i--)
+ for(i=possibleImports; i>=0; i--) {
[fieldMappingArray replaceObjectAtIndex:possibleImports-i withObject:[NSNumber numberWithInteger:i]];
+ [fieldMappingOperatorArray replaceObjectAtIndex:possibleImports-i withObject:doImport];
+ }
break;
case 2: // try to align header and table target field names via Levenshtein distance
[self matchHeaderNames];
@@ -763,14 +773,21 @@ static const NSString *SPTableViewSqlColumnID = @"sql";
}
}
+- (IBAction)goBackToFileChooserFromPathControl:(id)sender
+{
+ [gobackButton performSelector:@selector(performClick:) withObject:nil afterDelay:0.0f];
+}
+
- (IBAction)goBackToFileChooser:(id)sender
{
+
[NSApp endSheet:[self window] returnCode:[sender tag]];
- if([sourcePath hasPrefix:SPImportClipboardTempFileNamePrefix]) {
+
+ if([sourcePath hasPrefix:SPImportClipboardTempFileNamePrefix])
[theDelegate importFromClipboard];
- } else {
+ else
[theDelegate importFile];
- }
+
}
- (IBAction)newTable:(id)sender
@@ -1365,34 +1382,84 @@ static const NSString *SPTableViewSqlColumnID = @"sql";
NSMutableArray *tableHeaderNames = [NSMutableArray array];
[tableHeaderNames setArray:fieldMappingTableColumnNames];
+ // Create a distance matrix for each file-table name
+ // distance will be calculated by using Levenshtein distance minus common prefix and suffix length
+ // and minus the length of a fuzzy regex search for a common sequence of characters
NSInteger i,j;
- NSMutableArray *matchedHeaderNames = [NSMutableArray array];
+ NSMutableArray *distMatrix = [NSMutableArray array];
for(i=0; i < [tableHeaderNames count]; i++) {
- CGFloat minDist = 1e6;
+ CGFloat minDist = 1e6;
NSInteger minIndex = 0;
+ CGFloat dist = 1e6;
for(j=0; j < [fileHeaderNames count]; j++) {
id fileHeaderName = NSArrayObjectAtIndex(fileHeaderNames,j);
if([fileHeaderName isKindOfClass:[NSNull class]] || [fileHeaderName isSPNotLoaded]) continue;
NSString *headerName = [(NSString*)fileHeaderName lowercaseString];
- CGFloat dist = [[NSArrayObjectAtIndex(tableHeaderNames,i) lowercaseString] levenshteinDistanceWithWord:headerName];
- if(dist < minDist && ![matchedHeaderNames containsObject:headerName]) {
- minDist = dist;
- minIndex = j;
+ NSString *tableHeadName = [NSArrayObjectAtIndex(tableHeaderNames,i) lowercaseString];
+ dist = [tableHeadName levenshteinDistanceWithWord:headerName];
+
+ // if dist > 0 subtract the length of common prefixes, suffixes, and in common sequence characters
+ if(dist > 0.0) {
+ dist -= [[tableHeadName commonPrefixWithString:headerName options:NSCaseInsensitiveSearch] length];
+ dist -= [[tableHeadName commonPrefixWithString:headerName options:NSCaseInsensitiveSearch|NSBackwardsSearch] length];
+
+ NSMutableString *fuzzyRegexp = [[NSMutableString alloc] initWithCapacity:3];
+ NSInteger i;
+ unichar c;
+
+ for(i=0; i<[headerName length]; i++) {
+ c = [headerName characterAtIndex:i];
+ if (c == '.' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}')
+ [fuzzyRegexp appendFormat:@".*?\\%c",c];
+ else
+ [fuzzyRegexp appendFormat:@".*?%c",c];
+ }
+ dist -= [tableHeadName rangeOfRegex:fuzzyRegexp].length;
+ [fuzzyRegexp release];
+
+ } else {
+ // Levenshtein distance == 0 means that both names are equal set dist to
+ // a large negative number since dist can be negative due to search for in common chars
+ dist = -1e6;
}
- if(dist == 0.0f) [matchedHeaderNames addObject:headerName];
+
+ [distMatrix addObject:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat:dist], @"dist",
+ NSStringFromRange(NSMakeRange(i,j)), @"match",
+ (NSString*)fileHeaderName, @"file",
+ NSArrayObjectAtIndex(tableHeaderNames,i), @"table",
+ nil]];
+
}
- [fieldMappingArray replaceObjectAtIndex:i withObject:[NSNumber numberWithInteger:minIndex]];
- [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doImport];
+
}
- // If a pair with distance 0 was found set doNotImport to those fields which are still mapped
- // to such csv file header name
- if([matchedHeaderNames count])
- for(i=0; i < [tableHeaderNames count]; i++) {
- NSString *mappedFileHeaderName = [NSArrayObjectAtIndex(fileHeaderNames, [[fieldMappingArray objectAtIndex:i] integerValue]) lowercaseString];
- if([matchedHeaderNames containsObject:mappedFileHeaderName] && ![mappedFileHeaderName isEqualToString:[NSArrayObjectAtIndex(tableHeaderNames, i) lowercaseString]])
- [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doNotImport];
+ // Sort the matrix according distance
+ NSSortDescriptor *sortByDistance = [[[NSSortDescriptor alloc] initWithKey:@"dist" ascending:TRUE] autorelease];
+ [distMatrix sortUsingDescriptors:[NSArray arrayWithObjects:sortByDistance, nil]];
+
+ NSMutableArray *matchedFile = [NSMutableArray array];
+ NSMutableArray *matchedTable = [NSMutableArray array];
+ NSInteger cnt = 0;
+ for(NSDictionary* m in distMatrix) {
+ if(![matchedFile containsObject:[m objectForKey:@"file"]] && ![matchedTable containsObject:[m objectForKey:@"table"]]) {
+
+ NSRange match = NSRangeFromString([m objectForKey:@"match"]);
+
+ // Set best match
+ [fieldMappingArray replaceObjectAtIndex:match.location withObject:[NSNumber numberWithInteger:match.length]];
+ [fieldMappingOperatorArray replaceObjectAtIndex:match.location withObject:doImport];
+
+ // Remember matched pair
+ [matchedTable addObject:[m objectForKey:@"table"]];
+ [matchedFile addObject:[m objectForKey:@"file"]];
+ cnt++;
}
+
+ // break if all file names are mapped
+ if(cnt >= [fileHeaderNames count]) break;
+
+ }
}
/*
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 82bfdedf..705f2a8a 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -269,15 +269,16 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
// If caret is not inside backticks add keywords and all words coming from the view.
if(!dbBrowseMode)
{
- // Only parse for words if text size is less than 6MB
- if([[self string] length] && [[self string] length]<6000000)
+ // Only parse for words if text size is less than 1MB
+ if([[self string] length] && [[self string] length]<1000000)
{
NSMutableSet *uniqueArray = [NSMutableSet setWithCapacity:5];
for(id w in [[self textStorage] words])
- [uniqueArray addObject:[w string]];
- // Remove current word from list
+ if([[w string] hasPrefix:currentWord])
+ [uniqueArray addObject:[w string]];
+ // Remove current word from list
[uniqueArray removeObject:currentWord];
NSInteger reverseSort = NO;
@@ -863,7 +864,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
*/
- (NSUInteger) getLineNumberForCharacterIndex:(NSUInteger)anIndex
{
- return [lineNumberView lineNumberForCharacterIndex:anIndex inText:[self string]]+1;
+ return [lineNumberView lineNumberForCharacterIndex:anIndex]+1;
}
/**
@@ -2153,12 +2154,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
// Note: switch(insertedCharacter) {} does not work instead use charactersIgnoringModifiers
- if([charactersIgnMod isEqualToString:@"c"]) // ^C copy as RTF
- if(curFlags==(NSControlKeyMask))
- {
- [self copyAsRTF];
- return;
- }
if([charactersIgnMod isEqualToString:@"h"]) // ^H show MySQL Help
if(curFlags==(NSControlKeyMask))
{
@@ -2690,10 +2685,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
tokenColor = quoteColor;
allowToCheckForUpperCase = NO;
break;
- case SPT_BACKTICK_QUOTED_TEXT:
- tokenColor = backtickColor;
- allowToCheckForUpperCase = NO;
- break;
case SPT_RESERVED_WORD:
tokenColor = keywordColor;
break;
@@ -2701,6 +2692,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
tokenColor = numericColor;
allowToCheckForUpperCase = NO;
break;
+ case SPT_BACKTICK_QUOTED_TEXT:
+ tokenColor = backtickColor;
+ allowToCheckForUpperCase = NO;
+ break;
case SPT_COMMENT:
tokenColor = commentColor;
allowToCheckForUpperCase = NO;
@@ -2726,31 +2721,28 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if (!tokenRange.length) continue;
// If the current token is marked as SQL keyword, uppercase it if required.
- tokenEnd = tokenRange.location+tokenRange.length-1;
+ tokenEnd = NSMaxRange(tokenRange) - 1;
// Check the end of the token
- if (textBufferSizeIncreased
+ if (autouppercaseKeywordsEnabled
&& allowToCheckForUpperCase
- && autouppercaseKeywordsEnabled
+ && textBufferSizeIncreased
&& !delBackwardsWasPressed
+ && (tokenEnd+1) < strlength
&& [(NSString*)NSMutableAttributedStringAttributeAtIndex(textStore, kSQLkeyword, tokenEnd, nil) length])
// check if next char is not a kSQLkeyword or current kSQLkeyword is at the end;
// if so then upper case keyword if not already done
- // @try catch() for catching valid index esp. after deleteBackward:
{
- NSString* curTokenString = [selfstr substringWithRange:tokenRange];
- BOOL doIt = NO;
- @try
- {
- doIt = ![(NSString*)NSMutableAttributedStringAttributeAtIndex(textStore, kSQLkeyword,tokenEnd+1,nil) length];
- } @catch(id ae) { doIt = NO; }
-
- if(doIt)
+ NSString* curTokenString = [selfstr substringWithRange:tokenRange];
+ if(![(NSString*)NSMutableAttributedStringAttributeAtIndex(textStore, kSQLkeyword,tokenEnd+1,nil) length])
{
- // Register it for undo works only partly for now, at least the uppercased keyword will be selected
- [self shouldChangeTextInRange:tokenRange replacementString:curTokenString];
- [self replaceCharactersInRange:tokenRange withString:[curTokenString uppercaseString]];
+ NSString *curTokenStringUP = [curTokenString uppercaseString];
+ if(![curTokenString isEqualToString:curTokenStringUP]) {
+ // Register it for undo works only partly for now, at least the uppercased keyword will be selected
+ [self shouldChangeTextInRange:tokenRange replacementString:curTokenStringUP];
+ [self replaceCharactersInRange:tokenRange withString:curTokenStringUP];
+ }
}
}
@@ -2986,9 +2978,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
if ([[[self class] defaultMenu] itemWithTag:SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG] == nil)
{
- NSMenuItem *copyAsRTFMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy as RTF", @"Copy as RTF") action:@selector(copyAsRTF) keyEquivalent:@"c"];
+ NSMenuItem *copyAsRTFMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy as RTF", @"Copy as RTF") action:@selector(copyAsRTF) keyEquivalent:@""];
[copyAsRTFMenuItem setTag:SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG];
- [copyAsRTFMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
[menu insertItem:copyAsRTFMenuItem atIndex:2];
[copyAsRTFMenuItem release];
}