aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-06 12:36:37 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-06 12:36:37 +0000
commit5052718afb789f21654e094f2d065baf6bb6ac81 (patch)
tree88e9f2f8c03a7bf995208f17f619e3d40a437d71 /Source/CMTextView.m
parent37b41c535f442aa85750679dccc7885655cb3429 (diff)
downloadsequelpro-5052718afb789f21654e094f2d065baf6bb6ac81.tar.gz
sequelpro-5052718afb789f21654e094f2d065baf6bb6ac81.tar.bz2
sequelpro-5052718afb789f21654e094f2d065baf6bb6ac81.zip
• CSV Import Field Mapper
- fixed some issues for displaying the default values for auto_increment and time_stamp • added possibility to change the tab stop width in each CMTextView via Preference setting in Editor window
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r--Source/CMTextView.m81
1 files changed, 48 insertions, 33 deletions
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<numberOfTabs; i++) {
+ aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabWidth + ((float)i * tabWidth)];
+ [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];
+
+ 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];
+}
+
- (void)drawRect:(NSRect)rect {