Add project outline view with all tags

Opened via meta-J and limited to a maximum
of 10 tags similar to fuzzy-finder.
This commit is contained in:
Kevin Sawicki
2012-12-17 09:00:10 -08:00
parent 0bb1442652
commit 39408ec28d
8 changed files with 148 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
#include "include/cef_base.h"
#include "include/cef_v8.h"
#include "readtags.h"
namespace v8_extensions {
@@ -15,6 +16,9 @@ public:
// Provide the reference counting implementation for this class.
IMPLEMENT_REFCOUNTING(Tags);
private:
CefRefPtr<CefV8Value> ParseEntry(tagEntry entry);
};
}

View File

@@ -4,4 +4,7 @@ var $tags = {};
native function find(path, tag);
$tags.find = find;
native function getAllTagsAsync(path, callback);
$tags.getAllTagsAsync = getAllTagsAsync;
})();

View File

@@ -1,5 +1,4 @@
#import "tags.h"
#import "readtags.h"
#import <Cocoa/Cocoa.h>
namespace v8_extensions {
@@ -10,6 +9,16 @@ Tags::Tags() : CefV8Handler() {
CefRegisterExtension("v8/tags", [extensionCode UTF8String], this);
}
CefRefPtr<CefV8Value> Tags::ParseEntry(tagEntry entry) {
CefRefPtr<CefV8Value> tagEntry = CefV8Value::CreateObject(NULL);
tagEntry->SetValue("name", CefV8Value::CreateString(entry.name), V8_PROPERTY_ATTRIBUTE_NONE);
tagEntry->SetValue("file", CefV8Value::CreateString(entry.file), V8_PROPERTY_ATTRIBUTE_NONE);
if (entry.address.pattern) {
tagEntry->SetValue("pattern", CefV8Value::CreateString(entry.address.pattern), V8_PROPERTY_ATTRIBUTE_NONE);
}
return tagEntry;
}
bool Tags::Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
@@ -26,28 +35,9 @@ bool Tags::Execute(const CefString& name,
tagEntry entry;
std::vector<CefRefPtr<CefV8Value>> entries;
if (tagsFind(tagFile, &entry, tag.c_str(), TAG_FULLMATCH | TAG_OBSERVECASE) == TagSuccess) {
CefRefPtr<CefV8Value> tagEntry = CefV8Value::CreateObject(NULL);
tagEntry->SetValue("name", CefV8Value::CreateString(entry.name), V8_PROPERTY_ATTRIBUTE_NONE);
tagEntry->SetValue("file", CefV8Value::CreateString(entry.file), V8_PROPERTY_ATTRIBUTE_NONE);
if (entry.kind) {
tagEntry->SetValue("kind", CefV8Value::CreateString(entry.kind), V8_PROPERTY_ATTRIBUTE_NONE);
}
if (entry.address.pattern) {
tagEntry->SetValue("pattern", CefV8Value::CreateString(entry.address.pattern), V8_PROPERTY_ATTRIBUTE_NONE);
}
entries.push_back(tagEntry);
entries.push_back(ParseEntry(entry));
while (tagsFindNext(tagFile, &entry) == TagSuccess) {
tagEntry = CefV8Value::CreateObject(NULL);
tagEntry->SetValue("name", CefV8Value::CreateString(entry.name), V8_PROPERTY_ATTRIBUTE_NONE);
tagEntry->SetValue("file", CefV8Value::CreateString(entry.file), V8_PROPERTY_ATTRIBUTE_NONE);
if (entry.kind) {
tagEntry->SetValue("kind", CefV8Value::CreateString(entry.kind), V8_PROPERTY_ATTRIBUTE_NONE);
}
if (entry.address.pattern) {
tagEntry->SetValue("pattern", CefV8Value::CreateString(entry.address.pattern), V8_PROPERTY_ATTRIBUTE_NONE);
}
entries.push_back(tagEntry);
entries.push_back(ParseEntry(entry));
}
}
@@ -60,6 +50,52 @@ bool Tags::Execute(const CefString& name,
return true;
}
if (name == "getAllTagsAsync") {
std::string path = arguments[0]->GetStringValue().ToString();
CefRefPtr<CefV8Value> callback = arguments[1];
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
tagFileInfo info;
tagFile* tagFile;
tagFile = tagsOpen(path.c_str(), &info);
std::vector<tagEntry> entries;
if (info.status.opened) {
tagEntry entry;
while (tagsNext(tagFile, &entry) == TagSuccess) {
entry.name = strdup(entry.name);
entry.file = strdup(entry.file);
if (entry.address.pattern) {
entry.address.pattern = strdup(entry.address.pattern);
}
entries.push_back(entry);
}
tagsClose(tagFile);
}
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
context->Enter();
CefRefPtr<CefV8Value> v8Tags = CefV8Value::CreateArray(entries.size());
for (int i = 0; i < entries.size(); i++) {
v8Tags->SetValue(i, ParseEntry(entries[i]));
free((void*)entries[i].name);
free((void*)entries[i].file);
if (entries[i].address.pattern) {
free((void*)entries[i].address.pattern);
}
}
CefV8ValueList callbackArgs;
callbackArgs.push_back(v8Tags);
callback->ExecuteFunction(callback, callbackArgs);
context->Exit();
});
});
return true;
}
return false;
}