From 84c992c574b13f838258ae096d2205e09af52a6f Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 19 Jan 2026 23:16:32 +0100 Subject: [PATCH] CreateProject OpenProject --- build.sh | 2 +- project.te | 1 + src/text_editor/fuzzy_search_view.cpp | 3 +- src/text_editor/plugin_build_window.cpp | 4 +- .../plugin_directory_navigation.cpp | 38 +++++++++++ src/text_editor/plugin_project_management.cpp | 68 ++++++++++++++++--- .../plugin_search_open_buffers.cpp | 3 + 7 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 project.te diff --git a/build.sh b/build.sh index 380730e..aeef403 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ mkdir build cd build -FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -Wno-writable-strings -I../src -DDEBUG_BUILD=1" +FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -I../src -DDEBUG_BUILD=1" I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad" clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace diff --git a/project.te b/project.te new file mode 100644 index 0000000..a57aa40 --- /dev/null +++ b/project.te @@ -0,0 +1 @@ +:OpenCode \ No newline at end of file diff --git a/src/text_editor/fuzzy_search_view.cpp b/src/text_editor/fuzzy_search_view.cpp index a037c00..706259e 100644 --- a/src/text_editor/fuzzy_search_view.cpp +++ b/src/text_editor/fuzzy_search_view.cpp @@ -98,6 +98,7 @@ Array FuzzySearchLines(Allocator allocator, Buffer *buffer, Int line_ } void UpdateFuzzySearchView() { + ProfileFunction(); Scratch scratch; BSet active = GetBSet(ActiveWindowID); String16 line_string = GetLineStringWithoutNL(active.buffer, 0); @@ -108,7 +109,7 @@ void UpdateFuzzySearchView() { Buffer *scratch_buff = CreateScratchBuffer(scratch, active.buffer->cap); RawAppend(scratch_buff, line_string); - For(IterateInReverse(&ratings)) { + For (IterateInReverse(&ratings)) { String16 s = GetLineStringWithoutNL(active.buffer, it.index); if (s.len == 0) continue; RawAppend(scratch_buff, u"\n"); diff --git a/src/text_editor/plugin_build_window.cpp b/src/text_editor/plugin_build_window.cpp index 3556fba..d20660a 100644 --- a/src/text_editor/plugin_build_window.cpp +++ b/src/text_editor/plugin_build_window.cpp @@ -60,10 +60,10 @@ void CMD_RunFile() { SaveBuffer(primary.buffer); if (OS_WINDOWS) { - String cmd = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe", primary.buffer->name); + String cmd = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe && del cfile.*", primary.buffer->name); ExecBuild(cmd, GetDirectory(primary.buffer)); } else { - String cmd = Format(scratch, "bash <name); + String cmd = Format(scratch, "bash <name); ExecBuild(cmd, GetDirectory(primary.buffer)); } build.window->visible = true; diff --git a/src/text_editor/plugin_directory_navigation.cpp b/src/text_editor/plugin_directory_navigation.cpp index 24f5b8f..6586bf1 100644 --- a/src/text_editor/plugin_directory_navigation.cpp +++ b/src/text_editor/plugin_directory_navigation.cpp @@ -18,8 +18,46 @@ void InsertDirectoryNavigation(Buffer *buffer) { } } +void UpdateDirectoryNavigation() { +#if 0 + ProfileFunction(); + BSet active = GetBSet(ActiveWindowID); + Buffer *buffer = active.buffer; + + Scratch scratch; + Array existing_lines = Split(scratch, AllocCharString(scratch, buffer), "\n"); + bool modified = false; + for (FileIter it = IterateFiles(scratch, buffer->name); IsValid(it); Advance(&it)) { + bool found = false; + ForItem (existing, existing_lines) { + if (existing == it.filename) { + found = true; + UnorderedRemove(&existing_lines, existing); + break; + } + } + + if (found == false) { + modified = true; + break; + } + } + + if (existing_lines.len > 1) { + modified = true; + } + + if (modified) { + ReopenBuffer(buffer); + } + + UpdateFuzzySearchView(); +#endif +} + void OpenDirectoryNavigation(View *view) { SetFuzzy(view); + // view->update_hook = UpdateDirectoryNavigation; Buffer *buffer = GetBuffer(view->active_buffer); InsertDirectoryNavigation(buffer); SelectRange(view, GetBufferBeginAsRange(buffer)); diff --git a/src/text_editor/plugin_project_management.cpp b/src/text_editor/plugin_project_management.cpp index 5aa9efa..6b4a55e 100644 --- a/src/text_editor/plugin_project_management.cpp +++ b/src/text_editor/plugin_project_management.cpp @@ -55,9 +55,7 @@ void CO_OpenCode(mco_coro *co) { data->dont_wait_until_resolved = true; ); -void CMD_SetProjectHere() { - BSet main = GetBSet(PrimaryWindowID); - String directory = GetDirectory(main.buffer); +void OpenProject(String directory) { SetProjectDirectory(directory); #if PLUGIN_CONFIG Scratch scratch; @@ -67,18 +65,72 @@ void CMD_SetProjectHere() { } } #endif -} RegisterCommand(CMD_SetProjectHere, "", "Sets the project directory, opens the project file etc."); +} + +void CMD_OpenProject() { + BSet main = GetBSet(PrimaryWindowID); + String directory = GetDirectory(main.buffer); + OpenProject(directory); +} RegisterCommand(CMD_OpenProject, "", "Sets the project directory, opens the project file etc."); + +String16 CreateProjectBuildBat = uR"==(@echo off +mkdir build +pushd build +cl ../src/main.cpp /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column +popd +)=="; + +String16 CreateProjectBuildSh = uR"==(#!/usr/bin/bash +mkdir build +cd build +clang ../src/main.cpp -g -Wall -Wno-missing-braces -Wno-writable-strings -fdiagnostics-absolute-paths +)=="; + +String16 CreateProjectMain = uR"==(#include +int main() { + printf("hello world!\n"); + return 0; +} +)=="; void CO_CreateProject(mco_coro *co) { String16 project_name16 = QueryUserString(co, "Please tell me, how would you like to name your project?"); String directory = GetPrimaryDirectory(); + + // - project_directory + // - project.te + // - build.bat + // - build.sh + // - src + // - main.c { Scratch scratch; String project_name = ToString(scratch, project_name16); - String name = Format(scratch, "%S/%S", directory, project_name); - MakeDir(name); - Open(name); + String project_dir = Format(scratch, "%S/%S", directory, project_name); + String src_dir = Format(scratch, "%S/src", project_dir); + MakeDir(project_dir); + MakeDir(src_dir); + SetProjectDirectory(project_dir); + + Buffer *project = BufferOpenFile(Format(scratch, "%S/project.te", project_dir)); + RawAppendf(project, ":OpenCode\n:Set BinaryUnderDebug '%S/build/main.exe'\n", project_dir); + SaveBuffer(project); + + Buffer *build_bat = BufferOpenFile(Format(scratch, "%S/build.bat", project_dir)); + RawAppend(build_bat, CreateProjectBuildBat); + SaveBuffer(build_bat); + + Buffer *build_sh = BufferOpenFile(Format(scratch, "%S/build.sh", project_dir)); + RawAppend(build_sh, CreateProjectBuildSh); + SaveBuffer(build_sh); + + Buffer *main_file = BufferOpenFile(Format(scratch, "%S/main.cpp", src_dir)); + RawAppend(main_file, CreateProjectMain); + SaveBuffer(main_file); + + OpenProject(project_dir); + Open(main_file->name); } - + CO_OpenCode(co); } RegisterCoroutineCommand(CO_CreateProject, "", "Creates a project in current buffer directory with template files and all that, asks user for input etc."); \ No newline at end of file diff --git a/src/text_editor/plugin_search_open_buffers.cpp b/src/text_editor/plugin_search_open_buffers.cpp index 3079812..f0fc7b8 100644 --- a/src/text_editor/plugin_search_open_buffers.cpp +++ b/src/text_editor/plugin_search_open_buffers.cpp @@ -48,6 +48,8 @@ void UpdateSearchOpenBuffersView() { if (active.view->prev_search_line_hash != hash) { active.view->prev_search_line_hash = hash; if (line_string.len > 0) { + // @todo: somehow reintroduce history but manual, do the UndoKinds EditKind or something + // and implement EditKind_ExactBufferContent just save the Caret caret = active.view->carets[0]; SelectEntireBuffer(active.view); Replace(active.view, line_string); @@ -76,6 +78,7 @@ void CMD_SearchOpenBuffers() { NextActiveWindowID = main.window->id; JumpTempBuffer(&main); + main.buffer->no_history = true; AddCommand(&main.view->commands, "Open", OpenKeySet, []() { BSet active = GetBSet(ActiveWindowID); BSet main = GetBSet(PrimaryWindowID);