:Prev :Next, CatchAll
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
- From a user (novice) point of view, how does it look like?
|
||||
|
||||
Debug session:
|
||||
- Should highlight main buffer when clicking on status?
|
||||
- Report errorf - use coroutine dialogs
|
||||
- Replace in render layer also
|
||||
|
||||
Use session 1:
|
||||
- OpenCommand in command window freezes the app
|
||||
- :Rename command that will ask
|
||||
- :Rename command that will ask the user
|
||||
|
||||
New UI Session
|
||||
- Cleanup String16/String with Open and EvalCommands after lua refactor
|
||||
|
||||
@@ -164,7 +164,11 @@ void UIMessagef(const char *fmt, ...) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
RawAppendf(main.buffer, "\n %S\n", string);
|
||||
RawAppendf(main.buffer, "\n %S\n :Close\n", string);
|
||||
AddHook(&main.view->hooks, "Close", "escape", [](){
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
Close(active.buffer->id);
|
||||
});
|
||||
}
|
||||
|
||||
void ReportErrorf(const char *fmt, ...) {
|
||||
@@ -834,17 +838,17 @@ void Command_CloseAll() {
|
||||
CoAdd(Coro_CloseAll);
|
||||
} RegisterCommand(Command_CloseAll, "");
|
||||
|
||||
void Command_JumpBack() {
|
||||
void Command_Prev() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpBack(main.window);
|
||||
} RegisterCommand(Command_JumpBack, "alt-q | mousex1");
|
||||
} RegisterCommand(Command_Prev, "alt-q | mousex1");
|
||||
|
||||
void Command_JumpForward() {
|
||||
void Command_Next() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
main.window->skip_checkpoint = true;
|
||||
JumpForward(main.window);
|
||||
} RegisterCommand(Command_JumpForward, "alt-shift-q | mousex2");
|
||||
} RegisterCommand(Command_Next, "alt-shift-q | mousex2");
|
||||
|
||||
void Command_OpenUpFolder() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
|
||||
@@ -12,6 +12,7 @@ enum TriggerKind {
|
||||
TriggerKind_Key,
|
||||
TriggerKind_Mouse,
|
||||
TriggerKind_Binary,
|
||||
TriggerKind_CatchAll,
|
||||
};
|
||||
|
||||
struct Trigger {
|
||||
@@ -140,20 +141,31 @@ Trigger *ParseKeyChord(Lexer *lex) {
|
||||
return left;
|
||||
}
|
||||
|
||||
Trigger *ParseKeyExpr(Lexer *lex) {
|
||||
Trigger *ParseKeyOr(Lexer *lex) {
|
||||
Trigger *left = ParseKeyChord(lex);
|
||||
EatWhitespace(lex);
|
||||
while (At(lex) == '|') {
|
||||
Advance(lex);
|
||||
left = TriggerBinary(lex, left, ParseKeyExpr(lex), '|');
|
||||
left = TriggerBinary(lex, left, ParseKeyOr(lex), '|');
|
||||
EatWhitespace(lex);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
Trigger *ParseKeyCatchAll(Lexer *lex) {
|
||||
String string = AsString(lex);
|
||||
if (string == "catch_all") {
|
||||
Trigger *result = AllocType(lex->allocator, Trigger);
|
||||
result->kind = TriggerKind_CatchAll;
|
||||
return result;
|
||||
} else {
|
||||
return ParseKeyOr(lex);
|
||||
}
|
||||
}
|
||||
|
||||
Trigger *ParseKey(Allocator allocator, String key, char *debug_name) {
|
||||
Lexer lex = {allocator, key.data, key.data, key.data + key.len, debug_name};
|
||||
Trigger *result = ParseKeyExpr(&lex);
|
||||
Trigger *result = ParseKeyCatchAll(&lex);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -201,6 +213,10 @@ bool MatchEvent(Trigger *trigger, Event *event) {
|
||||
ok = MatchEvent(trigger->right, event);
|
||||
if (ok) return ok;
|
||||
} ElseInvalidCodepath();
|
||||
} else if (trigger->kind == TriggerKind_CatchAll) {
|
||||
if (event->kind == EVENT_MOUSE_LEFT || event->kind == EVENT_MOUSE_RIGHT || event->kind == EVENT_MOUSE_MIDDLE || event->kind == EVENT_MOUSE_X1 || event->kind == EVENT_MOUSE_X2 || event->kind == EVENT_KEY_PRESS || event->kind == EVENT_TEXT_INPUT) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -212,7 +228,7 @@ void TestParser() {
|
||||
{
|
||||
char *cmd = "ctrl-b";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyExpr(&base_lex);
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Key);
|
||||
Assert(trigger->key == SDLK_B);
|
||||
Assert(trigger->ctrl);
|
||||
@@ -222,7 +238,7 @@ void TestParser() {
|
||||
{
|
||||
char *cmd = "ctrl-b shift-ctrl-a";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyExpr(&base_lex);
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Binary);
|
||||
Assert(trigger->key == ' ');
|
||||
Assert(trigger->left->kind == TriggerKind_Key);
|
||||
@@ -238,7 +254,7 @@ void TestParser() {
|
||||
{
|
||||
char *cmd = "ctrl-b shift-ctrl-a | ctrl-c | ctrl-d";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyExpr(&base_lex);
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Binary);
|
||||
Assert(trigger->key == '|');
|
||||
|
||||
|
||||
@@ -282,13 +282,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Ctrl() && Shift() && Mouse(RIGHT)) {
|
||||
|
||||
} else if (Alt() && Ctrl() && Mouse(RIGHT)) {
|
||||
} else if (Ctrl() && Mouse(RIGHT)) {
|
||||
|
||||
} else if (Alt() && Mouse(RIGHT)) {
|
||||
} else if (Mouse(RIGHT)) {
|
||||
if (Ctrl() && Mouse(RIGHT)) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
bool mouse_in_document = AreOverlapping(mouse, active.window->document_rect);
|
||||
@@ -315,6 +309,8 @@ void OnCommand(Event event) {
|
||||
SaveStringInClipboard(string);
|
||||
}
|
||||
}
|
||||
} else if (Mouse(RIGHT)) {
|
||||
MouseLoadWord(event);
|
||||
}
|
||||
|
||||
if (Ctrl() && Mouse(LEFT)) {
|
||||
|
||||
@@ -178,7 +178,6 @@ struct Register_Variable {
|
||||
|
||||
void AddHook(Array<CommandData> *arr, String name, String binding, Function *function);
|
||||
|
||||
|
||||
enum OpenKind {
|
||||
OpenKind_Invalid,
|
||||
OpenKind_Skip,
|
||||
|
||||
@@ -14,28 +14,6 @@ void StatusWindowInit() {
|
||||
window->layout = false;
|
||||
window->jump_history = false;
|
||||
window->lose_focus_on_escape = true;
|
||||
|
||||
AddHook(&view->hooks, "Rename", "ctrl-r", [](){
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
BSet last = GetBSet(LastActiveLayoutWindowID);
|
||||
String16 buffer_string = GetString(active.buffer);
|
||||
Range replace_range = {0, active.buffer->len};
|
||||
bool found_separator = Seek(buffer_string, u" |", &replace_range.max);
|
||||
if (!found_separator) {
|
||||
ReportErrorf("Failed to :Rename, didn't find '|' separator");
|
||||
return;
|
||||
}
|
||||
|
||||
Scratch scratch;
|
||||
String16 buffer_name = GetString(active.buffer, replace_range);
|
||||
String buffer_name8 = ToString(scratch, buffer_name);
|
||||
ResolvedOpen o = ResolveOpen(scratch, buffer_name8, "dont_error");
|
||||
if (o.kind != OpenKind_Skip) {
|
||||
ReportErrorf("%S already exists, either on disk as file or as buffer", buffer_name8);
|
||||
return;
|
||||
}
|
||||
last.buffer->name = Intern(&GlobalInternTable, o.path);
|
||||
});
|
||||
}
|
||||
|
||||
void StatusWindowLayout(Rect2I *rect, Int wx, Int wy) {
|
||||
@@ -101,7 +79,7 @@ void StatusWindowUpdate() {
|
||||
// add separator at the end of buffer
|
||||
if (!found_separator) {
|
||||
SelectRange(title.view, GetBufferEndAsRange(title.buffer));
|
||||
ReplaceEx(scratch, title.view, u" | :Rename");
|
||||
ReplaceEx(scratch, title.view, u" | :Prev :Next");
|
||||
}
|
||||
|
||||
// replace data up to separator with filename and stuff
|
||||
|
||||
Reference in New Issue
Block a user