[latexila/wip/templates-revamp: 11/13] Dialog to manage templates



commit 5794a41c150531190d619614fa756bef80ba93e4
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Jul 3 11:27:06 2015 +0200

    Dialog to manage templates

 docs/reference/latexila-sections.txt               |    3 +
 src/liblatexila/Makefile.am                        |    2 +
 src/liblatexila/latexila-templates-manage-dialog.c |  105 ++++++++++++++++++++
 src/liblatexila/latexila-templates-manage-dialog.h |   31 ++++++
 src/liblatexila/latexila-templates-personal.c      |   22 ++++
 src/liblatexila/latexila-templates-personal.h      |    4 +
 src/liblatexila/latexila-utils.c                   |   33 ++++++
 src/liblatexila/latexila-utils.h                   |    3 +
 src/liblatexila/latexila.h                         |    1 +
 src/main_window_file.vala                          |    8 ++
 src/ui/ui.xml                                      |    1 +
 11 files changed, 213 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index 70d7b67..a3cf6c3 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -234,6 +234,7 @@ latexila_synctex_get_type
 <TITLE>LatexilaTemplatesDialogs</TITLE>
 latexila_templates_dialogs_open
 latexila_templates_dialogs_create_template
+latexila_templates_manage_dialog
 </SECTION>
 
 <SECTION>
@@ -253,6 +254,7 @@ LatexilaTemplatesPersonal
 latexila_templates_personal_get_instance
 latexila_templates_personal_get_contents
 latexila_templates_personal_create
+latexila_templates_personal_delete
 <SUBSECTION Standard>
 LATEXILA_TYPE_TEMPLATES_PERSONAL
 </SECTION>
@@ -271,4 +273,5 @@ latexila_utils_file_query_exists_finish
 latexila_utils_show_uri
 latexila_utils_get_dialog_component
 latexila_utils_create_parent_directories
+latexila_utils_join_widgets
 </SECTION>
diff --git a/src/liblatexila/Makefile.am b/src/liblatexila/Makefile.am
index 7a85fa4..b7ea768 100644
--- a/src/liblatexila/Makefile.am
+++ b/src/liblatexila/Makefile.am
@@ -26,6 +26,7 @@ liblatexila_headers =                         \
        latexila-templates-common.h             \
        latexila-templates-default.h            \
        latexila-templates-dialogs.h            \
+       latexila-templates-manage-dialog.h      \
        latexila-templates-personal.h           \
        latexila-types.h                        \
        latexila-utils.h
@@ -45,6 +46,7 @@ liblatexila_sources =                         \
        latexila-templates-common.c             \
        latexila-templates-default.c            \
        latexila-templates-dialogs.c            \
+       latexila-templates-manage-dialog.c      \
        latexila-templates-personal.c           \
        latexila-utils.c
 
diff --git a/src/liblatexila/latexila-templates-manage-dialog.c 
b/src/liblatexila/latexila-templates-manage-dialog.c
new file mode 100644
index 0000000..815d6f9
--- /dev/null
+++ b/src/liblatexila/latexila-templates-manage-dialog.c
@@ -0,0 +1,105 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2015 - 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-templates-manage-dialog.h"
+#include <glib/gi18n.h>
+#include "latexila-templates-personal.h"
+#include "latexila-templates-common.h"
+#include "latexila-utils.h"
+
+static GtkWidget *
+get_toolbar (void)
+{
+  GtkToolbar *toolbar;
+  GtkStyleContext *context;
+  GtkToolButton *delete_button;
+
+  toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
+  gtk_toolbar_set_icon_size (toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
+  gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_ICONS);
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
+
+  delete_button = GTK_TOOL_BUTTON (gtk_tool_button_new (NULL, NULL));
+  gtk_tool_button_set_icon_name (delete_button, "list-remove-symbolic");
+  gtk_widget_set_tooltip_text (GTK_WIDGET (delete_button), _("Delete"));
+
+  gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (delete_button), -1);
+
+  return GTK_WIDGET (toolbar);
+}
+
+static GtkWidget *
+get_dialog_content (void)
+{
+  LatexilaTemplatesPersonal *templates_store;
+  GtkTreeView *templates_view;
+  GtkWidget *scrolled_window;
+  GtkWidget *toolbar;
+
+  templates_store = latexila_templates_personal_get_instance ();
+  templates_view = latexila_templates_get_view (GTK_LIST_STORE (templates_store));
+
+  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_size_request (scrolled_window, 350, 300);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+                                       GTK_SHADOW_IN);
+
+  gtk_container_add (GTK_CONTAINER (scrolled_window),
+                     GTK_WIDGET (templates_view));
+
+  toolbar = get_toolbar ();
+
+  return latexila_utils_join_widgets (scrolled_window, toolbar);
+}
+
+/**
+ * latexila_templates_manage_dialog:
+ * @parent_window: transient parent window of the dialog.
+ *
+ * Runs a #GtkDialog to manage personal templates.
+ */
+void
+latexila_templates_manage_dialog (GtkWindow *parent_window)
+{
+  GtkDialog *dialog;
+  GtkWidget *dialog_content;
+  GtkBox *content_area;
+
+  g_return_if_fail (GTK_IS_WINDOW (parent_window));
+
+  dialog = GTK_DIALOG (gtk_dialog_new_with_buttons (_("Manage Personal Templates"),
+                                                    parent_window,
+                                                    GTK_DIALOG_MODAL |
+                                                    GTK_DIALOG_DESTROY_WITH_PARENT |
+                                                    GTK_DIALOG_USE_HEADER_BAR,
+                                                    NULL, NULL));
+
+  gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
+
+  dialog_content = get_dialog_content ();
+
+  content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
+  gtk_box_pack_start (content_area, dialog_content, TRUE, TRUE, 0);
+  gtk_widget_show_all (GTK_WIDGET (content_area));
+
+  gtk_dialog_run (dialog);
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
diff --git a/src/liblatexila/latexila-templates-manage-dialog.h 
b/src/liblatexila/latexila-templates-manage-dialog.h
new file mode 100644
index 0000000..60f0216
--- /dev/null
+++ b/src/liblatexila/latexila-templates-manage-dialog.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright (C) 2015 - 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_TEMPLATES_MANAGE_DIALOG_H__
+#define __LATEXILA_TEMPLATES_MANAGE_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+void      latexila_templates_manage_dialog        (GtkWindow *parent_window);
+
+G_END_DECLS
+
+#endif /* __LATEXILA_TEMPLATES_MANAGE_DIALOG_H__ */
diff --git a/src/liblatexila/latexila-templates-personal.c b/src/liblatexila/latexila-templates-personal.c
index da47f47..2659adb 100644
--- a/src/liblatexila/latexila-templates-personal.c
+++ b/src/liblatexila/latexila-templates-personal.c
@@ -408,3 +408,25 @@ out:
   g_clear_object (&stream);
   return ret;
 }
+
+/**
+ * latexila_templates_personal_delete:
+ * @templates: the #LatexilaTemplatesPersonal instance.
+ * @path: the #GtkTreePath of a personal template.
+ * @error: (out) (optional): a location to a %NULL #GError, or %NULL.
+ *
+ * Deletes a personal template.
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ */
+gboolean
+latexila_templates_personal_delete (LatexilaTemplatesPersonal  *templates,
+                                    GtkTreePath                *path,
+                                    GError                    **error)
+{
+  g_return_val_if_fail (LATEXILA_IS_TEMPLATES_PERSONAL (templates), FALSE);
+  g_return_val_if_fail (path != NULL, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  return TRUE;
+}
diff --git a/src/liblatexila/latexila-templates-personal.h b/src/liblatexila/latexila-templates-personal.h
index 3348cd7..e635ee7 100644
--- a/src/liblatexila/latexila-templates-personal.h
+++ b/src/liblatexila/latexila-templates-personal.h
@@ -40,6 +40,10 @@ gboolean      latexila_templates_personal_create                (LatexilaTemplat
                                                                  const gchar               *contents,
                                                                  GError                   **error);
 
+gboolean      latexila_templates_personal_delete                (LatexilaTemplatesPersonal  *templates,
+                                                                 GtkTreePath                *path,
+                                                                 GError                    **error);
+
 G_END_DECLS
 
 #endif /* __LATEXILA_TEMPLATES_PERSONAL_H__ */
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index 6b85b4b..60ccf12 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -423,3 +423,36 @@ latexila_utils_create_parent_directories (GFile   *file,
 
   return TRUE;
 }
+
+/**
+ * latexila_utils_join_widgets:
+ * @widget_top: the #GtkWidget at the top.
+ * @widget_bottom: the #GtkWidget at the bottom.
+ *
+ * Joins two widgets vertically, with junction sides.
+ *
+ * Returns: (transfer floating): a #GtkContainer containing @widget_top and
+ * @widget_bottom.
+ */
+GtkWidget *
+latexila_utils_join_widgets (GtkWidget *widget_top,
+                             GtkWidget *widget_bottom)
+{
+  GtkStyleContext *context;
+  GtkBox *vbox;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget_top), NULL);
+  g_return_val_if_fail (GTK_IS_WIDGET (widget_bottom), NULL);
+
+  context = gtk_widget_get_style_context (widget_top);
+  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
+
+  context = gtk_widget_get_style_context (widget_bottom);
+  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+
+  vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
+  gtk_box_pack_start (vbox, widget_top, TRUE, TRUE, 0);
+  gtk_box_pack_start (vbox, widget_bottom, FALSE, FALSE, 0);
+
+  return GTK_WIDGET (vbox);
+}
diff --git a/src/liblatexila/latexila-utils.h b/src/liblatexila/latexila-utils.h
index 729f393..415871d 100644
--- a/src/liblatexila/latexila-utils.h
+++ b/src/liblatexila/latexila-utils.h
@@ -58,6 +58,9 @@ GtkWidget *     latexila_utils_get_dialog_component             (const gchar *ti
 gboolean        latexila_utils_create_parent_directories        (GFile   *file,
                                                                  GError **error);
 
+GtkWidget *     latexila_utils_join_widgets                     (GtkWidget *widget_top,
+                                                                 GtkWidget *widget_bottom);
+
 G_END_DECLS
 
 #endif /* __LATEXILA_UTILS_H__ */
diff --git a/src/liblatexila/latexila.h b/src/liblatexila/latexila.h
index b0b305c..5be04c7 100644
--- a/src/liblatexila/latexila.h
+++ b/src/liblatexila/latexila.h
@@ -40,6 +40,7 @@
 #include "latexila-templates-default.h"
 #include "latexila-templates-personal.h"
 #include "latexila-templates-dialogs.h"
+#include "latexila-templates-manage-dialog.h"
 #include "latexila-utils.h"
 
 #endif /* __LATEXILA_H__ */
diff --git a/src/main_window_file.vala b/src/main_window_file.vala
index a760892..82065b0 100644
--- a/src/main_window_file.vala
+++ b/src/main_window_file.vala
@@ -47,6 +47,9 @@ public class MainWindowFile
         { "FileCreateTemplate", null, N_("Create _Template From Document..."), null,
             N_("Create a new template from the current document"), on_create_template },
 
+        { "FileManageTemplates", null, N_("_Manage Personal Templates..."), null,
+            N_("Manage personal templates"), on_manage_templates },
+
         { "FileClose", "window-close", N_("_Close"), "<Control>W",
             N_("Close the current file"), on_file_close }
     };
@@ -220,6 +223,11 @@ public class MainWindowFile
         Latexila.templates_dialogs_create_template (_main_window, template_contents);
     }
 
+    public void on_manage_templates ()
+    {
+        Latexila.templates_manage_dialog (_main_window);
+    }
+
     public void on_file_close ()
     {
         return_if_fail (_main_window.active_tab != null);
diff --git a/src/ui/ui.xml b/src/ui/ui.xml
index 36a51a4..d095d85 100644
--- a/src/ui/ui.xml
+++ b/src/ui/ui.xml
@@ -29,6 +29,7 @@ along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
       <menuitem action="FileSaveAs" />
       <separator />
       <menuitem action="FileCreateTemplate" />
+      <menuitem action="FileManageTemplates" />
       <separator />
       <menuitem action="FileClose" />
       <menuitem action="FileQuit" />


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