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.
Revert "Error handeling in merge code"
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 35 /** Number of pixels per mm */ 36 public static double units = 1; 37 38 public MainWindow () { 39 singleton = this; 40 41 glyph_canvas = new GlyphCanvas (); 42 tabs = new TabBar (); 43 tools = new Toolbox (glyph_canvas, tabs); 44 menu_tab = new MenuTab (); 45 file_tab = new RecentFiles (); 46 overview = new OverView(); 47 kerning_display = new KerningDisplay (); 48 character_database = new CharDatabase (); 49 ligature_display = new LigatureList (); 50 spacing_class_tab = new SpacingClassTab (); 51 menu = new Menu (); 52 dialog = new Dialog (); 53 spacing_tab = new SpacingTab (); 54 55 tools.select_tool (DrawingTools.bezier_tool); 56 } 57 58 public static SpacingTab get_spacing_tab () { 59 return spacing_tab; 60 } 61 62 public static Dialog get_dialog () { 63 return dialog; 64 } 65 66 public static void show_dialog (Dialog d) 67 requires (!is_null(MainWindow.get_tab_bar ())) { 68 Tab t = MainWindow.get_tab_bar ().get_selected_tab (); 69 string tab_name = t.get_display ().get_name (); 70 71 if (tab_name == "Preview") { 72 MenuTab.select_overview (); 73 } 74 75 dialog = d; 76 dialog.visible = true; 77 GlyphCanvas.redraw (); 78 79 set_cursor (NativeWindow.VISIBLE); 80 } 81 82 public static void set_cursor (int flags) { 83 if (BirdFont.has_argument ("--test")) { 84 if (dialog.visible) { 85 native_window.set_cursor (NativeWindow.VISIBLE); 86 } else { 87 native_window.set_cursor (flags); 88 } 89 } 90 } 91 92 public static void show_message (string text) { 93 show_dialog (new MessageDialog (text)); 94 } 95 96 public static void hide_dialog () { 97 dialog = new Dialog (); 98 dialog.visible = false; 99 GlyphCanvas.redraw (); 100 } 101 102 public static void set_menu (AbstractMenu m) { 103 menu = m; 104 } 105 106 public static AbstractMenu get_menu () { 107 return menu; 108 } 109 110 /** Set the number of pixels per millimeter for the current screen. */ 111 public static void set_units_per_pixel (double u) { 112 MainWindow.units = u; 113 } 114 115 public static void init () { 116 singleton = new MainWindow (); 117 } 118 119 public static RecentFiles get_recent_files_tab () { 120 return file_tab; 121 } 122 123 public static void open_recent_files_tab () { 124 // FIXME: do not idle 125 IdleSource idle = new IdleSource (); 126 tabs.add_unique_tab (file_tab); 127 idle.set_callback (() => { 128 tabs.select_tab_name ("Files"); 129 return false; 130 }); 131 idle.attach (null); 132 } 133 134 public static void select_all_paths () { 135 Tool t = tools.get_current_tool (); 136 137 if (! (t is MoveTool || t is ResizeTool)) { 138 get_toolbox ().select_tool (DrawingTools.move_tool); 139 } 140 141 IdleSource idle = new IdleSource (); 142 idle.set_callback (() => { 143 DrawingTools.move_tool.select_all_paths (); 144 return false; 145 }); 146 idle.attach (null); 147 } 148 149 public static DrawingTools get_drawing_tools () { 150 return Toolbox.drawing_tools; 151 } 152 153 public void set_native (NativeWindow nw) { 154 native_window = nw; 155 } 156 157 public static FontDisplay get_current_display () { 158 return get_glyph_canvas ().get_current_display (); 159 } 160 161 public static GlyphCanvas get_glyph_canvas () { 162 return glyph_canvas; 163 } 164 165 public static GlyphCollection get_current_glyph_collection () { 166 if (unlikely (is_null (BirdFont.current_glyph_collection))) { 167 GlyphCollection gc; 168 169 warning ("No default glyph have been set yet.\n"); 170 gc = new GlyphCollection ('\0', ""); 171 gc.add_glyph (new Glyph ("", '\0')); 172 173 return gc; 174 } 175 176 return BirdFont.current_glyph_collection; 177 } 178 179 public static Glyph get_current_glyph () { 180 return get_current_glyph_collection ().get_current (); 181 } 182 183 public static Toolbox get_toolbox () { 184 return tools; 185 } 186 187 public static Tool get_tool (string n) { 188 return tools.get_tool (n); 189 } 190 191 public static TabBar get_tab_bar () { 192 return tabs; 193 } 194 195 public static Tab get_current_tab () { 196 return tabs.get_selected_tab (); 197 } 198 199 public static bool select_tab (Tab t) { 200 return tabs.selected_open_tab (t); 201 } 202 203 public static OverView get_overview () { 204 foreach (Tab t in tabs.tabs) { 205 if (t.get_display () is OverView) { 206 return (OverView) t.get_display (); 207 } 208 } 209 210 return overview; 211 } 212 213 public static SpacingClassTab get_spacing_class_tab () { 214 return spacing_class_tab; 215 } 216 217 public static void update_glyph_sequence () { 218 TextListener listener = new TextListener (t_("Glyph sequence"), Preferences.get ("glyph_sequence"), t_("Close")); 219 listener.signal_text_input.connect ((text) => { 220 Preferences.set ("glyph_sequence", text); 221 GlyphCanvas.redraw (); 222 }); 223 listener.signal_submit.connect (() => { 224 TabContent.hide_text_input (); 225 }); 226 TabContent.show_text_input (listener); 227 } 228 229 public static MainWindow get_singleton () { 230 return singleton; 231 } 232 233 public static void file_chooser (string title, FileChooser fc, uint flags) { 234 MainWindow.native_window.file_chooser (title, fc, flags); 235 } 236 237 public static void set_scrollbar_size (double size) { 238 if (!is_null (MainWindow.native_window)) { 239 MainWindow.native_window.set_scrollbar_size (size); 240 } 241 } 242 243 public static void set_scrollbar_position (double position) { 244 if (!is_null (MainWindow.native_window)) { 245 MainWindow.native_window.set_scrollbar_position (position); 246 } 247 } 248 249 /** Reaload all paths and help lines from disk. */ 250 public static void clear_glyph_cache () { 251 Glyph g; 252 foreach (Tab t in get_tab_bar ().tabs) { 253 if (t.get_display () is Glyph) { 254 g = (Glyph) t.get_display (); 255 g.add_help_lines (); 256 } 257 } 258 259 GlyphCanvas.redraw (); 260 } 261 262 public static void close_all_tabs () { 263 get_tab_bar ().close_all_tabs (); 264 } 265 266 public static string translate (string s) { 267 return t_(s); 268 } 269 270 public static KerningDisplay get_kerning_display () { 271 return kerning_display; 272 } 273 274 public static LigatureList get_ligature_display () { 275 return ligature_display; 276 } 277 278 public static void next_tab () { 279 TabBar tb = MainWindow.get_tab_bar (); 280 int n = tb.get_selected () + 1; 281 282 if (!(0 <= n < tb.get_length ())) { 283 return; 284 } 285 286 tb.select_tab (n); 287 } 288 289 public static void previous_tab () { 290 TabBar tb = MainWindow.get_tab_bar (); 291 int n = tb.get_selected () - 1; 292 293 if (!(0 <= n < tb.get_length ())) { 294 return; 295 } 296 297 tb.select_tab (n); 298 } 299 300 public static void close_tab () { 301 TabBar tb = MainWindow.get_tab_bar (); 302 int n = tb.get_selected (); 303 304 if (!(0 <= n < tb.get_length ())) { 305 return; 306 } 307 308 tb.close_tab (n); 309 } 310 311 public static void set_toolbox (Toolbox tb) { 312 tools = tb; 313 } 314 } 315 316 } 317