Add Modal InfoStyle used for bufer reload info box

Modal info style wont be replaced by other info boxes.
NCursesUI will center that info box.

Fixes #1060
This commit is contained in:
Maxime Coste 2017-01-04 11:24:07 +00:00
parent 8f821f0fba
commit b3674a2f03
5 changed files with 21 additions and 5 deletions

View File

@ -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 <ret> or y to reload, <esc> 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;

View File

@ -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);

View File

@ -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 "";
}

View File

@ -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);

View File

@ -28,7 +28,8 @@ enum class InfoStyle
Inline,
InlineAbove,
InlineBelow,
MenuDoc
MenuDoc,
Modal
};
enum class EventMode;