UIYesNoCancel
This commit is contained in:
@@ -782,6 +782,37 @@ SaveResult TrySavingAllBuffers() {
|
||||
return SAVE_YES;
|
||||
}
|
||||
|
||||
String UIYesNoCancel(mco_coro *co, BSet main, String question) {
|
||||
JumpGarbageBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
|
||||
RawAppendf(main.buffer, R"==(
|
||||
%S
|
||||
|
||||
:Yes :No :Cancel
|
||||
)==", question);
|
||||
main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0));
|
||||
main.view->carets[0].range.min = main.view->carets[0].range.max;
|
||||
Add(&main.view->hooks, {"Yes", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Yes";}, ParseKeyCached("enter")});
|
||||
Add(&main.view->hooks, {"No", "", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "No";}, ParseKeyCached("")});
|
||||
Add(&main.view->hooks, {"Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";}, ParseKeyCached("escape")});
|
||||
String result = "Cancel";
|
||||
for (;;) {
|
||||
if (main.window->active_view != main.view->id || main.window->close) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (main.view->hook_cmd != "") {
|
||||
result = main.view->hook_cmd;
|
||||
break;
|
||||
}
|
||||
|
||||
CoYield(co);
|
||||
}
|
||||
Close(main.buffer->id);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Coro_Close(mco_coro *co) {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
if (main.buffer->special || main.buffer->garbage) {
|
||||
@@ -810,40 +841,15 @@ void Coro_Close(mco_coro *co) {
|
||||
return;
|
||||
}
|
||||
|
||||
Buffer *buffer = main.buffer;
|
||||
JumpGarbageBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
|
||||
RawAppendf(main.buffer, R"==(
|
||||
Do you want to save [%S] before closing?
|
||||
|
||||
:Yes :No :Cancel
|
||||
)==", buffer->name);
|
||||
main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0));
|
||||
main.view->carets[0].range.min = main.view->carets[0].range.max;
|
||||
Add(&main.view->hooks, {"Yes", "enter", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Yes";}, ParseKeyCached("enter")});
|
||||
Add(&main.view->hooks, {"No", "", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "No";}, ParseKeyCached("")});
|
||||
Add(&main.view->hooks, {"Cancel", "escape", [](){BSet active = GetBSet(ActiveWindowID); active.view->hook_cmd = "Cancel";}, ParseKeyCached("escape")});
|
||||
for (;;) {
|
||||
if (main.window->active_view != main.view->id || main.window->close) {
|
||||
Close(main.buffer->id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (main.view->hook_cmd != "") {
|
||||
break;
|
||||
}
|
||||
|
||||
CoYield(co);
|
||||
}
|
||||
|
||||
Close(main.buffer->id);
|
||||
if (main.view->hook_cmd == "Yes") {
|
||||
SaveBuffer(buffer);
|
||||
Close(buffer->id);
|
||||
} else if (main.view->hook_cmd == "No") {
|
||||
Close(buffer->id);
|
||||
} else if (main.view->hook_cmd == "Cancel") {
|
||||
Scratch scratch;
|
||||
String question = Format(scratch, "Do you want to save [%S] before closing?", main.buffer->name);
|
||||
String result = UIYesNoCancel(co, main, question);
|
||||
if (result == "Yes") {
|
||||
SaveBuffer(main.buffer);
|
||||
Close(main.buffer->id);
|
||||
} else if (result == "No") {
|
||||
Close(main.buffer->id);
|
||||
} else if (result == "Cancel") {
|
||||
return;
|
||||
} ElseInvalidCodepath();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user