[gitg] Convert clone dialog into a template
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Convert clone dialog into a template
- Date: Tue, 9 Jul 2013 16:25:12 +0000 (UTC)
commit 81be73e835fe1e5d0e3967232355c2376cc431a0
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jul 9 18:24:39 2013 +0200
Convert clone dialog into a template
gitg/Makefile.am | 1 +
gitg/gitg-clone-dialog.vala | 101 ++++++++++++++++++++++++++++++++
gitg/gitg-window.vala | 48 +--------------
gitg/resources/ui/gitg-clone-dialog.ui | 14 ++--
4 files changed, 111 insertions(+), 53 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index ad8aef9..74a174c 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -39,6 +39,7 @@ VALASOURCES = \
gitg.vala \
gitg-dirs.vala \
gitg-window.vala \
+ gitg-clone-dialog.vala \
gitg-resource.vala \
gitg-application.vala \
gitg-plugins-engine.vala \
diff --git a/gitg/gitg-clone-dialog.vala b/gitg/gitg-clone-dialog.vala
new file mode 100644
index 0000000..b246a7c
--- /dev/null
+++ b/gitg/gitg-clone-dialog.vala
@@ -0,0 +1,101 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * 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-clone-dialog.ui")]
+public class CloneDialog : Gtk.Dialog
+{
+ // Do this to pull in config.h before glib.h (for gettext...)
+ private const string version = Gitg.Config.VERSION;
+
+ [GtkChild (name = "entry_url")]
+ private Gtk.Entry d_entry_url;
+
+ [GtkChild (name = "button_location")]
+ private Gtk.FileChooserButton d_button_location;
+
+ [GtkChild (name = "bare_repository")]
+ private Gtk.CheckButton d_bare_repository;
+
+ public bool is_bare
+ {
+ get { return d_bare_repository.active; }
+ }
+
+ public File location
+ {
+ get { return d_button_location.get_file(); }
+ }
+
+ public string url
+ {
+ get { return d_entry_url.get_text(); }
+ }
+
+ public CloneDialog(Gtk.Window? parent)
+ {
+ Object();
+
+ if (parent != null)
+ {
+ set_transient_for(parent);
+ }
+ }
+
+ construct
+ {
+ var main_settings = new Settings("org.gnome.gitg.preferences.main");
+
+ set_default_response(Gtk.ResponseType.OK);
+
+ var default_dir = main_settings.get_string("clone-directory");
+ if (default_dir == "")
+ {
+ default_dir = Environment.get_home_dir();
+ }
+
+ d_button_location.set_current_folder(default_dir);
+ d_button_location.selection_changed.connect((c) => {
+ main_settings.set_string("clone-directory", c.get_file().get_path());
+ });
+
+ d_entry_url.changed.connect((e) => {
+ string ?tooltip_text = null;
+ string ?icon_name = null;
+ bool url_supported = Ggit.Remote.is_supported_url(d_entry_url.get_text());
+
+ if (!url_supported && (d_entry_url.text != ""))
+ {
+ icon_name = "dialog-warning-symbolic";
+ tooltip_text = _("The URL introduced is not supported");
+ }
+
+ d_entry_url.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, icon_name);
+ d_entry_url.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, tooltip_text);
+
+ set_response_sensitive(Gtk.ResponseType.OK, url_supported);
+ });
+ }
+}
+
+}
+
+// ex:ts=4 noet
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index f9d3d97..6049c94 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -24,7 +24,6 @@ namespace Gitg
public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
{
private Settings d_state_settings;
- private Settings d_main_settings;
private Settings d_interface_settings;
private Repository? d_repository;
private GitgExt.MessageBus d_message_bus;
@@ -133,7 +132,6 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
{
add_action_entries(win_entries, this);
- d_main_settings = new Settings("org.gnome.gitg.preferences.main");
d_interface_settings = new Settings("org.gnome.gitg.preferences.interface");
string menuname;
@@ -321,54 +319,12 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
private void on_clone_repository()
{
- var ret = GitgExt.UI.from_builder("ui/gitg-clone-dialog.ui",
- "dialog-clone",
- "entry-url",
- "filechooserbutton-location",
- "checkbutton-bare-repository");
-
- var dlg = ret["dialog-clone"] as Gtk.Dialog;
- var entry_url = ret["entry-url"] as Gtk.Entry;
- var chooser = ret["filechooserbutton-location"] as Gtk.FileChooserButton;
- var bare = ret["checkbutton-bare-repository"] as Gtk.CheckButton;
-
- dlg.set_transient_for(this);
- dlg.set_default_response(Gtk.ResponseType.OK);
-
- var default_dir = d_main_settings.get_string("clone-directory");
-
- if (default_dir == "")
- {
- default_dir = Environment.get_home_dir();
- }
-
- chooser.set_current_folder(default_dir);
-
- chooser.selection_changed.connect((c) => {
- d_main_settings.set_string("clone-directory", c.get_file().get_path());
- });
-
- entry_url.changed.connect((e) => {
- string ?tooltip_text = null;
- string ?icon_name = null;
- bool url_supported = Ggit.Remote.is_supported_url(entry_url.get_text());
-
- if (!url_supported && (entry_url.get_text_length() > 0))
- {
- icon_name = "dialog-warning-symbolic";
- tooltip_text = _("The URL introduced is not supported");
- }
-
- entry_url.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, icon_name);
- entry_url.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, tooltip_text);
-
- dlg.set_response_sensitive(Gtk.ResponseType.OK, url_supported);
- });
+ var dlg = new CloneDialog(this);
dlg.response.connect((d, id) => {
if (id == Gtk.ResponseType.OK)
{
- d_dash_view.clone_repository(entry_url.get_text(), chooser.get_file(),
bare.get_active());
+ d_dash_view.clone_repository(dlg.url, dlg.location, dlg.is_bare);
}
d.destroy();
diff --git a/gitg/resources/ui/gitg-clone-dialog.ui b/gitg/resources/ui/gitg-clone-dialog.ui
index 71658d6..1a126c6 100644
--- a/gitg/resources/ui/gitg-clone-dialog.ui
+++ b/gitg/resources/ui/gitg-clone-dialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkDialog" id="dialog-clone">
+ <template class="GitgCloneDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Clone Repository</property>
@@ -69,7 +69,7 @@
<property name="xalign">1</property>
<property name="label" translatable="yes">Remote _URL:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">entry-url</property>
+ <property name="mnemonic_widget">entry_url</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -79,7 +79,7 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="entry-url">
+ <object class="GtkEntry" id="entry_url">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -100,7 +100,7 @@
<property name="xalign">1</property>
<property name="label" translatable="yes">_Local Folder:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">filechooserbutton-location</property>
+ <property name="mnemonic_widget">button_location</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -110,7 +110,7 @@
</packing>
</child>
<child>
- <object class="GtkFileChooserButton" id="filechooserbutton-location">
+ <object class="GtkFileChooserButton" id="button_location">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
@@ -125,7 +125,7 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="checkbutton-bare-repository">
+ <object class="GtkCheckButton" id="bare_repository">
<property name="label" translatable="yes">Bare repository</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -153,5 +153,5 @@
<action-widget response="-6">cancel-button</action-widget>
<action-widget response="-5">ok-button</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]