Ctrl + P to list buffers
This commit is contained in:
@@ -162,6 +162,29 @@ void MouseExecWord(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Command_ListBuffers() {
|
||||||
|
Window *window = GetActiveMainWindow();
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
CheckpointBeforeGoto(window->id);
|
||||||
|
|
||||||
|
Scratch scratch;
|
||||||
|
Array<String> strings = {scratch};
|
||||||
|
For(Buffers) {
|
||||||
|
String string = Format(scratch, "%.*s id=%d is_dir=%d", FmtString(it.o->name), (int)it.id, it.o->is_directory);
|
||||||
|
Add(&strings, string);
|
||||||
|
}
|
||||||
|
String result = Merge(scratch, strings, "\n");
|
||||||
|
String16 string16 = ToString16(scratch, result);
|
||||||
|
|
||||||
|
String buffer_name = GetUniqueBufferName(scratch, GetDir(buffer), "+list_buffers-");
|
||||||
|
View *new_view = WindowOpenBufferView(window, buffer_name);
|
||||||
|
|
||||||
|
Command_SelectEntireBuffer(new_view);
|
||||||
|
Command_Replace(new_view, string16);
|
||||||
|
Command_SelectRangeOneCursor(new_view, {});
|
||||||
|
}
|
||||||
|
|
||||||
void MouseLoadWord(Event event) {
|
void MouseLoadWord(Event event) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
Window *window = GetActiveWindow();
|
Window *window = GetActiveWindow();
|
||||||
@@ -419,6 +442,10 @@ bool GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_P)) {
|
||||||
|
Command_ListBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
if (CtrlShift(SDLK_BACKSLASH)) {
|
if (CtrlShift(SDLK_BACKSLASH)) {
|
||||||
AddRowWindow();
|
AddRowWindow();
|
||||||
} else if (Ctrl(SDLK_BACKSLASH)) {
|
} else if (Ctrl(SDLK_BACKSLASH)) {
|
||||||
|
|||||||
@@ -28,13 +28,6 @@ String FieldString(lua_State *L, String name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomSeed UniqueBufferNameSeed = {13};
|
|
||||||
String GetUniqueBufferName(Allocator allocator, String working_dir, String prepend_name) {
|
|
||||||
uint64_t number = GetRandomU64(&UniqueBufferNameSeed);
|
|
||||||
String buffer_name = Format(allocator, "%.*s/%.*s%llu", FmtString(working_dir), FmtString(prepend_name), number);
|
|
||||||
return buffer_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExecInNewBuffer(String cmd, String working_dir) {
|
void ExecInNewBuffer(String cmd, String working_dir) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
CheckpointBeforeGoto(GetActiveMainWindowID());
|
CheckpointBeforeGoto(GetActiveMainWindowID());
|
||||||
@@ -144,27 +137,7 @@ int Lua_Print(lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Lua_ListBuffers(lua_State *L) {
|
int Lua_ListBuffers(lua_State *L) {
|
||||||
Window *window = GetActiveMainWindow();
|
Command_ListBuffers();
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
CheckpointBeforeGoto(window->id);
|
|
||||||
|
|
||||||
Scratch scratch;
|
|
||||||
Array<String> strings = {scratch};
|
|
||||||
For(Buffers) {
|
|
||||||
String string = Format(scratch, "%.*s id=%d is_dir=%d", FmtString(it.o->name), (int)it.id, it.o->is_directory);
|
|
||||||
Add(&strings, string);
|
|
||||||
}
|
|
||||||
String result = Merge(scratch, strings, "\n");
|
|
||||||
String16 string16 = ToString16(scratch, result);
|
|
||||||
|
|
||||||
String buffer_name = GetUniqueBufferName(scratch, GetDir(buffer), "+list_buffers-");
|
|
||||||
View *new_view = WindowOpenBufferView(window, buffer_name);
|
|
||||||
|
|
||||||
Command_SelectEntireBuffer(new_view);
|
|
||||||
Command_Replace(new_view, string16);
|
|
||||||
Command_SelectRangeOneCursor(new_view, {});
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,13 @@ WindowID GetActiveMainWindowID() {
|
|||||||
return GetActiveMainWindow()->id;
|
return GetActiveMainWindow()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomSeed UniqueBufferNameSeed = {13};
|
||||||
|
String GetUniqueBufferName(Allocator allocator, String working_dir, String prepend_name) {
|
||||||
|
uint64_t number = GetRandomU64(&UniqueBufferNameSeed);
|
||||||
|
String buffer_name = Format(allocator, "%.*s/%.*s%llu", FmtString(working_dir), FmtString(prepend_name), number);
|
||||||
|
return buffer_name;
|
||||||
|
}
|
||||||
|
|
||||||
String GetActiveMainWindowBufferName() {
|
String GetActiveMainWindowBufferName() {
|
||||||
Window *window = GetActiveMainWindow();
|
Window *window = GetActiveMainWindow();
|
||||||
View *view = GetView(window->active_view);
|
View *view = GetView(window->active_view);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
- garbage collect the buffers, views - store them in free list on destroy
|
- garbage collect the buffers, views - store them in free list on destroy
|
||||||
- Remove console and command window, provide alternatives but unify the interface?
|
|
||||||
- We can create 2 buffers with same name
|
|
||||||
- window splitting leaves a whitegap at the end
|
|
||||||
- PageUp for some reason stops at 2 line before last line
|
- PageUp for some reason stops at 2 line before last line
|
||||||
|
- adding items to directory should create files on save - it should ask the user (syntax: dir/ | file)
|
||||||
|
|
||||||
- apply clang format
|
- apply clang format
|
||||||
- apply clang format on save
|
- apply clang format on save
|
||||||
|
|||||||
Reference in New Issue
Block a user