Save state window buffers?
This commit is contained in:
@@ -76,29 +76,6 @@ Int ScreenSpaceToBufferPosErrorOutOfBounds(Window *window, View *view, Buffer *b
|
||||
return result;
|
||||
}
|
||||
|
||||
void Command_ListBuffers() {
|
||||
BSet main = GetActiveMainSet();
|
||||
CheckpointBeforeGoto(main.window);
|
||||
|
||||
Scratch scratch;
|
||||
Array<String> strings = {scratch};
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
String string = Format(scratch, "%.*s", FmtString(it->name));
|
||||
Add(&strings, string);
|
||||
}
|
||||
String result = Merge(scratch, strings, "\n");
|
||||
String16 string16 = ToString16(scratch, result);
|
||||
|
||||
String buffer_name = GetUniqueBufferName(GetDir(main.buffer), "buffer_list");
|
||||
View *new_view = WindowOpenBufferView(main.window, buffer_name);
|
||||
Buffer *new_buffer = GetBuffer(new_view->active_buffer);
|
||||
new_buffer->gc = true;
|
||||
|
||||
Command_SelectEntireBuffer(new_view);
|
||||
Command_Replace(new_view, string16);
|
||||
Command_SelectRangeOneCursor(new_view, {});
|
||||
}
|
||||
|
||||
void MouseLoadWord(Event event, void (*cmd_function)(String16 string)) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
BSet active = GetActiveSet();
|
||||
|
||||
@@ -412,6 +412,7 @@ void OnCommand(Event event) {
|
||||
|
||||
|
||||
if (CtrlPress(SDLK_P)) {
|
||||
void Command_ListBuffers();
|
||||
Command_ListBuffers();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,23 +40,41 @@ View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
|
||||
return view;
|
||||
}
|
||||
|
||||
void Command_BeginConsoleJump(BSet *set) {
|
||||
void Command_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
set->buffer = GetBuffer(NullBufferID);
|
||||
set->buffer = GetBuffer(buffer_id);
|
||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
||||
}
|
||||
|
||||
void Command_EndConsoleJump(BSet set) {
|
||||
void Command_BeginJumpCommandBuffer(BSet *set) {
|
||||
String current_dir = Command_GetDir();
|
||||
Command_BeginJump(set, set->window->command_buffer);
|
||||
set->buffer->name = GetUniqueBufferName(current_dir, WindowBufferName);
|
||||
Command_SelectEntireBuffer(set->view);
|
||||
Command_Replace(set->view, u"");
|
||||
}
|
||||
|
||||
void Command_EndJump(BSet set) {
|
||||
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
||||
set.view->carets[0] = MakeCaret(pos);
|
||||
UpdateScroll(set.window, true);
|
||||
}
|
||||
|
||||
void Command_ListBuffers() {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_BeginJumpCommandBuffer(&main);
|
||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it->name));
|
||||
}
|
||||
Command_EndJump(main);
|
||||
ActiveWindow = main.window->id;
|
||||
}
|
||||
|
||||
BSet Command_Exec(String cmd, String working_dir) {
|
||||
BSet set = GetActiveMainSet();
|
||||
Command_BeginConsoleJump(&set);
|
||||
Command_BeginJumpCommandBuffer(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndConsoleJump(set);
|
||||
Command_EndJump(set);
|
||||
ActiveWindow = set.window->id;
|
||||
return set;
|
||||
}
|
||||
@@ -83,12 +101,12 @@ BSet Command_Open(String path) {
|
||||
Int col = strtoll(col_string.data, NULL, 10);
|
||||
|
||||
if (IsDir(file_path)) {
|
||||
Command_BeginConsoleJump(&main);
|
||||
Command_BeginJumpCommandBuffer(&main);
|
||||
Command_Appendf(main.view, "%.*s/..\n", FmtString(file_path));
|
||||
for (FileIter it = IterateFiles(scratch, file_path); IsValid(it); Advance(&it)) {
|
||||
Command_Appendf(main.view, "%.*s\n", FmtString(it.absolute_path));
|
||||
}
|
||||
Command_EndConsoleJump(main);
|
||||
Command_EndJump(main);
|
||||
ActiveWindow = main.window->id;
|
||||
} else {
|
||||
CheckpointBeforeGoto(main.window);
|
||||
@@ -179,17 +197,16 @@ int Lua_Cmd(lua_State *L) {
|
||||
String destination = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
BSet set = {};
|
||||
if (destination == "console") {
|
||||
set = GetConsoleSet();
|
||||
BSet set = GetConsoleSet();
|
||||
Command_BeginJump(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndJump(set);
|
||||
} else {
|
||||
set = GetActiveMainSet();
|
||||
}
|
||||
|
||||
Command_BeginConsoleJump(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndConsoleJump(set);
|
||||
if (destination != "console") {
|
||||
BSet set = GetActiveMainSet();
|
||||
Command_BeginJumpCommandBuffer(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
Command_EndJump(set);
|
||||
ActiveWindow = set.window->id;
|
||||
}
|
||||
|
||||
@@ -260,14 +277,14 @@ int Lua_SetProjectFile(lua_State *L) {
|
||||
|
||||
int Lua_ListCommands(lua_State *L) {
|
||||
BSet main = GetActiveMainSet();
|
||||
Command_BeginConsoleJump(&main);
|
||||
Command_BeginJump(&main);
|
||||
for (int i = 0; LuaFunctions[i].name != NULL; i += 1) {
|
||||
Command_Appendf(main.view, "%20s() ", LuaFunctions[i].name);
|
||||
if (((i + 1) % 6) == 0) {
|
||||
Command_Appendf(main.view, "\n");
|
||||
}
|
||||
}
|
||||
Command_EndConsoleJump(main);
|
||||
Command_EndJump(main);
|
||||
ActiveWindow = main.window->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,12 +146,16 @@ Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Window *CreateWindow() {
|
||||
String WindowBufferName = "window_buffer";
|
||||
Window *CreateWindow(bool create_command_buffer = true) {
|
||||
Window *w = AllocType(Perm, Window);
|
||||
w->visible = true;
|
||||
w->draw_scrollbar = StyleDrawScrollbar;
|
||||
w->draw_line_numbers = StyleDrawLineNumbers;
|
||||
w->id = AllocWindowID(w);
|
||||
if (create_command_buffer) {
|
||||
w->command_buffer = CreateBuffer(GetSystemAllocator(), GetUniqueBufferName(WorkingDir, WindowBufferName), 4096*2)->id;
|
||||
}
|
||||
DLL_QUEUE_ADD(FirstWindow, LastWindow, w);
|
||||
WindowCount += 1;
|
||||
return w;
|
||||
|
||||
@@ -42,6 +42,7 @@ struct Window {
|
||||
Array<GotoCrumb> goto_redo;
|
||||
|
||||
ViewID active_goto_list;
|
||||
BufferID command_buffer;
|
||||
|
||||
double mouse_scroller_offset;
|
||||
int z;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
!!As little lua code as possible, but lua code should be powerful just in case of quick edits
|
||||
- maybe we could allow user to change window titles which would make them special in some way. A:/text_editor/+test_buffer:1:1:ADE |
|
||||
- Fix B: not opening
|
||||
- need a buffer for every window that will be cleared on command and replaced with new content
|
||||
- buffer_list shouldn't be a thing
|
||||
- Scroll the console properly
|
||||
- commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
|
||||
- need a buffer for every window that will be cleared on command and replaced with new content
|
||||
|
||||
--------------
|
||||
buffer = make_buffer()
|
||||
|
||||
@@ -7,7 +7,7 @@ Array<Window *> GetWindowZOrder(Allocator allocator) {
|
||||
}
|
||||
|
||||
Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
Window *window = CreateWindow();
|
||||
Window *window = CreateWindow(false);
|
||||
window->draw_scrollbar = false;
|
||||
window->deactivate_on_escape = true;
|
||||
window->is_search_bar = true;
|
||||
@@ -30,7 +30,7 @@ Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
}
|
||||
|
||||
Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
Window *window = CreateWindow();
|
||||
Window *window = CreateWindow(false);
|
||||
window->draw_scrollbar = false;
|
||||
window->deactivate_on_escape = true;
|
||||
window->is_title_bar = true;
|
||||
|
||||
Reference in New Issue
Block a user