[tepl] Add tepl_side_panel_new()



commit ba47099fe35c768e715ec0fb735540f331ffdf51
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Apr 20 19:47:08 2020 +0200

    Add tepl_side_panel_new()

 docs/reference/tepl-docs.xml     |   1 +
 docs/reference/tepl-sections.txt |   5 ++
 po/POTFILES.in                   |   1 +
 tepl/meson.build                 |   2 +
 tepl/tepl-side-panel.c           | 104 +++++++++++++++++++++++++++++++++++++++
 tepl/tepl-side-panel.h           |  35 +++++++++++++
 tepl/tepl.h                      |   1 +
 7 files changed, 149 insertions(+)
---
diff --git a/docs/reference/tepl-docs.xml b/docs/reference/tepl-docs.xml
index 8c08fe8..594771f 100644
--- a/docs/reference/tepl-docs.xml
+++ b/docs/reference/tepl-docs.xml
@@ -42,6 +42,7 @@
 
     <chapter id="panels">
       <title>Side and Bottom Panels</title>
+      <xi:include href="xml/side-panel.xml"/>
       <xi:include href="xml/stack.xml"/>
     </chapter>
 
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index a31b2b2..0d584ac 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -318,6 +318,11 @@ TeplMetadataManagerPrivate
 tepl_metadata_manager_get_type
 </SECTION>
 
+<SECTION>
+<FILE>side-panel</FILE>
+tepl_side_panel_new
+</SECTION>
+
 <SECTION>
 <FILE>stack</FILE>
 tepl_stack_add_component
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f852939..d9208c2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,7 @@ tepl/tepl-metadata.c
 tepl/tepl-metadata-manager.c
 tepl/tepl-metadata-parser.c
 tepl/tepl-notebook.c
+tepl/tepl-side-panel.c
 tepl/tepl-signal-group.c
 tepl/tepl-stack.c
 tepl/tepl-statusbar.c
diff --git a/tepl/meson.build b/tepl/meson.build
index dc4395e..6c11d32 100644
--- a/tepl/meson.build
+++ b/tepl/meson.build
@@ -18,6 +18,7 @@ tepl_public_headers = [
   'tepl-metadata.h',
   'tepl-metadata-manager.h',
   'tepl-notebook.h',
+  'tepl-side-panel.h',
   'tepl-stack.h',
   'tepl-statusbar.h',
   'tepl-tab.h',
@@ -46,6 +47,7 @@ tepl_public_c_files = [
   'tepl-metadata.c',
   'tepl-metadata-manager.c',
   'tepl-notebook.c',
+  'tepl-side-panel.c',
   'tepl-stack.c',
   'tepl-statusbar.c',
   'tepl-tab.c',
diff --git a/tepl/tepl-side-panel.c b/tepl/tepl-side-panel.c
new file mode 100644
index 0000000..073c822
--- /dev/null
+++ b/tepl/tepl-side-panel.c
@@ -0,0 +1,104 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "tepl-side-panel.h"
+#include <glib/gi18n-lib.h>
+#include "tepl-utils.h"
+
+/**
+ * SECTION:side-panel
+ * @Title: TeplSidePanel
+ * @Short_description: Functions to create a side panel
+ *
+ * Functions to create a side panel.
+ *
+ * The workflow to create a side panel is as follows:
+ * 1. gtk_stack_new()
+ * 2. tepl_stack_add_component() multiple times.
+ * 3. tepl_side_panel_new()
+ * 4. tepl_stack_bind_setting()
+ */
+
+static void
+close_button_clicked_cb (GtkButton *close_button,
+                        GtkWidget *side_panel)
+{
+       gtk_widget_hide (side_panel);
+}
+
+static GtkWidget *
+create_close_button (GtkWidget *side_panel)
+{
+       GtkWidget *close_button;
+
+       close_button = tepl_utils_create_close_button ();
+       gtk_widget_set_tooltip_text (close_button, _("Hide panel"));
+
+       g_signal_connect (close_button,
+                         "clicked",
+                         G_CALLBACK (close_button_clicked_cb),
+                         side_panel);
+
+       return close_button;
+}
+
+/**
+ * tepl_side_panel_new:
+ * @stack: a #GtkStack.
+ *
+ * Creates a new container intended to be used as a side panel. It contains:
+ * - A #GtkStackSwitcher.
+ * - A close button that hides the side panel when clicked.
+ * - The provided @stack.
+ *
+ * Returns: (transfer floating): a new side panel container.
+ * Since: 5.0
+ */
+GtkWidget *
+tepl_side_panel_new (GtkStack *stack)
+{
+       GtkWidget *vgrid;
+       GtkStackSwitcher *stack_switcher;
+       GtkActionBar *action_bar;
+
+       g_return_val_if_fail (GTK_IS_STACK (stack), NULL);
+
+       vgrid = gtk_grid_new ();
+       gtk_orientable_set_orientation (GTK_ORIENTABLE (vgrid), GTK_ORIENTATION_VERTICAL);
+       /* We assume here that it's a *left* side panel. */
+       gtk_widget_set_margin_start (vgrid, 6);
+
+       stack_switcher = GTK_STACK_SWITCHER (gtk_stack_switcher_new ());
+       gtk_stack_switcher_set_stack (stack_switcher, stack);
+
+       action_bar = GTK_ACTION_BAR (gtk_action_bar_new ());
+       gtk_action_bar_set_center_widget (action_bar, GTK_WIDGET (stack_switcher));
+       gtk_action_bar_pack_end (action_bar, create_close_button (vgrid));
+
+       gtk_container_add (GTK_CONTAINER (vgrid), GTK_WIDGET (action_bar));
+       gtk_widget_show_all (vgrid);
+
+       gtk_container_add (GTK_CONTAINER (vgrid), GTK_WIDGET (stack));
+
+       /* Do not call gtk_widget_show_all() on stack, it's externally-provided. */
+       gtk_widget_show (GTK_WIDGET (stack));
+
+       return vgrid;
+}
diff --git a/tepl/tepl-side-panel.h b/tepl/tepl-side-panel.h
new file mode 100644
index 0000000..653975b
--- /dev/null
+++ b/tepl/tepl-side-panel.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEPL_SIDE_PANEL_H
+#define TEPL_SIDE_PANEL_H
+
+#if !defined (TEPL_H_INSIDE) && !defined (TEPL_COMPILATION)
+#error "Only <tepl/tepl.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkWidget *    tepl_side_panel_new     (GtkStack *stack);
+
+G_END_DECLS
+
+#endif /* TEPL_SIDE_PANEL_H */
diff --git a/tepl/tepl.h b/tepl/tepl.h
index 987ef25..1b933cf 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -44,6 +44,7 @@
 #include <tepl/tepl-metadata.h>
 #include <tepl/tepl-metadata-manager.h>
 #include <tepl/tepl-notebook.h>
+#include <tepl/tepl-side-panel.h>
 #include <tepl/tepl-stack.h>
 #include <tepl/tepl-statusbar.h>
 #include <tepl/tepl-tab.h>


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