Window.vala 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Adw;
  2. using Gtk;
  3. namespace Publicate {
  4. public class ViewerWindow : Adw.ApplicationWindow {
  5. private Stack stack;
  6. private StartupMenu startup_menu;
  7. public PpubEditor editor {get; set;}
  8. public Ppub.Publication publication {get; set;}
  9. private SimpleAction extract_action;
  10. public ViewerWindow(Adw.Application app) {
  11. application = app;
  12. stack = new Stack();
  13. startup_menu = new StartupMenu(this);
  14. editor = new PpubEditor(this);
  15. default_height = 600;
  16. default_width = 800;
  17. content = stack;
  18. stack.add_child(startup_menu);
  19. stack.add_child(editor);
  20. stack.transition_type = StackTransitionType.CROSSFADE;
  21. var save_action = new SimpleAction("save", null);
  22. save_action.activate.connect(() => editor.save_tab.begin());
  23. add_action(save_action);
  24. add_binding_action(Gdk.Key.s, Gdk.ModifierType.CONTROL_MASK, "win.save", "Save current tab");
  25. }
  26. public async void open_ppub() throws Error {
  27. var dialog = new FileDialog();
  28. var filter = new FileFilter();
  29. var filters = new GLib.ListStore(Type.OBJECT);
  30. filters.append(filter);
  31. filter.add_pattern("*.ppub");
  32. filter.name = "Portable Publications";
  33. dialog.filters = filters;
  34. var file = yield dialog.open(this, null);
  35. if(file == null) {
  36. return;
  37. }
  38. yield load_ppub(file);
  39. }
  40. public async void load_ppub(File file) {
  41. stack.visible_child = editor;
  42. yield editor.load_ppub(file);
  43. }
  44. }
  45. }