diff --git a/src/AboutWindow.vala b/src/AboutWindow.vala index d686768..3186b52 100644 --- a/src/AboutWindow.vala +++ b/src/AboutWindow.vala @@ -8,15 +8,16 @@ namespace LAview.Desktop { public class AboutDialogWindow { AboutDialog dialog; - public AboutDialogWindow (Window parent) throws Error { + public AboutDialogWindow (Gtk.Application application, Window parent) throws Error { var builder = new Builder (); builder.add_from_file (AppDirs.ui_dir + "/laview-desktop.glade"); builder.connect_signals (this); dialog = builder.get_object ("aboutdialog_window") as AboutDialog; - dialog.set_destroy_with_parent (true); - dialog.set_transient_for (parent); - dialog.set_modal (true); + dialog.destroy_with_parent = true; + dialog.transient_for = parent; + dialog.modal = true; + dialog.application = application; dialog.delete_event.connect ((source) => {return true;}); dialog.version = @" $(Config.VERSION_MAJOR).$(Config.VERSION_MINOR).$(Config.VERSION_PATCH)"; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f5190ae..9017bd7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -7,7 +7,7 @@ namespace LAview.Desktop { */ public class MainWindow { - Window window; + ApplicationWindow window; PreferencesDialog pref_dialog; AboutDialogWindow about_dialog; SubprocessDialog subprocess_dialog; @@ -17,12 +17,12 @@ namespace LAview.Desktop { TreeView treeview_templates; TreeView treeview_objects; - public MainWindow () throws Error { + public MainWindow (Gtk.Application application) throws Error { var builder = new Builder (); builder.add_from_file (AppDirs.ui_dir + "/laview-desktop.glade"); builder.connect_signals (this); - window = builder.get_object ("main_window") as Window; + window = builder.get_object ("main_window") as ApplicationWindow; statusbar = builder.get_object ("statusbar") as Statusbar; liststore_templates = builder.get_object ("liststore_templates") as Gtk.ListStore; liststore_doc_objects = builder.get_object ("liststore_objects") as Gtk.ListStore; @@ -31,11 +31,15 @@ namespace LAview.Desktop { window.title = "LAview Desktop" + @" $(Config.VERSION_MAJOR).$(Config.VERSION_MINOR).$(Config.VERSION_PATCH)"; - pref_dialog = new PreferencesDialog (window); - subprocess_dialog = new SubprocessDialog (window); - about_dialog = new AboutDialogWindow (window); + pref_dialog = new PreferencesDialog (application, window); + subprocess_dialog = new SubprocessDialog (application, window); + about_dialog = new AboutDialogWindow (application, window); fill_liststore_templates (); + + application.app_menu = builder.get_object ("menubar") as MenuModel; + application.menubar = builder.get_object ("main_toolbar") as MenuModel; + window.application = application; } void fill_liststore_templates () { @@ -314,5 +318,10 @@ namespace LAview.Desktop { chooser.close (); } + + [CCode (instance_pos = -1)] + public void action_quit_activate (Gtk.Action action) { + window.application.quit(); + } } } diff --git a/src/PreferencesWindow.vala b/src/PreferencesWindow.vala index 75022c1..976e4cb 100644 --- a/src/PreferencesWindow.vala +++ b/src/PreferencesWindow.vala @@ -12,14 +12,15 @@ namespace LAview.Desktop { FileChooserButton filechooserbutton_lyx; FileChooserButton filechooserbutton_pdflatex; - public PreferencesDialog (Window parent) throws Error { + public PreferencesDialog (Gtk.Application application, Window parent) throws Error { var builder = new Builder (); builder.add_from_file (AppDirs.ui_dir + "/laview-desktop.glade"); builder.connect_signals (this); dialog = builder.get_object ("preferences_window") as Dialog; - dialog.set_transient_for (parent); - dialog.set_modal (true); + dialog.transient_for = parent; + dialog.modal = true; + dialog.application = application; dialog.delete_event.connect ((source) => {return true;}); liststore_data = builder.get_object ("liststore_data") as Gtk.ListStore; liststore_protocols = builder.get_object ("liststore_protocols") as Gtk.ListStore; diff --git a/src/SubprocessDialog.vala b/src/SubprocessDialog.vala index 45ed139..cd30114 100644 --- a/src/SubprocessDialog.vala +++ b/src/SubprocessDialog.vala @@ -13,14 +13,15 @@ namespace LAview.Desktop { public delegate void PostProcessDelegate (); - public SubprocessDialog (Window parent) throws Error { + public SubprocessDialog (Gtk.Application application, Window parent) throws Error { var builder = new Builder (); builder.add_from_file (AppDirs.ui_dir + "/laview-desktop.glade"); builder.connect_signals (this); dialog = builder.get_object ("subprocess_dialog") as Dialog; - dialog.set_transient_for (parent); - dialog.set_modal (true); + dialog.transient_for = parent; + dialog.modal = true; + dialog.application = application; dialog.delete_event.connect ((source) => {return true;}); textview_stderrout = builder.get_object ("textview_stderrout") as TextView; } diff --git a/src/main.vala b/src/main.vala index ccdcc06..c50a61f 100644 --- a/src/main.vala +++ b/src/main.vala @@ -4,7 +4,7 @@ namespace LAview.Desktop { using Gtk, LAview.Desktop; - namespace CommandlineOptions { + /*namespace CommandlineOptions { // bool no_startup_progress = false; // string data_dir = null; bool show_version = false; @@ -38,34 +38,46 @@ namespace LAview.Desktop { return entries; } - } + }*/ - void main (string[] args) { - try { + public class LAviewDesktopApp : Gtk.Application { - AppDirs.init (args); - AppCore.init (args); - Resources.init (args); + MainWindow main_window; - Gtk.init_with_args (ref args, _("[FILE]"), CommandlineOptions.get_options (), GETTEXT_PACKAGE); - - // Internationalization - Intl.bindtextdomain (GETTEXT_PACKAGE, AppDirs.locale_dir); - Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - - var main_window = new MainWindow (); - main_window.show_all (); - - Gtk.main (); - - } catch (Error e) { - stderr.printf (_("Error: %s\n"), e.message); - stderr.printf (_("Run '%s --help' to see a full list of available command line options.\n"), args[0]); + public LAviewDesktopApp () { + Object(application_id: "ws.backbone.laview.desktop", + flags: ApplicationFlags.FLAGS_NONE); } - AppDirs.terminate(); + protected override void activate () { + try { + main_window = new MainWindow (this); + main_window.show_all (); + } catch (Error e) { + stderr.printf (_("Error: %s\n"), e.message); + } + } - return; + public static int main (string[] args) { + try { + AppDirs.init (args); + AppCore.init (args); + Resources.init (args); + //Gtk.init_with_args (ref args, _("[FILE]"), CommandlineOptions.get_options (), GETTEXT_PACKAGE); + + // Internationalization + Intl.bindtextdomain (GETTEXT_PACKAGE, AppDirs.locale_dir); + Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + + var app = new LAviewDesktopApp (); + return app.run (args); + + } catch (Error e) { + stderr.printf (_("Error: %s\n"), e.message); + stderr.printf (_("Run '%s --help' to see a full list of available command line options.\n"), args[0]); + return e.code; + } + } } } diff --git a/ui/glade/laview-desktop.glade b/ui/glade/laview-desktop.glade index b0cf718..0e43671 100644 --- a/ui/glade/laview-desktop.glade +++ b/ui/glade/laview-desktop.glade @@ -100,6 +100,12 @@ + + + True + + + @@ -382,7 +388,7 @@ - + 640 480 False @@ -469,12 +475,12 @@ gtk-quit False + action_quit True False True True True - @@ -807,12 +813,13 @@ + False + action_quit True False Close the application True gtk-quit - False