Closes #100: Application class + ID.

This commit is contained in:
Kolan Sh 2016-01-30 05:52:02 +03:00
parent 38ef905dde
commit fea1168533
6 changed files with 73 additions and 42 deletions

View File

@ -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)";

View File

@ -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();
}
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}
}
}

View File

@ -100,6 +100,12 @@
<signal name="activate" handler="laview_desktop_main_window_action_saveas_activate" swapped="no"/>
</object>
</child>
<child>
<object class="GtkAction" id="action_quit">
<property name="always_show_image">True</property>
<signal name="activate" handler="laview_desktop_main_window_action_quit_activate" swapped="no"/>
</object>
</child>
</object>
<object class="GtkFileFilter" id="filefilter_open">
<patterns>
@ -382,7 +388,7 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="main_window">
<object class="GtkApplicationWindow" id="main_window">
<property name="width_request">640</property>
<property name="height_request">480</property>
<property name="can_focus">False</property>
@ -469,12 +475,12 @@
<object class="GtkImageMenuItem" id="menuitem_quit">
<property name="label">gtk-quit</property>
<property name="use_action_appearance">False</property>
<property name="related_action">action_quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="gtk_main_quit" swapped="no"/>
</object>
</child>
</object>
@ -807,12 +813,13 @@
</child>
<child>
<object class="GtkToolButton" id="toolbutton_quit">
<property name="use_action_appearance">False</property>
<property name="related_action">action_quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Close the application</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-quit</property>
<signal name="clicked" handler="gtk_main_quit" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>