[gnome-latex] Use tepl_utils_replace_home_dir_with_tilde()



commit 34c67a5c430c44679f01946d7682ad88ae835f11
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Nov 18 13:58:10 2019 +0100

    Use tepl_utils_replace_home_dir_with_tilde()

 docs/reference/gnome-latex-sections.txt |  1 -
 src/document.vala                       |  2 +-
 src/liblatexila/latexila-build-view.c   |  3 +-
 src/liblatexila/latexila-utils.c        | 54 ---------------------------------
 src/liblatexila/latexila-utils.h        |  2 --
 src/project_dialogs.vala                |  6 ++--
 src/utils.vala                          |  2 +-
 tests/test-utils.c                      | 23 --------------
 8 files changed, 7 insertions(+), 86 deletions(-)
---
diff --git a/docs/reference/gnome-latex-sections.txt b/docs/reference/gnome-latex-sections.txt
index bb76537..61aa423 100644
--- a/docs/reference/gnome-latex-sections.txt
+++ b/docs/reference/gnome-latex-sections.txt
@@ -267,7 +267,6 @@ LATEXILA_TYPE_TEMPLATES_PERSONAL
 
 <SECTION>
 <FILE>utils</FILE>
-latexila_utils_replace_home_dir_with_tilde
 latexila_utils_file_query_exists_async
 latexila_utils_file_query_exists_finish
 latexila_utils_create_parent_directories
diff --git a/src/document.vala b/src/document.vala
index c4ef85f..a678b28 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -305,7 +305,7 @@ public class Document : Tepl.Buffer
         if (location == null)
             return get_file ().get_short_name ();
 
-        return Latexila.utils_replace_home_dir_with_tilde (location.get_parse_name ());
+        return Tepl.utils_replace_home_dir_with_tilde (location.get_parse_name ());
     }
 
     public string get_short_name_for_display ()
diff --git a/src/liblatexila/latexila-build-view.c b/src/liblatexila/latexila-build-view.c
index 4e10b45..2e4f963 100644
--- a/src/liblatexila/latexila-build-view.c
+++ b/src/liblatexila/latexila-build-view.c
@@ -28,6 +28,7 @@
 
 #include "latexila-build-view.h"
 #include <string.h>
+#include <tepl/tepl.h>
 #include "latexila-utils.h"
 #include "latexila-enum-types.h"
 
@@ -750,7 +751,7 @@ latexila_build_view_append_single_message (LatexilaBuildView *build_view,
 
                file = g_file_new_for_path (message->filename);
 
-               filename_with_tilde = latexila_utils_replace_home_dir_with_tilde (message->filename);
+               filename_with_tilde = tepl_utils_replace_home_dir_with_tilde (message->filename);
                path = g_markup_escape_text (filename_with_tilde, -1);
                g_free (filename_with_tilde);
 
diff --git a/src/liblatexila/latexila-utils.c b/src/liblatexila/latexila-utils.c
index abb51a2..1b7195f 100644
--- a/src/liblatexila/latexila-utils.c
+++ b/src/liblatexila/latexila-utils.c
@@ -40,60 +40,6 @@
 #include "dh-dconf-migration.h"
 #endif
 
-/**
- * latexila_utils_replace_home_dir_with_tilde:
- * @filename: the filename.
- *
- * Replaces the home directory with a tilde, if the home directory is present in
- * the @filename.
- *
- * This function comes from gedit.
- *
- * Returns: the new filename. Free with g_free().
- */
-gchar *
-latexila_utils_replace_home_dir_with_tilde (const gchar *filename)
-{
-       gchar *tmp;
-       gchar *home;
-
-       g_return_val_if_fail (filename != NULL, NULL);
-
-       /* Note that g_get_home_dir returns a const string */
-       tmp = (gchar *) g_get_home_dir ();
-
-       if (tmp == NULL)
-       {
-               return g_strdup (filename);
-       }
-
-       home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
-       if (home == NULL)
-       {
-               return g_strdup (filename);
-       }
-
-       if (strcmp (filename, home) == 0)
-       {
-               g_free (home);
-               return g_strdup ("~");
-       }
-
-       tmp = home;
-       home = g_strdup_printf ("%s/", tmp);
-       g_free (tmp);
-
-       if (g_str_has_prefix (filename, home))
-       {
-               gchar *res = g_strdup_printf ("~/%s", filename + strlen (home));
-               g_free (home);
-               return res;
-       }
-
-       g_free (home);
-       return g_strdup (filename);
-}
-
 /**
  * latexila_utils_register_icons:
  *
diff --git a/src/liblatexila/latexila-utils.h b/src/liblatexila/latexila-utils.h
index ab70fac..8f7e37f 100644
--- a/src/liblatexila/latexila-utils.h
+++ b/src/liblatexila/latexila-utils.h
@@ -26,8 +26,6 @@ G_BEGIN_DECLS
 
 /* File utilities */
 
-gchar *                latexila_utils_replace_home_dir_with_tilde      (const gchar *filename);
-
 void           latexila_utils_file_query_exists_async          (GFile               *file,
                                                                 GCancellable        *cancellable,
                                                                 GAsyncReadyCallback  callback,
diff --git a/src/project_dialogs.vala b/src/project_dialogs.vala
index 0ca669f..c407d44 100644
--- a/src/project_dialogs.vala
+++ b/src/project_dialogs.vala
@@ -100,7 +100,7 @@ namespace ProjectDialogs
                 MessageType.ERROR,
                 ButtonsType.OK,
                 _("There is a conflict with the project “%s”."),
-                Latexila.utils_replace_home_dir_with_tilde (conflict.get_parse_name ()) + "/");
+                Tepl.utils_replace_home_dir_with_tilde (conflict.get_parse_name ()) + "/");
             error_dialog.run ();
             error_dialog.destroy ();
         }
@@ -129,7 +129,7 @@ namespace ProjectDialogs
 
         // directory
         string project_dir = project.directory.get_parse_name ();
-        project_dir = Latexila.utils_replace_home_dir_with_tilde (project_dir) + "/";
+        project_dir = Tepl.utils_replace_home_dir_with_tilde (project_dir) + "/";
         Label location = new Label (project_dir);
         location.set_line_wrap (true);
         location.set_halign (Align.START);
@@ -334,7 +334,7 @@ namespace ProjectDialogs
             string uri_directory = project.directory.get_parse_name ();
             string uri_main_file = project.main_file.get_parse_name ();
 
-            string dir = Latexila.utils_replace_home_dir_with_tilde (uri_directory) + "/";
+            string dir = Tepl.utils_replace_home_dir_with_tilde (uri_directory) + "/";
 
             // relative path
             string main_file =
diff --git a/src/utils.vala b/src/utils.vala
index 67a842b..970b85a 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -77,7 +77,7 @@ namespace Utils
         string dir = Path.get_dirname (uri);
         if (dir == ".")
             return null;
-        return Latexila.utils_replace_home_dir_with_tilde (dir);
+        return Tepl.utils_replace_home_dir_with_tilde (dir);
     }
 
     /* Returns a string suitable to be displayed in the UI indicating
diff --git a/tests/test-utils.c b/tests/test-utils.c
index f0386ca..9d75eb2 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -19,28 +19,6 @@
 
 #include "latexila.h"
 
-static void
-test_replace_home_dir_with_tilde (void)
-{
-       const gchar *homedir = g_get_home_dir ();
-       gchar *before;
-       gchar *after;
-
-       before = g_build_filename (homedir, "blah", NULL);
-       after = latexila_utils_replace_home_dir_with_tilde (before);
-       g_assert_cmpstr (after, ==, "~/blah");
-       g_free (before);
-       g_free (after);
-
-       after = latexila_utils_replace_home_dir_with_tilde (homedir);
-       g_assert_cmpstr (after, ==, "~");
-       g_free (after);
-
-       after = latexila_utils_replace_home_dir_with_tilde ("/blah");
-       g_assert_cmpstr (after, ==, "/blah");
-       g_free (after);
-}
-
 static void
 test_str_replace (void)
 {
@@ -69,7 +47,6 @@ main (gint    argc,
 {
        g_test_init (&argc, &argv, NULL);
 
-       g_test_add_func ("/utils/replace-home-dir-with-tilde", test_replace_home_dir_with_tilde);
        g_test_add_func ("/utils/str-replace", test_str_replace);
 
        return g_test_run ();


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