Open and navigate directories

This commit is contained in:
Krzosa Karol
2024-08-06 07:49:33 +02:00
parent f419ffd1ca
commit f8c9e8fd3e
3 changed files with 22 additions and 7 deletions

View File

@@ -172,9 +172,13 @@ String GetCurrentBufferName() {
}
String GetCurrentBufferDir() {
String buffer_name = GetCurrentBufferName();
String name = ChopLastSlash(buffer_name);
if (name.len == buffer_name.len) return {};
Window *window = GetWindow(ActiveWindow);
if (window->is_title_bar) {
window = GetWindow(window->title_bar_window);
}
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
String name = buffer->is_directory ? buffer->name : ChopLastSlash(buffer->name);
return name;
}
@@ -196,10 +200,22 @@ Buffer *BufferOpenFile(String path) {
}
if (!FileExists(path)) {
path = Copy(sys_allocator, path);
path = GetAbsolutePath(sys_allocator, path);
buffer = CreateBuffer(sys_allocator, path);
} else if (IsDir(path)) {
path = GetAbsolutePath(sys_allocator, path);
buffer = CreateBuffer(sys_allocator, path, 4096 * 2);
buffer->is_directory = true;
int i = 1;
for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) {
Appendf(buffer, "%.*s", FmtString(it.filename));
if ((i % 8) == 0) Append(buffer, L"\n");
else Append(buffer, L" ");
i += 1;
}
} else {
path = Copy(sys_allocator, path);
path = GetAbsolutePath(sys_allocator, path);
String string = ReadFile(scratch, path);
buffer = CreateBuffer(sys_allocator, path, string.len * 4);

View File

@@ -39,6 +39,7 @@ struct Buffer {
int edit_phase;
bool no_history;
bool dirty;
bool is_directory;
};
struct View {

View File

@@ -1,6 +1,4 @@
- search as a command to execute which is going to be in the title bar
- each buffer needs a directory even the special ones: C:\a\b\c\+errors?
- open directories - resulting in buffer with dir listing and proper buffer name
- clean \r\n into \n on trim and load
- search backwards