Add command runner window

This commit is contained in:
KK
2026-06-30 10:55:58 +02:00
parent 43a79535e8
commit fbeb32097e
3 changed files with 80 additions and 1 deletions

View File

@@ -120,7 +120,6 @@ String16 FetchFuzzyViewLoadLine(View *view) {
}
void CMD_OpenLoadWord() {
Scratch scratch;
BSet active = GetBSet(ActiveWindowID);
For (active.view->carets) {
Range range = it.range;

View File

@@ -0,0 +1,67 @@
WindowID CommandRunnerWindowID;
void CMD_ShowCommandRunner() {
BSet command_bar = GetBSet(CommandRunnerWindowID);
command_bar.window->visible = true;
NextActiveWindowID = command_bar.window->id;
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetRange(command_bar.buffer));
} RegisterCommand(CMD_ShowCommandRunner, "alt-p", "Little helper window that allows you to quickly run commands");
void LayoutCommandRunnerWindow(Rect2I *rect, int16_t wx, int16_t wy) {
Unused(wy); Unused(wx);
Window *window = GetWindow(CommandRunnerWindowID);
Rect2I copy_rect = *rect;
if (!window->visible) {
rect = &copy_rect;
}
Int barsize = GetExpandingBarSize(window);
window->document_rect = window->total_rect = CutBottom(rect, barsize);
// Int barsize = Clamp((Int)window->font->line_spacing*4, (Int)0, (Int)wx - 100);
// window->document_rect = window->total_rect = CutBottom(rect, barsize);
}
void CMD_OpenForRunnerWindow() {
Scratch scratch;
BSet active = GetBSet(ActiveWindowID);
BSet main = GetBSet(PrimaryWindowID);
NextActiveWindowID = main.window->id;
if (active.view->carets.len == 1 && GetSize(active.view->carets[0].range) == 0) {
String16 string = GetString(active.buffer);
string = Concat(scratch, u"!", string);
Open(string);
} else {
For (active.view->carets) {
Range range = it.range;
if (GetSize(range) == 0) {
range = EncloseLoadWord(active.buffer, GetFront(it));
}
String16 load_word = GetString(active.buffer, range);
load_word = Concat(scratch, u"!", load_word);
Open(load_word);
}
}
}
void InitCommandRunnerWindow() {
Window *window = CreateWind();
CommandRunnerWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "command_runner_window"));
buffer->special = true;
View *view = CreateView(buffer->id);
view->special = true;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->secondary_window_style = true;
window->draw_line_highlight = true;
window->primary = false;
window->visible = false;
window->sync_visibility_with_focus = true;
window->lose_focus_on_escape = true;
window->jump_history = false;
AddCommand(&view->commands, "Open", OpenKeySet, CMD_OpenForRunnerWindow);
}

View File

@@ -81,6 +81,7 @@
#define PLUGIN_PROJECT_MANAGEMENT 1
#define PLUGIN_BASIC_COMMANDS 1
#define PLUGIN_COMMAND_WINDOW 1
#define PLUGIN_COMMAND_RUNNER_WINDOW 1
#define PLUGIN_SEARCH_WINDOW 1
#define PLUGIN_STATUS_WINDOW 1
#define PLUGIN_BUILD_WINDOW 1
@@ -118,6 +119,7 @@
#include "plugin_window_management.cpp"
#include "plugin_directory_navigation.cpp"
#include "plugin_search_open_buffers.cpp"
#include "plugin_command_runner_window.cpp"
#include "plugin_project_management.cpp"
#include "plugin_basic_commands.cpp"
#include "plugin_command_window.cpp"
@@ -674,6 +676,10 @@ void LayoutWindows(int16_t wx, int16_t wy) {
LayoutCommandWindow(&screen_rect, wx, wy);
#endif
#if PLUGIN_COMMAND_RUNNER_WINDOW
LayoutCommandRunnerWindow(&screen_rect, wx, wy);
#endif
#if PLUGIN_DEBUG_WINDOW
LayoutDebugWindow(&screen_rect, wx, wy);
#endif
@@ -824,6 +830,9 @@ void Update(Event event) {
#endif
#if PLUGIN_SEARCH_WINDOW
SearchWindowID,
#endif
#if PLUGIN_COMMAND_RUNNER_WINDOW
CommandRunnerWindowID,
#endif
};
for (int i = 1; i < Lengthof(id); i += 1) {
@@ -1140,6 +1149,10 @@ int main(int argc, char **argv, char **envp)
InitCommandWindow();
#endif
#if PLUGIN_COMMAND_RUNNER_WINDOW
InitCommandRunnerWindow();
#endif
#if PLUGIN_DEBUG_WINDOW
InitDebugWindow();
#endif