RegisterCommand

This commit is contained in:
Krzosa Karol
2025-12-14 17:32:48 +01:00
parent 5a12ab8d8c
commit 85ca1a6a9e
3 changed files with 34 additions and 23 deletions

View File

@@ -26,11 +26,6 @@ Splits:
- move titlebar, search to splits?
Linux
- Add backtrace
- Use DPI well, use as much resolution but scale with DPI
Commands TODO:
- Search
- Ctrl + F

View File

@@ -705,7 +705,7 @@ void SaveBuffer(Buffer *buffer) {
void Command_Save() {
BSet active = GetBSet(LastActiveLayoutWindowID);
SaveBuffer(active.buffer);
}
} RegisterCommand(Command_Save);
int Lua_Save(lua_State *L) {
Command_Save();
@@ -718,7 +718,7 @@ void Command_SaveAll() {
SaveBuffer(it);
}
}
}
} RegisterCommand(Command_SaveAll);
int Lua_SaveAll(lua_State *L) {
Command_SaveAll();
@@ -992,7 +992,7 @@ void Command_Reopen() {
BSet main = GetBSet(LastActiveLayoutWindowID);
ReopenBuffer(main.buffer);
NextActiveWindowID = main.window->id;
}
} RegisterCommand(Command_Reopen);
int Lua_Reopen(lua_State *L) {
Command_Reopen();
@@ -1016,15 +1016,16 @@ void New(Window *window, String name = "") {
WindowOpenBufferView(window, name);
}
void Command_New(String name = "") {
void Command_New() {
BSet main = GetBSet(LastActiveLayoutWindowID);
New(main.window, name);
}
New(main.window, "");
} RegisterCommand(Command_New);
int Lua_New(lua_State *L) {
String name = lua_tostring(L, 1);
lua_pop(L, 1);
Command_New(name);
BSet main = GetBSet(LastActiveLayoutWindowID);
New(main.window, name);
return 0;
}
@@ -1070,7 +1071,7 @@ void Command_ToggleFullscreen() {
}
IsInFullscreen = !IsInFullscreen;
}
} RegisterCommand(Command_ToggleFullscreen);
int Lua_ToggleFullscreen(lua_State *L) {
Command_ToggleFullscreen();
@@ -1102,7 +1103,7 @@ void Command_ListCode() {
main.view->fuzzy_search = true;
main.view->update_scroll = true;
SelectRange(main.view, GetBufferEndAsRange(main.buffer));
}
} RegisterCommand(Command_ListCode);
int Lua_ListCode(lua_State *L) {
Command_ListCode();
@@ -1252,7 +1253,7 @@ void Command_ShowBufferList() {
}
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
}
} RegisterCommand(Command_ShowBufferList);
void Command_ShowCommandList() {
BSet command_bar = GetBSet(CommandBarWindowID);
@@ -1265,7 +1266,7 @@ void Command_ShowCommandList() {
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
}
} RegisterCommand(Command_ShowCommandList);
void Command_ListViews() {
BSet command_bar = GetBSet(CommandBarWindowID);
@@ -1279,7 +1280,7 @@ void Command_ListViews() {
command_bar.view->fuzzy_search = true;
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
}
} RegisterCommand(Command_ListViews);
int Lua_ListViews(lua_State *L) {
Command_ListViews();
@@ -1316,7 +1317,7 @@ void SetProjectFile(Buffer *buffer) {
void Command_SetProjectFile() {
BSet main = GetBSet(LastActiveLayoutWindowID);
SetProjectFile(main.buffer);
}
} RegisterCommand(Command_SetProjectFile);
void Command_SetWorkDir() {
String dir = lua_tostring(LuaState, -1);
@@ -1331,7 +1332,7 @@ void Command_SetWorkDir() {
void Command_SetProject() {
Command_SetWorkDir();
Command_SetProjectFile();
}
} RegisterCommand(Command_SetProject);
int Lua_SetProjectFile(lua_State *L) {
Command_SetProjectFile();
@@ -1419,12 +1420,12 @@ String16 FetchLoadWord(void) {
void Command_ToggleDebug() {
Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible;
}
} RegisterCommand(Command_ToggleDebug);
void Command_KillProcess() {
BSet main = GetBSet(LastActiveLayoutWindowID);
KillProcess(main.view);
}
} RegisterCommand(Command_KillProcess);
int Lua_KillProcess(lua_State *L) {
Command_KillProcess();
@@ -1434,7 +1435,7 @@ int Lua_KillProcess(lua_State *L) {
void Command_KillWindow() {
BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->kill = true;
}
} RegisterCommand(Command_KillWindow);
int Lua_KillWindow(lua_State *L) {
Command_KillWindow();

View File

@@ -184,4 +184,19 @@ void ReloadStyle() {
StyleFont = GetStyleString("Font", StyleFont);
StyleVCVarsall = GetStyleString("VCVarsall", StyleVCVarsall);
StyleUndoMergeTimeout = GetStyleFloat("UndoMergeTimeout", StyleUndoMergeTimeout);
}
}
typedef void CommandFunction(void);
Array<CommandFunction *> CommandFunctions;
#define STRINGIFY_(x) x
#define STRINGIFY(x) STRINGIFY_(x)
#define CONCAT_(a, b) a ## b
#define CONCAT(a, b) CONCAT_(a, b)
struct Register_Command {
Register_Command(CommandFunction *f) {
Add(&CommandFunctions, f);
}
};
#define RegisterCommand(NAME) Register_Command CONCAT(COMMAND, __COUNTER__)(NAME)