diff --git a/src/client.cc b/src/client.cc index c2904199..0230ff4f 100644 --- a/src/client.cc +++ b/src/client.cc @@ -287,7 +287,7 @@ void Client::close_buffer_reload_dialog() { kak_assert(m_buffer_reload_dialog_opened); m_buffer_reload_dialog_opened = false; - info_hide(); + info_hide(true); m_input_handler.reset_normal_mode(); } @@ -311,7 +311,7 @@ void Client::check_if_buffer_needs_reloading() info_show(format("reload '{}' ?", bufname), format("'{}' was modified externally\n" "press or y to reload, or n to keep", - bufname), {}, InfoStyle::Prompt); + bufname), {}, InfoStyle::Modal); m_buffer_reload_dialog_opened = true; m_input_handler.on_next_key(KeymapMode::None, [this](Key key, Context&){ on_buffer_reload_key(key); }); @@ -360,13 +360,19 @@ void Client::menu_hide() void Client::info_show(String title, String content, BufferCoord anchor, InfoStyle style) { + if (m_info.style == InfoStyle::Modal) // We already have a modal info opened, do not touch it. + return; + m_info = Info{ std::move(title), std::move(content), anchor, {}, style }; m_ui_pending |= InfoShow; m_ui_pending &= ~InfoHide; } -void Client::info_hide() +void Client::info_hide(bool even_modal) { + if (not even_modal and m_info.style == InfoStyle::Modal) + return; + m_info = Info{}; m_ui_pending |= InfoHide; m_ui_pending &= ~InfoShow; diff --git a/src/client.hh b/src/client.hh index 7b2b36bd..087b6f98 100644 --- a/src/client.hh +++ b/src/client.hh @@ -41,7 +41,7 @@ public: void menu_hide(); void info_show(String title, String content, BufferCoord anchor, InfoStyle style); - void info_hide(); + void info_hide(bool even_modal = false); void print_status(DisplayLine status_line, bool immediate = false); diff --git a/src/json_ui.cc b/src/json_ui.cc index 95697d73..d35471dd 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -137,6 +137,7 @@ String to_json(InfoStyle style) case InfoStyle::InlineAbove: return R"("inlineAbove")"; case InfoStyle::InlineBelow: return R"("inlineBelow")"; case InfoStyle::MenuDoc: return R"("menuDoc")"; + case InfoStyle::Modal: return R"("modal")"; } return ""; } diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 3099c949..ee5a4241 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -893,6 +893,9 @@ void NCursesUI::info_show(StringView title, StringView content, anchor = DisplayCoord{m_status_on_top ? 0 : m_dimensions.line, m_dimensions.column-1}; } + else if (style == InfoStyle::Modal) + info_box = make_info_box(m_info.title, m_info.content, + m_dimensions.column, {}); else { if (m_status_on_top) @@ -913,6 +916,11 @@ void NCursesUI::info_show(StringView title, StringView content, const Rect rect = {m_status_on_top ? 1_line : 0_line, m_dimensions}; if (style == InfoStyle::MenuDoc and m_menu) pos = m_menu.pos + DisplayCoord{0_line, m_menu.size.column}; + else if (style == InfoStyle::Modal) + { + auto half = [](const DisplayCoord& c) { return DisplayCoord{c.line / 2, c.column / 2}; }; + pos = rect.pos + half(rect.size) - half(size); + } else pos = compute_pos(anchor, size, rect, m_menu, style == InfoStyle::InlineAbove); diff --git a/src/user_interface.hh b/src/user_interface.hh index 38abaefd..95dc9650 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -28,7 +28,8 @@ enum class InfoStyle Inline, InlineAbove, InlineBelow, - MenuDoc + MenuDoc, + Modal }; enum class EventMode;