The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

MainWindow.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/MainWindow.vala.
Fix translation
1 /* 2 Copyright (C) 2012 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class MainWindow : GLib.Object { 18 19 public static Toolbox tools; 20 public static GlyphCanvas glyph_canvas; 21 public static MainWindow singleton; 22 public static MenuTab menu_tab; 23 public static RecentFiles file_tab; 24 public static OverView overview; 25 public static TabBar tabs; 26 public static NativeWindow native_window; 27 public static KerningDisplay kerning_display; 28 public static CharDatabase character_database; 29 public static LigatureList ligature_display; 30 public static SpacingClassTab spacing_class_tab; 31 public static AbstractMenu menu; 32 public static Dialog dialog; 33 public static SpacingTab spacing_tab; 34 public static Task blocking_background_task; 35 public static Scrollbar scrollbar; 36 37 /** Number of pixels per mm */ 38 public static double units = 1; 39 40 private static double scrollbar_size = -1; 41 42 public MainWindow () { 43 singleton = this; 44 45 glyph_canvas = new GlyphCanvas (); 46 tabs = new TabBar (); 47 tools = new Toolbox (glyph_canvas, tabs); 48 menu_tab = new MenuTab (); 49 file_tab = new RecentFiles (); 50 overview = new OverView(); 51 kerning_display = new KerningDisplay (); 52 character_database = new CharDatabase (); 53 ligature_display = new LigatureList (); 54 spacing_class_tab = new SpacingClassTab (); 55 menu = new Menu (); 56 dialog = new Dialog (); 57 spacing_tab = new SpacingTab (); 58 blocking_background_task = new Task (null); 59 scrollbar = new Scrollbar (); 60 61 tools.select_tool (DrawingTools.bezier_tool); 62 } 63 64 public static bool has_scrollbar () { 65 return scrollbar.is_visible (); 66 } 67 68 public static void abort_task () { 69 blocking_background_task.cancel (); 70 } 71 72 public static void run_blocking_task (Task task) { 73 blocking_background_task = task; 74 native_window.run_background_thread (task); 75 } 76 77 public static SpacingTab get_spacing_tab () { 78 return spacing_tab; 79 } 80 81 public static Dialog get_dialog () { 82 return dialog; 83 } 84 85 public static void show_dialog (Dialog d) 86 requires (!is_null(MainWindow.get_tab_bar ())) { 87 Tab t = MainWindow.get_tab_bar ().get_selected_tab (); 88 string tab_name = t.get_display ().get_name (); 89 90 if (tab_name == "Preview") { 91 MenuTab.select_overview (); 92 } 93 94 dialog = d; 95 dialog.visible = true; 96 GlyphCanvas.redraw (); 97 98 set_cursor (NativeWindow.VISIBLE); 99 } 100 101 public static void show_license_dialog () { 102 show_dialog (new LicenseDialog ()); 103 } 104 105 public static void set_cursor (int flags) { 106 if (BirdFont.has_argument ("--test")) { 107 if (dialog.visible) { 108 native_window.set_cursor (NativeWindow.VISIBLE); 109 } else { 110 native_window.set_cursor (flags); 111 } 112 } 113 } 114 115 public static MessageDialog show_message (string text) { 116 Tab t = MainWindow.get_tab_bar ().get_selected_tab (); 117 string tab_name = t.get_display ().get_name (); 118 119 if (tab_name == "Preview") { 120 MenuTab.select_overview (); 121 } 122 123 MessageDialog md = new MessageDialog (text); 124 show_dialog (md); 125 126 return md; 127 } 128 129 public static void hide_dialog () { 130 dialog = new Dialog (); 131 dialog.visible = false; 132 GlyphCanvas.redraw (); 133 } 134 135 public static void set_menu (AbstractMenu m) { 136 menu = m; 137 } 138 139 public static AbstractMenu get_menu () { 140 return menu; 141 } 142 143 /** Set the number of pixels per millimeter for the current screen. */ 144 public static void set_units_per_pixel (double u) { 145 MainWindow.units = u; 146 } 147 148 public static void init () { 149 singleton = new MainWindow (); 150 } 151 152 public static RecentFiles get_recent_files_tab () { 153 return file_tab; 154 } 155 156 public static void open_recent_files_tab () { 157 // FIXME: do not idle 158 IdleSource idle = new IdleSource (); 159 tabs.add_unique_tab (file_tab); 160 idle.set_callback (() => { 161 tabs.select_tab_name ("Files"); 162 return false; 163 }); 164 idle.attach (null); 165 } 166 167 public static void select_all_paths () { 168 Tool t = tools.get_current_tool (); 169 170 if (! (t is MoveTool || t is ResizeTool)) { 171 get_toolbox ().select_tool (DrawingTools.move_tool); 172 } 173 174 IdleSource idle = new IdleSource (); 175 idle.set_callback (() => { 176 DrawingTools.move_tool.select_all_paths (); 177 return false; 178 }); 179 idle.attach (null); 180 } 181 182 public static DrawingTools get_drawing_tools () { 183 return Toolbox.drawing_tools; 184 } 185 186 public void set_native (NativeWindow nw) { 187 native_window = nw; 188 } 189 190 public static FontDisplay get_current_display () { 191 return get_glyph_canvas ().get_current_display (); 192 } 193 194 public static GlyphCanvas get_glyph_canvas () { 195 return glyph_canvas; 196 } 197 198 public static GlyphCollection get_current_glyph_collection () { 199 if (unlikely (is_null (BirdFont.current_glyph_collection))) { 200 GlyphCollection gc; 201 202 warning ("No default glyph have been set yet.\n"); 203 gc = new GlyphCollection.with_glyph ('\0', ""); 204 205 return gc; 206 } 207 208 return BirdFont.current_glyph_collection; 209 } 210 211 public static Glyph get_current_glyph () { 212 return get_current_glyph_collection ().get_current (); 213 } 214 215 public static Toolbox get_toolbox () { 216 return tools; 217 } 218 219 public static Tool get_tool (string n) { 220 return tools.get_tool (n); 221 } 222 223 public static TabBar get_tab_bar () { 224 return tabs; 225 } 226 227 public static Tab get_current_tab () { 228 return tabs.get_selected_tab (); 229 } 230 231 public static bool select_tab (Tab t) { 232 return tabs.selected_open_tab (t); 233 } 234 235 public static SpacingClassTab get_spacing_class_tab () { 236 return spacing_class_tab; 237 } 238 239 public static void update_glyph_sequence () { 240 TextListener listener = new TextListener (t_("Glyph sequence"), Preferences.get ("glyph_sequence"), t_("Close")); 241 listener.signal_text_input.connect ((text) => { 242 Preferences.set ("glyph_sequence", text); 243 GlyphCanvas.redraw (); 244 }); 245 listener.signal_submit.connect (() => { 246 TabContent.hide_text_input (); 247 }); 248 TabContent.show_text_input (listener); 249 } 250 251 public static MainWindow get_singleton () { 252 return singleton; 253 } 254 255 public static void file_chooser (string title, FileChooser fc, uint flags) { 256 MainWindow.native_window.file_chooser (title, fc, flags); 257 } 258 259 public static void hide_scrollbar () { 260 if (!is_null (MainWindow.native_window)) { 261 MainWindow.scrollbar.set_size (-1); 262 } 263 } 264 265 public static void show_scrollbar () { 266 if (!is_null (MainWindow.native_window)) { 267 MainWindow.scrollbar.set_size (scrollbar_size); 268 } 269 } 270 271 public static void set_scrollbar_size (double size) { 272 if (!is_null (MainWindow.native_window)) { 273 scrollbar_size = size; 274 MainWindow.scrollbar.set_size (size); 275 } 276 } 277 278 public static void set_scrollbar_position (double position) { 279 if (!is_null (MainWindow.native_window)) { 280 MainWindow.scrollbar.set_position (position); 281 } 282 } 283 284 public static void close_all_tabs () { 285 get_tab_bar ().close_all_tabs (); 286 } 287 288 public static string translate (string s) { 289 return t_(s); 290 } 291 292 public static KerningDisplay get_kerning_display () { 293 return kerning_display; 294 } 295 296 public static LigatureList get_ligature_display () { 297 return ligature_display; 298 } 299 300 public static void next_tab () { 301 TabBar tb = MainWindow.get_tab_bar (); 302 int n = tb.get_selected () + 1; 303 304 if (!(0 <= n < tb.get_length ())) { 305 return; 306 } 307 308 tb.select_tab (n); 309 } 310 311 public static void previous_tab () { 312 TabBar tb = MainWindow.get_tab_bar (); 313 int n = tb.get_selected () - 1; 314 315 if (!(0 <= n < tb.get_length ())) { 316 return; 317 } 318 319 tb.select_tab (n); 320 } 321 322 public static void close_tab () { 323 TabBar tb = MainWindow.get_tab_bar (); 324 int n = tb.get_selected (); 325 326 if (!(0 <= n < tb.get_length ())) { 327 return; 328 } 329 330 tb.close_tab (n); 331 } 332 333 public static void set_toolbox (Toolbox tb) { 334 tools = tb; 335 } 336 337 public static OverView get_overview () { 338 foreach (Tab t in tabs.tabs) { 339 if (t.get_display () is OverView) { 340 return (OverView) t.get_display (); 341 } 342 } 343 344 return overview; 345 } 346 } 347 348 } 349