From 8e7a5a35a686993ffbb7b888a7fcd0d32041f199 Mon Sep 17 00:00:00 2001 From: Sarah Gerweck Date: Sat, 8 Aug 2015 21:21:15 -0700 Subject: [PATCH] Simple `withKey` to bind a keyboard shortcut --- src/main/scala/org/gerweck/scalafx/util/package.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/gerweck/scalafx/util/package.scala b/src/main/scala/org/gerweck/scalafx/util/package.scala index 50d1ce4..359610a 100644 --- a/src/main/scala/org/gerweck/scalafx/util/package.scala +++ b/src/main/scala/org/gerweck/scalafx/util/package.scala @@ -8,6 +8,7 @@ import scalafx.beans.value._ import scalafx.event.subscriptions.Subscription import scalafx.scene.Node import scalafx.scene.control._ +import scalafx.scene.input._ import scalafx.scene.layout.GridPane import scalafx.util.StringConverter @@ -22,7 +23,6 @@ package object util extends ObservableImplicits { type Observable[A] = ObservableValue[A, _] type SimpleProperty[A] = Property[A, _] - object TextDisplay { import scalafx.beans.property._ import scalafx.scene.text.Text @@ -36,4 +36,12 @@ package object util extends ObservableImplicits { implicit class RichGridPane(val inner: GridPane) extends AnyVal { def addToRow(ri: Int, children: Node*) = inner.addRow(ri, children map {_.delegate}: _*) } + + implicit class RichMenuItem(val inner: MenuItem) extends AnyVal { + def withKey(char: Char): MenuItem = { + val c: Char = char.toUpper + inner.accelerator = new KeyCodeCombination(KeyCode(c.toString), KeyCombination.ShortcutDown) + inner + } + } }