[gnome-builder] codeindex: use subtitles for search results



commit ea2847f58bba835bf2e86e7cfa02c57060177e02
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 5 12:27:00 2017 -0700

    codeindex: use subtitles for search results
    
    This allows us to give some more info about which file the symbol is found
    within. Also, use a translatable string for declaration.

 plugins/code-index/ide-code-index-index.c         |   25 ++++++++++++--------
 plugins/code-index/ide-code-index-search-result.c |    2 +
 plugins/code-index/ide-code-index-search-result.h |    1 +
 po/POTFILES.in                                    |    1 +
 4 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/plugins/code-index/ide-code-index-index.c b/plugins/code-index/ide-code-index-index.c
index 4a5c80c..1697af7 100644
--- a/plugins/code-index/ide-code-index-index.c
+++ b/plugins/code-index/ide-code-index-index.c
@@ -19,6 +19,7 @@
 #define G_LOG_DOMAIN "ide-code-index-index"
 
 #include <glib/gprintf.h>
+#include <glib/gi18n.h>
 
 #include "ide-code-index-search-result.h"
 #include "ide-code-index-index.h"
@@ -310,31 +311,27 @@ ide_code_index_index_new_search_result (IdeCodeIndexIndex *self,
   guint file_id;
   gchar num [20];
   const gchar *path;
-  g_autofree gchar *title = NULL;
   guint line;
   guint line_offset;
   guint kind;
   guint flags;
+  const gchar *shortname;
   IdeContext *context;
   g_autoptr(IdeFile) file = NULL;
   g_autoptr(IdeSourceLocation) location = NULL;
+  g_autoptr(GString) subtitle = NULL;
 
   g_assert (IDE_IS_CODE_INDEX_INDEX (self));
   g_assert (fuzzy_match != NULL);
 
+  context = ide_object_get_context (IDE_OBJECT (self));
+
   key = dzl_fuzzy_index_match_get_key (fuzzy_match->match);
   value = dzl_fuzzy_index_match_get_document (fuzzy_match->match);
 
   g_variant_get (value, "(uuuuu)", &file_id, &line, &line_offset, &flags, &kind);
 
-  if ((kind == IDE_SYMBOL_FUNCTION) && !(flags & IDE_SYMBOL_FLAGS_IS_DEFINITION))
-    title = g_strconcat (key, " - decl", NULL);
-  else
-    title = g_strdup (key);
-
-  context = ide_object_get_context (IDE_OBJECT (self));
-
-  g_snprintf (num, sizeof(num), "%u", file_id);
+  g_snprintf (num, sizeof num, "%u", file_id);
   path = dzl_fuzzy_index_get_metadata_string (fuzzy_match->index, num);
   file = ide_file_new_for_path (context, path);
   location = ide_source_location_new (file, line - 1, line_offset - 1, 0);
@@ -342,8 +339,16 @@ ide_code_index_index_new_search_result (IdeCodeIndexIndex *self,
   icon_name = ide_symbol_kind_get_icon_name (kind);
   score = dzl_fuzzy_index_match_get_score (fuzzy_match->match);
 
+  subtitle = g_string_new (NULL);
+  if (NULL != (shortname = strrchr (path, G_DIR_SEPARATOR)))
+    g_string_append (subtitle, shortname + 1);
+  if ((kind == IDE_SYMBOL_FUNCTION) && !(flags & IDE_SYMBOL_FLAGS_IS_DEFINITION))
+    /* translators: "Declaration" is the forward-declaration (usually a header file), not the implementation 
*/
+    g_string_append_printf (subtitle, " (%s)", _("Declaration"));
+
   return ide_code_index_search_result_new (context,
-                                           title + 2,
+                                           key + 2,
+                                           subtitle->str,
                                            icon_name,
                                            location,
                                            score);
diff --git a/plugins/code-index/ide-code-index-search-result.c 
b/plugins/code-index/ide-code-index-search-result.c
index 9d27b0c..50b6154 100644
--- a/plugins/code-index/ide-code-index-search-result.c
+++ b/plugins/code-index/ide-code-index-search-result.c
@@ -143,6 +143,7 @@ ide_code_index_search_result_init (IdeCodeIndexSearchResult *self)
 IdeCodeIndexSearchResult*
 ide_code_index_search_result_new (IdeContext        *context,
                                   const gchar       *title,
+                                  const gchar       *subtitle,
                                   const gchar       *icon_name,
                                   IdeSourceLocation *location,
                                   gfloat             score)
@@ -150,6 +151,7 @@ ide_code_index_search_result_new (IdeContext        *context,
   return g_object_new (IDE_TYPE_CODE_INDEX_SEARCH_RESULT,
                        "context", context,
                        "title", title,
+                       "subtitle", subtitle,
                        "icon-name", icon_name,
                        "location", location,
                        "score", score,
diff --git a/plugins/code-index/ide-code-index-search-result.h 
b/plugins/code-index/ide-code-index-search-result.h
index b4145b8..f82eb61 100644
--- a/plugins/code-index/ide-code-index-search-result.h
+++ b/plugins/code-index/ide-code-index-search-result.h
@@ -30,6 +30,7 @@ G_DECLARE_FINAL_TYPE (IdeCodeIndexSearchResult, ide_code_index_search_result,
 
 IdeCodeIndexSearchResult* ide_code_index_search_result_new (IdeContext        *context,
                                                             const gchar       *title,
+                                                            const gchar       *subtitle,
                                                             const gchar       *icon_name,
                                                             IdeSourceLocation *location,
                                                             gfloat             score);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5513433..29f7820 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -115,6 +115,7 @@ plugins/clang/ide-clang-preferences-addin.c
 plugins/clang/ide-clang-service.c
 plugins/clang/ide-clang-symbol-node.c
 plugins/clang/ide-clang-translation-unit.c
+plugins/code-index/ide-code-index-index.c
 plugins/code-index/ide-code-index-service.c
 plugins/color-picker/data/basic.gstyle.xml
 plugins/color-picker/gb-color-picker-editor-addin.c


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