The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Add copy and paste functionality to text fields

These changes was commited to the Birdfont repository Sun, 14 Jul 2019 13:07:27 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 14 Jul 2019 13:07:27 +0000]

Updated Files

libbirdfont/ClipTool.vala
libbirdfont/DescriptionDisplay.vala
--- a/libbirdfont/ClipTool.vala +++ b/libbirdfont/ClipTool.vala @@ -41,6 +41,18 @@ MainWindow.native_window.set_inkscape_clipboard (data); } else if (fd is OverView) { copy_overview_glyphs (); + } else if (fd is DescriptionDisplay) { + DescriptionDisplay description_tab = (DescriptionDisplay) fd; + string t = description_tab.get_copy_selection (); + if (t != "") { + MainWindow.native_window.set_clipboard_text (t); + } + } else if (fd is ExportSettings) { + ExportSettings export_tab = (ExportSettings) fd; + string t = export_tab.get_copy_selection (); + if (t != "") { + MainWindow.native_window.set_clipboard_text (t); + } } } @@ -98,10 +110,28 @@ foreach (Path path in g.active_paths) { path.move (dx, dy); } + } else if (fd is SpacingTab) { + paste_letters_to_spacing_tab (); } else if (fd is KerningDisplay) { paste_letters_to_kerning_tab (); } else if (fd is OverView) { paste_to_overview (); + } else if (fd is DescriptionDisplay) { + DescriptionDisplay description_tab = (DescriptionDisplay) fd; + string clipboard_data = MainWindow.native_window.get_clipboard_data (); + + if (!clipboard_data.has_prefix ("<?xml")) { + description_tab.paste (clipboard_data); + GlyphCanvas.redraw (); + } + } else if (fd is ExportSettings) { + ExportSettings export_tab = (ExportSettings) fd; + string clipboard_data = MainWindow.native_window.get_clipboard_data (); + + if (!clipboard_data.has_prefix ("<?xml")) { + export_tab.paste (clipboard_data); + GlyphCanvas.redraw (); + } } } @@ -472,9 +502,18 @@ if (!clipboard_data.has_prefix ("<?xml")) { kerning_display.add_text (clipboard_data); + } + } + + static void paste_letters_to_spacing_tab () { + string clipboard_data = MainWindow.native_window.get_clipboard_data (); + SpacingTab spacing_tab = MainWindow.get_spacing_tab (); + + if (!clipboard_data.has_prefix ("<?xml")) { + spacing_tab.add_text (clipboard_data); } } } }
--- a/libbirdfont/DescriptionDisplay.vala +++ b/libbirdfont/DescriptionDisplay.vala @@ -284,8 +284,32 @@ public override void selected_canvas () { copyright.set_editable (!disable_copyright); base.selected_canvas (); + } + + public void paste (string text) { + if (0 <= focus_index < focus_ring.size) { + Widget widget = focus_ring.get (focus_index); + + if (widget is TextArea) { + TextArea text_area = (TextArea) widget; + text_area.insert_text (text); + } + } + } + + public string get_copy_selection () { + if (0 <= focus_index < focus_ring.size) { + Widget widget = focus_ring.get (focus_index); + + if (widget is TextArea) { + TextArea text_area = (TextArea) widget; + return text_area.get_selected_text (); + } + } + + return ""; } } }