Add utils_string_replace_first() to the plugin API.

Allow entering paths prefixed with '~' in the filebrowser path entry.
Show the full path for files and folders in the filebrowser plugin as tooltips.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3529 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2009-01-30 16:12:25 +00:00
parent 2758ac24b7
commit 56a1470bb9
6 changed files with 54 additions and 23 deletions

View File

@ -1,3 +1,13 @@
2009-01-30 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/plugins.c, src/plugindata.h, src/utils.c, plugins/filebrowser.c,
plugins/geanyfunctions.h:
Add utils_string_replace_first() to the plugin API.
Allow entering paths prefixed with '~' in the filebrowser path entry.
Show the full path for files and folders in the filebrowser plugin
as tooltips.
2009-01-29 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2009-01-29 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* autogen.sh: * autogen.sh:

View File

@ -45,7 +45,7 @@ GeanyData *geany_data;
GeanyFunctions *geany_functions; GeanyFunctions *geany_functions;
PLUGIN_VERSION_CHECK(69) PLUGIN_VERSION_CHECK(131)
PLUGIN_SET_INFO(_("File Browser"), _("Adds a file browser tab to the sidebar."), VERSION, PLUGIN_SET_INFO(_("File Browser"), _("Adds a file browser tab to the sidebar."), VERSION,
_("The Geany developer team")) _("The Geany developer team"))
@ -66,6 +66,7 @@ enum
{ {
FILEVIEW_COLUMN_ICON = 0, FILEVIEW_COLUMN_ICON = 0,
FILEVIEW_COLUMN_NAME, FILEVIEW_COLUMN_NAME,
FILEVIEW_COLUMN_FILENAME, /* the full filename, including path for display as tooltip */
FILEVIEW_N_COLUMNS FILEVIEW_N_COLUMNS
}; };
@ -146,7 +147,7 @@ static gboolean check_filtered(const gchar *base_name)
static void add_item(const gchar *name) static void add_item(const gchar *name)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gchar *fname, *utf8_name; gchar *fname, *utf8_name, *utf8_fullname, *sep;
gboolean dir; gboolean dir;
if (! show_hidden_files && check_hidden(name)) if (! show_hidden_files && check_hidden(name))
@ -155,8 +156,10 @@ static void add_item(const gchar *name)
if (check_filtered(name)) if (check_filtered(name))
return; return;
fname = g_strconcat(current_dir, G_DIR_SEPARATOR_S, name, NULL); sep = (utils_str_equal(current_dir, "/")) ? "" : G_DIR_SEPARATOR_S;
fname = g_strconcat(current_dir, sep, name, NULL);
dir = g_file_test(fname, G_FILE_TEST_IS_DIR); dir = g_file_test(fname, G_FILE_TEST_IS_DIR);
utf8_fullname = utils_get_locale_from_utf8(fname);
g_free(fname); g_free(fname);
if (dir) if (dir)
@ -177,8 +180,11 @@ static void add_item(const gchar *name)
gtk_list_store_set(file_store, &iter, gtk_list_store_set(file_store, &iter,
FILEVIEW_COLUMN_ICON, (dir) ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE, FILEVIEW_COLUMN_ICON, (dir) ? GTK_STOCK_DIRECTORY : GTK_STOCK_FILE,
FILEVIEW_COLUMN_NAME, utf8_name, -1); FILEVIEW_COLUMN_NAME, utf8_name,
FILEVIEW_COLUMN_FILENAME, utf8_fullname,
-1);
g_free(utf8_name); g_free(utf8_name);
g_free(utf8_fullname);
} }
@ -186,15 +192,23 @@ static void add_item(const gchar *name)
static void add_top_level_entry(void) static void add_top_level_entry(void)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gchar *utf8_dir;
if (! NZV(g_path_skip_root(current_dir))) if (! NZV(g_path_skip_root(current_dir)))
return; /* ignore 'C:\' or '/' */ return; /* ignore 'C:\' or '/' */
utf8_dir = g_path_get_dirname(current_dir);
setptr(utf8_dir, utils_get_utf8_from_locale(utf8_dir));
gtk_list_store_prepend(file_store, &iter); gtk_list_store_prepend(file_store, &iter);
last_dir_iter = gtk_tree_iter_copy(&iter); last_dir_iter = gtk_tree_iter_copy(&iter);
gtk_list_store_set(file_store, &iter, gtk_list_store_set(file_store, &iter,
FILEVIEW_COLUMN_ICON, GTK_STOCK_DIRECTORY, FILEVIEW_COLUMN_NAME, "..", -1); FILEVIEW_COLUMN_ICON, GTK_STOCK_DIRECTORY,
FILEVIEW_COLUMN_NAME, "..",
FILEVIEW_COLUMN_FILENAME, utf8_dir,
-1);
g_free(utf8_dir);
} }
@ -336,17 +350,9 @@ static gchar *get_tree_path_filename(GtkTreePath *treepath)
gchar *name, *fname; gchar *name, *fname;
gtk_tree_model_get_iter(model, &iter, treepath); gtk_tree_model_get_iter(model, &iter, treepath);
gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_NAME, &name, -1); gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_FILENAME, &name, -1);
if (utils_str_equal(name, "..")) fname = utils_get_locale_from_utf8(name);
{
fname = g_path_get_dirname(current_dir);
}
else
{
setptr(name, utils_get_locale_from_utf8(name));
fname = g_build_filename(current_dir, name, NULL);
}
g_free(name); g_free(name);
return fname; return fname;
@ -637,7 +643,14 @@ static void on_path_entry_activate(GtkEntry *entry, gpointer user_data)
on_go_up(); on_go_up();
return; return;
} }
new_dir = utils_get_locale_from_utf8(new_dir); else if (new_dir[0] == '~')
{
GString *str = g_string_new(new_dir);
utils_string_replace_first(str, "~", g_get_home_dir());
new_dir = g_string_free(str, FALSE);
}
else
new_dir = utils_get_locale_from_utf8(new_dir);
} }
else else
new_dir = g_strdup(g_get_home_dir()); new_dir = g_strdup(g_get_home_dir());
@ -668,7 +681,7 @@ static void prepare_file_view(void)
GtkTreeSelection *select; GtkTreeSelection *select;
PangoFontDescription *pfd; PangoFontDescription *pfd;
file_store = gtk_list_store_new(FILEVIEW_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); file_store = gtk_list_store_new(FILEVIEW_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(GTK_TREE_VIEW(file_view), GTK_TREE_MODEL(file_store)); gtk_tree_view_set_model(GTK_TREE_VIEW(file_view), GTK_TREE_MODEL(file_store));
g_object_unref(file_store); g_object_unref(file_store);
@ -690,6 +703,10 @@ static void prepare_file_view(void)
gtk_widget_modify_font(file_view, pfd); gtk_widget_modify_font(file_view, pfd);
pango_font_description_free(pfd); pango_font_description_free(pfd);
/* GTK 2.12 tooltips */
if (gtk_check_version(2, 12, 0) == NULL)
g_object_set(file_view, "has-tooltip", TRUE, "tooltip-column", FILEVIEW_COLUMN_FILENAME, NULL);
/* selection handling */ /* selection handling */
select = gtk_tree_view_get_selection(GTK_TREE_VIEW(file_view)); select = gtk_tree_view_get_selection(GTK_TREE_VIEW(file_view));
gtk_tree_selection_set_mode(select, GTK_SELECTION_MULTIPLE); gtk_tree_selection_set_mode(select, GTK_SELECTION_MULTIPLE);

View File

@ -166,6 +166,8 @@
geany_functions->p_utils->get_date_time geany_functions->p_utils->get_date_time
#define utils_open_browser \ #define utils_open_browser \
geany_functions->p_utils->open_browser geany_functions->p_utils->open_browser
#define utils_string_replace_first \
geany_functions->p_utils->string_replace_first
#define ui_dialog_vbox_new \ #define ui_dialog_vbox_new \
geany_functions->p_ui->dialog_vbox_new geany_functions->p_ui->dialog_vbox_new
#define ui_frame_new_with_alignment \ #define ui_frame_new_with_alignment \

View File

@ -45,7 +45,7 @@
enum { enum {
/** The Application Programming Interface (API) version, incremented /** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */ * whenever any plugin data types are modified or appended to. */
GEANY_API_VERSION = 130, GEANY_API_VERSION = 131,
/** The Application Binary Interface (ABI) version, incremented whenever /** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */ * existing fields in the plugin data types have to be changed or reordered. */
@ -354,6 +354,8 @@ typedef struct UtilsFuncs
gint (*str_casecmp) (const gchar *s1, const gchar *s2); gint (*str_casecmp) (const gchar *s1, const gchar *s2);
gchar* (*get_date_time) (const gchar *format, time_t *time_to_use); gchar* (*get_date_time) (const gchar *format, time_t *time_to_use);
void (*open_browser) (const gchar *uri); void (*open_browser) (const gchar *uri);
guint (*string_replace_first) (GString *haystack, const gchar *needle,
const gchar *replace);
} }
UtilsFuncs; UtilsFuncs;

View File

@ -214,7 +214,8 @@ static UtilsFuncs utils_funcs = {
&utils_spawn_async, &utils_spawn_async,
&utils_str_casecmp, &utils_str_casecmp,
&utils_get_date_time, &utils_get_date_time,
&utils_open_browser &utils_open_browser,
&utils_string_replace_first
}; };
static UIUtilsFuncs uiutils_funcs = { static UIUtilsFuncs uiutils_funcs = {

View File

@ -1333,10 +1333,9 @@ guint utils_string_replace_all(GString *haystack, const gchar *needle, const gch
} }
/* /**
* Replaces the first occurrence of @c needle in @c haystack with @c replace. * Convenience function to replace only the occurrence of @c needle in @c haystack with @c.
* As of Geany 0.16, @a replace can match @a needle, so the following will work: * For details, see utils_string_replace_all().
* @code utils_string_replace_all(text, "\n", "\r\n"); @endcode
* *
* @param haystack The input string to operate on. This string is modified in place. * @param haystack The input string to operate on. This string is modified in place.
* @param needle The string which should be replaced. * @param needle The string which should be replaced.