[gitg/wip/actions: 51/61] Generalize info bar to user query



commit 75eaec65d691968802e4fcb0a01f8e878aaa406f
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jan 19 19:13:23 2014 +0100

    Generalize info bar to user query

 gitg/Makefile.am                   |    1 +
 gitg/gitg-info-bar.vala            |   64 ++++++++++++++++++++++++++
 gitg/gitg-window.vala              |   88 +++++++++++++++++++++++++++---------
 gitg/resources/gitg-resources.xml  |    1 +
 gitg/resources/ui/gitg-info-bar.ui |   44 ++++++++++++++++++
 gitg/resources/ui/gitg-window.ui   |   58 -----------------------
 6 files changed, 177 insertions(+), 79 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 35eeaa7..6968c0b 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -53,6 +53,7 @@ gitg_gitg_VALASOURCES =                                               \
        gitg/gitg-window.vala                                   \
        gitg/gitg-clone-dialog.vala                             \
        gitg/gitg-author-details-dialog.vala                    \
+       gitg/gitg-info-bar.vala                                 \
        gitg/gitg-resource.vala                                 \
        gitg/gitg-application.vala                              \
        gitg/gitg-plugins-engine.vala                           \
diff --git a/gitg/gitg-info-bar.vala b/gitg/gitg-info-bar.vala
new file mode 100644
index 0000000..e09d714
--- /dev/null
+++ b/gitg/gitg-info-bar.vala
@@ -0,0 +1,64 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * gitg 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-info-bar.ui")]
+class InfoBar : Gtk.InfoBar
+{
+       [GtkChild]
+       private Gtk.Label d_title_label;
+
+       [GtkChild]
+       private Gtk.Label d_message_label;
+
+       private string d_title;
+       private string d_message;
+
+       public string title
+       {
+               get { return d_title; }
+               set
+               {
+                       d_title = value;
+
+                       var escaped = Markup.escape_text(d_title);
+                       d_title_label.set_markup(@"<b>$escaped</b>");
+               }
+       }
+
+       public string message
+       {
+               get { return d_message; }
+               set
+               {
+                       d_message = value;
+
+                       var escaped = Markup.escape_text(d_message);
+
+                       d_message_label.set_markup(@"<small>$escaped</small>");
+               }
+       }
+
+}
+
+}
+
+// ex:ts=4 noet
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 6c568d8..9dea995 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -69,14 +69,6 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, GitgExt.Action
 
        [GtkChild]
        private Gtk.Revealer d_infobar_revealer;
-       [GtkChild]
-       private Gtk.InfoBar d_infobar;
-       [GtkChild]
-       private Gtk.Label d_infobar_primary_label;
-       [GtkChild]
-       private Gtk.Label d_infobar_secondary_label;
-       [GtkChild]
-       private Gtk.Button d_infobar_close_button;
 
        private static const ActionEntry[] win_entries = {
                {"search", on_search_activated, null, "false", null},
@@ -125,9 +117,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, GitgExt.Action
        }
 
        [GtkCallback]
-       private void dash_view_show_error(string primary_msg, string secondary_message)
+       private void dash_view_show_error(string title, string message)
        {
-               show_infobar(primary_msg, secondary_message, Gtk.MessageType.ERROR);
+               show_infobar(title, message, Gtk.MessageType.ERROR);
        }
 
        construct
@@ -184,6 +176,21 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, GitgExt.Action
                        d_header_bar.pack_end(d_search_button);
                        d_header_bar.pack_end(d_activities_switcher);
                }
+
+               d_infobar_revealer.notify["child-revealed"].connect(on_infobar_child_revealed);
+       }
+
+       private void on_infobar_child_revealed()
+       {
+               if (!d_infobar_revealer.child_revealed)
+               {
+                       var child = d_infobar_revealer.get_child();
+
+                       if (child != null)
+                       {
+                               child.destroy();
+                       }
+               }
        }
 
        private void on_close_activated()
@@ -549,8 +556,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, GitgExt.Action
                {
                        string repo_name = path.get_basename();
 
-                       var primary_msg = _("'%s' is not a Git repository.").printf(repo_name);
-                       show_infobar(primary_msg, e.message, Gtk.MessageType.WARNING);
+                       var title = _("'%s' is not a Git repository.").printf(repo_name);
+                       show_infobar(title, e.message, Gtk.MessageType.WARNING);
 
                        return;
                }
@@ -564,22 +571,61 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, GitgExt.Action
                this.repository = repository;
        }
 
-       public void show_infobar(string          primary_msg,
-                                string          secondary_msg,
+       public void show_infobar(string          title,
+                                string          message,
                                 Gtk.MessageType type)
        {
-               d_infobar.message_type = type;
+               var query = new GitgExt.UserQuery();
 
-               var primary = "<b>%s</b>".printf(Markup.escape_text(primary_msg));
-               var secondary = "<small>%s</small>".printf(Markup.escape_text(secondary_msg));
+               query.title = title;
+               query.message = message;
+               query.message_type = type;
+               query.default_response = Gtk.ResponseType.CLOSE;
 
-               d_infobar_primary_label.set_label(primary);
-               d_infobar_secondary_label.set_label(secondary);
-               d_infobar_revealer.set_reveal_child(true);
+               query.responses = new GitgExt.UserQueryResponse[] {
+                       new GitgExt.UserQueryResponse(_("Close"), Gtk.ResponseType.CLOSE)
+               };
+
+               user_query(query);
+       }
 
-               d_infobar_close_button.clicked.connect(() => {
+       public void user_query(GitgExt.UserQuery query)
+       {
+               var infobar = new InfoBar();
+
+               infobar.title = query.title;
+               infobar.message = query.message;
+               infobar.message_type = query.message_type;
+               infobar.show();
+
+               var child = d_infobar_revealer.get_child();
+
+               if (child != null)
+               {
+                       child.destroy();
+                       d_infobar_revealer.transition_type = Gtk.RevealerTransitionType.NONE;
+               }
+               else
+               {
+                       d_infobar_revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
+               }
+
+               foreach (var r in query.responses)
+               {
+                       infobar.add_button(r.text, r.response_type);
+               }
+
+               d_infobar_revealer.add(infobar);
+
+               infobar.set_default_response(query.default_response);
+
+               infobar.response.connect((i, response) => {
                        d_infobar_revealer.set_reveal_child(false);
+
+                       query.response((Gtk.ResponseType)response);
                });
+
+               d_infobar_revealer.set_reveal_child(true);
        }
 
        public Gee.Map<string, string> environment
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index f913934..eefd833 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/gitg">
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-window.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-info-bar.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-menus.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-history.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-commit.ui</file>
diff --git a/gitg/resources/ui/gitg-info-bar.ui b/gitg/resources/ui/gitg-info-bar.ui
new file mode 100644
index 0000000..32df547
--- /dev/null
+++ b/gitg/resources/ui/gitg-info-bar.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.3 -->
+  <!-- interface-requires gitg 0.0 -->
+  <template class="GitgInfoBar" parent="GtkInfoBar">
+    <child internal-child="content_area">
+      <object class="GtkBox" id="content_area">
+        <property name="visible">True</property>
+        <property name="border_width">8</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">16</property>
+        <child>
+          <object class="GtkLabel" id="d_title_label">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="selectable">True</property>
+            <property name="use-markup">True</property>
+            <property name="halign">GTK_ALIGN_START</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="d_message_label">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="selectable">True</property>
+            <property name="use-markup">True</property>
+            <property name="halign">GTK_ALIGN_START</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+<!-- vi:ts=2:et -->
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index f74658b..18f002d 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -96,64 +96,6 @@
         <child>
           <object class="GtkRevealer" id="d_infobar_revealer">
             <property name="visible">True</property>
-            <child>
-              <object class="GtkInfoBar" id="d_infobar">
-                <property name="visible">True</property>
-                <child internal-child="content_area">
-                  <object class="GtkBox" id="infobar_content_area">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="border_width">8</property>
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">16</property>
-                    <child>
-                      <object class="GtkLabel" id="d_infobar_primary_label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="selectable">True</property>
-                        <property name="use-markup">True</property>
-                        <property name="halign">GTK_ALIGN_START</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="d_infobar_secondary_label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="selectable">True</property>
-                        <property name="use-markup">True</property>
-                        <property name="halign">GTK_ALIGN_START</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child internal-child="action_area">
-                      <object class="GtkButtonBox" id="infobar_action_area">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="border_width">5</property>
-                        <property name="orientation">vertical</property>
-                        <property name="spacing">6</property>
-                        <property name="layout_style">end</property>
-                        <child>
-                          <object class="GtkButton" id="d_infobar_close_button">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">Close</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
           </object>
         </child>
         <child>


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