From 90df6417504a0d0937dc4c0144462646b235c587 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sun, 10 Dec 2023 09:52:35 +0000 Subject: [PATCH] Update hotkey docs - Relates #826 --- .../ROOT/pages/appendices/tui/viewdev.adoc | 1 + .../modules/ROOT/pages/tui/events/key.adoc | 4 ++ .../modules/ROOT/pages/tui/views/menubar.adoc | 9 ++++ .../shell/docs/MenuBarViewSnippets.java | 45 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 spring-shell-docs/src/test/java/org/springframework/shell/docs/MenuBarViewSnippets.java diff --git a/spring-shell-docs/modules/ROOT/pages/appendices/tui/viewdev.adoc b/spring-shell-docs/modules/ROOT/pages/appendices/tui/viewdev.adoc index 0cabcee1..d47b2007 100644 --- a/spring-shell-docs/modules/ROOT/pages/appendices/tui/viewdev.adoc +++ b/spring-shell-docs/modules/ROOT/pages/appendices/tui/viewdev.adoc @@ -5,6 +5,7 @@ While a _view_ just need to implement `View` it's usually convenient to just use `BoxView` as a parent. +[[register-bindings]] == Register Bindings In an `AbstractView` use variants of _registerKeyBinding_, _registerHotKeyBinding_ diff --git a/spring-shell-docs/modules/ROOT/pages/tui/events/key.adoc b/spring-shell-docs/modules/ROOT/pages/tui/events/key.adoc index 87e42d85..6bb7ff19 100644 --- a/spring-shell-docs/modules/ROOT/pages/tui/events/key.adoc +++ b/spring-shell-docs/modules/ROOT/pages/tui/events/key.adoc @@ -15,3 +15,7 @@ include::{snippets}/KeyHandlingSnippets.java[tag=sample] `KeyEvent` is a record containing info about a binding coming out from a terminal. + +Some views allow you to register hot keys which are processed before +normal key handling. More about this can be found from +xref:appendices/tui/viewdev.adoc#register-bindings[Register Bindings]. diff --git a/spring-shell-docs/modules/ROOT/pages/tui/views/menubar.adoc b/spring-shell-docs/modules/ROOT/pages/tui/views/menubar.adoc index e9403146..22c44334 100644 --- a/spring-shell-docs/modules/ROOT/pages/tui/views/menubar.adoc +++ b/spring-shell-docs/modules/ROOT/pages/tui/views/menubar.adoc @@ -14,6 +14,15 @@ Inherits xref:tui/views/box.adoc[]. └─────────────────────────────┘ ---- +_MenuBarView_ is constructed with instances of _MenuBarItem_. _MenuBarItem_ itself +takes instances of _MenuItem_. _MenuItem_ can define its style and action. +_MenuBarItem_ can also define a hot key which is used to active particular menu. + +[source, java, indent=0] +---- +include::{snippets}/MenuBarViewSnippets.java[tag=snippet1] +---- + == Default Bindings Default _key bindigs_ are: diff --git a/spring-shell-docs/src/test/java/org/springframework/shell/docs/MenuBarViewSnippets.java b/spring-shell-docs/src/test/java/org/springframework/shell/docs/MenuBarViewSnippets.java new file mode 100644 index 00000000..9d0602f8 --- /dev/null +++ b/spring-shell-docs/src/test/java/org/springframework/shell/docs/MenuBarViewSnippets.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.shell.docs; + +import org.springframework.shell.component.view.control.MenuBarView; +import org.springframework.shell.component.view.control.MenuBarView.MenuBarItem; +import org.springframework.shell.component.view.control.MenuView.MenuItem; +import org.springframework.shell.component.view.control.MenuView.MenuItemCheckStyle; +import org.springframework.shell.component.view.event.KeyEvent.Key; +import org.springframework.shell.component.view.event.KeyEvent.KeyMask; + +public class MenuBarViewSnippets { + + class Dump1 { + + @SuppressWarnings("unused") + void dump1() { + // tag::snippet1[] + Runnable quitAction = () -> {}; + Runnable aboutAction = () -> {}; + MenuBarView menuBar = MenuBarView.of( + MenuBarItem.of("File", + MenuItem.of("Quit", MenuItemCheckStyle.NOCHECK, quitAction)) + .setHotKey(Key.f | KeyMask.AltMask), + MenuBarItem.of("Help", + MenuItem.of("About", MenuItemCheckStyle.NOCHECK, aboutAction)) + ); + // end::snippet1[] + } + + } +}