[latexila/wip/build-tools-revamp] LatexilaSynctex (not finished)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/build-tools-revamp] LatexilaSynctex (not finished)
- Date: Sat, 17 May 2014 21:40:12 +0000 (UTC)
commit ec7ef469b3449f4372c48bed5661e284ad073209
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat May 17 01:25:32 2014 +0200
LatexilaSynctex (not finished)
It is needed for the build tools for opening a PDF file with synctex
support with evince. Since I don't want to use the Vala code in C, a
rewrite of synctex.vala in C was needed.
synctex.vala uses the synchronous API, which is bad. The rewrite in C
uses the asynchronous API (it's better).
configure.ac | 2 +
src/Makefile.am | 2 +-
src/evince/Makefile.am | 22 +++++
src/evince/evince-gdbus.xml | 30 +++++++
src/liblatexila/Makefile.am | 34 ++++++---
src/liblatexila/latexila-synctex.c | 156 ++++++++++++++++++++++++++++++++++++
src/liblatexila/latexila-synctex.h | 59 ++++++++++++++
src/liblatexila/latexila-types.h | 1 +
src/liblatexila/latexila.h | 1 +
9 files changed, 296 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 07a1342..d420cc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_PROG_INSTALL
AM_PROG_CC_C_O
AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources])
AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])
+AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
AM_PROG_VALAC([${VALA_REQUIRED_VERSION}],
[found_vala=true]
[found_vala=false])
@@ -168,6 +169,7 @@ AC_CONFIG_FILES([Makefile
man/Makefile
po/Makefile.in
src/Makefile
+ src/evince/Makefile
src/gedit/Makefile
src/liblatexila/Makefile
src/ui/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 508fd87..92f905e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = gedit liblatexila ui
+SUBDIRS = evince gedit liblatexila ui
bin_PROGRAMS = latexila
diff --git a/src/evince/Makefile.am b/src/evince/Makefile.am
new file mode 100644
index 0000000..b787b83
--- /dev/null
+++ b/src/evince/Makefile.am
@@ -0,0 +1,22 @@
+noinst_LTLIBRARIES = libevince.la
+
+libevince_la_CFLAGS = $(WARN_CFLAGS)
+
+libevince_built_sources = \
+ evince-gdbus-generated.c \
+ evince-gdbus-generated.h
+
+nodist_libevince_la_SOURCES = $(libevince_built_sources)
+
+BUILT_SOURCES = $(libevince_built_sources)
+
+evince-gdbus-generated.c evince-gdbus-generated.h: evince-gdbus.xml Makefile
+ $(AM_V_GEN) $(GDBUS_CODEGEN) \
+ --interface-prefix=org.gnome.evince. \
+ --c-namespace=Evince \
+ --generate-c-code evince-gdbus-generated \
+ evince-gdbus.xml
+
+EXTRA_DIST = evince-gdbus.xml
+
+-include $(top_srcdir)/git.mk
diff --git a/src/evince/evince-gdbus.xml b/src/evince/evince-gdbus.xml
new file mode 100644
index 0000000..0da995f
--- /dev/null
+++ b/src/evince/evince-gdbus.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Introspection 0.1//EN"
+ "http://www.freedesktop.org/software/dbus/introspection.dtd">
+<node>
+ <interface name="org.gnome.evince.Daemon">
+ <method name="FindDocument">
+ <arg type="s" name="uri" direction="in"/>
+ <arg type="b" name="spawn" direction="in"/>
+ <arg type="s" name="owner" direction="out"/>
+ </method>
+ </interface>
+ <interface name='org.gnome.evince.Application'>
+ <method name='GetWindowList'>
+ <arg type='ao' name='window_list' direction='out'/>
+ </method>
+ </interface>
+ <interface name='org.gnome.evince.Window'>
+ <method name='SyncView'>
+ <arg type='s' name='source_file' direction='in'/>
+ <arg type='(ii)' name='source_point' direction='in'/>
+ <arg type='u' name='timestamp' direction='in'/>
+ </method>
+ <signal name='SyncSource'>
+ <arg type='s' name='source_file' direction='out'/>
+ <arg type='(ii)' name='source_point' direction='out'/>
+ <arg type='u' name='timestamp' direction='out'/>
+ </signal>
+ <signal name='Closed'/>
+ </interface>
+</node>
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 538c4e5..1beb3cc 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -2,10 +2,16 @@
noinst_LTLIBRARIES = liblatexila.la
-liblatexila_la_CFLAGS = $(WARN_CFLAGS) $(CODE_COVERAGE_CFLAGS)
+liblatexila_la_CFLAGS = \
+ $(WARN_CFLAGS) \
+ $(CODE_COVERAGE_CFLAGS) \
+ -I$(top_builddir)/src/evince
+
liblatexila_la_LDFLAGS = $(CODE_COVERAGE_LDFLAGS)
+liblatexila_la_LIBADD = ../evince/libevince.la
liblatexila_headers = \
+ latexila.h \
latexila-build-job.h \
latexila-build-tool.h \
latexila-build-tools.h \
@@ -14,14 +20,11 @@ liblatexila_headers = \
latexila-build-view.h \
latexila-post-processor.h \
latexila-post-processor-all-output.h \
+ latexila-synctex.h \
latexila-types.h \
latexila-utils.h
-BUILT_SOURCES = \
- latexila-enum-types.c \
- latexila-enum-types.h
-
-liblatexila_la_SOURCES = \
+liblatexila_sources = \
latexila-build-job.c \
latexila-build-tool.c \
latexila-build-tools.c \
@@ -30,9 +33,20 @@ liblatexila_la_SOURCES = \
latexila-build-view.c \
latexila-post-processor.c \
latexila-post-processor-all-output.c \
- latexila-utils.c \
- $(liblatexila_headers) \
- $(BUILT_SOURCES)
+ latexila-synctex.c \
+ latexila-utils.c
+
+liblatexila_built_sources = \
+ latexila-enum-types.c \
+ latexila-enum-types.h
+
+liblatexila_la_SOURCES = \
+ $(liblatexila_headers) \
+ $(liblatexila_sources)
+
+nodist_liblatexila_la_SOURCES = $(liblatexila_built_sources)
+
+BUILT_SOURCES = $(liblatexila_built_sources)
ENUM_TYPES = $(liblatexila_headers)
@@ -64,7 +78,7 @@ Latexila.gir: liblatexila.la
Latexila_gir_NAMESPACE = Latexila
Latexila_gir_INCLUDES = Gtk-3.0
Latexila_gir_LIBS = liblatexila.la
-Latexila_gir_FILES = $(liblatexila_la_SOURCES)
+Latexila_gir_FILES = $(liblatexila_la_SOURCES) $(nodist_liblatexila_la_SOURCES)
noinst_DATA += Latexila.gir Latexila.typelib
CLEANFILES += Latexila.gir Latexila.typelib
diff --git a/src/liblatexila/latexila-synctex.c b/src/liblatexila/latexila-synctex.c
new file mode 100644
index 0000000..32efd55
--- /dev/null
+++ b/src/liblatexila/latexila-synctex.c
@@ -0,0 +1,156 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "latexila-synctex.h"
+#include <glib/gi18n.h>
+#include "evince-gdbus-generated.h"
+#include "latexila-utils.h"
+
+static LatexilaSynctex *instance = NULL;
+
+struct _LatexilaSynctexPrivate
+{
+ /* PDF URI -> EvinceWindow object */
+ GHashTable *evince_windows;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (LatexilaSynctex, latexila_synctex, G_TYPE_OBJECT)
+
+static void
+latexila_synctex_dispose (GObject *object)
+{
+ LatexilaSynctex *synctex = LATEXILA_SYNCTEX (object);
+
+ if (synctex->priv->evince_windows != NULL)
+ {
+ g_hash_table_unref (synctex->priv->evince_windows);
+ synctex->priv->evince_windows = NULL;
+ }
+
+ G_OBJECT_CLASS (latexila_synctex_parent_class)->dispose (object);
+}
+
+static void
+latexila_synctex_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (latexila_synctex_parent_class)->finalize (object);
+}
+
+static void
+latexila_synctex_class_init (LatexilaSynctexClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = latexila_synctex_dispose;
+ object_class->finalize = latexila_synctex_finalize;
+}
+
+static void
+latexila_synctex_init (LatexilaSynctex *synctex)
+{
+ synctex->priv = latexila_synctex_get_instance_private (synctex);
+
+ synctex->priv->evince_windows = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+}
+
+/**
+ * latexila_synctex_get_instance:
+ *
+ * Returns: (transfer none): the #LatexilaSynctex singleton instance.
+ */
+LatexilaSynctex *
+latexila_synctex_get_instance (void)
+{
+ if (instance == NULL)
+ {
+ instance = g_object_new (LATEXILA_TYPE_SYNCTEX, NULL);
+ }
+
+ return instance;
+}
+
+static void
+show_warning (const gchar *message)
+{
+ GtkApplication *app;
+ GtkWindow *parent;
+ GtkWidget *dialog;
+
+ app = GTK_APPLICATION (g_application_get_default ());
+ parent = gtk_application_get_active_window (app);
+
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", _("Impossible to do the forward search."));
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", message);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+static gchar *
+get_pdf_uri (GFile *main_tex_file)
+{
+ gchar *tex_uri;
+ gchar *short_uri;
+ gchar *pdf_uri;
+
+ tex_uri = g_file_get_uri (main_tex_file);
+ short_uri = latexila_utils_get_shortname (tex_uri);
+ pdf_uri = g_strdup_printf ("%s.pdf", short_uri);
+
+ g_free (tex_uri);
+ g_free (short_uri);
+ return pdf_uri;
+}
+
+/**
+ * latexila_synctex_forward_search:
+ * @buffer: a #GtkTextBuffer.
+ * @main_tex_file: the main *.tex file of @buffer.
+ *
+ * Does a forward search, i.e. switch from the *.tex file to the PDF file at the
+ * same position as the cursor position in @buffer.
+ */
+void
+latexila_synctex_forward_search (GtkTextBuffer *buffer,
+ GFile *main_tex_file)
+{
+ gchar *pdf_uri;
+
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+
+ if (main_tex_file == NULL)
+ {
+ show_warning (_("The document is not saved."));
+ return;
+ }
+
+ g_return_if_fail (G_IS_FILE (main_tex_file));
+
+ pdf_uri = get_pdf_uri (main_tex_file);
+}
diff --git a/src/liblatexila/latexila-synctex.h b/src/liblatexila/latexila-synctex.h
new file mode 100644
index 0000000..cc05052
--- /dev/null
+++ b/src/liblatexila/latexila-synctex.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * LaTeXila is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LATEXILA_SYNCTEX_H__
+#define __LATEXILA_SYNCTEX_H__
+
+#include "latexila-types.h"
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define LATEXILA_TYPE_SYNCTEX (latexila_synctex_get_type ())
+#define LATEXILA_SYNCTEX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LATEXILA_TYPE_SYNCTEX,
LatexilaSynctex))
+#define LATEXILA_SYNCTEX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LATEXILA_TYPE_SYNCTEX,
LatexilaSynctexClass))
+#define LATEXILA_IS_SYNCTEX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LATEXILA_TYPE_SYNCTEX))
+#define LATEXILA_IS_SYNCTEX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LATEXILA_TYPE_SYNCTEX))
+#define LATEXILA_SYNCTEX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LATEXILA_TYPE_SYNCTEX,
LatexilaSynctexClass))
+
+typedef struct _LatexilaSynctexClass LatexilaSynctexClass;
+typedef struct _LatexilaSynctexPrivate LatexilaSynctexPrivate;
+
+struct _LatexilaSynctex
+{
+ GObject parent;
+
+ LatexilaSynctexPrivate *priv;
+};
+
+struct _LatexilaSynctexClass
+{
+ GObjectClass parent_class;
+};
+
+GType latexila_synctex_get_type (void) G_GNUC_CONST;
+
+LatexilaSynctex * latexila_synctex_get_instance (void);
+
+void latexila_synctex_forward_search (GtkTextBuffer *buffer,
+ GFile *main_tex_file);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_SYNCTEX_H__ */
diff --git a/src/liblatexila/latexila-types.h b/src/liblatexila/latexila-types.h
index 9ca5d99..1dd9da4 100644
--- a/src/liblatexila/latexila-types.h
+++ b/src/liblatexila/latexila-types.h
@@ -32,6 +32,7 @@ typedef struct _LatexilaBuildToolsPersonal LatexilaBuildToolsPersonal;
typedef struct _LatexilaBuildView LatexilaBuildView;
typedef struct _LatexilaPostProcessor LatexilaPostProcessor;
typedef struct _LatexilaPostProcessorAllOutput LatexilaPostProcessorAllOutput;
+typedef struct _LatexilaSynctex LatexilaSynctex;
G_END_DECLS
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index 0d799f0..a200ab9 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -31,6 +31,7 @@
#include "latexila-build-view.h"
#include "latexila-post-processor.h"
#include "latexila-post-processor-all-output.h"
+#include "latexila-synctex.h"
#include "latexila-utils.h"
#endif /* __LATEXILA_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]