Commit 8a04f7c
Use gtk for text input This commit adds a gtk texfield that updates juxta position of glyphs (glyph sequence).
Changed files (7)
modifiedbirdfont/GtkWindow.valamodifiedlayout/style.cssmodifiedlibbirdfont/MainWindow.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/TabBar.valaaddedlibbirdfont/TextListener.vala
Diff
@@ -45,6 +45,13 @@ public class GtkWindow : Gtk.Window, NativeWindow { VScrollbar scrollbar; bool scrollbar_supress_signal = false; + /** Text input and callbacks to libbirdfont. */+ TextListener text_listener = new TextListener ();+ Label text_input_label;+ Entry text_entry;+ HBox text_box;+ Button submit_text_button;+ public GtkWindow (string title) { scrollbar = new VScrollbar (new Adjustment (0, 0, 1, 1, 0.01, 0.1));; ((Gtk.Window)this).set_title ("BirdFont");@@ -190,15 +197,33 @@ public class GtkWindow : Gtk.Window, NativeWindow { MainWindow.tabs.add_unique_tab (MainWindow.menu_tab, 60, true); MainWindow.tabs.select_tab_name ("Menu");-+ canvas_box = new HBox (false, 0); canvas_box.pack_start (glyph_canvas_area, true, true, 0); canvas_box.pack_start (html_box, true, true, 0); canvas_box.pack_start (scrollbar, false, true, 0);++ submit_text_button = new Button ();+ submit_text_button.set_label ("Submit");+ text_input_label = new Label (" " + "Text");+ text_entry = new Entry ();+ text_box = new HBox (false, 6);+ text_box.pack_start (text_input_label, false, false, 0);+ text_box.pack_start (text_entry, true, true, 0);+ text_box.pack_start (submit_text_button, false, false, 0);++ text_entry.changed.connect (() => {+ text_listener.signal_text_input (text_entry.text);+ });++ submit_text_button.clicked.connect (() => {+ text_listener.signal_submit (text_entry.text);+ }); tab_box = new VBox (false, 0);- tab_box.pack_start (new TabbarCanvas (MainWindow.tabs), false, false, 0); + tab_box.pack_start (new TabbarCanvas (MainWindow.tabs), false, false, 0);+ tab_box.pack_start (text_box, false, false, 5); tab_box.pack_start (canvas_box, true, true, 0); tab_box.pack_start (new TooltipCanvas (MainWindow.tool_tip), false, false, 0);@@ -244,7 +269,9 @@ public class GtkWindow : Gtk.Window, NativeWindow { }); show_all ();+ scrollbar.set_visible (false);+ hide_text_input (); } public void set_scrollbar_size (double size) {@@ -462,6 +489,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { edit_menu.append (close_path_item); close_path_item.activate.connect (() => { PenTool.close_all_paths (); }); close_path_item.add_accelerator ("activate", accel_group, 'B', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);++ Gtk.MenuItem glyph_sequence_item = new Gtk.MenuItem.with_mnemonic (_("_Glyph sequence"));+ edit_menu.append (glyph_sequence_item);+ glyph_sequence_item.activate.connect (() => { MainWindow.update_glyph_sequence (); }); edit_menu.append (new SeparatorMenuItem ()); @@ -717,7 +748,23 @@ public class GtkWindow : Gtk.Window, NativeWindow { file_chooser.destroy (); return fn;- } + }+ + public void hide_text_input () {+ text_listener = new TextListener ();+ text_box.hide ();+ }+ + public void set_text_listener (string label, TextListener listener, string default_text, string button_label) {+ text_listener = listener;+ text_input_label.set_text (" " + label);+ submit_text_button.set_label (button_label);+ text_box.show ();+ text_entry.set_text (default_text);+ listener.signal_submit.connect (() => {+ hide_text_input ();+ });+ } } class TabbarCanvas : DrawingArea {@@ -60,7 +60,7 @@ div.recent_font { } div.recent_list {- margin: 50px 0 0 0; + margin: 10px 0 0 0; } h2 {@@ -101,6 +101,15 @@ public class MainWindow { return over_view; } + public static void update_glyph_sequence () { + TextListener listener = new TextListener (); + listener.signal_text_input.connect ((text) => { + Preferences.set ("glyph_sequence", text); + get_glyph_canvas ().redraw (); + }); + native_window.set_text_listener (_("Glyph sequence"), listener, Preferences.get ("glyph_sequence"), _("Close")); + } + public static MainWindow get_singleton () { return singleton; } @@ -28,18 +28,6 @@ public class MenuTab : FontDisplay { public MenuTab () { // html callbacks:- add_html_callback ("export", (val) => {- if (BirdFont.get_current_font ().initialised) {- ExportTool.export_all ();- }- });-- add_html_callback ("preview", (val) => {- if (BirdFont.get_current_font ().initialised) {- preview ();- }- }); - add_html_callback ("load", (val) => { load_font (val); });@@ -48,10 +36,6 @@ public class MenuTab : FontDisplay { load_backup (val); }); - add_html_callback ("glyph_sequence", (val) => {- Preferences.set ("glyph_sequence", val);- });- add_html_callback ("help", (val) => { MainWindow.get_tool_tip ().show_text (val); });@@ -60,14 +44,6 @@ public class MenuTab : FontDisplay { delete_backups (); MainWindow.get_tab_bar ().select_tab_name ("Menu"); });- - add_html_callback ("set_name", (val) => {- show_description ();- });-- add_html_callback ("new_font", (val) => {- new_file ();- }); } public static void set_suppress_event (bool e) {@@ -99,33 +75,10 @@ public class MenuTab : FontDisplay { </script> </head> <body>- <div class="inner_format_box">- <div class="content">- <div class="heading"><h2>""" + _("Preferences") + """</h2></div>- <form>-""");- -c.append ("""- <h3>""" + _("Glyph sequence") + """</h3>- <input class="text" type="text" id="glyph_sequence" value=""" + "\"" + Preferences.get ("glyph_sequence") + "\"" + """ onchange="update_text_fields ();"/><br />- <br>-- <input class="button" type="button" value=""" + "\"" + _("New font") + "\"" + """ id="new_font" onclick="call ('new_font:');" onmouseover="call ('help:(Ctrl+n) """ + _("Create a new font") + """');"/><br />- <input class="button" type="button" value=""" + "\"" + _("Export") + "\"" + """ id="export_button" onclick="call ('export:fonts');" onmouseover="call ('help:(Ctrl+e) """ + _("Export SVG, TTF & EOT fonts") + """');"/><br />- <input class="button" type="button" value=""" + "\"" + _("Preview") + "\"" + """ id="preview_button" onclick="call ('preview:fonts');" onmouseover="call ('help:(Ctrl+p) """ + _("Export SVG font and view the result") + """');"/><br />- <input class="button" type="button" value=""" + "\"" + _("Update name & description") + "\"" + """ id="description" onclick="call ('set_name:');" onmouseover="call ('help:""" + _("Add name and description to this font.") + """');"/><br />-""");- -c.append (""" - </form> -- </div>- </div> """); if (has_backup ()) {- c.append ("""<br class="clearBoth" />"""); c.append ("""<div class="recent_list">"""); c.append (""" <div class="heading"><h2>""" + _("Recover") + """</h2></div>"""); @@ -151,7 +104,7 @@ if (has_backup ()) { } if (get_backups ().length () > 0) {- c.append ("""<div class="recent_font" onclick=\"call ('delete_backups:')">""");+ c.append ("""<div class="recent_font" onclick="call ('delete_backups:')">"""); c.append ("<div class=\"one_line\">"); c.append (_("Delete all"));@@ -166,18 +119,13 @@ if (has_backup ()) { } c.append ("""</div>""");+ c.append ("""<br class="clearBoth" />"""); } c.append ("""- <br class="clearBoth" /> <div class="recent_list"> """); -if (recent_fonts.length () > 0) {- c.append ("""<div class="heading"><h2>""" + _("Recent files") + """</h2></div>""");- c.append ("\n");-}- foreach (Font font in recent_fonts) { fn = (!) font.font_file; fn = fn.substring (fn.replace ("\\", "/").last_index_of ("/") + 1); @@ -1,5 +1,5 @@ /*- Copyright (C) 2012 Johan Mattsson+ Copyright (C) 2012, 2013 Johan Mattsson This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by@@ -37,6 +37,12 @@ public interface NativeWindow : GLib.Object { public abstract void set_scrollbar_size (double size); public abstract void set_scrollbar_position (double position); + /** Request text input from the UI. */+ public abstract void set_text_listener (string label, TextListener listener, string default_text, string button_label);+ + /** Remove the text listener and hode the text area. */+ public abstract void hide_text_input ();+ protected void webkit_callback (string s) { FontDisplay fd = MainWindow.get_current_display (); fd.process_property (s);@@ -296,6 +296,9 @@ public class TabBar : GLib.Object { public void select_tab (int index) { Tab t;+ + // always close any pending text input if the user switches tab+ MainWindow.native_window.hide_text_input (); if (index == NEXT_TAB) { selected++;new file mode 100644@@ -0,0 +1,25 @@+/*+ Copyright (C) 2013 Johan Mattsson++ This program is free software: you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation, either version 3 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License+ along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++namespace BirdFont {++public class TextListener : GLib.Object {+ public signal void signal_text_input (string text);+ public signal void signal_submit (string text); +}++}