Fix mouse, fix allocator in file iter, GetCFiles
This commit is contained in:
@@ -397,6 +397,14 @@ function AddCo(f)
|
|||||||
return Coroutines[i]
|
return Coroutines[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
OnCommandCallbacks = {}
|
||||||
|
table.insert(OnCommandCallbacks, function (e)
|
||||||
|
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
|
||||||
|
C("git grep -n "..GetLoadWord().." :/") end
|
||||||
|
if e.key == SDLK_L and e.ctrl == 1 then
|
||||||
|
Eval(GetLoadWord()) end
|
||||||
|
end)
|
||||||
|
|
||||||
function OnUpdate(e)
|
function OnUpdate(e)
|
||||||
local new_co_list = {}
|
local new_co_list = {}
|
||||||
for key, co in pairs(Coroutines) do
|
for key, co in pairs(Coroutines) do
|
||||||
@@ -409,14 +417,6 @@ function OnUpdate(e)
|
|||||||
Coroutines = new_co_list
|
Coroutines = new_co_list
|
||||||
end
|
end
|
||||||
|
|
||||||
OnCommandCallbacks = {}
|
|
||||||
table.insert(OnCommandCallbacks, function (e)
|
|
||||||
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
|
|
||||||
C("git grep -n "..GetLoadWord().." :/") end
|
|
||||||
if e.key == SDLK_L and e.ctrl == 1 then
|
|
||||||
Eval(GetLoadWord()) end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function OnCommand(e)
|
function OnCommand(e)
|
||||||
for i = #OnCommandCallbacks,1,-1 do
|
for i = #OnCommandCallbacks,1,-1 do
|
||||||
on_command = OnCommandCallbacks[i]
|
on_command = OnCommandCallbacks[i]
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ struct FileIter {
|
|||||||
|
|
||||||
String path;
|
String path;
|
||||||
Allocator allocator;
|
Allocator allocator;
|
||||||
Arena *arena;
|
|
||||||
TempArena temp;
|
|
||||||
union {
|
union {
|
||||||
struct Win32_FileIter *w32;
|
struct Win32_FileIter *w32;
|
||||||
void *dir;
|
void *dir;
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ bool IsValid(const FileIter &it) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Advance(FileIter *it) {
|
void Advance(FileIter *it) {
|
||||||
if (it->temp.arena) EndTemp(it->temp);
|
|
||||||
it->temp = BeginTemp(it->arena);
|
|
||||||
while (FindNextFileW(it->w32->handle, &it->w32->data) != 0) {
|
while (FindNextFileW(it->w32->handle, &it->w32->data) != 0) {
|
||||||
WIN32_FIND_DATAW *data = &it->w32->data;
|
WIN32_FIND_DATAW *data = &it->w32->data;
|
||||||
|
|
||||||
@@ -109,11 +107,11 @@ void Advance(FileIter *it) {
|
|||||||
if (data->cFileName[0] == '.' && data->cFileName[1] == 0) continue;
|
if (data->cFileName[0] == '.' && data->cFileName[1] == 0) continue;
|
||||||
|
|
||||||
it->is_directory = data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
it->is_directory = data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||||
it->filename = ToString(*it->arena, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
|
it->filename = ToString(it->allocator, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
|
||||||
const char *is_dir = it->is_directory ? "/" : "";
|
const char *is_dir = it->is_directory ? "/" : "";
|
||||||
const char *separator = it->path.data[it->path.len - 1] == '/' ? "" : "/";
|
const char *separator = it->path.data[it->path.len - 1] == '/' ? "" : "/";
|
||||||
it->relative_path = Format(*it->arena, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
|
it->relative_path = Format(it->allocator, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
|
||||||
it->absolute_path = GetAbsolutePath(*it->arena, it->relative_path);
|
it->absolute_path = GetAbsolutePath(it->allocator, it->relative_path);
|
||||||
it->is_valid = true;
|
it->is_valid = true;
|
||||||
|
|
||||||
if (it->is_directory) {
|
if (it->is_directory) {
|
||||||
@@ -127,19 +125,17 @@ void Advance(FileIter *it) {
|
|||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
Assert(error == ERROR_NO_MORE_FILES);
|
Assert(error == ERROR_NO_MORE_FILES);
|
||||||
FindClose(it->w32->handle);
|
FindClose(it->w32->handle);
|
||||||
Dealloc(it->allocator, &it->arena);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileIter IterateFiles(Allocator alo, String path) {
|
FileIter IterateFiles(Allocator alo, String path) {
|
||||||
FileIter it = {0};
|
FileIter it = {0};
|
||||||
it.allocator = alo;
|
it.allocator = alo;
|
||||||
it.arena = AllocArena(alo, MiB(2));
|
|
||||||
it.path = path;
|
it.path = path;
|
||||||
|
|
||||||
String modified_path = Format(*it.arena, "%.*s\\*", FmtString(path));
|
String modified_path = Format(it.allocator, "%.*s\\*", FmtString(path));
|
||||||
String16 modified_path16 = ToString16(*it.arena, modified_path);
|
String16 modified_path16 = ToString16(it.allocator, modified_path);
|
||||||
|
|
||||||
it.w32 = AllocType(*it.arena, Win32_FileIter);
|
it.w32 = AllocType(it.allocator, Win32_FileIter);
|
||||||
it.w32->handle = FindFirstFileW((wchar_t *)modified_path16.data, &it.w32->data);
|
it.w32->handle = FindFirstFileW((wchar_t *)modified_path16.data, &it.w32->data);
|
||||||
if (it.w32->handle == INVALID_HANDLE_VALUE) {
|
if (it.w32->handle == INVALID_HANDLE_VALUE) {
|
||||||
it.is_valid = false;
|
it.is_valid = false;
|
||||||
|
|||||||
@@ -60,16 +60,18 @@ void GotoForward(Window *window) {
|
|||||||
|
|
||||||
Int ScreenSpaceToBufferPos(Window *window, View *view, Buffer *buffer, Vec2I mouse) {
|
Int ScreenSpaceToBufferPos(Window *window, View *view, Buffer *buffer, Vec2I mouse) {
|
||||||
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
||||||
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
double px = (double)mworld.x / (double)FontCharSpacing;
|
||||||
XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
double py = (double)mworld.y / (double)FontLineSpacing;
|
||||||
|
XY xy = {(Int)round(px), (Int)floor(py)};
|
||||||
Int result = XYToPosWithoutNL(buffer, xy);
|
Int result = XYToPosWithoutNL(buffer, xy);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int ScreenSpaceToBufferPosErrorOutOfBounds(Window *window, View *view, Buffer *buffer, Vec2I mouse) {
|
Int ScreenSpaceToBufferPosErrorOutOfBounds(Window *window, View *view, Buffer *buffer, Vec2I mouse) {
|
||||||
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
|
||||||
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
|
double px = (double)mworld.x / (double)FontCharSpacing;
|
||||||
XY xy = {(Int)(pos.x), (Int)(pos.y)};
|
double py = (double)mworld.y / (double)FontLineSpacing;
|
||||||
|
XY xy = {(Int)round(px), (Int)floor(py)};
|
||||||
Int result = XYToPosErrorOutOfBounds(buffer, xy);
|
Int result = XYToPosErrorOutOfBounds(buffer, xy);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,35 @@ String16 GetSearchString(Window *window) {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListFilesRecursive(Buffer *buffer, String filename) {
|
||||||
|
Scratch scratch(buffer->line_starts.allocator);
|
||||||
|
for (FileIter it = IterateFiles(scratch, filename); IsValid(it); Advance(&it)) {
|
||||||
|
if (it.filename == ".git") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (it.is_directory) {
|
||||||
|
ListFilesRecursive(buffer, it.absolute_path);
|
||||||
|
} else {
|
||||||
|
bool good = EndsWith(it.filename, ".c") || EndsWith(it.filename, ".h") || EndsWith(it.filename, ".cpp") || EndsWith(it.filename, ".hpp");
|
||||||
|
if (!good) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RawAppendf(buffer, "%.*s\n", FmtString(it.absolute_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_GetCFiles(void) {
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
|
||||||
|
Scratch scratch;
|
||||||
|
String buffer_name = GetUniqueBufferName(scratch, GetDir(main.buffer), "+ls-");
|
||||||
|
|
||||||
|
Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4);
|
||||||
|
ListFilesRecursive(buffer, Command_GetDir());
|
||||||
|
WindowOpenBufferView(main.window, buffer_name);
|
||||||
|
}
|
||||||
|
|
||||||
void OnCommand(Event event) {
|
void OnCommand(Event event) {
|
||||||
ProfileFunction();
|
ProfileFunction();
|
||||||
WindowID start_command_active_window = ActiveWindow;
|
WindowID start_command_active_window = ActiveWindow;
|
||||||
@@ -245,8 +274,10 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_P)) {
|
if (CtrlShiftPress(SDLK_P)) {
|
||||||
Command_ListBuffers();
|
Command_ListBuffers();
|
||||||
|
} else if (CtrlPress(SDLK_P)) {
|
||||||
|
Command_GetCFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShiftPress(SDLK_BACKSLASH)) {
|
if (CtrlShiftPress(SDLK_BACKSLASH)) {
|
||||||
|
|||||||
@@ -281,6 +281,14 @@ function AddCo(f)
|
|||||||
return Coroutines[i]
|
return Coroutines[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
OnCommandCallbacks = {}
|
||||||
|
table.insert(OnCommandCallbacks, function (e)
|
||||||
|
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
|
||||||
|
C("git grep -n "..GetLoadWord().." :/") end
|
||||||
|
if e.key == SDLK_L and e.ctrl == 1 then
|
||||||
|
Eval(GetLoadWord()) end
|
||||||
|
end)
|
||||||
|
|
||||||
function OnUpdate(e)
|
function OnUpdate(e)
|
||||||
local new_co_list = {}
|
local new_co_list = {}
|
||||||
for key, co in pairs(Coroutines) do
|
for key, co in pairs(Coroutines) do
|
||||||
@@ -293,14 +301,6 @@ function OnUpdate(e)
|
|||||||
Coroutines = new_co_list
|
Coroutines = new_co_list
|
||||||
end
|
end
|
||||||
|
|
||||||
OnCommandCallbacks = {}
|
|
||||||
table.insert(OnCommandCallbacks, function (e)
|
|
||||||
if e.key == SDLK_F and e.ctrl == 1 and e.shift == 1 then
|
|
||||||
C("git grep -n "..GetLoadWord().." :/") end
|
|
||||||
if e.key == SDLK_L and e.ctrl == 1 then
|
|
||||||
Eval(GetLoadWord()) end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function OnCommand(e)
|
function OnCommand(e)
|
||||||
for i = #OnCommandCallbacks,1,-1 do
|
for i = #OnCommandCallbacks,1,-1 do
|
||||||
on_command = OnCommandCallbacks[i]
|
on_command = OnCommandCallbacks[i]
|
||||||
|
|||||||
@@ -250,28 +250,8 @@ int Lua_BufferExists(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListFilesRecursive(Buffer *buffer, String filename) {
|
int Lua_GetCFiles(lua_State *L) {
|
||||||
Scratch scratch(buffer->line_starts.allocator);
|
Command_GetCFiles();
|
||||||
for (FileIter it = IterateFiles(scratch, filename); IsValid(it); Advance(&it)) {
|
|
||||||
if (it.filename == ".git") continue;
|
|
||||||
if (it.is_directory) {
|
|
||||||
ListFilesRecursive(buffer, it.absolute_path);
|
|
||||||
} else {
|
|
||||||
RawAppendf(buffer, "%.*s\n", FmtString(it.absolute_path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Lua_Ls(lua_State *L) {
|
|
||||||
BSet main = GetActiveMainSet();
|
|
||||||
|
|
||||||
Scratch scratch;
|
|
||||||
String buffer_name = GetUniqueBufferName(scratch, GetDir(main.buffer), "+ls-");
|
|
||||||
|
|
||||||
Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4);
|
|
||||||
ListFilesRecursive(buffer, Command_GetDir());
|
|
||||||
WindowOpenBufferView(main.window, buffer_name);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"ListBuffers", Lua_ListBuffers},
|
{"ListBuffers", Lua_ListBuffers},
|
||||||
{"GetBufferList", Lua_GetBufferList},
|
{"GetBufferList", Lua_GetBufferList},
|
||||||
{"BufferExists", Lua_BufferExists},
|
{"BufferExists", Lua_BufferExists},
|
||||||
{"Ls", Lua_Ls},
|
{"GetCFiles", Lua_GetCFiles},
|
||||||
{"Rename", Lua_Rename},
|
{"Rename", Lua_Rename},
|
||||||
{"GetSelection", Lua_GetSelection},
|
{"GetSelection", Lua_GetSelection},
|
||||||
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
||||||
|
|||||||
Reference in New Issue
Block a user