[gitg] Add User information config menu in dash and views.
- From: Sindhu S <sindhus src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Add User information config menu in dash and views.
- Date: Tue, 14 May 2013 13:39:33 +0000 (UTC)
commit 963b4d8699dd953fe1677f87f20831875de571ee
Author: Sindhu S <sindhus live in>
Date: Sat Apr 13 14:56:38 2013 -0400
Add User information config menu in dash and views.
Add error handling message dialogs.
gitg/gitg-window.vala | 152 ++++++++++++++++++++++++++++-
gitg/resources/gitg-resources.xml | 1 +
gitg/resources/ui/gitg-menus.ui | 24 +++++
gitg/resources/ui/gitg-user-dialog.ui | 176 +++++++++++++++++++++++++++++++++
4 files changed, 352 insertions(+), 1 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 12e526a..9a5524e 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -63,6 +63,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
{"open-repository", on_open_repository},
{"clone-repository", on_clone_repository},
{"close", on_close_activated},
+ {"user-information-global", on_global_user_info_activated},
+ {"user-information-repo", on_repo_user_info_activated},
};
construct
@@ -261,6 +263,154 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
dlg.show();
}
+ private void show_user_information_dialog(Ggit.Config config, string? repository_name)
+ {
+ var ret = GitgExt.UI.from_builder("ui/gitg-user-dialog.ui",
+ "dialog",
+ "input-name",
+ "input-email",
+ "label-view",
+ "label-dash");
+
+ var user_information_dialog = ret["dialog"] as Gtk.Dialog;
+ var input_name = ret["input-name"] as Gtk.Entry;
+ var input_email = ret["input-email"] as Gtk.Entry;
+ var label_view = ret["label-view"] as Gtk.Label;
+ var label_dash = ret["label-dash"] as Gtk.Label;
+
+ if (repository_name == null)
+ {
+ label_view.hide();
+ label_dash.show();
+
+ if (Ggit.Config.find_global().get_path() == null)
+ {
+ show_config_error(user_information_dialog, "Unable to open the .gitconfig
file", "");
+ return;
+ }
+ }
+ else
+ {
+ label_view.label = label_view.label.printf(repository_name);
+ label_view.show();
+ label_dash.hide();
+ }
+
+ string user_name = "";
+ string user_email = "";
+
+ try
+ {
+ user_name = config.get_string("user.name");
+ }
+ catch {}
+
+ try
+ {
+ user_email = config.get_string("user.email");
+ }
+ catch {}
+
+ if (user_name != "")
+ {
+ input_name.set_text(user_name);
+ }
+ if (user_email != "")
+ {
+ input_email.set_text(user_email);
+ }
+
+ user_information_dialog.set_transient_for(this);
+
+ user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, false);
+
+ input_name.changed.connect((e) => {
+ user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, true);
+ });
+
+ input_email.changed.connect((e) => {
+ user_information_dialog.set_response_sensitive(Gtk.ResponseType.OK, true);
+ });
+
+ user_information_dialog.response.connect((d, id) => {
+ if (id == Gtk.ResponseType.OK)
+ {
+ try
+ {
+ if (input_name.get_text() == "")
+ {
+ config.delete_entry("user.name");
+ }
+ else
+ {
+ config.set_string("user.name", input_name.get_text());
+ }
+
+ if (input_email.get_text() == "")
+ {
+ config.delete_entry("user.email");
+ }
+ else
+ {
+ config.set_string("user.email", input_email.get_text());
+ }
+ }
+ catch (Error e)
+ {
+ show_config_error(user_information_dialog, "Failed to set Git user
config.", e.message);
+ d.destroy();
+ return;
+ }
+ }
+ d.destroy();
+ });
+ user_information_dialog.show();
+ }
+
+ private void on_global_user_info_activated()
+ {
+ Ggit.Config global_config = null;
+ try
+ {
+ global_config = new Ggit.Config.default();
+ }
+ catch (Error e)
+ {
+ return;
+ }
+
+ show_user_information_dialog(global_config, null);
+ }
+
+ private void on_repo_user_info_activated()
+ {
+ Ggit.Config repo_config = null;
+ try
+ {
+ repo_config = d_repository.get_config();
+ }
+ catch (Error e)
+ {
+ return;
+ }
+ show_user_information_dialog(repo_config, d_repository.name);
+ }
+
+ private void show_config_error(Gtk.Window parent, string primary_message, string secondary_message)
+ {
+ var error_dialog = new Gtk.MessageDialog(parent,
+ Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.OK,
+ primary_message);
+
+ error_dialog.secondary_text = secondary_message;
+ error_dialog.show();
+ error_dialog.response.connect((d, id) => {
+ error_dialog.destroy();
+ });
+ }
+
private void parser_finished(Gtk.Builder builder)
{
// Extract widgets from the builder
@@ -531,4 +681,4 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
}
-// ex:ts=4 noet
+// ex:ts=4 noet
\ No newline at end of file
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index c4a0fad..d9b745e 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -6,6 +6,7 @@
<file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences-interface.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/gitg-preferences.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/gitg-clone-dialog.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">ui/gitg-user-dialog.ui</file>
<file compressed="true">ui/style.css</file>
<file alias="icons/gitg.svg" compressed="true"
preprocess="xml-stripblanks">../../data/icons/gitg.svg</file>
<file alias="icons/gitg128x128.png">../../data/icons/gitg128x128.png</file>
diff --git a/gitg/resources/ui/gitg-menus.ui b/gitg/resources/ui/gitg-menus.ui
index b2c5f46..f17c59a 100644
--- a/gitg/resources/ui/gitg-menus.ui
+++ b/gitg/resources/ui/gitg-menus.ui
@@ -48,6 +48,12 @@
</section>
<section>
<item>
+ <attribute name="label" translatable="yes">User Information</attribute>
+ <attribute name="action">win.user-information-global</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_Close</attribute>
<attribute name="action">win.close</attribute>
<attribute name="accel"><Primary>w</attribute>
@@ -57,6 +63,12 @@
<menu id="win-menu-views">
<section>
<item>
+ <attribute name="label" translatable="yes">User Information</attribute>
+ <attribute name="action">win.user-information-repo</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_Close</attribute>
<attribute name="action">win.close</attribute>
<attribute name="accel"><Primary>w</attribute>
@@ -84,6 +96,12 @@
</section>
<section>
<item>
+ <attribute name="label" translatable="yes">User Information</attribute>
+ <attribute name="action">win.user-information-global</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
</item>
@@ -122,6 +140,12 @@
</section>
<section>
<item>
+ <attribute name="label" translatable="yes">User Information</attribute>
+ <attribute name="action">win.user-information-repo</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>
</item>
diff --git a/gitg/resources/ui/gitg-user-dialog.ui b/gitg/resources/ui/gitg-user-dialog.ui
new file mode 100644
index 0000000..f7439b7
--- /dev/null
+++ b/gitg/resources/ui/gitg-user-dialog.ui
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.3 -->
+ <!-- interface-requires gitg 0.0 -->
+ <!-- interface-requires gd 1.0 -->
+ <object class="GtkDialog" id="dialog">
+ <property name="width_request">390</property>
+ <property name="height_request">185</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="type_hint">dialog</property>
+ <property name="gravity">north</property>
+ <property name="has_resize_grip">False</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="user-details-box">
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="label-file-not-found">
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Note: The git config file '%s' does not
exist.</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="padding">4</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label-dash">
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Enter details to set as default for all
repositories:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label-view">
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Enter details for %s repository:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="user-details-grid">
+ <property name="width_request">0</property>
+ <property name="height_request">0</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_right">5</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkEntry" id="input-name">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="max_length">18</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="input-email">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label-email">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">E-mail : </property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label-name">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Name : </property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="user-action-area">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="cancel-button">
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="save-button">
+ <property name="label" translatable="yes">Save</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">cancel-button</action-widget>
+ <action-widget response="-5">save-button</action-widget>
+ </action-widgets>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]