Move recent file item to the top when it is clicked on
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@680 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
92a3f0a4b8
commit
795fc85083
@ -2,6 +2,8 @@
|
||||
|
||||
* src/callbacks.c: Allow Find even when the replace text is the same.
|
||||
Place the cursor in "" for insert blank include.
|
||||
* src/utils.c, src/utils.h, src/callbacks.c, src/document.c:
|
||||
Move recent file item to the top when it is clicked on.
|
||||
|
||||
|
||||
2006-08-06 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||
|
@ -930,15 +930,7 @@ on_file_save_dialog_response (GtkDialog *dialog,
|
||||
utils_build_show_hide(idx);
|
||||
|
||||
// finally add current file to recent files menu
|
||||
if (g_queue_find_custom(app->recent_queue, doc_list[idx].file_name, (GCompareFunc) strcmp) == NULL)
|
||||
{
|
||||
g_queue_push_head(app->recent_queue, g_strdup(doc_list[idx].file_name));
|
||||
if (g_queue_get_length(app->recent_queue) > app->mru_length)
|
||||
{
|
||||
g_free(g_queue_pop_tail(app->recent_queue));
|
||||
}
|
||||
utils_update_recent_menu();
|
||||
}
|
||||
utils_add_recent_file(doc_list[idx].file_name);
|
||||
}
|
||||
else gtk_widget_hide(app->save_filesel);
|
||||
}
|
||||
@ -2516,6 +2508,7 @@ on_recent_file_activate (GtkMenuItem *menuitem,
|
||||
if (locale_filename == NULL) locale_filename = g_strdup((gchar*) user_data);
|
||||
|
||||
document_open_file(-1, locale_filename, 0, FALSE, NULL, NULL);
|
||||
utils_recent_file_loaded((gchar*) user_data);
|
||||
|
||||
g_free(locale_filename);
|
||||
}
|
||||
|
@ -642,16 +642,7 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado
|
||||
|
||||
|
||||
// finally add current file to recent files menu, but not the files from the last session
|
||||
if (! app->opening_session_files &&
|
||||
g_queue_find_custom(app->recent_queue, utf8_filename, (GCompareFunc) strcmp) == NULL)
|
||||
{
|
||||
g_queue_push_head(app->recent_queue, g_strdup(utf8_filename));
|
||||
if (g_queue_get_length(app->recent_queue) > app->mru_length)
|
||||
{
|
||||
g_free(g_queue_pop_tail(app->recent_queue));
|
||||
}
|
||||
utils_update_recent_menu();
|
||||
}
|
||||
if (! app->opening_session_files) utils_add_recent_file(utf8_filename);
|
||||
|
||||
if (reload)
|
||||
msgwin_status_add(_("File %s reloaded."), utf8_filename);
|
||||
|
65
src/utils.c
65
src/utils.c
@ -55,6 +55,11 @@
|
||||
#include "images.c"
|
||||
|
||||
|
||||
static void utils_update_recent_menu();
|
||||
|
||||
static void utils_recreate_recent_menu();
|
||||
|
||||
|
||||
void utils_start_browser(const gchar *uri)
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
@ -1757,7 +1762,21 @@ void utils_update_fold_items(void)
|
||||
}
|
||||
|
||||
|
||||
void utils_update_recent_menu(void)
|
||||
void utils_add_recent_file(const gchar *filename)
|
||||
{
|
||||
if (g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp) == NULL)
|
||||
{
|
||||
g_queue_push_head(app->recent_queue, g_strdup(filename));
|
||||
if (g_queue_get_length(app->recent_queue) > app->mru_length)
|
||||
{
|
||||
g_free(g_queue_pop_tail(app->recent_queue));
|
||||
}
|
||||
utils_update_recent_menu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void utils_update_recent_menu()
|
||||
{
|
||||
GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu");
|
||||
GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1");
|
||||
@ -1779,11 +1798,11 @@ void utils_update_recent_menu(void)
|
||||
children = gtk_container_get_children(GTK_CONTAINER(recent_menu));
|
||||
if (g_list_length(children) > app->mru_length - 1)
|
||||
{
|
||||
children = g_list_nth(children, app->mru_length - 1);
|
||||
while (children != NULL)
|
||||
GList *item = g_list_nth(children, app->mru_length - 1);
|
||||
while (item != NULL)
|
||||
{
|
||||
if (GTK_IS_WIDGET(children->data)) gtk_widget_destroy(GTK_WIDGET(children->data));
|
||||
children = g_list_next(children);
|
||||
if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
|
||||
item = g_list_next(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1796,6 +1815,42 @@ void utils_update_recent_menu(void)
|
||||
}
|
||||
|
||||
|
||||
static void utils_recreate_recent_menu()
|
||||
{
|
||||
GList *item, *children;
|
||||
void *data;
|
||||
GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu");
|
||||
|
||||
children = gtk_container_get_children(GTK_CONTAINER(recent_menu));
|
||||
|
||||
// remove all menu items (but not the list elements)
|
||||
for (item = children; item != NULL; item = g_list_next(item))
|
||||
{
|
||||
data = item->data;
|
||||
if (! GTK_IS_MENU_ITEM(data)) continue;
|
||||
gtk_widget_destroy(GTK_WIDGET(data));
|
||||
}
|
||||
dialogs_create_recent_menu();
|
||||
}
|
||||
|
||||
|
||||
void utils_recent_file_loaded(const gchar *filename)
|
||||
{
|
||||
GList *item =
|
||||
g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp);
|
||||
gchar *data;
|
||||
|
||||
g_return_if_fail(item != NULL);
|
||||
// first reorder the queue
|
||||
data = item->data;
|
||||
g_queue_remove(app->recent_queue, data);
|
||||
g_queue_push_head(app->recent_queue, data);
|
||||
|
||||
// now recreate the recent files menu
|
||||
utils_recreate_recent_menu();
|
||||
}
|
||||
|
||||
|
||||
/* Wrapper functions for Key-File-Parser from GLib in keyfile.c to reduce code size */
|
||||
gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value)
|
||||
{
|
||||
|
@ -167,7 +167,9 @@ gchar *utils_get_initials(gchar *name);
|
||||
|
||||
void utils_update_toolbar_icons(GtkIconSize size);
|
||||
|
||||
void utils_update_recent_menu(void);
|
||||
void utils_add_recent_file(const gchar *filename);
|
||||
|
||||
void utils_recent_file_loaded(const gchar *filename);
|
||||
|
||||
gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user