From 02d7d47daa453c92ac160261564ffbcb14f18ecd Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Sun, 28 Feb 2016 22:25:26 +0300 Subject: [PATCH] LAview Core API fixed: null-returns replaced with exceptions. --- src/MainWindow.vala | 51 ++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 50729c3..3a63088 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -162,11 +162,18 @@ namespace LAview.Desktop { } void compose_object () { - var t_indices = get_template_indices (); - var o_indices = get_objects_indices (); - if (t_indices.length != 0 && o_indices.length != 0) - AppCore.core.compose_object (t_indices[0], o_indices[0]); - statusbar_show (_("After composing all objects print the document.")); + try { + var t_indices = get_template_indices (); + var o_indices = get_objects_indices (); + if (t_indices.length != 0 && o_indices.length != 0) + AppCore.core.compose_object (t_indices[0], o_indices[0]); + statusbar_show (_("After composing all objects print the document.")); + } catch (Error err) { + var msg = new MessageDialog (window, DialogFlags.MODAL, MessageType.ERROR, + ButtonsType.CLOSE, _("Error")+@": $(err.message)."); + msg.response.connect ((response_id) => { msg.destroy (); } ); + msg.show (); + } } [CCode (instance_pos = -1)] @@ -183,18 +190,30 @@ namespace LAview.Desktop { [CCode (instance_pos = -1)] public void action_edit_result_activate (Gtk.Action action) { - var indices = get_template_indices(); - if (indices.length != 0) { - var lyx_path = AppCore.core.get_lyx_file_path (indices[0]); - edit_lyx_files ({ lyx_path }); + try { + var indices = get_template_indices(); + if (indices.length != 0) { + var lyx_path = AppCore.core.get_lyx_file_path (indices[0]); + edit_lyx_files ({ lyx_path }); + } + } catch (Error err) { + var msg = new MessageDialog (window, DialogFlags.MODAL, MessageType.ERROR, + ButtonsType.CLOSE, _("Error")+@": $(err.message)."); + msg.response.connect ((response_id) => { msg.destroy (); } ); + msg.show (); } } void post_print () { - var indices = get_template_indices(); - var pdf_file = AppCore.core.get_pdf_file_path (indices[0]); - if (pdf_file != null && pdf_file != "") - Utils.open_document (pdf_file, window); + try { + var indices = get_template_indices(); + Utils.open_document (AppCore.core.get_pdf_file_path (indices[0]), window); + } catch (Error err) { + var msg = new MessageDialog (window, DialogFlags.MODAL, MessageType.ERROR, + ButtonsType.CLOSE, _("Error")+@": $(err.message)."); + msg.response.connect ((response_id) => { msg.destroy (); } ); + msg.show (); + } } [CCode (instance_pos = -1)] @@ -281,8 +300,10 @@ namespace LAview.Desktop { public void action_saveas_activate (Gtk.Action action) { var indices = get_template_indices (); if (indices.length == 0) return; - var tmp_pdf = AppCore.core.get_pdf_file_path (indices[0]); - if (tmp_pdf == null || tmp_pdf == "") { + string tmp_pdf = ""; + try { + tmp_pdf = AppCore.core.get_pdf_file_path (indices[0]); + } catch (Error err) { statusbar_show (_("Prepare the document first! >;-]")); return; }