[gitg] Add utility to strip home dir
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Add utility to strip home dir
- Date: Wed, 5 Aug 2015 20:09:58 +0000 (UTC)
commit da97b253672ae4e1380263215d03663a28dd8f23
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Wed Aug 5 22:09:06 2015 +0200
Add utility to strip home dir
gitg/Makefile.am | 1 +
gitg/gitg-dash-view.vala | 24 +-------------------
gitg/gitg-utils.vala | 55 ++++++++++++++++++++++++++++++++++++++++++++++
gitg/gitg-window.vala | 9 +------
4 files changed, 58 insertions(+), 31 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 348ae99..3d8026f 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -76,6 +76,7 @@ gitg_gitg_VALASOURCES = \
gitg/gitg-remote-manager.vala \
gitg/gitg-resource.vala \
gitg/gitg-ui-elements.vala \
+ gitg/gitg-utils.vala \
gitg/gitg-window.vala \
gitg/gitg.vala \
gitg/history/gitg-history-action-interface.vala \
diff --git a/gitg/gitg-dash-view.vala b/gitg/gitg-dash-view.vala
index 33386f0..9ac3073 100644
--- a/gitg/gitg-dash-view.vala
+++ b/gitg/gitg-dash-view.vala
@@ -355,29 +355,7 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
private void query_create_repository(File location)
{
var q = new GitgExt.UserQuery();
- var name = location.get_parse_name();
-
- var homedir = Environment.get_home_dir();
-
- if (homedir != null)
- {
- try
- {
- var hd = Filename.to_utf8(homedir, -1, null, null);
-
- if (hd == name)
- {
- name = "~/";
- }
- else
- {
- if (name.has_prefix(hd + "/"))
- {
- name = "~" + name[hd.length:name.length];
- }
- }
- } catch {}
- }
+ var name = Utils.replace_home_dir_with_tilde(location);
name = Markup.escape_text(name);
diff --git a/gitg/gitg-utils.vala b/gitg/gitg-utils.vala
new file mode 100644
index 0000000..b352557
--- /dev/null
+++ b/gitg/gitg-utils.vala
@@ -0,0 +1,55 @@
+/*
+ *
+ * Copyright (C) 2015 - 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
+{
+
+class Utils
+{
+ public static string replace_home_dir_with_tilde(File file)
+ {
+ var name = file.get_parse_name();
+ var homedir = Environment.get_home_dir();
+
+ if (homedir != null)
+ {
+ try
+ {
+ var hd = Filename.to_utf8(homedir, -1, null, null);
+
+ if (hd == name)
+ {
+ name = "~/";
+ }
+ else
+ {
+ if (name.has_prefix(hd + "/"))
+ {
+ name = "~" + name[hd.length:name.length];
+ }
+ }
+ } catch {}
+ }
+
+ return name;
+ }
+}
+
+}
+
+// ex:ts=4 noet
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 0209946..ed4dfb0 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -352,16 +352,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
if (workdir != null)
{
- string parent_path = workdir.get_parent().get_path();
- bool contains_home_dir = parent_path.has_prefix(Environment.get_home_dir());
-
- if (contains_home_dir)
- {
- parent_path = parent_path.replace(Environment.get_home_dir(), "~");
- }
+ var parent_path = Utils.replace_home_dir_with_tilde(workdir.get_parent());
name = @"$(d_repository.name) ($parent_path)";
-
title = @"$name - gitg";
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]