From 5052718afb789f21654e094f2d065baf6bb6ac81 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 6 Mar 2010 12:36:37 +0000 Subject: =?UTF-8?q?=E2=80=A2=20CSV=20Import=20Field=20Mapper=20-=20fixed?= =?UTF-8?q?=20some=20issues=20for=20displaying=20the=20default=20values=20?= =?UTF-8?q?for=20auto=5Fincrement=20and=20time=5Fstamp=20=E2=80=A2=20added?= =?UTF-8?q?=20possibility=20to=20change=20the=20tab=20stop=20width=20in=20?= =?UTF-8?q?each=20CMTextView=20via=20Preference=20setting=20in=20Editor=20?= =?UTF-8?q?window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.h | 1 + Source/CMTextView.m | 81 ++++++++++++++++++++++++---------------- Source/SPConstants.h | 1 + Source/SPConstants.m | 1 + Source/SPFieldMapperController.m | 17 ++++++--- 5 files changed, 63 insertions(+), 38 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.h b/Source/CMTextView.h index c278c2c3..53afe0df 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -121,6 +121,7 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS - (BOOL) autouppercaseKeywords; - (void) setAutohelp:(BOOL)enableAutohelp; - (BOOL) autohelp; +- (void) setTabStops; - (void) selectLineNumber:(NSUInteger)lineNumber ignoreLeadingNewLines:(BOOL)ignLeadingNewLines; - (NSUInteger) getLineNumberForCharacterIndex:(NSUInteger)anIndex; - (void) autoHelp; diff --git a/Source/CMTextView.m b/Source/CMTextView.m index d6a1e9d7..3a95a6b5 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -140,40 +140,9 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]]; [self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]]; - // Re-define 64 tab stops for a better editing - NSFont *tvFont = [self font]; - float firstColumnInch = 0.5, otherColumnInch = 0.5, pntPerInch = 72.0; - NSInteger i; - NSTextTab *aTab; - NSMutableArray *myArrayOfTabs; - NSMutableParagraphStyle *paragraphStyle; - myArrayOfTabs = [NSMutableArray arrayWithCapacity:64]; - aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:firstColumnInch*pntPerInch]; - [myArrayOfTabs addObject:aTab]; - [aTab release]; - for(i=1; i<64; i++) { - aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:(firstColumnInch*pntPerInch) + ((float)i * otherColumnInch * pntPerInch)]; - [myArrayOfTabs addObject:aTab]; - [aTab release]; - } - paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; - [paragraphStyle setTabStops:myArrayOfTabs]; - // Soft wrapped lines are indented slightly - [paragraphStyle setHeadIndent:4.0]; - - NSMutableDictionary *textAttributes = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease]; - [textAttributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; + // Re-define tab stops for a better editing + [self setTabStops]; - NSRange range = NSMakeRange(0, [[self textStorage] length]); - if ([self shouldChangeTextInRange:range replacementString:nil]) { - [[self textStorage] setAttributes:textAttributes range: range]; - [self didChangeText]; - } - [self setTypingAttributes:textAttributes]; - [self setDefaultParagraphStyle:paragraphStyle]; - [paragraphStyle release]; - [self setFont:tvFont]; - // disabled to get the current text range in textView safer [[self layoutManager] setBackgroundLayoutEnabled:NO]; @@ -207,6 +176,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [prefs addObserver:self forKeyPath:SPCustomQueryEditorNumericColor options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryEditorVariableColor options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:self forKeyPath:SPCustomQueryEditorTextColor options:NSKeyValueObservingOptionNew context:NULL]; + [prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL]; } @@ -262,6 +232,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self setTextColor:[self otherTextColor]]; if([[self string] length]<100000 && [self isEditable]) [self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1]; + } else if ([keyPath isEqualToString:SPCustomQueryEditorTabStopWidth]) { + [self setTabStops]; } } @@ -3117,6 +3089,49 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } +- (void) setTabStops +{ + NSFont *tvFont = [self font]; + NSInteger i; + NSTextTab *aTab; + NSMutableArray *myArrayOfTabs; + NSMutableParagraphStyle *paragraphStyle; + + NSInteger tabStopWidth = [prefs integerForKey:SPCustomQueryEditorTabStopWidth]; + if(tabStopWidth < 1) tabStopWidth = 1; + + float tabWidth = NSSizeToCGSize([[NSString stringWithString:@" "] sizeWithAttributes:[NSDictionary dictionaryWithObject:tvFont forKey:NSFontAttributeName]]).width; + tabWidth = (float)tabStopWidth * tabWidth; + + NSInteger numberOfTabs = 256/tabStopWidth; + myArrayOfTabs = [NSMutableArray arrayWithCapacity:numberOfTabs]; + aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabWidth]; + [myArrayOfTabs addObject:aTab]; + [aTab release]; + for(i=1; i