Skip to content

Commit

Permalink
symbols: provide a bit more path information in the goto-symbol popup.
Browse files Browse the repository at this point in the history
From #1069:
> At the moment if symbols of the same name are defined in identically named
> files, it's hard to distinguish which file is which because there's no path
> in the popup.

> The popup should show part of the path until a directory where the paths
> differ so it's possible to distinguish the different files. At the same time
> there should probably be some top limit for the length of the paths as they
> can make the popup too wide.

This addresses the above by showing more of the file's paths but still try
to make it as short as possible. The file list is processed by the new
utils_strv_shorten_file_list(), as a result the popup will list files with
the common prefix stripped and the longest common sub-path ellipsized.

As a result, the file list shows enough of the path to make them unique but
still is still very short and doesn't make the dialog too wide.

Fixes #1069.
  • Loading branch information
kugel- committed Dec 3, 2018
1 parent 4956b05 commit b116a66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/symbols.c
Expand Up @@ -1933,15 +1933,23 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b
GdkEventButton *button_event = NULL;
TMTag *tmtag;
guint i;

gchar **short_names, **file_names, **p;
menu = gtk_menu_new();

/* If popup would show multiple files presend a smart file list that allows
* to easily distinguish the files while avoiding the file paths in their entirety */
file_names = g_new(gchar *, tags->len);
foreach_ptr_array(tmtag, i, tags)
file_names[i] = tmtag->file->file_name;
short_names = utils_strv_shorten_file_list(file_names, tags->len);
g_free(file_names);

foreach_ptr_array(tmtag, i, tags)
{
GtkWidget *item;
GtkWidget *label;
GtkWidget *image;
gchar *fname = g_path_get_basename(tmtag->file->file_name);
gchar *fname = short_names[i];
gchar *text;

if (! first && have_best)
Expand All @@ -1964,6 +1972,7 @@ static void show_goto_popup(GeanyDocument *doc, GPtrArray *tags, gboolean have_b
g_free(text);
g_free(fname);
}
g_free(short_names);

gtk_widget_show_all(menu);

Expand Down
9 changes: 3 additions & 6 deletions src/utils.c
Expand Up @@ -2146,7 +2146,7 @@ gchar *utils_strv_find_lcs(gchar **strv, size_t num)
}


/** Transform file names in a list to be shorter.
/* * Transform file names in a list to be shorter.
*
* This function takes a list of file names (porbably with absolute paths), and
* transforms the paths such that they are short but still unique. This is intended
Expand All @@ -2156,13 +2156,10 @@ gchar *utils_strv_find_lcs(gchar **strv, size_t num)
* The algorthm strips the common prefix (e-g. the user's home directory) and
* replaces the longest common substring with "...".
*
* @param file_names @arraylen{num} The list of strings to process.
* @param file_names The list of strings to process.
* @param num The number of strings contained in @a strv. Can be 0 if @a strv is a @c GStrv
* @return @transfer{full} A newly-allocated NULL-terminated array of transformed paths strings. Use @c g_strfreev() to free it.
*
* @since 1.31 (API 232
* @return A newly-allocated NULL-terminated array of transformed paths strings. Use @c g_strfreev() to free it.
*/
GEANY_API_SYMBOL
gchar **utils_strv_shorten_file_list(gchar **file_names, size_t num)
{
gint i, j;
Expand Down

0 comments on commit b116a66

Please sign in to comment.