aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-28 22:40:28 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-28 22:40:28 +0000
commit5e6610549483e09d47ef8c0432673393f5abc349 (patch)
tree9c561bcdfa7bea64c0ed3cf796f0a86876329f55 /Source
parent35678468fac4fe5bd954f4f640aadf235f83686d (diff)
downloadsequelpro-5e6610549483e09d47ef8c0432673393f5abc349.tar.gz
sequelpro-5e6610549483e09d47ef8c0432673393f5abc349.tar.bz2
sequelpro-5e6610549483e09d47ef8c0432673393f5abc349.zip
• text macro improvements
- added dynamically set SP variables $SP_SELECTED_TABLE and $SP_SELECTED_DATABASE available in each ${x:…} snippet to allow to create a query fav à la: SELECT ${1:$SP_SELECTED_TABLE.} FROM ${1:$SP_SELECTED_TABLE} whereby for the first snippet one can press ESC to insert one or by holding down the CTRL key while inserting more field names from the current table - improved snippet range detection for current caret position - reduced the border width of snippet highlighting and changed slightly the colour for the current selected snippet
Diffstat (limited to 'Source')
-rw-r--r--Source/CMTextView.m49
1 files changed, 44 insertions, 5 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 6bd6f315..cccbc6e8 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -571,7 +571,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
inView:self
dictMode:isDictMode
dbMode:dbBrowseMode
- tabTriggerMode:((snippetControlCounter > -1) ? YES : NO)
+ tabTriggerMode:[self isSnippetMode]
fuzzySearch:fuzzySearch
backtickMode:backtickMode
withDbName:dbName
@@ -994,14 +994,51 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if(snipCnt>snippetControlMax)
snippetControlMax = snipCnt;
- [snip replaceCharactersInRange:snipRange withString:[snip substringWithRange:hintRange]];
+ // Replace internal variables
+ NSMutableString *theHintString = [[NSMutableString alloc] initWithCapacity:hintRange.length];
+ [theHintString setString:[snip substringWithRange:hintRange]];
+ if([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_"]) {
+ NSRange r;
+ NSString *currentTable = nil;
+ if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tableName"] != nil)
+ currentTable = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"tableName"];
+ NSString *currentDb = nil;
+ if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"selectedDatabase"] != nil)
+ currentDb = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"];
+
+ while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"]) {
+ r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"];
+ if(r.length) {
+ if(currentTable && [currentTable length])
+ [theHintString replaceCharactersInRange:r withString:[currentTable backtickQuotedString]];
+ else
+ [theHintString replaceCharactersInRange:r withString:@"<table>"];
+ }
+ [theHintString flushCachedRegexData];
+ }
+
+ while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_DATABASE"]) {
+ r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_DATABASE"];
+ if(r.length) {
+ if(currentDb && [currentDb length])
+ [theHintString replaceCharactersInRange:r withString:[currentDb backtickQuotedString]];
+ else
+ [theHintString replaceCharactersInRange:r withString:@"<database>"];
+ }
+ [theHintString flushCachedRegexData];
+ }
+ }
+
+ [snip replaceCharactersInRange:snipRange withString:theHintString];
[snip flushCachedRegexData];
// Store found snippet range
snippetControlArray[snipCnt][0] = snipRange.location + targetRange.location;
- snippetControlArray[snipCnt][1] = snipRange.length-4-((snipCnt>9)?2:1);
+ snippetControlArray[snipCnt][1] = [theHintString length];
snippetControlArray[snipCnt][2] = 0;
+ [theHintString release];
+
// Adjust successive snippets
for(i=0; i<20; i++)
if(snippetControlArray[i][0] > -1 && i != snipCnt && snippetControlArray[i][0] > snippetControlArray[snipCnt][0])
@@ -1064,6 +1101,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
return NO;
}
+ [[self textStorage] ensureAttributesAreFixedInRange:[self selectedRange]];
+
NSInteger caretPos = [self selectedRange].location;
NSInteger i, j;
NSInteger foundSnippetIndices[20]; // array to hold nested snippets
@@ -2880,11 +2919,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
boundingRect = NSInsetRect(boundingRect, -4, 0.2);
NSBezierPath *aBezierPath = [NSBezierPath bezierPathWithRoundedRect:boundingRect xRadius:6 yRadius:10];
if(i == currentSnippetIndex)
- [[NSColor colorWithCalibratedRed:1.0 green:0.3 blue:0.0 alpha:0.7] setFill];
+ [[NSColor colorWithCalibratedRed:1.0 green:0.6 blue:0.0 alpha:0.7] setFill];
else
[[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:0.4] setFill];
[aBezierPath fill];
- boundingRect = NSInsetRect(boundingRect, 2, 2);
+ boundingRect = NSInsetRect(boundingRect, 1.3, 1.3);
aBezierPath = [NSBezierPath bezierPathWithRoundedRect:boundingRect xRadius:6 yRadius:10];
[[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:0.8] setFill];
[aBezierPath fill];