diff --git a/config.te b/config.te new file mode 100644 index 0000000..2d23c5a --- /dev/null +++ b/config.te @@ -0,0 +1,2 @@ +:Set FontSize 20 +:Set InternetBrowser '"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"' diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 8594b30..355bb49 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -2,10 +2,15 @@ ! From a user (novice) point of view, how does it look like? - We need regex for: [FormatCode matching, IsCode matching, -- Variable documentation -- Project configuration (the semantics: pass through command line (don't like simply open in dir) or use command to open?) +- Project config - IndentKind has issues with stuff still like cleaning whitespace etc. - Remedybg commands integrated! (like clicking f5 and opening up the window) +- Variable documentation ????? not looking too good due to formatting +- OnUpdate view hooks! +- JumpHistory maybe a smarter algorithm is needed, like accept only if line also changed +- Macros +- ctrl-shift-f should insert the selected into search +- jump history batching doesn't work ... Use session 4 - ListVariables instead of GenerateConfig, auto saving of variables diff --git a/src/render/font.cpp b/src/render/font.cpp index 1d40f2f..4f3513d 100644 --- a/src/render/font.cpp +++ b/src/render/font.cpp @@ -105,6 +105,7 @@ Glyph *GetGlyph(Font *font, uint32_t codepoint) { return &font->glyphs[index]; } } + Font CreateFont(Atlas *atlas, int32_t size, String path) { Allocator allocator = GetSystemAllocator(); Scratch scratch; diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index a2e9ffb..bee17ef 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -547,12 +547,11 @@ void Set(String string) { } ElseInvalidCodepath(); - if (name == "FontSize" || name == "Font") { - ReloadFont(Font, (U32)FontSize); + if (name == "FontSize" || name == "PathToFont") { + ReloadFont(PathToFont, (U32)FontSize); } else if (name == "WorkDir") { SetWorkDirHere(*var->string); } - return; } @@ -1150,13 +1149,13 @@ void CMD_Undo() { void CMD_MakeFontLarger() { FontSize += 1; - ReloadFont(Font, (U32)FontSize); + ReloadFont(PathToFont, (U32)FontSize); } RegisterCommand(CMD_MakeFontLarger, "ctrl-equals", "Increase the font size"); void CMD_MakeFontSmaller() { if (FontSize > 4) { FontSize -= 1; - ReloadFont(Font, (U32)FontSize); + ReloadFont(PathToFont, (U32)FontSize); } } RegisterCommand(CMD_MakeFontSmaller, "ctrl-minus", "Decrease the font size"); diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index 17e8082..925d1e9 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -36,6 +36,7 @@ WindowID BuildWindowID; ViewID BuildViewID; BufferID BuildBufferID; BufferID SearchProjectBufferID; +BufferID GlobalConfigBufferID; WindowID NextActiveWindowID; WindowID ActiveWindowID; @@ -154,14 +155,15 @@ RegisterVariable(Int, WaitForEvents, 1); RegisterVariable(Int, DrawLineNumbers, 1); RegisterVariable(Int, DrawScrollbar, 1); RegisterVariable(Int, IndentSize, 4); -RegisterVariable(String, IndentKind, "spaces"); +RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces"); RegisterVariable(Int, FontSize, 15); RegisterVariable(String, WorkDir, ""); -RegisterVariable(String, Font, ""); -RegisterVariable(String, VCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); +RegisterVariable(String, PathToFont, ""); +RegisterVariable(String, WindowsVCVarsPathToLoadDevEnviroment, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); RegisterVariable(Float, UndoMergeTime, 0.3); RegisterVariable(Float, JumpHistoryMergeTime, 0.3); RegisterVariable(String, InternetBrowser, "firefox"); RegisterVariable(String, NonCodePatterns_EndsWith, ".git/|.obj|.o|.pdb|.exe|.ilk|.ttf|.ico|.gif|.jpg|.png|.spall|.dll|.so|.a|.lib"); RegisterVariable(Int, TrimTrailingWhitespace, 1); -RegisterVariable(Int, FormatCode, 0); \ No newline at end of file +RegisterVariable(Int, FormatCode, 0); +RegisterVariable(Int, SetModifiesConfig, 1); \ No newline at end of file diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 69a23a8..9e8e097 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -676,7 +676,7 @@ void Windows_SetupVCVarsall(mco_coro *co) { Scratch scratch; String working_dir = WorkDir; String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-"); - String cmd = Format(scratch, "\"%S\" && set", VCVarsall); + String cmd = Format(scratch, "\"%S\" && set", WindowsVCVarsPathToLoadDevEnviroment); view = ExecHidden(buffer_name, cmd, working_dir); } for (;;) { @@ -874,7 +874,7 @@ int main(int argc, char **argv) InitBuffers(); InitRender(); - ReloadFont(Font, (U32)FontSize); + ReloadFont(PathToFont, (U32)FontSize); InitWindows(); InitOS(ReportWarningf); @@ -895,13 +895,9 @@ int main(int argc, char **argv) Window *window = GetWindow(NullWindowID); View *view = WindowOpenBufferView(window, config_path); Buffer *buffer = GetBuffer(view->active_buffer); - bool file_exists = buffer->file_mod_time != 0; - if (!file_exists) { - GenerateConfig(view); - } else { - EvalCommandsLineByLine({window, view, buffer}); - } - buffer->dirty = false; + buffer->special = true; + GlobalConfigBufferID = buffer->id; + EvalCommandsLineByLine({window, view, buffer}); if (window->active_view == view->id) { window->active_view = NullViewID; } diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 5835303..035c172 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -167,7 +167,7 @@ struct Variable { struct Register_Variable { Register_Variable(Array *variables, VariableType type, String name, void *addr) { - Add(variables, {type, name, addr}); + Add(variables, {type, name, {addr}}); } }; #define RegisterVariable(type, name, ...) \ @@ -199,6 +199,7 @@ struct ResolvedOpen { Int line, col; bool existing_buffer; }; + ResolvedOpen ResolveOpen(Allocator scratch, String path, ResolveOpenMeta meta); BSet Open(String path, ResolveOpenMeta meta = ResolveOpenMeta_Normal); BSet Open(String16 path, ResolveOpenMeta meta = ResolveOpenMeta_Normal); diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 580cf7a..5dd06b5 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -508,12 +508,12 @@ Array GetSelectedLinesSorted(Allocator allocator, View *view) { char16_t GetIndentChar() { char16_t c = u' '; - if (IndentKind == "spaces") { + if (IndentKindWhichIsTabsOrSpaces == "spaces") { c = u' '; - } else if (IndentKind == "tabs") { + } else if (IndentKindWhichIsTabsOrSpaces == "tabs") { c = u'\t'; } else { - ReportErrorf("Invalid IndentKind value: %S", IndentKind); + ReportErrorf("Invalid IndentKindWhichIsTabsOrSpaces value: %S", IndentKindWhichIsTabsOrSpaces); } return c; } diff --git a/src/text_editor/view.h b/src/text_editor/view.h index 96474f1..cc292e3 100644 --- a/src/text_editor/view.h +++ b/src/text_editor/view.h @@ -2,8 +2,18 @@ struct View; struct ViewID { Int id; View *o; }; typedef void Function(); -struct FunctionData { String name; Function *function; }; -struct CommandData { String name; String binding; Function *function; String doc; struct Trigger *trigger; }; +struct FunctionData { + String name; + Function *function; +}; + +struct CommandData { + String name; + String binding; + Function *function; + String doc; + struct Trigger *trigger; +}; enum ViewKind { ViewKind_Normal, diff --git a/src/text_editor/window_command.cpp b/src/text_editor/window_command.cpp index cf367f1..3376916 100644 --- a/src/text_editor/window_command.cpp +++ b/src/text_editor/window_command.cpp @@ -13,15 +13,49 @@ void CMD_ShowCommands() { if (it.name == "OpenCommand") { continue; } - RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding); + // RawAppendf(command_bar.buffer, "\n:%-30S <|| :Set %-30S '%-30S'", it.name, it.name, it.binding); + RawAppendf(command_bar.buffer, "\n:%-30S <|| ", it.name); if (it.doc.len) { - RawAppendf(command_bar.buffer, " |::| %S", it.doc); + RawAppendf(command_bar.buffer, "%S", it.doc); } } command_bar.view->update_scroll = true; SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); } RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window"); +void CMD_OpenConfig() { + Buffer *buffer = GetBuffer(GlobalConfigBufferID); + Open(buffer->name); +} RegisterCommand(CMD_OpenConfig, "", "Open the global config file"); + +void CMD_OpenConfigOptions() { + if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_OpenConfigOptions) { + NextActiveWindowID = PrimaryWindowID; + return; + } + ProfileFunction(); + + BSet command_bar = GetBSet(CommandWindowID); + command_bar.window->visible = true; + NextActiveWindowID = command_bar.window->id; + ResetBuffer(command_bar.buffer); + For (Variables) { + RawAppendf(command_bar.buffer, "\n:Set %-50S ", it.name); + switch(it.type) { + case VariableType_Color: RawAppendf(command_bar.buffer, "%x", it.color->value); break; + case VariableType_String: RawAppendf(command_bar.buffer, "'%S'", *it.string); break; + case VariableType_Int: RawAppendf(command_bar.buffer, "%lld", (long long)*it.i); break; + case VariableType_Float: RawAppendf(command_bar.buffer, "%f", *it.f); break; + default: InvalidCodepath(); + } + } + For (CommandFunctions) { + RawAppendf(command_bar.buffer, "\n:Set %-50S '%S'", it.name, it.binding); + } + command_bar.view->update_scroll = true; + SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer)); +} RegisterCommand(CMD_OpenConfigOptions, "", "List available variables and associated documentation inside the command window"); + void CMD_ShowDebugBufferList() { if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowDebugBufferList) { NextActiveWindowID = PrimaryWindowID;