[gitg] Added user query API in GitgExt



commit ada8a407eb5d86d069e03f02c240a7fcb2d9898b
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Tue Jul 1 14:15:28 2014 +0200

    Added user query API in GitgExt

 gitg/gitg-window.vala                 |   42 +++++++++++++++++++++++++++
 libgitg-ext/Makefile.am               |    1 +
 libgitg-ext/gitg-ext-application.vala |    2 +
 libgitg-ext/gitg-ext-user-query.vala  |   50 +++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 513fb06..8ca3e07 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -29,6 +29,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private GitgExt.MessageBus d_message_bus;
        private string? d_action;
        private Gee.HashMap<string, string> d_environment;
+       private Gtk.Dialog? d_dialog;
 
        private UIElements<GitgExt.Activity> d_activities;
 
@@ -568,8 +569,49 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                d_infobar.message_type = type;
 
                d_infobar.show();
+       }
+
+       public void user_query(GitgExt.UserQuery query)
+       {
+               var dlg = new Gtk.MessageDialog(this,
+                                               Gtk.DialogFlags.MODAL,
+                                               query.message_type,
+                                               Gtk.ButtonsType.NONE,
+                                               "");
+
+               var primary = "<b>%s</b>".printf(Markup.escape_text(query.title));
+               dlg.set_markup(primary);
+
+               dlg.format_secondary_text("%s", query.message);
+
+               foreach (var response in query.responses)
+               {
+                       dlg.add_button(response.text, response.response_type);
+               }
+
+               dlg.set_default_response(query.default_response);
 
+               d_dialog = dlg;
+               dlg.add_weak_pointer(&d_dialog);
+
+               ulong qid = 0;
+
+               qid = query.quit.connect(() => {
+                       dlg.destroy();
+                       query.disconnect(qid);
                });
+
+               dlg.response.connect((w, r) => {
+                       dlg.sensitive = false;
+
+                       if (query.response((Gtk.ResponseType)r))
+                       {
+                               dlg.destroy();
+                               query.disconnect(qid);
+                       }
+               });
+
+               dlg.show();
        }
 
        public Gee.Map<string, string> environment
diff --git a/libgitg-ext/Makefile.am b/libgitg-ext/Makefile.am
index 7551259..4411446 100644
--- a/libgitg-ext/Makefile.am
+++ b/libgitg-ext/Makefile.am
@@ -52,6 +52,7 @@ libgitg_ext_libgitg_ext_1_0_la_VALASOURCES =          \
        libgitg-ext/gitg-ext-history.vala               \
        libgitg-ext/gitg-ext-history-panel.vala         \
        libgitg-ext/gitg-ext-command-line.vala          \
+       libgitg-ext/gitg-ext-user-query.vala            \
        libgitg-ext/gitg-ext-preferences.vala           \
        libgitg-ext/gitg-ext-ui.vala                    \
        libgitg/libgitg-1.0.vapi
diff --git a/libgitg-ext/gitg-ext-application.vala b/libgitg-ext/gitg-ext-application.vala
index cffeb12..4cf9c6a 100644
--- a/libgitg-ext/gitg-ext-application.vala
+++ b/libgitg-ext/gitg-ext-application.vala
@@ -55,6 +55,8 @@ public interface Application : Object
         */
        public abstract GitgExt.Activity? activity(string id);
 
+       public abstract void user_query(UserQuery query);
+
        public abstract void show_infobar(string          primary_msg,
                                          string          secondary_msg,
                                          Gtk.MessageType type);
diff --git a/libgitg-ext/gitg-ext-user-query.vala b/libgitg-ext/gitg-ext-user-query.vala
new file mode 100644
index 0000000..a13d990
--- /dev/null
+++ b/libgitg-ext/gitg-ext-user-query.vala
@@ -0,0 +1,50 @@
+/*
+ * 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 GitgExt
+{
+
+public class UserQueryResponse : Object
+{
+       public string text;
+       public Gtk.ResponseType response_type;
+
+       public UserQueryResponse(string text, Gtk.ResponseType response_type)
+       {
+               this.text = text;
+               this.response_type = response_type;
+       }
+}
+
+public class UserQuery : Object
+{
+       public string title { get; set; }
+       public string message { get; set; }
+       public Gtk.MessageType message_type { get; set; }
+       public Gtk.ResponseType default_response { get; set; default = Gtk.ResponseType.CLOSE; }
+       public UserQueryResponse[] responses { get; set; }
+
+       public signal void quit();
+       public signal bool response(Gtk.ResponseType response_type);
+}
+
+}
+
+// ex:set ts=4 noet:
+


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