Add command runner window
This commit is contained in:
67
src/plugin_command_runner_window.cpp
Normal file
67
src/plugin_command_runner_window.cpp
Normal 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 = ©_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);
|
||||
}
|
||||
Reference in New Issue
Block a user