[latexila] View: implement get_indentation_style() in liblatexila
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] View: implement get_indentation_style() in liblatexila
- Date: Wed, 25 Oct 2017 15:30:59 +0000 (UTC)
commit 1b7dfe30583fa9b149ddfeb530e243f0b85432cf
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Oct 25 16:55:08 2017 +0200
View: implement get_indentation_style() in liblatexila
docs/reference/latexila-docs.xml | 5 +++
docs/reference/latexila-sections.txt | 5 +++
po/POTFILES.in | 1 +
src/completion.vala | 2 +-
src/document_view.vala | 7 ----
src/latex_menu.vala | 2 +-
src/liblatexila/Makefile.am | 10 +++--
src/liblatexila/latexila-view.c | 59 ++++++++++++++++++++++++++++++++++
src/liblatexila/latexila-view.h | 31 ++++++++++++++++++
src/liblatexila/latexila.h | 1 +
10 files changed, 110 insertions(+), 13 deletions(-)
---
diff --git a/docs/reference/latexila-docs.xml b/docs/reference/latexila-docs.xml
index bf1f88d..06892a7 100644
--- a/docs/reference/latexila-docs.xml
+++ b/docs/reference/latexila-docs.xml
@@ -13,6 +13,11 @@
<title>API reference</title>
<chapter>
+ <title>Main Classes</title>
+ <xi:include href="xml/view.xml"/>
+ </chapter>
+
+ <chapter>
<title>Build Tools</title>
<xi:include href="xml/build-job.xml"/>
<xi:include href="xml/build-tool.xml"/>
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index 113a175..ccf6767 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -280,3 +280,8 @@ latexila_utils_get_pixbuf_from_icon_name
latexila_utils_str_replace
latexila_utils_register_icons
</SECTION>
+
+<SECTION>
+<FILE>view</FILE>
+latexila_view_get_indentation_style
+</SECTION>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bdc2ab6..db529c0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -43,6 +43,7 @@ src/liblatexila/latexila-templates-dialogs.c
src/liblatexila/latexila-templates-manage-dialog.c
src/liblatexila/latexila-templates-personal.c
src/liblatexila/latexila-utils.c
+src/liblatexila/latexila-view.c
src/main.vala
src/main_window_build_tools.vala
src/main_window_documents.vala
diff --git a/src/completion.vala b/src/completion.vala
index bac0239..6580d68 100644
--- a/src/completion.vala
+++ b/src/completion.vala
@@ -496,7 +496,7 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
Document doc = iter.get_buffer () as Document;
string cur_indent = Tepl.iter_get_line_indentation (iter);
- string indent = doc.tab.document_view.get_indentation_style ();
+ string indent = Latexila.view_get_indentation_style (doc.tab.document_view);
CompletionChoice? env = _environments[env_name];
diff --git a/src/document_view.vala b/src/document_view.vala
index 68e2cf3..9b3eccb 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -121,13 +121,6 @@ public class DocumentView : Tepl.View
override_font (_font_desc);
}
- public string get_indentation_style ()
- {
- if (insert_spaces_instead_of_tabs)
- return string.nfill (tab_width, ' ');
- return "\t";
- }
-
private bool on_button_release_event (Gdk.EventButton event)
{
// Forward search on Ctrl + left click
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index a3406bf..c64a576 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -560,7 +560,7 @@ public class LatexMenu : Gtk.ActionGroup
private string get_indentation ()
{
- return main_window.active_view.get_indentation_style ();
+ return Latexila.view_get_indentation_style (main_window.active_view);
}
private void insert_character_style (string style)
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 578a6c7..934bcad 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -39,7 +39,8 @@ liblatexila_headers = \
latexila-templates-manage-dialog.h \
latexila-templates-personal.h \
latexila-types.h \
- latexila-utils.h
+ latexila-utils.h \
+ latexila-view.h
liblatexila_sources = \
latexila-build-job.c \
@@ -59,7 +60,8 @@ liblatexila_sources = \
latexila-templates-dialogs.c \
latexila-templates-manage-dialog.c \
latexila-templates-personal.c \
- latexila-utils.c
+ latexila-utils.c \
+ latexila-view.c
liblatexila_built_sources = \
latexila-enum-types.c \
@@ -102,7 +104,7 @@ INTROSPECTION_GIRS = Latexila.gir
Latexila.gir: liblatexila.la
Latexila_gir_NAMESPACE = Latexila
-Latexila_gir_INCLUDES = Gtk-3.0 Tepl-3
+Latexila_gir_INCLUDES = Gtk-3.0 GtkSource-3.0 Tepl-3
Latexila_gir_LIBS = liblatexila.la
Latexila_gir_FILES = $(liblatexila_la_SOURCES) $(nodist_liblatexila_la_SOURCES)
Latexila_gir_SCANNERFLAGS = $(WARN_SCANNERFLAGS)
@@ -119,7 +121,7 @@ latexila.vapi: Latexila.gir
VAPIGEN_VAPIS = latexila.vapi
-latexila_vapi_DEPS = gio-2.0 gtk+-3.0 Tepl-3
+latexila_vapi_DEPS = gio-2.0 gtk+-3.0 gtksourceview-3.0 Tepl-3
latexila_vapi_FILES = Latexila.gir
noinst_DATA += latexila.vapi
diff --git a/src/liblatexila/latexila-view.c b/src/liblatexila/latexila-view.c
new file mode 100644
index 0000000..f204f6c
--- /dev/null
+++ b/src/liblatexila/latexila-view.c
@@ -0,0 +1,59 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2017 - 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/>.
+ */
+
+/**
+ * SECTION:view
+ * @title: LatexilaView
+ * @short_description: Additional #TeplView functions
+ *
+ * Additional #TeplView functions.
+ */
+
+#include "latexila-view.h"
+
+/**
+ * latexila_view_get_indentation_style:
+ * @view: a #GtkSourceView.
+ *
+ * Returns one indentation level, as a string.
+ *
+ * Attention, this function assumes that the #GtkSourceView:indent-width is -1
+ * or equal to the #GtkSourceView:tab-width, which is always the case in
+ * LaTeXila (there is no #GSettings for the #GtkSourceView:indent-width).
+ *
+ * Returns: one indentation level, as a string. Free with g_free() when no
+ * longer needed.
+ */
+gchar *
+latexila_view_get_indentation_style (GtkSourceView *view)
+{
+ guint tab_width;
+ gint indent_width;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
+
+ tab_width = gtk_source_view_get_tab_width (view);
+ indent_width = gtk_source_view_get_indent_width (view);
+ g_return_val_if_fail (indent_width == -1 || indent_width == (gint)tab_width, NULL);
+
+ if (gtk_source_view_get_insert_spaces_instead_of_tabs (view))
+ return g_strnfill (tab_width, ' ');
+
+ return g_strdup ("\t");
+}
diff --git a/src/liblatexila/latexila-view.h b/src/liblatexila/latexila-view.h
new file mode 100644
index 0000000..7738211
--- /dev/null
+++ b/src/liblatexila/latexila-view.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2017 - 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_VIEW_H
+#define LATEXILA_VIEW_H
+
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+gchar * latexila_view_get_indentation_style (GtkSourceView *view);
+
+G_END_DECLS
+
+#endif /* LATEXILA_VIEW_H */
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index 6ea593c..66ffbeb 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -43,5 +43,6 @@
#include "latexila-templates-dialogs.h"
#include "latexila-templates-manage-dialog.h"
#include "latexila-utils.h"
+#include "latexila-view.h"
#endif /* __LATEXILA_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]