Allow other applications to open text files with Odysseus.

And while I was trying to make that work, I corrected some problems in
the .desktop file.
Specifically I wrote down the wrong executable name and
the categories I selected for it didn't validate.
So I focused it on the publishing category.

16min
This commit is contained in:
Adrian Cochrane 2018-04-17 15:46:38 +12:00
parent 7b4117a282
commit 25923d8354
3 changed files with 20 additions and 6 deletions

View File

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

View File

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

View File

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