Commit c33a350
Propagate key press events in menu
Changed files (6)
modifiedlibbirdfont/GlyphCanvas.valamodifiedlibbirdfont/Menu.valamodifiedlibbirdfont/MenuItem.valamodifiedlibbirdfont/TabContent.valamodifiedlibbirdfont/ToolItem.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -40,15 +40,8 @@ public class GlyphCanvas : GLib.Object { current_display.key_release (e); } - public void key_press (uint e) { - Toolbox tb;- - current_display.key_press (e);- - if (current_display is Glyph) {- tb = MainWindow.get_toolbox ();- tb.key_press (e);- } + public void key_press (uint e) {+ current_display.key_press (e); } internal static void set_display (FontDisplay fd) { @@ -431,15 +431,16 @@ public class Menu : GLib.Object { public void process_key_binding_events (uint keyval) { string display;+ FontDisplay current_display = MainWindow.get_current_display (); foreach (MenuItem item in sorted_menu_items) { if (item.key == (unichar) keyval && item.modifiers == KeyBindings.modifier) { - if (BirdFont.get_current_display () is Glyph && item.display == "Glyph") {+ if (current_display is Glyph && item.display == "Glyph") { item.action (); } - display = BirdFont.get_current_display ().get_name ();+ display = current_display.get_name (); if (item.display == "" || item.display == display) { item.action (); }@@ -539,19 +540,21 @@ public class Menu : GLib.Object { double y = 0; double x = allocation.width - width; - foreach (MenuItem item in current_menu.items) {- if (x <= ex < allocation.width && y <= ey <= y + height) {- item.action ();- GlyphCanvas.redraw ();- return;+ if (button == 1) {+ foreach (MenuItem item in current_menu.items) {+ if (x <= ex < allocation.width && y <= ey <= y + height) {+ item.action ();+ GlyphCanvas.redraw ();+ return;+ }+ + y += height; } - y += height;+ menu_visibility = false;+ current_menu = (!) top_menu;+ GlyphCanvas.redraw (); }- - menu_visibility = false;- current_menu = (!) top_menu;- GlyphCanvas.redraw (); } void add_tool_key_bindings () {@@ -561,6 +564,7 @@ public class Menu : GLib.Object { foreach (Tool t in e.tool) { tool_item = new ToolItem (t); if (tool_item.identifier != "") {+ remove_menu_item (tool_item.identifier); menu_items.set (tool_item.identifier, tool_item); sorted_menu_items.add (tool_item); }@@ -569,6 +573,18 @@ public class Menu : GLib.Object { } } + public void remove_menu_item (string identifier) {+ int i = 0;+ foreach (MenuItem mi in sorted_menu_items) {+ if (mi.identifier == identifier) {+ sorted_menu_items.remove_at (i);+ break;+ }+ }+ + menu_items.unset (identifier);+ }+ public void set_menu (SubMenu m) { current_menu = m; GlyphCanvas.redraw ();@@ -56,7 +56,24 @@ public class MenuItem : GLib.Object { key_binding += "Shift+"; } - key_binding += (!) key.to_string ();+ switch (key) {+ case Key.UP:+ key_binding += "UP";+ break;+ case Key.DOWN:+ key_binding += "DOWN";+ break;+ case Key.LEFT:+ key_binding += "LEFT";+ break;+ case Key.RIGHT:+ key_binding += "RIGHT";+ break;+ default:+ key_binding += (!) key.to_string ();+ break;+ }+ key_binding += ")"; } @@ -83,12 +83,8 @@ public class TabContent : GLib.Object { return; } - if (GlyphCanvas.current_display is Glyph) {- MainWindow.tools.key_press (keyval);- }- KeyBindings.add_modifier_from_keyval (keyval);- + MainWindow.get_menu ().process_key_binding_events (keyval); GlyphCanvas.current_display.key_press (keyval); } @@ -98,7 +94,6 @@ public class TabContent : GLib.Object { } GlyphCanvas.current_display.key_release (keyval);- KeyBindings.remove_modifier_from_keyval (keyval); } @@ -19,7 +19,7 @@ public class ToolItem : MenuItem { public Tool tool; public ToolItem (Tool tool) {- base (tool.tip, tool.tip); // FIXME: untranslated tip.+ base (tool.tip, tool.name); this.tool = tool; @@ -103,25 +103,6 @@ public class Toolbox : GLib.Object { Toolbox.redraw_tool_box (); } }-- public void key_press (uint keyval) {- if (MenuTab.suppress_event) {- warn_if_test ("Event suppressed");- return;- }- - foreach (Expander exp in current_set.get_expanders ()) {- foreach (Tool t in exp.tool) {- t.set_active (false);- - if (t.tool_is_visible () && t.key == keyval - && t.modifier_flag == NONE - && KeyBindings.modifier == NONE) {- select_tool (t);- }- }- }- } public void press (uint button, double x, double y) { if (MenuTab.suppress_event) {