The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Menu.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/Menu.vala.
Merge branch 'master' of github.com:johanmattssonm/birdfont
1 /* 2 Copyright (C) 2014 - 2016 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 using Cairo; 16 using B; 17 18 namespace BirdFont { 19 20 /** Interface for events from native window to the current tab. */ 21 public class Menu : AbstractMenu { 22 23 public Menu () { 24 base (); 25 26 SubMenu menu = new SubMenu (); 27 SubMenu file_menu = new SubMenu (); 28 SubMenu edit_menu = new SubMenu (); 29 SubMenu layers_menu = new SubMenu (); 30 SubMenu export_menu = new SubMenu (); 31 SubMenu tab_menu = new SubMenu (); 32 SubMenu kerning_menu = new SubMenu (); 33 SubMenu ligature_menu = new SubMenu (); 34 SubMenu git_menu = new SubMenu (); 35 36 // file menu 37 MenuItem file = add_menu_item (t_("File")); 38 file.action.connect (() => { 39 set_menu (file_menu); 40 }); 41 menu.items.add (file); 42 43 MenuItem new_file = add_menu_item (t_("New"), "new"); 44 new_file.action.connect (() => { 45 MenuTab.new_file (); 46 show_menu = false; 47 }); 48 file_menu.items.add (new_file); 49 50 MenuItem open = add_menu_item (t_("Open"), "open"); 51 open.action.connect (() => { 52 show_menu = false; 53 MenuTab.load (); 54 }); 55 file_menu.items.add (open); 56 57 MenuItem recent_files = add_menu_item (t_("Recent Files"), "recent files"); 58 recent_files.action.connect (() => { 59 show_menu = false; 60 MainWindow.open_recent_files_tab (); 61 }); 62 file_menu.items.add (recent_files); 63 64 MenuItem save = add_menu_item (t_("Save"), "save"); 65 save.action.connect (() => { 66 MenuTab.save (); 67 show_menu = false; 68 }); 69 file_menu.items.add (save); 70 71 MenuItem save_as = add_menu_item (t_("Save As"), "save as"); 72 save_as.action.connect (() => { 73 MenuTab.save_as (); 74 show_menu = false; 75 }); 76 file_menu.items.add (save_as); 77 78 MenuItem select_character_set = add_menu_item (t_("Select Character Set"), "select character set"); 79 select_character_set.action.connect (() => { 80 MenuTab.select_language (); 81 show_menu = false; 82 }); 83 file_menu.items.add (select_character_set); 84 85 MenuItem quit = add_menu_item (t_("Quit"), "quit"); 86 quit.action.connect (() => { 87 MenuTab.quit (); 88 show_menu = false; 89 }); 90 file_menu.items.add (quit); 91 92 // edit menu 93 MenuItem edit = add_menu_item (t_("Edit")); 94 edit.action.connect (() => { 95 set_menu (edit_menu); 96 }); 97 menu.items.add (edit); 98 99 MenuItem undo = add_menu_item (t_("Undo"), "undo"); 100 undo.action.connect (() => { 101 TabContent.undo (); 102 show_menu = false; 103 }); 104 edit_menu.items.add (undo); 105 106 MenuItem redo = add_menu_item (t_("Redo"), "redo"); 107 redo.action.connect (() => { 108 TabContent.redo (); 109 show_menu = false; 110 }); 111 edit_menu.items.add (redo); 112 113 MenuItem copy = add_menu_item (t_("Copy"), "copy"); 114 copy.action.connect (() => { 115 ClipTool.copy (); 116 show_menu = false; 117 }); 118 edit_menu.items.add (copy); 119 120 MenuItem paste = add_menu_item (t_("Paste"), "paste"); 121 paste.action.connect (() => { 122 ClipTool.paste (); 123 show_menu = false; 124 }); 125 edit_menu.items.add (paste); 126 127 MenuItem paste_in_place = add_menu_item (t_("Paste In Place"), "paste in place", "Glyph"); 128 paste_in_place.action.connect (() => { 129 ClipTool.paste_in_place (); 130 show_menu = false; 131 }); 132 edit_menu.items.add (paste_in_place); 133 134 MenuItem select_all_paths = add_menu_item (t_("Select All Paths"), "select all paths", "Glyph"); 135 select_all_paths.action.connect (() => { 136 MainWindow.select_all_paths (); 137 show_menu = false; 138 }); 139 edit_menu.items.add (select_all_paths); 140 141 MenuItem select_all_glyphs = add_menu_item (t_("Select All Glyphs"), "select all glyphs", "Overview"); 142 select_all_glyphs.action.connect (() => { 143 MainWindow.get_overview ().select_all_glyphs (); 144 show_menu = false; 145 }); 146 edit_menu.items.add (select_all_glyphs); 147 148 MenuItem move_to_baseline = add_menu_item (t_("Move To Baseline"), "move to baseline", "Glyph"); 149 move_to_baseline.action.connect (() => { 150 MenuTab.move_to_baseline (); 151 show_menu = false; 152 }); 153 edit_menu.items.add (move_to_baseline); 154 155 MenuItem search = add_menu_item (t_("Search"), "search"); 156 search.action.connect (() => { 157 OverView.search (); 158 show_menu = false; 159 }); 160 edit_menu.items.add (search); 161 162 MenuItem simplify_path = add_menu_item (t_("Simplify Path"), "simplify path", "Glyph"); 163 simplify_path.action.connect (() => { 164 MenuTab.simplify_path (); 165 show_menu = false; 166 }); 167 edit_menu.items.add (simplify_path); 168 169 MenuItem merge_paths = add_menu_item (t_("Merge Paths"), "merge_paths", "Glyph"); 170 merge_paths.action.connect (() => { 171 merge_selected_paths (); 172 show_menu = false; 173 }); 174 edit_menu.items.add (merge_paths); 175 176 MenuItem close_path = add_menu_item (t_("Close Path"), "close path", "Glyph"); 177 close_path.action.connect (() => { 178 PenTool.close_all_paths (); 179 show_menu = false; 180 }); 181 edit_menu.items.add (close_path); 182 183 MenuItem glyph_sequence = add_menu_item (t_("Glyph Sequence"), "glyph sequence"); 184 glyph_sequence.action.connect (() => { 185 MainWindow.update_glyph_sequence (); 186 show_menu = false; 187 }); 188 edit_menu.items.add (glyph_sequence); 189 190 MenuItem set_background_glyph = add_menu_item (t_("Set Background Glyph"), "set background glyph", "Glyph"); 191 set_background_glyph.action.connect (() => { 192 MenuTab.use_current_glyph_as_background (); 193 show_menu = false; 194 }); 195 edit_menu.items.add (set_background_glyph); 196 197 MenuItem remove_background_glyph = add_menu_item (t_("Remove Background Glyph"), "remove background glyph", "Glyph"); 198 remove_background_glyph.action.connect (() => { 199 MenuTab.reset_glyph_background (); 200 show_menu = false; 201 }); 202 edit_menu.items.add (remove_background_glyph); 203 204 MenuItem create_guide = add_menu_item (t_("Create Guide"), "create guide"); 205 create_guide.action.connect (() => { 206 MainWindow.get_current_glyph ().add_custom_guide (); 207 show_menu = false; 208 }); 209 edit_menu.items.add (create_guide); 210 211 MenuItem show_guide_guide = add_menu_item (t_("List Guides"), "show guide tab"); 212 show_guide_guide.action.connect (() => { 213 MenuTab.show_guide_tab (); 214 show_menu = false; 215 }); 216 edit_menu.items.add (show_guide_guide); 217 218 MenuItem select_point_above = add_menu_item (t_("Select Point Above"), "select point above", "Glyph"); 219 select_point_above.action.connect (() => { 220 PenTool.select_point_up (); 221 show_menu = false; 222 }); 223 edit_menu.items.add (select_point_above); 224 225 MenuItem select_next_point = add_menu_item (t_("Select Next Point"), "select next point", "Glyph"); 226 select_next_point.action.connect (() => { 227 PenTool.select_point_right (); 228 show_menu = false; 229 }); 230 edit_menu.items.add (select_next_point); 231 232 MenuItem select_previous_point = add_menu_item (t_("Select Previous Point"), "select previous point", "Glyph"); 233 select_previous_point.action.connect (() => { 234 PenTool.select_point_left (); 235 show_menu = false; 236 }); 237 edit_menu.items.add (select_previous_point); 238 239 MenuItem select_point_below = add_menu_item (t_("Select Point Below"), "select point below", "Glyph"); 240 select_point_below.action.connect (() => { 241 PenTool.select_point_down (); 242 show_menu = false; 243 }); 244 edit_menu.items.add (select_point_below); 245 246 // layers 247 MenuItem layers = add_menu_item (t_("Layers")); 248 layers.action.connect (() => { 249 set_menu (layers_menu); 250 }); 251 menu.items.add (layers); 252 253 MenuItem layer_up = add_menu_item (t_("Move Layer Up"), "move layer up", "Glyph"); 254 layer_up.action.connect (() => { 255 MainWindow.get_current_glyph ().move_layer_up (); 256 DrawingTools.update_layers (); 257 }); 258 layers_menu.items.add (layer_up); 259 260 MenuItem layer_down = add_menu_item (t_("Move Layer Down"), "move layer down", "Glyph"); 261 layer_down.action.connect (() => { 262 MainWindow.get_current_glyph ().move_layer_down (); 263 DrawingTools.update_layers (); 264 }); 265 layers_menu.items.add (layer_down); 266 267 // import and export 268 MenuItem export = add_menu_item (t_("Import and Export")); 269 export.action.connect (() => { 270 set_menu (export_menu); 271 }); 272 menu.items.add (export); 273 274 MenuItem export_fonts = add_menu_item (t_("Export Fonts"), "export"); 275 export_fonts.action.connect (() => { 276 MenuTab.export_fonts_in_background (); 277 show_menu = false; 278 }); 279 export_menu.items.add (export_fonts); 280 281 MenuItem export_glyph = add_menu_item (t_("Export Glyph as SVG"), "export glyph as svg", "Glyph"); 282 export_glyph.action.connect (() => { 283 ExportTool.export_current_glyph (); 284 show_menu = false; 285 }); 286 export_menu.items.add (export_glyph); 287 288 MenuItem import_color_svg; 289 import_color_svg = add_menu_item (t_("Import SVG file"), 290 "import svg file color", ""); 291 import_color_svg.action.connect (() => { 292 FontDisplay current_display = MainWindow.get_current_display (); 293 OverView overview = MainWindow.get_overview (); 294 295 if (current_display is OverView) { 296 GlyphCollection? gc; 297 298 gc = overview.get_selected_item ().glyphs; 299 300 OverViewItem item = overview.get_selected_item (); 301 302 if (gc == null) { 303 // ignore control characters 304 if (item.character <= 0x1F) { 305 show_menu = false; 306 return; 307 } 308 309 gc = overview.create_new_glyph (item.character, false); 310 } 311 312 GlyphCanvas canvas = MainWindow.get_glyph_canvas (); 313 canvas.set_current_glyph_collection ((!) gc, false); 314 } 315 316 SvgParser.import (SvgType.COLOR); 317 318 if (current_display is OverView) { 319 overview.reset_thumbnails (); 320 GlyphCanvas.redraw (); 321 } 322 323 show_menu = false; 324 }); 325 export_menu.items.add (import_color_svg); 326 327 MenuItem import_svg_color_folder; 328 import_svg_color_folder = add_menu_item (t_("Import SVG folder"), 329 "import svg folder color", ""); 330 import_svg_color_folder.action.connect (() => { 331 SvgParser.import_folder (SvgType.COLOR); 332 show_menu = false; 333 }); 334 export_menu.items.add (import_svg_color_folder); 335 336 MenuItem import_background_image = add_menu_item (t_("Import Background Image"), "import background image"); 337 import_background_image.action.connect (() => { 338 MenuTab.show_background_tab (); 339 show_menu = false; 340 }); 341 export_menu.items.add (import_background_image); 342 343 MenuItem export_settings = add_menu_item (t_("Export Settings"), "export settings"); 344 export_settings.action.connect (() => { 345 MenuTab.show_export_settings_tab (); 346 show_menu = false; 347 }); 348 export_menu.items.add (export_settings); 349 350 MenuItem preview = add_menu_item (t_("Preview"), "preview"); 351 preview.action.connect (() => { 352 MenuTab.preview (); 353 show_menu = false; 354 }); 355 export_menu.items.add (preview); 356 357 // tab menu 358 MenuItem tab = add_menu_item (t_("Tab")); 359 tab.action.connect (() => { 360 set_menu (tab_menu); 361 }); 362 menu.items.add (tab); 363 364 MenuItem next_tab = add_menu_item (t_("Next Tab"), "next tab"); 365 next_tab.action.connect (() => { 366 MainWindow.next_tab (); 367 show_menu = false; 368 }); 369 tab_menu.items.add (next_tab); 370 371 MenuItem previous_tab = add_menu_item (t_("Previous Tab"), "previous tab"); 372 previous_tab.action.connect (() => { 373 MainWindow.previous_tab (); 374 show_menu = false; 375 }); 376 tab_menu.items.add (previous_tab); 377 378 MenuItem close_tab = add_menu_item (t_("Close Tab"), "close tab"); 379 close_tab.action.connect (() => { 380 MainWindow.close_tab (); 381 show_menu = false; 382 }); 383 tab_menu.items.add (close_tab); 384 385 MenuItem close_all_tabs = add_menu_item (t_("Close All Tabs"), "close all tabs"); 386 close_all_tabs.action.connect (() => { 387 MainWindow.close_all_tabs (); 388 show_menu = false; 389 }); 390 tab_menu.items.add (close_all_tabs); 391 392 // tab menu 393 MenuItem kerning = add_menu_item (t_("Spacing and Kerning")); 394 kerning.action.connect (() => { 395 set_menu (kerning_menu); 396 }); 397 menu.items.add (kerning); 398 399 MenuItem spacing_tab = add_menu_item (t_("Show Spacing Tab"), "show spacing tab"); 400 spacing_tab.action.connect (() => { 401 MenuTab.show_spacing_tab (); 402 show_menu = false; 403 }); 404 kerning_menu.items.add (spacing_tab); 405 406 MenuItem kerning_tab = add_menu_item (t_("Show Kerning Tab"), "show kerning tab"); 407 kerning_tab.action.connect (() => { 408 MenuTab.show_kerning_context (); 409 show_menu = false; 410 }); 411 kerning_menu.items.add (kerning_tab); 412 413 MenuItem list_kernings = add_menu_item (t_("List Kerning Pairs"), "list kerning pairs"); 414 list_kernings.action.connect (() => { 415 MenuTab.list_all_kerning_pairs (); 416 show_menu = false; 417 }); 418 kerning_menu.items.add (list_kernings); 419 420 MenuItem show_spacing = add_menu_item (t_("Spacing Classes"), "show spacing classes"); 421 show_spacing.action.connect (() => { 422 MenuTab.show_spacing_class_tab (); 423 show_menu = false; 424 }); 425 kerning_menu.items.add (show_spacing); 426 427 MenuItem next_kerning_pair = add_menu_item (t_("Select Next Kerning Pair"), "select next kerning pair"); 428 next_kerning_pair.action.connect (() => { 429 if (KerningDisplay.right_to_left) { 430 KerningDisplay.previous_pair (); 431 } else { 432 KerningDisplay.next_pair (); 433 } 434 435 show_menu = false; 436 }); 437 next_kerning_pair.add_display("Kerning"); 438 next_kerning_pair.add_display("Spacing"); 439 kerning_menu.items.add (next_kerning_pair); 440 441 MenuItem previous_kerning_pair = add_menu_item (t_("Select Previous Kerning Pair"), "select previous kerning pair"); 442 previous_kerning_pair.action.connect (() => { 443 if (KerningDisplay.right_to_left) { 444 KerningDisplay.next_pair (); 445 } else { 446 KerningDisplay.previous_pair (); 447 } 448 449 show_menu = false; 450 }); 451 previous_kerning_pair.add_display("Kerning"); 452 previous_kerning_pair.add_display("Spacing"); 453 kerning_menu.items.add (previous_kerning_pair); 454 455 MenuItem load_kerning_strings = add_menu_item (t_("Load Kerning Strings"), "load kerning strings"); 456 load_kerning_strings.action.connect (() => { 457 BirdFont.get_current_font ().kerning_strings.load_file (); 458 show_menu = false; 459 }); 460 kerning_menu.items.add (load_kerning_strings); 461 462 MenuItem reload_kerning_strings = add_menu_item (t_("Reload Kerning Strings"), "reloadload kerning strings"); 463 reload_kerning_strings.action.connect (() => { 464 Font f = BirdFont.get_current_font (); 465 f.kerning_strings.load (f); 466 show_menu = false; 467 }); 468 kerning_menu.items.add (reload_kerning_strings); 469 470 // ligature menu 471 MenuItem ligature = add_menu_item (t_("Ligatures")); 472 ligature.action.connect (() => { 473 set_menu (ligature_menu); 474 }); 475 menu.items.add (ligature); 476 477 MenuItem ligature_tab = add_menu_item (t_("Show Ligatures"), "show ligature tab"); 478 ligature_tab.action.connect (() => { 479 MenuTab.show_ligature_tab (); 480 show_menu = false; 481 }); 482 ligature_menu.items.add (ligature_tab); 483 484 MenuItem add_ligature = add_menu_item (t_("Add Ligature"), "add ligature"); 485 add_ligature.action.connect (() => { 486 MenuTab.add_ligature (); 487 show_menu = false; 488 }); 489 ligature_menu.items.add (add_ligature); 490 491 // git menu 492 if (BirdFont.has_argument ("--test")) { 493 MenuItem git = add_menu_item (t_("Git")); 494 git.action.connect (() => { 495 set_menu (git_menu); 496 }); 497 menu.items.add (git); 498 499 MenuItem save_bfp = add_menu_item (t_("Save As .bfp"), "save as .bfp"); 500 save_bfp.action.connect (() => { 501 MenuTab.save_as_bfp (); 502 show_menu = false; 503 }); 504 git_menu.items.add (save_bfp); 505 } 506 507 // show overview 508 MenuItem overview = add_menu_item (t_("Overview")); 509 overview.action.connect (() => { 510 MenuTab.select_overview (); 511 show_menu = false; 512 }); 513 menu.items.add (overview); 514 515 // settings 516 MenuItem settings = add_menu_item (t_("Settings"), "settings"); 517 settings.action.connect (() => { 518 MenuTab.show_settings_tab (); 519 show_menu = false; 520 }); 521 menu.items.add (settings); 522 523 MenuItem description = add_menu_item (t_("Name and Description"), "name and description"); 524 description.action.connect (() => { 525 MenuTab.show_description (); 526 show_menu = false; 527 }); 528 menu.items.add (description); 529 530 MenuItem version = add_menu_item (t_("Version"), "birdfont version"); 531 version.action.connect (() => { 532 MainWindow.show_message (t_("Version") + ": " + get_version ()); 533 show_menu = false; 534 }); 535 menu.items.add (version); 536 537 set_current_menu (menu); 538 top_menu = menu; 539 540 add_tool_key_bindings (); 541 load_key_bindings (); 542 } 543 544 void merge_selected_paths () { 545 MergeTask t = new MergeTask (); 546 MainWindow.run_blocking_task (t); 547 } 548 } 549 550 } 551