[gnome-builder/wip/gtk4-port] libide/vcs: add display name for version control systems



commit 24f83d0391d53b6f5139371343bea118d1ef18ea
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 10 17:19:49 2022 -0700

    libide/vcs: add display name for version control systems

 src/libide/vcs/ide-vcs.c      | 24 +++++++++++++++++++++++-
 src/libide/vcs/ide-vcs.h      |  3 +++
 src/plugins/git/gbp-git-vcs.c |  7 +++++++
 3 files changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/vcs/ide-vcs.c b/src/libide/vcs/ide-vcs.c
index a457416b2..ed4bc7d6e 100644
--- a/src/libide/vcs/ide-vcs.c
+++ b/src/libide/vcs/ide-vcs.c
@@ -22,8 +22,10 @@
 
 #include "config.h"
 
-#include <libide-io.h>
 #include <string.h>
+#include <glib/gi18n.h>
+
+#include <libide-io.h>
 
 #include "ide-directory-vcs.h"
 #include "ide-vcs.h"
@@ -668,3 +670,23 @@ ide_vcs_push_branch_finish (IdeVcs        *self,
 
   return IDE_VCS_GET_IFACE (self)->push_branch_finish (self, result, error);
 }
+
+/**
+ * ide_vcs_get_display_name:
+ * @self: a #IdeVcs
+ *
+ * Gets the display name for the VCS.
+ *
+ * Returns: (transfer full): a string describing the VCS
+ */
+char *
+ide_vcs_get_display_name (IdeVcs *self)
+{
+  g_return_val_if_fail (IDE_IS_VCS (self), NULL);
+
+  if (IDE_VCS_GET_IFACE (self)->get_display_name == NULL)
+    /* translators: None means "no version control system" */
+    return g_strdup (_("None"));
+
+  return IDE_VCS_GET_IFACE (self)->get_display_name (self);
+}
diff --git a/src/libide/vcs/ide-vcs.h b/src/libide/vcs/ide-vcs.h
index 3b5410e72..412b82505 100644
--- a/src/libide/vcs/ide-vcs.h
+++ b/src/libide/vcs/ide-vcs.h
@@ -40,6 +40,7 @@ struct _IdeVcsInterface
 {
   GTypeInterface            parent_interface;
 
+  char                   *(*get_display_name)          (IdeVcs               *self);
   GFile                  *(*get_workdir)               (IdeVcs               *self);
   gboolean                (*is_ignored)                (IdeVcs               *self,
                                                         GFile                *file,
@@ -162,5 +163,7 @@ IDE_AVAILABLE_IN_3_34
 gboolean      ide_vcs_push_branch_finish   (IdeVcs               *self,
                                             GAsyncResult         *result,
                                             GError              **error);
+IDE_AVAILABLE_IN_ALL
+char         *ide_vcs_get_display_name     (IdeVcs               *self);
 
 G_END_DECLS
diff --git a/src/plugins/git/gbp-git-vcs.c b/src/plugins/git/gbp-git-vcs.c
index 36d89733d..2188efff7 100644
--- a/src/plugins/git/gbp-git-vcs.c
+++ b/src/plugins/git/gbp-git-vcs.c
@@ -530,9 +530,16 @@ gbp_git_vcs_list_status_finish (IdeVcs        *vcs,
   return ide_task_propagate_object (IDE_TASK (result), error);
 }
 
+static char *
+gbp_git_vcs_get_display_name (IdeVcs *vcs)
+{
+  return g_strdup (_("Git"));
+}
+
 static void
 vcs_iface_init (IdeVcsInterface *iface)
 {
+  iface->get_display_name = gbp_git_vcs_get_display_name;
   iface->get_workdir = gbp_git_vcs_get_workdir;
   iface->is_ignored = gbp_git_vcs_is_ignored;
   iface->get_config = gbp_git_vcs_get_config;


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