The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Show key bindings in tool tip

These changes was commited to the Birdfont repository Thu, 25 Jun 2015 04:45:47 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 25 Jun 2015 04:45:47 +0000 (06:45 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 25 Jun 2015 04:45:47 +0000 (06:45 +0200)
commit b5e7c8abb6385b4938dce9dc05d1b30321655d84
tree ca3bcf3907793d118e1477648fd479374e023379
parent f5c2e612e7ff9ce2997afd7a36d1a468591ac8fa
Show key bindings in tool tip

libbirdfont/AbstractMenu.vala
libbirdfont/PenTool.vala
libbirdfont/Tool.vala
libbirdfont/ToolItem.vala
--- a/libbirdfont/AbstractMenu.vala +++ b/libbirdfont/AbstractMenu.vala @@ -53,6 +53,22 @@ public Gee.ArrayList<MenuItem> sorted_menu_items = new Gee.ArrayList<MenuItem> (); public AbstractMenu () { + } + + public ToolItem? get_item_for_tool (Tool t) { + ToolItem tm; + + foreach (MenuItem item in sorted_menu_items) { + if (item is ToolItem) { + tm = (ToolItem) item; + + if (tm.tool == t) { + return tm; + } + } + } + + return null; } public void process_key_binding_events (uint keyval) {
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -149,7 +149,6 @@ release_action.connect ((self, b, ix, iy) => { double x, y; Glyph g; - EditPoint? a; g = MainWindow.get_current_glyph (); x = Glyph.path_coordinate_x (ix);
--- a/libbirdfont/Tool.vala +++ b/libbirdfont/Tool.vala @@ -66,10 +66,6 @@ bool show_bg = true; public string tip = ""; - - // keyboard bindings - public uint modifier_flag; - public unichar key; public bool persistent = false; public bool editor_events = false; @@ -188,6 +184,8 @@ public static void show_tooltip () { TimeoutSource timer_hide; Toolbox toolbox; + string tip; + string key_binding; toolbox = MainWindow.get_toolbox (); @@ -206,9 +204,56 @@ } active_tooltip.showing_this_tooltip = true; - + + tip = @"$(active_tooltip.tip)"; + key_binding = active_tooltip.get_key_binding (); + + if (key_binding != "") { + tip += " (" + key_binding + ")"; + } + toolbox.hide_tooltip (); - toolbox.show_tooltip (active_tooltip.tip, (int) active_tooltip.x, (int) active_tooltip.y); + toolbox.show_tooltip (tip, (int) active_tooltip.x, (int) active_tooltip.y); + } + + public string get_key_binding () { + StringBuilder sb = new StringBuilder (); + ToolItem? ti = MainWindow.get_menu ().get_item_for_tool (this); + ToolItem t; + + if (ti == null) { + return ""; + } + + t = (!) ti; + + if (t.key == '\0') { + return ""; + } + + if ((t.modifiers & CTRL) > 0) { + sb.append ("Ctrl"); + sb.append ("+"); + } + + if ((t.modifiers & SHIFT) > 0) { + sb.append (t_("Shift")); + sb.append ("+"); + } + + if ((t.modifiers & ALT) > 0) { + sb.append ("Alt"); + sb.append ("+"); + } + + if ((t.modifiers & LOGO) > 0) { + sb.append ("Super"); + sb.append ("+"); + } + + sb.append_unichar (t.key); + + return sb.str; } public void set_icon (string name) {
--- a/libbirdfont/ToolItem.vala +++ b/libbirdfont/ToolItem.vala @@ -22,9 +22,6 @@ base (tool.tip, tool.name); this.tool = tool; - - modifiers = tool.modifier_flag; - key = tool.key; action.connect (() => { tool.select_action (tool);