UIYesNoCancel
This commit is contained in:
@@ -782,6 +782,37 @@ SaveResult TrySavingAllBuffers() {
|
|||||||
return SAVE_YES;
|
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) {
|
void Coro_Close(mco_coro *co) {
|
||||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||||
if (main.buffer->special || main.buffer->garbage) {
|
if (main.buffer->special || main.buffer->garbage) {
|
||||||
@@ -810,40 +841,15 @@ void Coro_Close(mco_coro *co) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer *buffer = main.buffer;
|
Scratch scratch;
|
||||||
JumpGarbageBuffer(&main);
|
String question = Format(scratch, "Do you want to save [%S] before closing?", main.buffer->name);
|
||||||
NextActiveWindowID = main.window->id;
|
String result = UIYesNoCancel(co, main, question);
|
||||||
|
if (result == "Yes") {
|
||||||
RawAppendf(main.buffer, R"==(
|
SaveBuffer(main.buffer);
|
||||||
Do you want to save [%S] before closing?
|
Close(main.buffer->id);
|
||||||
|
} else if (result == "No") {
|
||||||
:Yes :No :Cancel
|
Close(main.buffer->id);
|
||||||
)==", buffer->name);
|
} else if (result == "Cancel") {
|
||||||
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") {
|
|
||||||
return;
|
return;
|
||||||
} ElseInvalidCodepath();
|
} ElseInvalidCodepath();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user