This commit is contained in:
Krzosa Karol
2026-01-10 10:36:09 +01:00
parent 4c9c0e5210
commit e575569d8a
9 changed files with 19 additions and 12 deletions

View File

@@ -1553,7 +1553,7 @@ void SaveBuffer(Buffer *buffer) {
ProfileFunction(); ProfileFunction();
For (GlobalHooks) { For (GlobalHooks) {
if (it.kind == HookKind_BeforeBufferSave) { if (it.kind == HookKind_BeforeSavingBuffer) {
ProfileScopeEx(it.name); ProfileScopeEx(it.name);
HookParam param = {}; HookParam param = {};
param.buffer = buffer; param.buffer = buffer;

View File

@@ -295,7 +295,7 @@ void HOOK_TrimTrailingWhitespace(HookParam param) {
if (TrimTrailingWhitespace) { if (TrimTrailingWhitespace) {
TrimWhitespace(param.buffer, false); TrimWhitespace(param.buffer, false);
} }
} RegisterHook(HOOK_TrimTrailingWhitespace, HookKind_BeforeBufferSave, "", "Cleans trailing whitespace before saving to file"); } RegisterHook(HOOK_TrimTrailingWhitespace, HookKind_BeforeSavingBuffer, "", "Cleans trailing whitespace before saving to file");
void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) { void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) {
Scratch scratch; Scratch scratch;

View File

@@ -39,10 +39,15 @@ enum HookKind {
// How can this be expanded? // How can this be expanded?
// - Changing the layout algorithm: this seems like a decent one // - Changing the layout algorithm: this seems like a decent one
// - What beside that? // - What beside that?
HookKind_LayoutWindow, HookKind_HandleWindowLayout,
HookKind_RenderWindow,
HookKind_BeforeBufferSave, // Move the special window rendering to hooks?
// HookKind_RenderWindow,
// HookKind_CreateWindow,
// How to handle formatters for multiple languages and other saving rules???
HookKind_BeforeSavingBuffer,
HookKind_CreateBuffer,
// HookKind_BufferSave, // HookKind_BufferSave,
// HookKind_AfterBufferSave, // HookKind_AfterBufferSave,
@@ -52,6 +57,8 @@ enum HookKind {
// HookKind_BufferOpen, // HookKind_BufferOpen,
// HookKind_AfterBufferOpen, // HookKind_AfterBufferOpen,
HookKind_CreateView,
}; };
// Global hooks, per (window, view, buffer) hooks // Global hooks, per (window, view, buffer) hooks

View File

@@ -140,7 +140,7 @@ void LayoutWindows(int16_t wx, int16_t wy) {
ForItem (n, Windows) { ForItem (n, Windows) {
ForItem (hook, n->hooks) { ForItem (hook, n->hooks) {
if (hook.kind == HookKind_LayoutWindow) { if (hook.kind == HookKind_HandleWindowLayout) {
ProfileScopeEx(it.name); ProfileScopeEx(it.name);
HookParam param = {}; HookParam param = {};
param.layout.window = n; param.layout.window = n;

View File

@@ -35,5 +35,5 @@ void InitBuildWindow(HookParam param) {
window->visible = false; window->visible = false;
window->lose_visibility_on_escape = true; window->lose_visibility_on_escape = true;
window->jump_history = false; window->jump_history = false;
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutBuildWindow", "", LayoutBuildWindow); AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutBuildWindow", "", LayoutBuildWindow);
} RegisterHook(InitBuildWindow, HookKind_AppInit, "", "Init the build window"); } RegisterHook(InitBuildWindow, HookKind_AppInit, "", "Init the build window");

View File

@@ -248,5 +248,5 @@ void InitCommandWindow(HookParam param) {
window->sync_visibility_with_focus = true; window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true; window->lose_focus_on_escape = true;
window->jump_history = false; window->jump_history = false;
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutCommandWindow", "", LayoutCommandWindow); AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutCommandWindow", "", LayoutCommandWindow);
} RegisterHook(InitCommandWindow, HookKind_AppInit, "", "Init command window"); } RegisterHook(InitCommandWindow, HookKind_AppInit, "", "Init command window");

View File

@@ -78,7 +78,7 @@ void InitDebugWindow(HookParam param) {
window->active_view = view->id; window->active_view = view->id;
window->visible = false; window->visible = false;
AddHook(&window->hooks, HookKind_LayoutWindow, "@todo: LayoutDebugWindow", "", LayoutDebugWindow); AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo: LayoutDebugWindow", "", LayoutDebugWindow);
} RegisterHook(InitDebugWindow, HookKind_AppInit, "", "Init the debug window"); } RegisterHook(InitDebugWindow, HookKind_AppInit, "", "Init the debug window");
void CMD_ToggleDebug(HookParam param) { void CMD_ToggleDebug(HookParam param) {

View File

@@ -99,5 +99,5 @@ void InitSearchWindow(HookParam param) {
AddCommand(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll); AddCommand(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll);
AddCommand(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch); AddCommand(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
AddCommand(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch); AddCommand(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutSearchWindow", "", LayoutSearchWindow); AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutSearchWindow", "", LayoutSearchWindow);
} RegisterHook(InitSearchWindow, HookKind_AppInit, "", "Init the search window"); } RegisterHook(InitSearchWindow, HookKind_AppInit, "", "Init the search window");

View File

@@ -77,7 +77,7 @@ void LayoutStatusWindow(HookParam param) {
} }
Int barsize = GetExpandingBarSize(p.window); Int barsize = GetExpandingBarSize(p.window);
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize); p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
} RegisterHook(LayoutStatusWindow, HookKind_LayoutWindow, "", "Layout the status window"); } RegisterHook(LayoutStatusWindow, HookKind_HandleWindowLayout, "", "Layout the status window");
void StatusWindowInit(HookParam param) { void StatusWindowInit(HookParam param) {
Window *window = CreateWind(); Window *window = CreateWind();
@@ -95,5 +95,5 @@ void StatusWindowInit(HookParam param) {
window->primary = false; window->primary = false;
window->jump_history = false; window->jump_history = false;
window->lose_focus_on_escape = true; window->lose_focus_on_escape = true;
AddHook(&window->hooks, HookKind_LayoutWindow, "@todo LayoutStatusWindow", "", LayoutStatusWindow); AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo LayoutStatusWindow", "", LayoutStatusWindow);
} RegisterHook(StatusWindowInit, HookKind_AppInit, "", "Init the status window"); } RegisterHook(StatusWindowInit, HookKind_AppInit, "", "Init the status window");