diff --git a/data/write-as-gtk.desktop b/data/write-as-gtk.desktop index a70f09a..39b221e 100644 --- a/data/write-as-gtk.desktop +++ b/data/write-as-gtk.desktop @@ -2,10 +2,11 @@ Type=Application Name=write.as Comment=Spread your ideas -Exec=write.as-gtk +Exec=write-as-gtk %f Icon=write-as Terminal=false -Categories=Network;GTK;Development;Office;Utility;Publishing;TextTools;TextEditor; +MimeType=text/plain; +Categories=GTK;Office;Publishing; Keywords=blog;pastebin;snippets;code;publish; StartupNotify=true diff --git a/src/application.vala b/src/application.vala index e81d875..bedbd70 100644 --- a/src/application.vala +++ b/src/application.vala @@ -1,5 +1,6 @@ public class WriteAs.Application : Gtk.Application { construct { + this.flags |= ApplicationFlags.HANDLES_OPEN; Intl.setlocale(LocaleCategory.ALL, ""); Intl.textdomain("write.as"); @@ -11,6 +12,15 @@ public class WriteAs.Application : Gtk.Application { new WriteAs.MainWindow(this).show_all(); } + public override void open(File[] files, string hint) { + activate(); // ensure we have a window open. + try { + (get_windows().data as MainWindow).open_file(files[0]); + } catch (Error e) { + error(e.message); + } + } + public static int main(string[] args) { return new WriteAs.Application().run(args); } diff --git a/src/window.vala b/src/window.vala index 92451ed..16aa45f 100644 --- a/src/window.vala +++ b/src/window.vala @@ -120,10 +120,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow { accels.connect(Gdk.Key.O, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED, (g, a, k, m) => { try { - uint8[] text; - var file = prompt_file(Gtk.FileChooserAction.OPEN, _("_Open")); - file.load_contents(null, out text, null); - canvas.buffer.text = (string) text; + open_file(prompt_file(Gtk.FileChooserAction.OPEN, _("_Open"))); } catch (Error e) { // It's fine... } @@ -161,6 +158,12 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow { if (resp == Gtk.ResponseType.ACCEPT) return file_chooser.get_file(); else throw new UserCancellable.USER_CANCELLED("FileChooserDialog"); } + + public void open_file(File file) throws Error { + uint8[] text; + file.load_contents(null, out text, null); + canvas.buffer.text = (string) text; + } } errordomain WriteAs.UserCancellable {USER_CANCELLED}