Notify attached UIs whenever menus change

This adds a redraw notification "update_menu" which is sent whenever
Vim's menus are changed by the :menu command and friends.
This commit is contained in:
Robin Allen 2015-07-11 00:03:30 +01:00
parent 250aca4f89
commit d5b5063622
7 changed files with 78 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "nvim/keymap.h" #include "nvim/keymap.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/ui.h"
#define MENUDEPTH 10 /* maximum depth of menus */ #define MENUDEPTH 10 /* maximum depth of menus */
@ -249,6 +250,7 @@ ex_menu (
xfree(map_buf); xfree(map_buf);
} }
ui_update_menu();
theend: theend:
; ;

View File

@ -82,6 +82,7 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
ui->clear = remote_ui_clear; ui->clear = remote_ui_clear;
ui->eol_clear = remote_ui_eol_clear; ui->eol_clear = remote_ui_eol_clear;
ui->cursor_goto = remote_ui_cursor_goto; ui->cursor_goto = remote_ui_cursor_goto;
ui->update_menu = remote_ui_update_menu;
ui->busy_start = remote_ui_busy_start; ui->busy_start = remote_ui_busy_start;
ui->busy_stop = remote_ui_busy_stop; ui->busy_stop = remote_ui_busy_stop;
ui->mouse_on = remote_ui_mouse_on; ui->mouse_on = remote_ui_mouse_on;
@ -189,6 +190,12 @@ static void remote_ui_cursor_goto(UI *ui, int row, int col)
push_call(ui, "cursor_goto", args); push_call(ui, "cursor_goto", args);
} }
static void remote_ui_update_menu(UI *ui)
{
Array args = ARRAY_DICT_INIT;
push_call(ui, "update_menu", args);
}
static void remote_ui_busy_start(UI *ui) static void remote_ui_busy_start(UI *ui)
{ {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;

View File

@ -149,6 +149,7 @@ UI *tui_start(void)
ui->clear = tui_clear; ui->clear = tui_clear;
ui->eol_clear = tui_eol_clear; ui->eol_clear = tui_eol_clear;
ui->cursor_goto = tui_cursor_goto; ui->cursor_goto = tui_cursor_goto;
ui->update_menu = tui_update_menu;
ui->busy_start = tui_busy_start; ui->busy_start = tui_busy_start;
ui->busy_stop = tui_busy_stop; ui->busy_stop = tui_busy_stop;
ui->mouse_on = tui_mouse_on; ui->mouse_on = tui_mouse_on;
@ -378,6 +379,11 @@ static void tui_cursor_goto(UI *ui, int row, int col)
unibi_goto(ui, row, col); unibi_goto(ui, row, col);
} }
static void tui_update_menu(UI *ui)
{
// Do nothing; menus are for GUI only
}
static void tui_busy_start(UI *ui) static void tui_busy_start(UI *ui)
{ {
((TUIData *)ui->data)->busy = true; ((TUIData *)ui->data)->busy = true;

View File

@ -324,6 +324,11 @@ void ui_cursor_goto(int new_row, int new_col)
pending_cursor_update = true; pending_cursor_update = true;
} }
void ui_update_menu(void)
{
UI_CALL(update_menu);
}
int ui_current_row(void) int ui_current_row(void)
{ {
return row; return row;

View File

@ -20,6 +20,7 @@ struct ui_t {
void (*clear)(UI *ui); void (*clear)(UI *ui);
void (*eol_clear)(UI *ui); void (*eol_clear)(UI *ui);
void (*cursor_goto)(UI *ui, int row, int col); void (*cursor_goto)(UI *ui, int row, int col);
void (*update_menu)(UI *ui);
void (*busy_start)(UI *ui); void (*busy_start)(UI *ui);
void (*busy_stop)(UI *ui); void (*busy_stop)(UI *ui);
void (*mouse_on)(UI *ui); void (*mouse_on)(UI *ui);

View File

@ -0,0 +1,52 @@
local helpers = require('test.functional.helpers')
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
local feed = helpers.feed
describe("update_menu notification", function()
local screen
before_each(function()
clear()
screen = Screen.new()
screen:attach()
end)
after_each(function()
screen:detach()
end)
function expect_sent(expected)
screen:wait(function()
if screen.update_menu ~= expected then
if expected then
return 'update_menu was expected but not sent'
else
return 'update_menu was sent unexpectedly'
end
end
end)
end
it("should be sent when adding a menu", function()
command('menu Test.Test :')
expect_sent(true)
end)
it("should be sent when deleting a menu", function()
command('menu Test.Test :')
screen.update_menu = false
command('unmenu Test.Test')
expect_sent(true)
end)
it("should not be sent unnecessarily", function()
feed('i12345<ESC>:redraw<CR>')
expect_sent(false)
end)
end)

View File

@ -166,6 +166,7 @@ function Screen.new(width, height)
title = '', title = '',
icon = '', icon = '',
bell = false, bell = false,
update_menu = false,
visual_bell = false, visual_bell = false,
suspended = false, suspended = false,
_default_attr_ids = nil, _default_attr_ids = nil,
@ -416,6 +417,10 @@ function Screen:_handle_suspend()
self.suspended = true self.suspended = true
end end
function Screen:_handle_update_menu()
self.update_menu = true
end
function Screen:_handle_set_title(title) function Screen:_handle_set_title(title)
self.title = title self.title = title
end end