diff --git a/data/io.github.wpkelso.slate.desktop.in b/data/io.github.wpkelso.slate.desktop.in index 81c2b2f..4efc11f 100644 --- a/data/io.github.wpkelso.slate.desktop.in +++ b/data/io.github.wpkelso.slate.desktop.in @@ -9,3 +9,8 @@ Type=Application StartupNotify=true Categories=Utility;GTK;Office;Development;TextTools;TextEditor; MimeType=text/plain; +Actions=NewDocument; + +[Desktop Action NewDocument] +Exec=io.github.wpkelso.slate --new-document +Name=New Document diff --git a/src/Application.vala b/src/Application.vala index 82f4b18..bc52d03 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -11,11 +11,10 @@ public class Application : Gtk.Application { public static uint created_documents = 1; public static string data_dir_path = Environment.get_user_data_dir () + "/slate"; - public Application () { Object ( application_id: APP_ID, - flags: ApplicationFlags.DEFAULT_FLAGS | ApplicationFlags.HANDLES_OPEN + flags: ApplicationFlags.DEFAULT_FLAGS | ApplicationFlags.HANDLES_OPEN | ApplicationFlags.HANDLES_COMMAND_LINE ); } @@ -178,4 +177,26 @@ public class Application : Gtk.Application { } }); } + + protected override int command_line (ApplicationCommandLine command_line) { + string[] args = command_line.get_arguments (); + + switch (args[1]) { + case "--new-document": + on_new_document (); + break; + + case (null): + activate (); + break; + + default: + foreach (var arg in args[1:args.length]) { + open_window_with_file (File.new_for_commandline_arg (arg)); + } + break; + } + return 0; + + } }