Listing open windows, views and buffers
This commit is contained in:
@@ -550,7 +550,9 @@ void ReplaceInfobarData() {
|
||||
}
|
||||
|
||||
Scratch scratch;
|
||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name));
|
||||
String error = {};
|
||||
if (InfoBarErrorMessage.len) error = Format(scratch, "| error: %.*s", FmtString(InfoBarErrorMessage));
|
||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), FmtString(error));
|
||||
String16 string = ToString16(scratch, s);
|
||||
ReplaceText(buffer, {0, buffer->len}, string);
|
||||
}
|
||||
@@ -2,28 +2,122 @@ lua_State *LuaState = NULL;
|
||||
|
||||
int LuaOpenFile(lua_State *L) {
|
||||
const char *text = luaL_checkstring(L, 1);
|
||||
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = ViewOpenFile(window, text);
|
||||
SetActiveWindow(window->id);
|
||||
return 0; // number of results
|
||||
}
|
||||
|
||||
// struct ResolvedSet {
|
||||
// Window *window;
|
||||
// View *view;
|
||||
// Buffer *buffer;
|
||||
// };
|
||||
|
||||
// ResolvedSet GetActiveWindow() {
|
||||
// if (ActiveWindow.id == CommandWindowID.id) {
|
||||
// Window *window = GetWindow(LastActiveWindow);
|
||||
// View *view = GetView(window->active_view);
|
||||
// SetActiveWindow(window->id);
|
||||
// Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
// return {window, view, buffer};
|
||||
// }
|
||||
|
||||
// Window *window = GetWindow(ActiveWindow);
|
||||
// View *view = GetView(window->active_view);
|
||||
// Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
// return {window, view, buffer};
|
||||
// }
|
||||
|
||||
int LuaListOpenBuffers(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Buffers) {
|
||||
String string = Format(scratch, "%.*s\n", FmtString(it.name));
|
||||
Add(&strings, ToString16(scratch, string));
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaListViews(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Views) {
|
||||
Buffer *buffer = GetBuffer(it.buffer_id);
|
||||
String string = Format(scratch, "view = %lld buffer = %lld name = %.*s", (long long)it.id.id, (long long)buffer->id.id, FmtString(buffer->name));
|
||||
Add(&strings, ToString16(scratch, string));
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaListWindows(lua_State *L) {
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String16> strings = {scratch};
|
||||
For(Windows) {
|
||||
View *view = GetActiveView(&it);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
String string = Format(scratch, "window = %lld active_view = %lld buffer_name = %.*s", (long long)it.id.id, (long long)it.active_view.id, FmtString(buffer->name));
|
||||
Add(&strings, ToString16(scratch, string));
|
||||
ForItem(child_view_id, it.views) {
|
||||
View *child_view = GetView(child_view_id);
|
||||
Buffer *child_buffer = GetBuffer(child_view->buffer_id);
|
||||
String child_string = Format(scratch, " view = %lld buffer = %lld name = %.*s", (long long)child_view->id.id, (long long)child_buffer->id.id, FmtString(child_buffer->name));
|
||||
Add(&strings, ToString16(scratch, child_string));
|
||||
}
|
||||
}
|
||||
String16 string = Merge(scratch, strings, L"\n");
|
||||
Command_Replace(view, string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InitLua() {
|
||||
LuaState = luaL_newstate();
|
||||
luaL_openlibs(LuaState);
|
||||
|
||||
lua_pushcfunction(LuaState, LuaOpenFile);
|
||||
lua_setglobal(LuaState, "open");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListOpenBuffers);
|
||||
lua_setglobal(LuaState, "list_buffers");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListViews);
|
||||
lua_setglobal(LuaState, "list_views");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListWindows);
|
||||
lua_setglobal(LuaState, "list_windows");
|
||||
}
|
||||
|
||||
// @todo: also log to buffer or something
|
||||
void SetInfoBarErrorMessage(String string) {
|
||||
Allocator sys = GetSystemAllocator();
|
||||
if (InfoBarErrorMessage.data) Dealloc(sys, &InfoBarErrorMessage.data);
|
||||
if (string.len) InfoBarErrorMessage = Copy(sys, string);
|
||||
}
|
||||
|
||||
void EvalString(String16 string16) {
|
||||
if (!LuaState) InitLua();
|
||||
Scratch scratch;
|
||||
String string = ToString(scratch, string16);
|
||||
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
|
||||
// @todo:
|
||||
const char *text = lua_tostring(LuaState, -1);
|
||||
printf("lua error: %s\n", text);
|
||||
SetInfoBarErrorMessage(text);
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,10 @@
|
||||
#include "lua_api.cpp"
|
||||
|
||||
/*
|
||||
- replace info bar with 2 windows
|
||||
- Save file (utf16->utf8)
|
||||
- reuse buffers!!
|
||||
- resize windows
|
||||
- Change font size
|
||||
- command window
|
||||
- maybe use lua and have there be lua commands that you choose with cursor
|
||||
- open "asd/asd/asd/asd"
|
||||
@@ -80,6 +80,7 @@ int main(void) {
|
||||
FontLineSpacing = FontSize;
|
||||
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
|
||||
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
|
||||
InitLua();
|
||||
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
// Create null
|
||||
@@ -123,16 +124,7 @@ int main(void) {
|
||||
AddView(w, v->id);
|
||||
InfoBarWindowID = w->id;
|
||||
}
|
||||
{
|
||||
Window *w = CreateWindow();
|
||||
w->draw_scrollbar = false;
|
||||
w->draw_line_numbers = false;
|
||||
w->execute_line = true;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*execbar*");
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
ExecBarWindowID = w->id;
|
||||
}
|
||||
|
||||
{
|
||||
Window *w = CreateWindow();
|
||||
w->draw_scrollbar = false;
|
||||
@@ -179,18 +171,18 @@ int main(void) {
|
||||
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
|
||||
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
|
||||
}
|
||||
// {
|
||||
// int i = 3;
|
||||
// Windows[i].total_rect = CutLeft(&infobar_rect, GetSize(infobar_rect).x / 2);
|
||||
// Windows[i].document_rect = Windows[i].total_rect;
|
||||
// }
|
||||
{
|
||||
int i = 3;
|
||||
Windows[i].total_rect = CutLeft(&infobar_rect, GetSize(infobar_rect).x / 2);
|
||||
Windows[i].document_rect = Windows[i].total_rect;
|
||||
}
|
||||
{
|
||||
int i = 4;
|
||||
Windows[i].total_rect = infobar_rect;
|
||||
Windows[i].document_rect = Windows[i].total_rect;
|
||||
}
|
||||
{
|
||||
int i = 5;
|
||||
int i = 4;
|
||||
Rect2 screen_rect = GetScreenRectF();
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
CutTop(&screen_rect, size.y * 0.05f);
|
||||
|
||||
@@ -86,7 +86,7 @@ BufferID NullBufferID = {0};
|
||||
ViewID NullViewID = {0};
|
||||
WindowID CommandWindowID = {0};
|
||||
WindowID InfoBarWindowID = {0};
|
||||
WindowID ExecBarWindowID = {0};
|
||||
// WindowID ExecBarWindowID = {0};
|
||||
|
||||
Array<Buffer> Buffers = {};
|
||||
Array<View> Views = {};
|
||||
@@ -107,6 +107,7 @@ Int LastFrameIDWhenScrolled;
|
||||
|
||||
WindowID LastActiveWindow;
|
||||
Int LastFrameIDWhenSwitchedActiveWindow;
|
||||
String InfoBarErrorMessage;
|
||||
|
||||
void EvalString(String16 string16);
|
||||
Rect2I GetVisibleCells(Window &window);
|
||||
|
||||
Reference in New Issue
Block a user