[latexila/gnome-3] Main: --new-document and --new-window options
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/gnome-3] Main: --new-document and --new-window options
- Date: Mon, 2 Apr 2012 22:18:39 +0000 (UTC)
commit 0e0388acc9837f1a4ab3f6f6afd5bc50b3fba471
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Tue Apr 3 00:17:35 2012 +0200
Main: --new-document and --new-window options
src/latexila.vala | 32 ++++++++++++++++++++++++++++++++
src/main.vala | 52 ++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 76 insertions(+), 8 deletions(-)
---
diff --git a/src/latexila.vala b/src/latexila.vala
index d0ce8ad..fbe4a2b 100644
--- a/src/latexila.vala
+++ b/src/latexila.vala
@@ -28,7 +28,14 @@ public class Latexila : Gtk.Application
Object (application_id: "org.gnome.latexila");
Environment.set_application_name ("LaTeXila");
+ connect_signals ();
+ add_actions ();
+ }
+
+ private void connect_signals ()
+ {
startup.connect (init_primary_instance);
+
activate.connect (() =>
{
hold ();
@@ -56,6 +63,31 @@ public class Latexila : Gtk.Application
});
}
+ private void add_actions ()
+ {
+ /* New document */
+ SimpleAction new_document_action = new SimpleAction ("new-document", null);
+ add_action (new_document_action);
+
+ new_document_action.activate.connect (() =>
+ {
+ hold ();
+ create_document ();
+ release ();
+ });
+
+ /* New window */
+ SimpleAction new_window_action = new SimpleAction ("new-window", null);
+ add_action (new_window_action);
+
+ new_window_action.activate.connect (() =>
+ {
+ hold ();
+ create_window ();
+ release ();
+ });
+ }
+
public static Latexila get_instance ()
{
return GLib.Application.get_default () as Latexila;
diff --git a/src/main.vala b/src/main.vala
index 3c85e20..0c9f453 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -21,6 +21,12 @@
using Gtk;
+private struct CmdLineData
+{
+ bool new_document;
+ bool new_window;
+}
+
private void check_xdg_data_dirs ()
{
// GSettings looks for compiled schemas in locations specified by the XDG_DATA_DIRS
@@ -48,16 +54,27 @@ private void init_i18n ()
Intl.textdomain (Config.GETTEXT_PACKAGE);
}
-private void parse_cmd_line_options (ref unowned string[] args)
+private CmdLineData parse_cmd_line_options (string[] args)
{
- bool option_version = false;
+ bool show_version = false;
+ string[] files_list;
+ CmdLineData data = CmdLineData ();
- OptionEntry[] options = new OptionEntry[2];
+ OptionEntry[] options = new OptionEntry[5];
- options[0] = {"version", 'V', 0, OptionArg.NONE, ref option_version,
+ options[0] = { "version", 'V', 0, OptionArg.NONE, ref show_version,
N_("Show the application's version"), null };
- options[1] = {null};
+ options[1] = { "new-document", 'n', 0, OptionArg.NONE, ref data.new_document,
+ N_("Create new document"), null };
+
+ options[2] = { "new-window", 0, 0, OptionArg.NONE, ref data.new_window,
+ N_("Create a new top-level window in an existing instance of LaTeXila"), null };
+
+ options[3] = { "", 0, 0, OptionArg.FILENAME_ARRAY, ref files_list,
+ null, "[FILE...]" };
+
+ options[4] = { null };
OptionContext context = Utils.get_option_context (options);
@@ -75,19 +92,38 @@ private void parse_cmd_line_options (ref unowned string[] args)
Process.exit (1);
}
- if (option_version)
+ if (show_version)
{
stdout.printf ("%s %s\n", Config.APP_NAME, Config.APP_VERSION);
Process.exit (0);
}
+
+ return data;
}
int main (string[] args)
{
check_xdg_data_dirs ();
init_i18n ();
- parse_cmd_line_options (ref args);
+
+ CmdLineData data = parse_cmd_line_options (args);
Latexila app = new Latexila ();
- return app.run (args);
+
+ try
+ {
+ app.register ();
+ }
+ catch (Error e)
+ {
+ error ("Failed to register the application: %s", e.message);
+ }
+
+ if (data.new_window)
+ app.activate_action ("new-window", null);
+
+ if (data.new_document)
+ app.activate_action ("new-document", null);
+
+ return app.run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]