symbols: provide a bit more path information in the goto-symbol popup.
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.
This commit is contained in:
parent
4956b05d1e
commit
b116a66862
@ -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)
|
||||
@ -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);
|
||||
|
||||
|
@ -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
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user