Skip to content

Commit

Permalink
patch 8.0.1123: cannot define a toolbar for a window
Browse files Browse the repository at this point in the history
Problem:    Cannot define a toolbar for a window.
Solution:   Add a window-local toolbar.
  • Loading branch information
brammool committed Sep 17, 2017
1 parent dde403c commit 1b9645d
Show file tree
Hide file tree
Showing 20 changed files with 679 additions and 238 deletions.
23 changes: 22 additions & 1 deletion runtime/doc/gui.txt
@@ -1,4 +1,4 @@
*gui.txt* For Vim version 8.0. Last change: 2017 Aug 27
*gui.txt* For Vim version 8.0. Last change: 2017 Sep 16


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -784,10 +784,31 @@ In the Win32 and GTK+ GUI, starting a menu name with ']' excludes that menu
from the main menu bar. You must then use the |:popup| or |:tearoff| command
to display it.

*window-toolbar*
Each window can have a local toolbar. This uses the first line of the window,
thus reduces the space for the text by one line.

Only text can be used. When using Unicode special characters can be used to
make the items look like icons.

If the items do not fit then the last ones cannot be used. The toolbar does
not wrap.

Example for debugger tools: >
amenu 1.10 WinBar.Step :Step<CR>
amenu 1.20 WinBar.Next :Next<CR>
amenu 1.30 WinBar.Finish :Finish<CR>
amenu 1.40 WinBar.Cont :Continue<CR>
<
The window toolbar uses the ToolbarLine and ToolbarButton highlight groups.

*popup-menu*
In the Win32, GTK+, Motif, Athena and Photon GUI, you can define the
special menu "PopUp". This is the menu that is displayed when the right mouse
button is pressed, if 'mousemodel' is set to popup or popup_setpos.
Example: >
nnoremenu 1.40 PopUp.&Paste "+gP
menu PopUp
5.3 Showing What Menus Are Mapped To *showing-menus*
Expand Down
14 changes: 11 additions & 3 deletions runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
*terminal.txt* For Vim version 8.0. Last change: 2017 Sep 14
*terminal.txt* For Vim version 8.0. Last change: 2017 Sep 17


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -226,15 +226,15 @@ Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the
contents of the terminal window is under control of Vim, the job output is
suspended. CTRL-\ CTRL-N does the same.

Terminal-Job mode is where |tmap| mappings are applied. Keys sent by
Terminal-Job mode is where |:tmap| mappings are applied. Keys sent by
|term_sendkeys()| are not subject to tmap, but keys from |feedkeys()| are.

*E946*
In Terminal-Normal mode you can move the cursor around with the usual Vim
commands, Visually mark text, yank text, etc. But you cannot change the
contents of the buffer. The commands that would start insert mode, such as
'i' and 'a', return to Terminal-Job mode. The window will be updated to show
the contents of the terminal.
the contents of the terminal. |:startinsert| is ineffective.

In Terminal-Normal mode the statusline and window title show "(Terminal)". If
the job ends while in Terminal-Normal mode this changes to
Expand Down Expand Up @@ -372,6 +372,14 @@ In the window showing the source code some commands can used to control gdb:
:Finish execute the gdb "finish" command
:Continue execute the gdb "continue" command

The plugin adds a window toolbar with these entries:
Step :Step
Next :Over
Finish :Finish
Cont :Continue
Eval :Evaluate
This way you can use the mouse to perform the most common commands.


Inspecting variables ~

Expand Down
85 changes: 75 additions & 10 deletions runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
Expand Up @@ -104,6 +104,11 @@ func s:StartDebug(cmd)
call win_gotoid(s:gdbwin)

let s:breakpoints = {}

augroup TermDebug
au BufRead * call s:BufRead()
au BufUnload * call s:BufUnloaded()
augroup END
endfunc

func s:EndDebug(job, status)
Expand All @@ -120,6 +125,8 @@ func s:EndDebug(job, status)
if s:save_columns > 0
let &columns = s:save_columns
endif

au! TermDebug
endfunc

" Handle a message received from gdb on the GDB/MI interface.
Expand All @@ -132,7 +139,7 @@ func s:CommOutput(chan, msg)
let msg = msg[1:]
endif
if msg != ''
if msg =~ '^\*\(stopped\|running\)'
if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)'
call s:HandleCursor(msg)
elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,'
call s:HandleNewBreakpoint(msg)
Expand Down Expand Up @@ -161,6 +168,14 @@ func s:InstallCommands()

" TODO: can the K mapping be restored?
nnoremap K :Evaluate<CR>
if has('menu')
amenu WinBar.Step :Step<CR>
amenu WinBar.Next :Over<CR>
amenu WinBar.Finish :Finish<CR>
amenu WinBar.Cont :Continue<CR>
amenu WinBar.Eval :Evaluate<CR>
endif
endfunc

" Delete installed debugger commands in the current window.
Expand All @@ -176,6 +191,15 @@ func s:DeleteCommands()
delcommand Program

nunmap K

if has('menu')
aunmenu WinBar.Step
aunmenu WinBar.Next
aunmenu WinBar.Finish
aunmenu WinBar.Cont
aunmenu WinBar.Eval
endif

exe 'sign unplace ' . s:pc_id
for key in keys(s:breakpoints)
exe 'sign unplace ' . (s:break_id + key)
Expand Down Expand Up @@ -232,7 +256,15 @@ endfunc

" Handle the result of data-evaluate-expression
func s:HandleEvaluate(msg)
echomsg '"' . s:evalexpr . '": ' . substitute(a:msg, '.*value="\(.*\)"', '\1', '')
let value = substitute(a:msg, '.*value="\(.*\)"', '\1', '')
let value = substitute(value, '\\"', '"', 'g')
echomsg '"' . s:evalexpr . '": ' . value

if s:evalexpr[0] != '*' && value =~ '^0x' && value !~ '"$'
" Looks like a pointer, also display what it points to.
let s:evalexpr = '*' . s:evalexpr
call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . s:evalexpr . "\"\r")
endif
endfunc

" Handle an error.
Expand All @@ -247,10 +279,10 @@ func s:HandleCursor(msg)

if win_gotoid(s:startwin)
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
if a:msg =~ '^\*stopped' && filereadable(fname)
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
if lnum =~ '^[0-9]*$'
if expand('%:h') != fname
if expand('%:p') != fnamemodify(fname, ':p')
if &modified
" TODO: find existing window
exe 'split ' . fnameescape(fname)
Expand All @@ -260,7 +292,7 @@ func s:HandleCursor(msg)
endif
endif
exe lnum
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fnameescape(fname)
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
setlocal signcolumn=yes
endif
else
Expand Down Expand Up @@ -288,11 +320,17 @@ func s:HandleNewBreakpoint(msg)

let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')

exe 'sign place ' . (s:break_id + nr) . ' line=' . lnum . ' name=debugBreakpoint file=' . fnameescape(fname)

let entry['fname'] = fname
let entry['lnum'] = lnum

if bufloaded(fname)
call s:PlaceSign(nr, entry)
endif
endfunc

func s:PlaceSign(nr, entry)
exe 'sign place ' . (s:break_id + a:nr) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint file=' . a:entry['fname']
let a:entry['placed'] = 1
endfunc

" Handle deleting a breakpoint
Expand All @@ -302,6 +340,33 @@ func s:HandleBreakpointDelete(msg)
if nr == 0
return
endif
exe 'sign unplace ' . (s:break_id + nr)
unlet s:breakpoints[nr]
if has_key(s:breakpoints, nr)
let entry = s:breakpoints[nr]
if has_key(entry, 'placed')
exe 'sign unplace ' . (s:break_id + nr)
unlet entry['placed']
endif
unlet s:breakpoints[nr]
endif
endfunc

" Handle a BufRead autocommand event: place any signs.
func s:BufRead()
let fname = expand('<afile>:p')
for [nr, entry] in items(s:breakpoints)
if entry['fname'] == fname
call s:PlaceSign(nr, entry)
endif
endfor
endfunc

" Handle a BufUnloaded autocommand event: unplace any signs.
func s:BufUnloaded()
let fname = expand('<afile>:p')
for [nr, entry] in items(s:breakpoints)
if entry['fname'] == fname
let entry['placed'] = 0
endif
endfor
endfunc

1 change: 1 addition & 0 deletions src/Makefile
Expand Up @@ -2278,6 +2278,7 @@ test_arglist \
test_vimscript \
test_virtualedit \
test_visual \
test_winbar \
test_window_cmd \
test_window_id \
test_windows_home \
Expand Down
8 changes: 1 addition & 7 deletions src/eval.c
Expand Up @@ -8252,13 +8252,7 @@ ex_echo(exarg_T *eap)
void
ex_echohl(exarg_T *eap)
{
int id;

id = syn_name2id(eap->arg);
if (id == 0)
echo_attr = 0;
else
echo_attr = syn_id2attr(id);
echo_attr = syn_name2attr(eap->arg);
}

/*
Expand Down
3 changes: 3 additions & 0 deletions src/evalfunc.c
Expand Up @@ -5229,6 +5229,9 @@ get_win_info(win_T *wp, short tpnr, short winnr)
dict_add_nr_str(dict, "winnr", winnr, NULL);
dict_add_nr_str(dict, "winid", wp->w_id, NULL);
dict_add_nr_str(dict, "height", wp->w_height, NULL);
#ifdef FEAT_MENU
dict_add_nr_str(dict, "winbar", wp->w_winbar_height, NULL);
#endif
dict_add_nr_str(dict, "width", wp->w_width, NULL);
dict_add_nr_str(dict, "bufnr", wp->w_buffer->b_fnum, NULL);

Expand Down
13 changes: 3 additions & 10 deletions src/if_perl.xs
Expand Up @@ -1387,11 +1387,8 @@ PerlIOVim_pushed(pTHX_ PerlIO *f, const char *mode,
{
PerlIOVim *s = PerlIOSelf(f, PerlIOVim);
s->attr = 0;
if (arg && SvPOK(arg)) {
int id = syn_name2id((char_u *)SvPV_nolen(arg));
if (id != 0)
s->attr = syn_id2attr(id);
}
if (arg && SvPOK(arg))
s->attr = syn_name2attr((char_u *)SvPV_nolen(arg));
return PerlIOBase_pushed(aTHX_ f, mode, (SV *)NULL, tab);
}

Expand Down Expand Up @@ -1482,11 +1479,7 @@ Msg(text, hl=NULL)
{
attr = 0;
if (hl != NULL)
{
id = syn_name2id((char_u *)hl);
if (id != 0)
attr = syn_id2attr(id);
}
attr = syn_name2attr((char_u *)hl);
msg_split((char_u *)text, attr);
}

Expand Down

0 comments on commit 1b9645d

Please sign in to comment.