aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Resources/English.lproj/SPQLPluginSQLTemplate.html15
-rw-r--r--Resources/German.lproj/SPQLPluginSQLTemplate.html15
-rw-r--r--Source/GeneratePreviewForURL.m75
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj4
4 files changed, 86 insertions, 23 deletions
diff --git a/Resources/English.lproj/SPQLPluginSQLTemplate.html b/Resources/English.lproj/SPQLPluginSQLTemplate.html
index fd016891..3097b10f 100644
--- a/Resources/English.lproj/SPQLPluginSQLTemplate.html
+++ b/Resources/English.lproj/SPQLPluginSQLTemplate.html
@@ -6,13 +6,8 @@
body {
font-family:'Lucida Grande';
font-size:10pt;
- background-color:#222222;
- color:white;
-}
-textarea {
- background-color:#222222;
- color:white;
- white-space: nowrap;
+ background-color:white;
+ color:black;
}
</style>
</head>
@@ -21,17 +16,19 @@ textarea {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="100%" src="data:image/auto;base64,%@">
</td>
<td>
<center>
<b style="font-size:12pt">Sequel Pro SQL File</b><br />
size: %@
</center><br /><br />
-<textarea cols="50" rows="10" readonly>%@</textarea>
</td>
</tr>
</table>
</center>
+<pre style="padding:2mm; background-color:white" width="100%">
+%@
+</pre>
</body>
</html>
diff --git a/Resources/German.lproj/SPQLPluginSQLTemplate.html b/Resources/German.lproj/SPQLPluginSQLTemplate.html
index 6c905539..ca256c81 100644
--- a/Resources/German.lproj/SPQLPluginSQLTemplate.html
+++ b/Resources/German.lproj/SPQLPluginSQLTemplate.html
@@ -6,13 +6,8 @@
body {
font-family:'Lucida Grande';
font-size:10pt;
- background-color:#222222;
- color:white;
-}
-textarea {
- background-color:#222222;
- color:white;
- white-space: nowrap;
+ background-color:white;
+ color:black;
}
</style>
</head>
@@ -21,17 +16,19 @@ textarea {
<table>
<tr>
<td valign="right">
-<img width="200%" src="data:image/auto;base64,%@">
+<img width="100%" src="data:image/auto;base64,%@">
</td>
<td>
<center>
<b style="font-size:12pt">Sequel Pro SQL Datei</b><br />
Größe: %@
</center><br /><br />
-<textarea cols="50" rows="10" readonly>%@</textarea>
</td>
</tr>
</table>
</center>
+<pre style="padding:2mm; background-color:white" width="100%">
+%@
+</pre>
</body>
</html>
diff --git a/Source/GeneratePreviewForURL.m b/Source/GeneratePreviewForURL.m
index d2a60c2b..8d1783ec 100644
--- a/Source/GeneratePreviewForURL.m
+++ b/Source/GeneratePreviewForURL.m
@@ -28,12 +28,27 @@
#import "SPDataAdditions.h"
#import "SPStringAdditions.h"
#import <Cocoa/Cocoa.h>
+#import "SPEditorTokens.h"
+
/* -----------------------------------------------------------------------------
- Generate a preview for file
+ Generate a preview for file
+
+ This function's job is to create preview for designated file
+ ----------------------------------------------------------------------------- */
+
+
+#pragma mark lex init
+
+/*
+* Include all the extern variables and prototypes required for flex (used for syntax highlighting)
+*/
+extern NSUInteger yylex();
+extern NSUInteger yyuoffset, yyuleng;
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+void yy_switch_to_buffer(YY_BUFFER_STATE);
+YY_BUFFER_STATE yy_scan_string (const char *);
- This function's job is to create preview for designated file
- ----------------------------------------------------------------------------- */
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
@@ -191,11 +206,60 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
@"... SQL ..."
]];
} else {
+
+ // perform syntax highlighting
+ NSString *sqlText = [NSString stringWithContentsOfFile:[myURL path] encoding:NSUTF8StringEncoding error:nil];
+ NSMutableString *sqlHTML = [NSMutableString string];
+
+ NSRange textRange = NSMakeRange(0, [sqlText length]);
+ NSString *tokenColor;
+ size_t token;
+ NSRange tokenRange;
+
+ // initialise flex
+ yyuoffset = 0; yyuleng = 0;
+ yy_switch_to_buffer(yy_scan_string([sqlText UTF8String]));
+
+ // now loop through all the tokens
+ while (token=yylex()){
+ switch (token) {
+ case SPT_SINGLE_QUOTED_TEXT:
+ case SPT_DOUBLE_QUOTED_TEXT:
+ tokenColor = @"#A7221C";
+ break;
+ case SPT_BACKTICK_QUOTED_TEXT:
+ tokenColor = @"#001892";
+ break;
+ case SPT_RESERVED_WORD:
+ tokenColor = @"#0041F6";
+ break;
+ case SPT_NUMERIC:
+ tokenColor = @"#67350F";
+ break;
+ case SPT_COMMENT:
+ tokenColor = @"#265C10";
+ break;
+ case SPT_VARIABLE:
+ tokenColor = @"#6C6C6C";
+ break;
+ case SPT_WHITESPACE:
+ tokenColor = @"black";
+ break;
+ default:
+ tokenColor = @"black";
+ }
+
+ tokenRange = NSMakeRange(yyuoffset, yyuleng);
+ [sqlHTML appendFormat:@"<font color='%@'>%@</font>", tokenColor, [sqlText substringWithRange:tokenRange]];
+
+ }
+
html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template,
[[iconImage TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0],
[NSString stringForByteSize:[[fileAttributes objectForKey:NSFileSize] longLongValue]],
- [NSString stringWithContentsOfFile:[myURL path] encoding:NSUTF8StringEncoding error:nil]
+ sqlHTML
]];
+
}
} else {
html = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:template,
@@ -221,5 +285,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
void CancelPreviewGeneration(void* thisInterface, QLPreviewRequestRef preview)
{
- // implement only if supported
+ // implement only if supported
}
+
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index e6f3112b..0abaea58 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -349,6 +349,8 @@
BC65C3B2107CE3EE003F7B02 /* ImportAccessory.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC65C3B0107CE3EE003F7B02 /* ImportAccessory.xib */; };
BC675A141072039C00C5ACD4 /* SPContentFilterManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BC675A131072039C00C5ACD4 /* SPContentFilterManager.m */; };
BC675A17107203BA00C5ACD4 /* ContentFilterManager.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC675A15107203BA00C5ACD4 /* ContentFilterManager.xib */; };
+ BC6D709D120C4C97008027B5 /* SPEditorTokens.h in Headers */ = {isa = PBXBuildFile; fileRef = 179F15040F7C433C00579954 /* SPEditorTokens.h */; };
+ BC6D709E120C4C9F008027B5 /* SPEditorTokens.l in Sources */ = {isa = PBXBuildFile; fileRef = 179F15050F7C433C00579954 /* SPEditorTokens.l */; };
BC8B0DAF104004F900FC02EC /* EncodingPopupView.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC8B0DAD104004F900FC02EC /* EncodingPopupView.xib */; };
BC8C8532100E0A8000D7A129 /* SPTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC8C8531100E0A8000D7A129 /* SPTableView.m */; };
BC93FBBD11514ADE005F1D9F /* Navigator.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC93FBBB11514ADE005F1D9F /* Navigator.xib */; };
@@ -2160,6 +2162,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ BC6D709D120C4C97008027B5 /* SPEditorTokens.h in Headers */,
BCD06FC7120AAACB00C73602 /* SPStringAdditions.h in Headers */,
BCD06FC6120AAAC200C73602 /* SPDataAdditions.h in Headers */,
);
@@ -2553,6 +2556,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ BC6D709E120C4C9F008027B5 /* SPEditorTokens.l in Sources */,
BC0E1487120AAB5C00E52E25 /* SPStringAdditions.m in Sources */,
BC0E1486120AAB5600E52E25 /* SPDataAdditions.m in Sources */,
584754D3120A05910057631F /* GeneratePreviewForURL.m in Sources */,