[latexila/wip/templates-revamp-1] LatexilaTemplatesDialogs: dialog to create a new template (wip)



commit 39513604bc59723905e6705b71941e2b4620b0ff
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Apr 18 15:07:24 2015 +0200

    LatexilaTemplatesDialogs: dialog to create a new template (wip)

 src/liblatexila/latexila-templates-dialogs.c |   83 ++++++++++++++++++++++++++
 src/templates_dialogs.vala                   |   34 -----------
 2 files changed, 83 insertions(+), 34 deletions(-)
---
diff --git a/src/liblatexila/latexila-templates-dialogs.c b/src/liblatexila/latexila-templates-dialogs.c
index 8259cff..1b0ae21 100644
--- a/src/liblatexila/latexila-templates-dialogs.c
+++ b/src/liblatexila/latexila-templates-dialogs.c
@@ -197,3 +197,86 @@ latexila_templates_dialogs_open (GtkWindow *parent_window)
   gtk_widget_destroy (GTK_WIDGET (dialog));
   return contents;
 }
+
+void
+latexila_templates_dialogs_create_template (GtkWindow   *parent_window,
+                                            const gchar *template_contents)
+{
+  GtkDialog *dialog;
+  GtkBox *content_area;
+  GtkEntry *entry;
+  GtkWidget *component;
+  LatexilaTemplates *templates;
+  GtkTreeView *templates_view;
+  GtkWidget *scrolled_window;
+
+  dialog = g_object_new (GTK_TYPE_DIALOG,
+                         "use-header-bar", TRUE,
+                         "title", _("New Template..."),
+                         "destroy-with-parent", TRUE,
+                         "transient-for", parent_window,
+                         NULL);
+
+  gtk_dialog_add_buttons (dialog,
+                          _("_Cancel"), GTK_RESPONSE_CANCEL,
+                          _("Crea_te"), GTK_RESPONSE_OK,
+                          NULL);
+
+  gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
+
+  content_area = GTK_BOX (gtk_dialog_get_content_area (dialog));
+
+  /* FIXME needed? */
+  /*gtk_box_set_homogeneous (content_area, FALSE);*/
+
+  /* Name */
+  entry = GTK_ENTRY (gtk_entry_new ());
+  gtk_widget_set_hexpand (GTK_WIDGET (entry), TRUE);
+  component = latexila_utils_get_dialog_component (_("Name of the new template"),
+                                                   entry);
+  gtk_box_pack_start (content_area, component, FALSE, TRUE, 0);
+
+  /* Icon.
+   * Take the default store because it contains all the icons.
+   */
+  templates = latexila_templates_get_instance ();
+  templates_view = latexila_templates_get_default_templates_view (templates);
+
+  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_size_request (scrolled_window, 250, 200);
+  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));
+
+  component = latexila_utils_get_dialog_component (_("Choose an icon"), scrolled_window);
+  gtk_box_pack_start (content_area, component, TRUE, TRUE, 0);
+
+  gtk_widget_show_all (GTK_WIDGET (content_area));
+
+  while (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)
+    {
+      GtkTreeSelection *selection;
+      GList *selected_rows;
+      GtkTreePath *path;
+
+      /* If no name specified. */
+      if (gtk_entry_get_text_length (entry) == 0)
+        continue;
+
+      selection = gtk_tree_view_get_selection (templates_view);
+
+      /* If no icons selected. */
+      if (gtk_tree_selection_count_selected_rows (selection) == 0)
+        continue;
+
+      /* Get config icon name. */
+      selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
+      g_assert (g_list_length (selected_rows) == 1);
+
+      path = selected_rows->data;
+
+      g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+    }
+}
diff --git a/src/templates_dialogs.vala b/src/templates_dialogs.vala
index 766ef07..cb23deb 100644
--- a/src/templates_dialogs.vala
+++ b/src/templates_dialogs.vala
@@ -23,41 +23,7 @@ public class CreateTemplateDialog : Dialog
 {
     public CreateTemplateDialog (MainWindow parent)
     {
-        Object (use_header_bar: 1);
         return_val_if_fail (parent.active_tab != null, null);
-
-        title = _("New Template...");
-        set_transient_for (parent);
-        destroy_with_parent = true;
-        add_button (_("_Cancel"), ResponseType.CANCEL);
-        add_button (_("Crea_te"), ResponseType.OK);
-        set_default_response (ResponseType.OK);
-
-        Box content_area = get_content_area () as Box;
-        content_area.homogeneous = false;
-
-        /* name */
-        Entry entry = new Entry ();
-        entry.hexpand = true;
-        Widget component = Latexila.utils_get_dialog_component (_("Name of the new template"),
-            entry);
-        content_area.pack_start (component, false);
-
-        /* icon */
-        Templates templates = Templates.get_default ();
-
-        // Take the default store because it contains all the icons.
-        TreeView templates_list = templates.get_default_templates_list ();
-
-        ScrolledWindow scrollbar = Utils.add_scrollbar (templates_list);
-        scrollbar.set_shadow_type (ShadowType.IN);
-        scrollbar.set_size_request (250, 200);
-        component = Latexila.utils_get_dialog_component (_("Choose an icon"), scrollbar);
-        content_area.pack_start (component);
-
-        content_area.show_all ();
-
-        run_me (parent, entry, templates_list);
     }
 
     private void run_me (MainWindow parent, Entry entry, TreeView templates_list)


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