[latexila/wip/build-tools-revamp] Synctex: backward search signal
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/build-tools-revamp] Synctex: backward search signal
- Date: Wed, 21 May 2014 22:05:54 +0000 (UTC)
commit 50a086c08e1a0998f388ae01aa385fe52e3d5798
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu May 22 00:03:16 2014 +0200
Synctex: backward search signal
src/latexila_app.vala | 20 ++++++++++++++++++
src/liblatexila/latexila-synctex.c | 40 ++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/src/latexila_app.vala b/src/latexila_app.vala
index bf5bed8..51392e6 100644
--- a/src/latexila_app.vala
+++ b/src/latexila_app.vala
@@ -112,6 +112,7 @@ public class LatexilaApp : Gtk.Application
create_window ();
reopen_files ();
Gtk.AccelMap.load (get_accel_filename ());
+ support_backward_search ();
release ();
}
@@ -218,4 +219,23 @@ public class LatexilaApp : Gtk.Application
return Path.build_filename (Environment.get_user_config_dir (),
"latexila", "accels");
}
+
+ private void support_backward_search ()
+ {
+ Latexila.Synctex synctex = Latexila.Synctex.get_instance ();
+
+ synctex.backward_search.connect ((tex_uri, line, timestamp) =>
+ {
+ File tex_file = File.new_for_uri (tex_uri);
+ if (! tex_file.query_exists ())
+ {
+ warning (@"Backward search: the file \"$tex_uri\" doesn't exist.");
+ return;
+ }
+
+ MainWindow main_window = active_window as MainWindow;
+ main_window.jump_to_file_position (tex_file, line, line + 1);
+ main_window.present_with_time (timestamp);
+ });
+ }
}
diff --git a/src/liblatexila/latexila-synctex.c b/src/liblatexila/latexila-synctex.c
index 0703ecc..ab1d758 100644
--- a/src/liblatexila/latexila-synctex.c
+++ b/src/liblatexila/latexila-synctex.c
@@ -37,8 +37,6 @@
#include "evince-gdbus-generated.h"
#include "latexila-utils.h"
-static LatexilaSynctex *instance = NULL;
-
struct _LatexilaSynctexPrivate
{
/* PDF URI -> EvinceWindow object */
@@ -58,8 +56,17 @@ typedef struct
gchar *owner;
} ConnectEvinceWindowData;
+enum
+{
+ SIGNAL_BACKWARD_SEARCH,
+ LAST_SIGNAL
+};
+
G_DEFINE_TYPE_WITH_PRIVATE (LatexilaSynctex, latexila_synctex, G_TYPE_OBJECT)
+static LatexilaSynctex *instance = NULL;
+static guint signals[LAST_SIGNAL];
+
static ForwardSearchData *
forward_search_data_new (void)
{
@@ -115,6 +122,25 @@ latexila_synctex_class_init (LatexilaSynctexClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = latexila_synctex_dispose;
+
+ /**
+ * LatexilaSynctex::backward-search:
+ * @synctex: the #LatexilaSynctex instance.
+ * @tex_uri: the *.tex file URI.
+ * @line: the line to jump to.
+ * @timestamp: timestamp of the event.
+ *
+ * The ::backward-search signal is emitted to perform a backward search, i.e.
+ * switching from the PDF to the source *.tex file.
+ */
+ signals[SIGNAL_BACKWARD_SEARCH] = g_signal_new ("backward-search",
+ LATEXILA_TYPE_SYNCTEX,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 3,
+ G_TYPE_STRING,
+ G_TYPE_INT,
+ G_TYPE_UINT);
}
static void
@@ -216,6 +242,16 @@ sync_source_cb (EvinceWindow *window,
guint timestamp,
LatexilaSynctex *synctex)
{
+ gint line;
+ gint column; /* not used */
+
+ g_variant_get (pos, "(ii)", &line, &column);
+
+ g_signal_emit (synctex,
+ signals[SIGNAL_BACKWARD_SEARCH], 0,
+ tex_uri,
+ line - 1,
+ timestamp);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]