[latexila] Build Tool Runner: call gtk_show_uri() to open files
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Build Tool Runner: call gtk_show_uri() to open files
- Date: Fri, 13 Jul 2012 03:41:33 +0000 (UTC)
commit c0db3aea9bf8fe5e8e7bf93f19ff3d53384c3265
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Fri Jul 13 05:31:56 2012 +0200
Build Tool Runner: call gtk_show_uri() to open files
src/build_job_runner.vala | 12 +++--
src/build_tool_runner.vala | 95 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 96 insertions(+), 11 deletions(-)
---
diff --git a/src/build_job_runner.vala b/src/build_job_runner.vala
index cbc9c6a..9382891 100644
--- a/src/build_job_runner.vala
+++ b/src/build_job_runner.vala
@@ -127,16 +127,18 @@ public class BuildJobRunner : GLib.Object
string[] new_args = {};
foreach (string arg in args)
{
- if (arg.contains ("$view"))
- // TODO use gtk_show_uri() instead of xdg-open
- new_args += arg.replace ("$view", "xdg-open");
-
- else if (arg.contains ("$filename"))
+ if (arg.contains ("$filename"))
new_args += arg.replace ("$filename", base_filename);
else if (arg.contains ("$shortname"))
new_args += arg.replace ("$shortname", base_shortname);
+ else if (arg.contains ("$view"))
+ {
+ warning ("Build job runner: the '$view' placeholder is deprecated.");
+ new_args += arg.replace ("$view", "xdg-open");
+ }
+
else
new_args += arg;
}
diff --git a/src/build_tool_runner.vala b/src/build_tool_runner.vala
index 2682cb6..298a2b6 100644
--- a/src/build_tool_runner.vala
+++ b/src/build_tool_runner.vala
@@ -63,16 +63,21 @@ public class BuildToolRunner : GLib.Object
private void proceed ()
{
- // All jobs executed, finished.
- if (_tool.jobs.size <= _job_num)
+ _current_job_runner = null;
+
+ // Run the next job.
+ if (_job_num < _tool.jobs.size)
+ {
+ _current_job = _tool.jobs[_job_num];
+ run_current_job ();
+ }
+
+ // All the jobs have run successfully, open the files.
+ else if (open_files ())
{
_view.set_title_state (_main_title, BuildState.SUCCEEDED);
finished ();
- return;
}
-
- _current_job = _tool.jobs[_job_num];
- run_current_job ();
}
private void run_current_job ()
@@ -161,6 +166,84 @@ public class BuildToolRunner : GLib.Object
}
}
+ private bool open_files ()
+ {
+ string[] files_to_open = _tool.files_to_open.split (" ");
+
+ foreach (string file_to_open in files_to_open)
+ {
+ if (! open_file (file_to_open))
+ return false;
+ }
+
+ return true;
+ }
+
+ // Returns true on success.
+ private bool open_file (string file_to_open)
+ {
+ /* Replace placeholders */
+
+ string filename = _on_file.get_uri ();
+ string shortname = Utils.get_shortname (filename);
+
+ string uri;
+
+ if (file_to_open.contains ("$filename"))
+ uri = file_to_open.replace ("$filename", filename);
+
+ else if (file_to_open.contains ("$shortname"))
+ uri = file_to_open.replace ("$shortname", shortname);
+
+ else
+ uri = "file://" + file_to_open;
+
+ /* Add title in the build view */
+
+ string basename = Path.get_basename (uri);
+
+ _current_job_title = _view.add_job_title (_("Open %s").printf (basename),
+ BuildState.RUNNING);
+
+ /* Check if the file exists */
+
+ File file = File.new_for_uri (uri);
+ if (! file.query_exists ())
+ {
+ BuildMsg message = BuildMsg ();
+ message.text = _("The file '%s' doesn't exist.").printf (uri);
+ message.type = BuildMsgType.ERROR;
+ _view.append_single_message (_current_job_title, message);
+
+ failed ();
+ return false;
+ }
+
+ /* Show uri */
+
+ try
+ {
+ Gtk.show_uri (_view.get_screen (), uri, Gdk.CURRENT_TIME);
+ }
+ catch (Error e)
+ {
+ BuildMsg message = BuildMsg ();
+ message.text = _("Failed to open '%s':").printf (uri);
+ message.type = BuildMsgType.ERROR;
+ _view.append_single_message (_current_job_title, message);
+
+ message.text = e.message;
+ _view.append_single_message (_current_job_title, message);
+
+ failed ();
+ return false;
+ }
+
+ _view.set_title_state (_current_job_title, BuildState.SUCCEEDED);
+
+ return true;
+ }
+
private void failed ()
{
_view.set_title_state (_main_title, BuildState.FAILED);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]