@@ -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_
|
||||
|
||||
@@ -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].
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user