Add UI and implement saving details and logs to file

This commit is contained in:
Michael Gratton 2019-04-06 18:49:10 +11:00 committed by Michael James Gratton
parent 0e4486bbf4
commit b5f27dce79
2 changed files with 83 additions and 4 deletions

View file

@ -87,6 +87,41 @@ public class Components.Inspector : Gtk.Window {
this.details = details.str;
}
private async void save(string path,
GLib.Cancellable? cancellable)
throws GLib.Error {
GLib.File dest = GLib.File.new_for_path(path);
GLib.FileIOStream dest_io = yield dest.create_readwrite_async(
GLib.FileCreateFlags.NONE,
GLib.Priority.DEFAULT,
cancellable
);
GLib.DataOutputStream out = new GLib.DataOutputStream(
new GLib.BufferedOutputStream(dest_io.get_output_stream())
);
out.put_string(this.details);
out.put_byte('\n');
out.put_byte('\n');
Gtk.TreeModel model = this.logs_view.model;
Gtk.TreeIter? iter;
bool valid = model.get_iter_first(out iter);
while (valid && !cancellable.is_cancelled()) {
Value value;
model.get_value(iter, COL_MESSAGE, out value);
string? message = (string) value;
if (message != null) {
out.put_string(message);
out.put_byte('\n');
}
valid = model.iter_next(ref iter);
}
yield out.close_async();
yield dest_io.close_async();
}
private void update_ui() {
bool logs_visible = this.stack.visible_child == this.logs_pane;
uint logs_selected = this.logs_view.get_selection().count_selected_rows();
@ -129,6 +164,34 @@ public class Components.Inspector : Gtk.Window {
}
}
[GtkCallback]
private void on_save_as_clicked() {
Gtk.FileChooserNative chooser = new Gtk.FileChooserNative(
_("Save As"),
this,
Gtk.FileChooserAction.SAVE,
_("Save As"),
_("Cancel")
);
chooser.set_current_name(
new GLib.DateTime.now_local().format("Geary Inspector - %F %T.txt")
);
if (chooser.run() == Gtk.ResponseType.ACCEPT) {
this.save.begin(
chooser.get_filename(),
null,
(obj, res) => {
try {
this.save.end(res);
} catch (GLib.Error err) {
warning("Failed to save inspector data: %s", err.message);
}
}
);
}
}
[GtkCallback]
private void on_search_clicked() {
this.search_bar.set_search_mode(!this.search_bar.get_search_mode());

View file

@ -38,9 +38,6 @@
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="title">
<object class="GtkStackSwitcher">
@ -49,6 +46,25 @@
<property name="stack">stack</property>
</object>
</child>
<child>
<object class="GtkButton" id="save_as_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_save_as_clicked" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-save-as-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="copy_button">
<property name="visible">True</property>
@ -66,7 +82,7 @@
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>