Decompile .scpt files when generating QuickLook preview/thumbnail

This commit is contained in:
Allan Odgaard
2015-10-02 23:15:33 +07:00
parent 5738792b36
commit 26d4ebf302
2 changed files with 18 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
#import <OSAKit/OSAKit.h>
#import "plugin.h"
#import <buffer/buffer.h>
#import <bundles/bundles.h>
@@ -58,7 +59,22 @@ static std::string URLtoString (CFURLRef url)
static std::string setup_buffer (CFURLRef url, ng::buffer_t& buffer, size_t maxSize = 20480, size_t maxLines = SIZE_T_MAX)
{
std::string filePath = URLtoString(url);
std::string fileContents = file::read_utf8(filePath, nullptr, maxSize);
std::string fileContents = NULL_STR;
if(path::extension(filePath) == ".scpt")
{
@autoreleasepool {
NSDictionary* err = nil;
if(OSAScript* script = [[OSAScript alloc] initWithContentsOfURL:(__bridge NSURL*)url error:&err])
{
fileContents = [[script source] UTF8String] ?: NULL_STR;
std::replace(fileContents.begin(), fileContents.end(), '\r', '\n');
}
}
}
if(fileContents == NULL_STR)
fileContents = file::read_utf8(filePath, nullptr, maxSize);
if(maxLines != SIZE_T_MAX)
fileContents.erase(std::find_if(fileContents.begin(), fileContents.end(), [&maxLines](char ch) { return ch == '\n' && --maxLines == 0; }), fileContents.end());

View File

@@ -1,7 +1,7 @@
TARGET_NAME = TextMateQL
SOURCES = src/*.{c,mm}
CP_Resources = resources/*
FRAMEWORKS = CoreFoundation QuickLook AppKit
FRAMEWORKS = CoreFoundation QuickLook AppKit OSAKit
LINK += layout buffer bundles file cf ns OakAppKit OakFoundation
LN_FLAGS -= -Wl,-dead_strip_dylibs