mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-18 17:02:06 +03:00
Add a MenuDoc style for info box, that will place it next to the menu
This commit is contained in:
parent
484fffc288
commit
e1fc2677e3
@ -144,7 +144,7 @@ void Client::check_buffer_fs_timestamp()
|
|||||||
"reload '" + buffer.display_name() + "' ?",
|
"reload '" + buffer.display_name() + "' ?",
|
||||||
"'" + buffer.display_name() + "' was modified externally\n"
|
"'" + buffer.display_name() + "' was modified externally\n"
|
||||||
"press r or y to reload, k or n to keep",
|
"press r or y to reload, k or n to keep",
|
||||||
pos, get_face("Information"), MenuStyle::Prompt);
|
pos, get_face("Information"), InfoStyle::Prompt);
|
||||||
|
|
||||||
m_input_handler.on_next_key(KeymapMode::None,
|
m_input_handler.on_next_key(KeymapMode::None,
|
||||||
[this, filename](Key key, Context& context) {
|
[this, filename](Key key, Context& context) {
|
||||||
|
@ -1234,7 +1234,7 @@ const CommandDesc info_cmd = {
|
|||||||
context.ui().info_hide();
|
context.ui().info_hide();
|
||||||
if (parser.positional_count() > 0)
|
if (parser.positional_count() > 0)
|
||||||
{
|
{
|
||||||
MenuStyle style = MenuStyle::Prompt;
|
InfoStyle style = InfoStyle::Prompt;
|
||||||
CharCoord pos = context.ui().dimensions();
|
CharCoord pos = context.ui().dimensions();
|
||||||
pos.column -= 1;
|
pos.column -= 1;
|
||||||
if (parser.has_option("anchor"))
|
if (parser.has_option("anchor"))
|
||||||
@ -1247,7 +1247,7 @@ const CommandDesc info_cmd = {
|
|||||||
ByteCoord coord{str_to_int(anchor.substr(0, dotb))-1,
|
ByteCoord coord{str_to_int(anchor.substr(0, dotb))-1,
|
||||||
str_to_int(anchor.substr(dotb+1))-1};
|
str_to_int(anchor.substr(dotb+1))-1};
|
||||||
pos = context.window().display_position(coord);
|
pos = context.window().display_position(coord);
|
||||||
style = MenuStyle::Inline;
|
style = InfoStyle::Inline;
|
||||||
}
|
}
|
||||||
const String& title = parser.has_option("title") ? parser.option_value("title") : "";
|
const String& title = parser.has_option("title") ? parser.option_value("title") : "";
|
||||||
context.ui().info_show(title, parser[0], pos, get_face("Information"), style);
|
context.ui().info_show(title, parser[0], pos, get_face("Information"), style);
|
||||||
|
@ -118,7 +118,7 @@ public:
|
|||||||
Face col = get_face("Information");
|
Face col = get_face("Information");
|
||||||
CharCoord pos = context().window().dimensions();
|
CharCoord pos = context().window().dimensions();
|
||||||
pos.column -= 1;
|
pos.column -= 1;
|
||||||
context().ui().info_show(key_to_str(key), it->second.docstring, pos, col, MenuStyle::Prompt);
|
context().ui().info_show(key_to_str(key), it->second.docstring, pos, col, InfoStyle::Prompt);
|
||||||
}
|
}
|
||||||
it->second.func(context(), m_count);
|
it->second.func(context(), m_count);
|
||||||
}
|
}
|
||||||
|
@ -279,12 +279,8 @@ void InsertCompleter::select(int offset)
|
|||||||
{
|
{
|
||||||
m_context.ui().menu_select(m_current_candidate);
|
m_context.ui().menu_select(m_current_candidate);
|
||||||
if (not candidate.second.empty())
|
if (not candidate.second.empty())
|
||||||
{
|
m_context.ui().info_show(candidate.first, candidate.second, CharCoord{},
|
||||||
CharCoord pos = m_context.window().dimensions();
|
get_face("Information"), InfoStyle::MenuDoc);
|
||||||
pos.column -= 1;
|
|
||||||
m_context.ui().info_show(candidate.first, candidate.second, pos,
|
|
||||||
get_face("Information"), MenuStyle::Prompt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// when we select a match, remove non displayed matches from the candidates
|
// when we select a match, remove non displayed matches from the candidates
|
||||||
// which are considered as invalid with the new completion timestamp
|
// which are considered as invalid with the new completion timestamp
|
||||||
|
@ -767,22 +767,26 @@ static String make_info_box(StringView title, StringView message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NCursesUI::info_show(StringView title, StringView content,
|
void NCursesUI::info_show(StringView title, StringView content,
|
||||||
CharCoord anchor, Face face, MenuStyle style)
|
CharCoord anchor, Face face, InfoStyle style)
|
||||||
{
|
{
|
||||||
if (m_info_win)
|
if (m_info_win)
|
||||||
delwin(m_info_win);
|
delwin(m_info_win);
|
||||||
|
|
||||||
StringView info_box = content;
|
StringView info_box = content;
|
||||||
String fancy_info_box;
|
String fancy_info_box;
|
||||||
if (style == MenuStyle::Prompt)
|
if (style == InfoStyle::Prompt)
|
||||||
{
|
{
|
||||||
fancy_info_box = make_info_box(title, content, m_dimensions.column);
|
fancy_info_box = make_info_box(title, content, m_dimensions.column);
|
||||||
info_box = fancy_info_box;
|
info_box = fancy_info_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharCoord size = compute_needed_size(info_box);
|
CharCoord size = compute_needed_size(info_box);
|
||||||
|
CharCoord pos;
|
||||||
CharCoord pos = compute_pos(anchor, size, m_menu_win);
|
if (style == InfoStyle::MenuDoc and m_menu_win and m_menu_columns == 1)
|
||||||
|
pos = window_pos(m_menu_win) +
|
||||||
|
CharCoord{0_line, window_size(m_menu_win).column};
|
||||||
|
else
|
||||||
|
pos = compute_pos(anchor, size, m_menu_win);
|
||||||
|
|
||||||
m_info_win = (NCursesWin*)newwin((int)size.line, (int)size.column,
|
m_info_win = (NCursesWin*)newwin((int)size.line, (int)size.column,
|
||||||
(int)pos.line, (int)pos.column);
|
(int)pos.line, (int)pos.column);
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
void info_show(StringView title, StringView content,
|
void info_show(StringView title, StringView content,
|
||||||
CharCoord anchor, Face face,
|
CharCoord anchor, Face face,
|
||||||
MenuStyle style) override;
|
InfoStyle style) override;
|
||||||
void info_hide() override;
|
void info_hide() override;
|
||||||
|
|
||||||
void refresh() override;
|
void refresh() override;
|
||||||
|
@ -116,7 +116,7 @@ bool show_auto_info_ifn(StringView title, StringView info,
|
|||||||
Face face = get_face("Information");
|
Face face = get_face("Information");
|
||||||
CharCoord pos = context.window().dimensions();
|
CharCoord pos = context.window().dimensions();
|
||||||
pos.column -= 1;
|
pos.column -= 1;
|
||||||
context.ui().info_show(title, info, pos, face, MenuStyle::Prompt);
|
context.ui().info_show(title, info, pos, face, InfoStyle::Prompt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ void command(Context& context, int)
|
|||||||
CharCoord pos = context.window().dimensions();
|
CharCoord pos = context.window().dimensions();
|
||||||
pos.column -= 1;
|
pos.column -= 1;
|
||||||
if (not info.first.empty() and not info.second.empty())
|
if (not info.first.empty() and not info.second.empty())
|
||||||
context.ui().info_show(info.first, info.second, pos , col, MenuStyle::Prompt);
|
context.ui().info_show(info.first, info.second, pos , col, InfoStyle::Prompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event == PromptEvent::Validate)
|
if (event == PromptEvent::Validate)
|
||||||
@ -569,7 +569,7 @@ void regex_prompt(Context& context, const String prompt, T func)
|
|||||||
Face face = get_face("Information");
|
Face face = get_face("Information");
|
||||||
CharCoord pos = context.window().dimensions();
|
CharCoord pos = context.window().dimensions();
|
||||||
pos.column -= 1;
|
pos.column -= 1;
|
||||||
context.ui().info_show("regex error", err.what(), pos, face, MenuStyle::Prompt);
|
context.ui().info_show("regex error", err.what(), pos, face, InfoStyle::Prompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ public:
|
|||||||
|
|
||||||
void info_show(StringView title, StringView content,
|
void info_show(StringView title, StringView content,
|
||||||
CharCoord anchor, Face face,
|
CharCoord anchor, Face face,
|
||||||
MenuStyle style) override;
|
InfoStyle style) override;
|
||||||
void info_hide() override;
|
void info_hide() override;
|
||||||
|
|
||||||
void draw(const DisplayBuffer& display_buffer,
|
void draw(const DisplayBuffer& display_buffer,
|
||||||
@ -323,7 +323,7 @@ void RemoteUI::menu_hide()
|
|||||||
|
|
||||||
void RemoteUI::info_show(StringView title, StringView content,
|
void RemoteUI::info_show(StringView title, StringView content,
|
||||||
CharCoord anchor, Face face,
|
CharCoord anchor, Face face,
|
||||||
MenuStyle style)
|
InfoStyle style)
|
||||||
{
|
{
|
||||||
Message msg(m_socket_watcher.fd());
|
Message msg(m_socket_watcher.fd());
|
||||||
msg.write(RemoteUIMsg::InfoShow);
|
msg.write(RemoteUIMsg::InfoShow);
|
||||||
@ -490,7 +490,7 @@ void RemoteClient::process_next_message()
|
|||||||
auto content = read<String>(socket);
|
auto content = read<String>(socket);
|
||||||
auto anchor = read<CharCoord>(socket);
|
auto anchor = read<CharCoord>(socket);
|
||||||
auto face = read<Face>(socket);
|
auto face = read<Face>(socket);
|
||||||
auto style = read<MenuStyle>(socket);
|
auto style = read<InfoStyle>(socket);
|
||||||
m_ui->info_show(title, content, anchor, face, style);
|
m_ui->info_show(title, content, anchor, face, style);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,13 @@ enum class MenuStyle
|
|||||||
Inline
|
Inline
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class InfoStyle
|
||||||
|
{
|
||||||
|
Prompt,
|
||||||
|
Inline,
|
||||||
|
MenuDoc
|
||||||
|
};
|
||||||
|
|
||||||
using InputCallback = std::function<void()>;
|
using InputCallback = std::function<void()>;
|
||||||
|
|
||||||
class UserInterface : public SafeCountable
|
class UserInterface : public SafeCountable
|
||||||
@ -35,7 +42,7 @@ public:
|
|||||||
|
|
||||||
virtual void info_show(StringView title, StringView content,
|
virtual void info_show(StringView title, StringView content,
|
||||||
CharCoord anchor, Face face,
|
CharCoord anchor, Face face,
|
||||||
MenuStyle style) = 0;
|
InfoStyle style) = 0;
|
||||||
virtual void info_hide() = 0;
|
virtual void info_hide() = 0;
|
||||||
|
|
||||||
virtual void draw(const DisplayBuffer& display_buffer,
|
virtual void draw(const DisplayBuffer& display_buffer,
|
||||||
|
Loading…
Reference in New Issue
Block a user