Open and navigate directories
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ struct Buffer {
|
||||
int edit_phase;
|
||||
bool no_history;
|
||||
bool dirty;
|
||||
bool is_directory;
|
||||
};
|
||||
|
||||
struct View {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user