diff --git a/CMakeLists.txt b/CMakeLists.txt index 42f4a48..aff55e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET (PROJECT_DESCRIPTION "LAview Desktop Application.") SET (MAJOR 1) SET (MINOR 1) -SET (PATCH 1) +SET (PATCH 2) LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/backbone) 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/AppDirs.vala b/src/AppDirs.vala index bf33f3e..2f06b66 100644 --- a/src/AppDirs.vala +++ b/src/AppDirs.vala @@ -24,8 +24,5 @@ namespace LAview.Desktop { if (File.new_for_path(w32dhack_sdir+"/gschemas.compiled").query_exists ()) settings_dir = w32dhack_sdir; } - - public static void terminate () { - } } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f5190ae..aa584a9 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,17 @@ 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; + + window.destroy.connect (() => { window.application.quit (); }); } void fill_liststore_templates () { @@ -86,14 +92,13 @@ namespace LAview.Desktop { _("_Cancel"), ResponseType.CANCEL, _("_Open"), ResponseType.ACCEPT); chooser.select_multiple = true; - FileFilter filter = new FileFilter (); - chooser.set_filter (filter); - filter.add_mime_type ("application/x-tex"); - filter.add_mime_type ("application/x-latex"); - filter.add_mime_type ("application/x-lyx"); - filter.add_pattern ("*.tex"); - filter.add_pattern ("*.latex"); - filter.add_pattern ("*.lyx"); + chooser.filter = new FileFilter (); + chooser.filter.add_mime_type ("application/x-tex"); + chooser.filter.add_mime_type ("application/x-latex"); + chooser.filter.add_mime_type ("application/x-lyx"); + chooser.filter.add_pattern ("*.tex"); + chooser.filter.add_pattern ("*.latex"); + chooser.filter.add_pattern ("*.lyx"); if (chooser.run () == ResponseType.ACCEPT) { var paths = chooser.get_filenames (); @@ -268,14 +273,13 @@ namespace LAview.Desktop { _("_Cancel"), ResponseType.CANCEL, _("_Save"), ResponseType.ACCEPT); chooser.select_multiple = false; - FileFilter filter = new FileFilter (); - chooser.set_filter (filter); - filter.add_mime_type ("application/pdf"); - filter.add_pattern ("*.pdf"); + chooser.filter = new FileFilter (); + chooser.filter.add_mime_type ("application/pdf"); + chooser.filter.add_pattern ("*.pdf"); // set folder if (AppCore.settings.pdf_save_path != "") - chooser.set_current_folder(AppCore.settings.pdf_save_path); + chooser.set_current_folder (AppCore.settings.pdf_save_path); // set current pdf file name or select an existance one var template_name = AppCore.core.get_template_path_by_index (indices[0]); @@ -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..aa49e8f 100644 --- a/ui/glade/laview-desktop.glade +++ b/ui/glade/laview-desktop.glade @@ -100,6 +100,12 @@ + + + True + + + @@ -382,14 +388,13 @@ - + 640 480 False 3 4 LAview Desktop - True @@ -469,12 +474,12 @@ gtk-quit False + action_quit True False True True True - @@ -807,12 +812,13 @@ + False + action_quit True False Close the application True gtk-quit - False