Skip to content

Conversation

@ychin
Copy link
Member

@ychin ychin commented Sep 8, 2020

Touch Bar add submenu/title/emoji picker support

Can now specify submenus. E.g. TouchBar.Debugger.Run. When trying to create a submenu it will first create a popover item and then only create the NSButton at the leaf.

  • Unfortunatley macOS currently can't do multiple levels of submenus (the API will allow it, but it doesn't really work), presumably for usability concerns. Limit it to only one level of nesting for now.

Add ability to set a title on a Touch Bar button, using tmenu. This allows us to override the displayed button name, and when an icon is specified the override name will still be shown alongside the icon.

Add emoji picker support, and add it to the list of default Touch Bar menus. Only enable it in modes where the user is typing (insert, command, terminal, etc).

Fixed up the internal implementation of Touch Bar management so it's easier to add metadata to it now.

Also, add documentation.

TODO:

  • Using tmenu after amenu doesn't really work (unless it's specified in vimrc and loaded on initialization). This is because MacVim hasn't implemented gui_mch_menu_set_tip. Should fix it by adding support for it. For now, the user can just call tmenu before amenu.
  • Disabling menus currently just hides the menu. Since the user can already do aunmenu to hide, should change the disable behavior to show the button but disabled instead, similar to how toolbars and normal menus work.
    • Edit: This is probably not going to be done, because doing it would mean menus designated for insert mode (imenu) would show up in normal mode, which is a waste of space. Vim doesn't let the GUI know whether a menu item is disabled via the amenu disable command or not.

@ychin
Copy link
Member Author

ychin commented Sep 8, 2020

Just some examples of what it looks like.

Here's some example configs in a vimrc:

an                                          TouchBar.-flexspace1- <Nop>
amenu icon=NSTouchBarSkipToStartTemplate    TouchBar.GoFirst :cfirst<CR>
tmenu TouchBar.GoFirst First
amenu icon=NSTouchBarGoBackTemplate         TouchBar.GoPrev :cprev<CR>
amenu icon=NSTouchBarGoForwardTemplate      TouchBar.GoNext :cnext<CR>
amenu icon=NSTouchBarSkipToEndTemplate      TouchBar.GoLast :clast<CR>
tmenu TouchBar.GoLast Last
amenu TouchBar.Debug›.▶️Run <Nop>
amenu TouchBar.Debug›.🛑Stop <Nop>

It looks like this in Normal mode (note that GoFirst and GoLast have both icons and text):
image

Tapping into Debug› will expose the submenus:
image

When in Insert mode, the character emoji picker shows up:
image

And you can use it to select emoji to enter:
image

If you tap the search button on the Touch Bar emoji picker, it will bring up an interactive emoji picker that you can search and enter the emoji you want:
image

Can now specify submenus. E.g. TouchBar.Debugger.Run. When trying to
create a submenu it will first create a popover item and then only
create the NSButton at the leaf.

- Unfortunatley macOS currently can't do multiple levels of submenus (the
  API will allow it, but it doesn't really work), presumably for
  usability concerns. Limit it to only one level of nesting for now.

Add ability to set a title on a Touch Bar button, using `tmenu`. This
allows us to override the displayed button name, and when an icon is
specified the override name will still be shown alongside the icon.

Add emoji picker support, and add it to the list of default Touch Bar
menus. Only enable it in modes where the user is typing (insert,
command, terminal, etc).

Fixed up the internal implementation of Touch Bar management so it's
easier to add metadata to it now.

Also, add documentation.

TODO:

- Using `tmenu` after `amenu` doesn't really work (unless it's specified
  in vimrc). This is because MacVim hasn't implemented
  `gui_mch_menu_set_tip`. Should fix it by adding support for it. For
  now, the user can just call `tmenu` before `amenu`.
- Disabling menus currently just hides the menu. Since the user can
  already do `aunmenu` to hide, should change the disable behavior to
  show the button but disabled instead, similar to how toolbars and
  normal menus work.
@ychin ychin force-pushed the touchbar_subfolders_title_emoji branch from 129582e to e13d237 Compare September 8, 2020 09:36
@ychin ychin merged commit e0d1117 into macvim-dev:master Sep 8, 2020
@ychin ychin deleted the touchbar_subfolders_title_emoji branch September 8, 2020 19:16
@ychin ychin added this to the snapshot-166 milestone Sep 8, 2020
ychin added a commit to ychin/macvim that referenced this pull request Sep 9, 2020
Fix `tmenu` to work when it's called after the menu has already been
created, by implementing `gui_mch_menu_set_tip`. This works for menus,
tool bar, and Touch Bar (see macvim-dev#1084 which added tmenu support for
TouchBar).

Also, fix Touch Bar's submenu handling to reuse more common shared
function. Previously enabling/disabling/removing Touch Bar submenu items
didn't work as it had a hard-coded length check.
@ychin ychin added the Input Issues related to keyboard or other types of input label Sep 9, 2020
ychin added a commit that referenced this pull request Sep 21, 2020
Updated to Vim 8.2.1719.

Features
====================

Touch Bar improvements
--------------------

Touch Bar now supports submenus, and allows mixed icon/text displays
using `tmenu`. When in edit modes (e.g. insert), it will also display an
emoji picker as well. See `:help touchbar` for documentation. #1084

Fixes
====================

- Window menu no longer shows duplicate "Enter Full Screen" or "Tile
  Window to Left of Screen" entries whenever the user switches among
  different MacVim windows. #566 #992
- Fix issue where going to full screen mode when titlebar appearance is
  set to "hidden" would result in lost focus of the window. #1078
- The password dialog box when using `:!sudo` or other commands that
  require password entry (`macvim-askpass`) will no longer focus on
  Finder, and will keep the focus on MacVim. #1091
- Fix minor wrong tooltip in the "Appearance" preference pane. #1087
- "General" preference pane will now be correctly sized when Sparkle
  updater is disabled (e.g. Homebrew builds). #1089
- Misc issues were fixed by Vim upstream, e.g. `vimgrep` causing a
  crash, and odd behaviors with using Shift-O on the first line. #1082
  #1083

Compatibility
====================

Requires macOS 10.9 or above.

Script interfaces have compatibility with these versions:

- Lua 5.3
- Perl 5.18
- Python2 2.7
- Python3 3.8
- Ruby 2.7
@DesantBucie
Copy link

Any way to add custom icons?

@ychin
Copy link
Member Author

ychin commented Sep 21, 2020

Yup. @DesantBucie, see :help macvim-touchbar-icon:

You can specify icons for Touch Bar buttons the same way for toolbar icons. Touch Bar icons should ideally be 36x36 pixels, and no larger than 44x44 pixels.

Also, see :help macvim-toolbar:

Toolbar icons should be tiff, png, icns, or heic, of dimension 32x32 or 24x24 pixels.

What the above means is you just use the builtin Vim functionality to do something like:

 anoremenu icon=/my/path/to/icon.png TouchBar.DoSomething :echo 'Hello!'<CR>

Currently you can't specify an image as a "template image" (see https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/). If you want that feature, feel free to file another issue on it.

@DesantBucie
Copy link

Thank you very much.

@ychin ychin added UI Issues related to UI elements, tabs, scrollbars, window resizing, etc. and removed Input Issues related to keyboard or other types of input labels Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI Issues related to UI elements, tabs, scrollbars, window resizing, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants