[tepl] Statusbar: implementation



commit 28df085d18bdaf90cce09e4ae041fdf0752a379f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Apr 20 00:59:51 2020 +0200

    Statusbar: implementation

 docs/reference/tepl-sections.txt |  2 ++
 tepl/tepl-statusbar.c            | 78 ++++++++++++++++++++++++++++++++++------
 tepl/tepl-statusbar.h            | 10 ++++--
 3 files changed, 77 insertions(+), 13 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index 76a6736..2bda7a5 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -322,6 +322,8 @@ tepl_metadata_manager_get_type
 <FILE>statusbar</FILE>
 TeplStatusbar
 tepl_statusbar_new
+tepl_statusbar_show_cursor_position
+tepl_statusbar_hide_cursor_position
 <SUBSECTION Standard>
 TEPL_IS_STATUSBAR
 TEPL_IS_STATUSBAR_CLASS
diff --git a/tepl/tepl-statusbar.c b/tepl/tepl-statusbar.c
index d2699ed..a5f809a 100644
--- a/tepl/tepl-statusbar.c
+++ b/tepl/tepl-statusbar.c
@@ -17,7 +17,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 #include "tepl-statusbar.h"
+#include <glib/gi18n-lib.h>
 
 /**
  * SECTION:statusbar
@@ -27,30 +29,33 @@
 
 struct _TeplStatusbarPrivate
 {
-       gint something;
+       GtkLabel *label;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (TeplStatusbar, tepl_statusbar, GTK_TYPE_STATUSBAR)
 
-static void
-tepl_statusbar_finalize (GObject *object)
-{
-
-       G_OBJECT_CLASS (tepl_statusbar_parent_class)->finalize (object);
-}
-
 static void
 tepl_statusbar_class_init (TeplStatusbarClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-       object_class->finalize = tepl_statusbar_finalize;
 }
 
 static void
 tepl_statusbar_init (TeplStatusbar *statusbar)
 {
        statusbar->priv = tepl_statusbar_get_instance_private (statusbar);
+
+       /* FIXME: still needed? */
+       /*
+       gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0);
+       gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);
+       */
+
+       statusbar->priv->label = GTK_LABEL (gtk_label_new (NULL));
+       gtk_widget_set_no_show_all (GTK_WIDGET (statusbar->priv->label), TRUE);
+
+       gtk_box_pack_end (GTK_BOX (statusbar),
+                         GTK_WIDGET (statusbar->priv->label),
+                         FALSE, TRUE, 0);
 }
 
 /**
@@ -64,3 +69,54 @@ tepl_statusbar_new (void)
 {
        return g_object_new (TEPL_TYPE_STATUSBAR, NULL);
 }
+
+/**
+ * tepl_statusbar_show_cursor_position:
+ * @statusbar: a #TeplStatusbar.
+ * @line: the line number, must be >= 1.
+ * @column: the column number, must be >= 1.
+ *
+ * Shows the line and column numbers on the right side of the @statusbar. (So
+ * messages added with gtk_statusbar_push() are still visible after calling this
+ * function).
+ *
+ * Since: 5.0
+ */
+void
+tepl_statusbar_show_cursor_position (TeplStatusbar *statusbar,
+                                    gint           line,
+                                    gint           column)
+{
+       gchar *text;
+
+       g_return_if_fail (TEPL_IS_STATUSBAR (statusbar));
+       g_return_if_fail (line >= 1);
+       g_return_if_fail (column >= 1);
+
+       /* Translators: "Ln" is an abbreviation for "Line", Col is an
+        * abbreviation for "Column". Please, use abbreviations if possible.
+        */
+       text = g_strdup_printf (_("Ln %d, Col %d"), line, column);
+
+       gtk_label_set_text (statusbar->priv->label, text);
+       gtk_widget_show (GTK_WIDGET (statusbar->priv->label));
+
+       g_free (text);
+}
+
+/**
+ * tepl_statusbar_hide_cursor_position:
+ * @statusbar: a #TeplStatusbar.
+ *
+ * The reverse action of tepl_statusbar_show_cursor_position(). This function
+ * hides the text used to show the line and column numbers.
+ *
+ * Since: 5.0
+ */
+void
+tepl_statusbar_hide_cursor_position (TeplStatusbar *statusbar)
+{
+       g_return_if_fail (TEPL_IS_STATUSBAR (statusbar));
+
+       gtk_widget_hide (GTK_WIDGET (statusbar->priv->label));
+}
diff --git a/tepl/tepl-statusbar.h b/tepl/tepl-statusbar.h
index a80fb8a..6adc4d7 100644
--- a/tepl/tepl-statusbar.h
+++ b/tepl/tepl-statusbar.h
@@ -53,9 +53,15 @@ struct _TeplStatusbarClass
        gpointer padding[12];
 };
 
-GType          tepl_statusbar_get_type         (void);
+GType          tepl_statusbar_get_type                 (void);
 
-TeplStatusbar *        tepl_statusbar_new              (void);
+TeplStatusbar *        tepl_statusbar_new                      (void);
+
+void           tepl_statusbar_show_cursor_position     (TeplStatusbar *statusbar,
+                                                        gint           line,
+                                                        gint           column);
+
+void           tepl_statusbar_hide_cursor_position     (TeplStatusbar *statusbar);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]