Tidy up new publishing code.

Now supports multiple fonts and the caller can be written more naturally.
This commit is contained in:
Adrian Cochrane 2018-04-19 10:32:38 +12:00
parent 86e2c0f7b6
commit ef5d657d0c

View File

@ -63,12 +63,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
var publish_button = new Gtk.Button.from_icon_name("document-send", var publish_button = new Gtk.Button.from_icon_name("document-send",
Gtk.IconSize.SMALL_TOOLBAR); Gtk.IconSize.SMALL_TOOLBAR);
publish_button.clicked.connect(() => { publish_button.clicked.connect(() => {
title = _("Publishing post…"); canvas.buffer.text += "\n\n" + publish();
canvas.sensitive = false;
publish.begin((obj, res) => {
canvas.buffer.text += "\n\n" + publish.end(res);
canvas.sensitive = true;
});
}); });
header.pack_end(publish_button); header.pack_end(publish_button);
@ -149,7 +144,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
} }
} }
private async string publish() { private string publish() {
try { try {
if (text_changed) {; if (text_changed) {;
draft_file().replace_contents(canvas.buffer.text.data, null, false, draft_file().replace_contents(canvas.buffer.text.data, null, false,
@ -158,7 +153,8 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
text_changed = false; text_changed = false;
} }
var cmd = "sh -c 'cat ~/.writeas-draft.txt | writeas'"; var cmd = "sh -c 'cat ~/.writeas-draft.txt | writeas --font %s'";
cmd = cmd.printf(fontstyle);
string stdout, stderr; string stdout, stderr;
int status; int status;
Process.spawn_command_line_sync(cmd, Process.spawn_command_line_sync(cmd,