Kaydet (Commit) 795fc850 authored tarafından Nick Treleaven's avatar Nick Treleaven

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
üst 92a3f0a4
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
* src/callbacks.c: Allow Find even when the replace text is the same. * src/callbacks.c: Allow Find even when the replace text is the same.
Place the cursor in "" for insert blank include. 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> 2006-08-06 Nick Treleaven <nick.treleaven@btinternet.com>
......
...@@ -930,15 +930,7 @@ on_file_save_dialog_response (GtkDialog *dialog, ...@@ -930,15 +930,7 @@ on_file_save_dialog_response (GtkDialog *dialog,
utils_build_show_hide(idx); utils_build_show_hide(idx);
// finally add current file to recent files menu // finally add current file to recent files menu
if (g_queue_find_custom(app->recent_queue, doc_list[idx].file_name, (GCompareFunc) strcmp) == NULL) utils_add_recent_file(doc_list[idx].file_name);
{
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();
}
} }
else gtk_widget_hide(app->save_filesel); else gtk_widget_hide(app->save_filesel);
} }
...@@ -2516,6 +2508,7 @@ on_recent_file_activate (GtkMenuItem *menuitem, ...@@ -2516,6 +2508,7 @@ on_recent_file_activate (GtkMenuItem *menuitem,
if (locale_filename == NULL) locale_filename = g_strdup((gchar*) user_data); if (locale_filename == NULL) locale_filename = g_strdup((gchar*) user_data);
document_open_file(-1, locale_filename, 0, FALSE, NULL, NULL); document_open_file(-1, locale_filename, 0, FALSE, NULL, NULL);
utils_recent_file_loaded((gchar*) user_data);
g_free(locale_filename); g_free(locale_filename);
} }
......
...@@ -642,16 +642,7 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado ...@@ -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 // finally add current file to recent files menu, but not the files from the last session
if (! app->opening_session_files && if (! app->opening_session_files) utils_add_recent_file(utf8_filename);
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 (reload) if (reload)
msgwin_status_add(_("File %s reloaded."), utf8_filename); msgwin_status_add(_("File %s reloaded."), utf8_filename);
......
...@@ -55,6 +55,11 @@ ...@@ -55,6 +55,11 @@
#include "images.c" #include "images.c"
static void utils_update_recent_menu();
static void utils_recreate_recent_menu();
void utils_start_browser(const gchar *uri) void utils_start_browser(const gchar *uri)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
...@@ -1757,7 +1762,21 @@ void utils_update_fold_items(void) ...@@ -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_menu = lookup_widget(app->window, "recent_files1_menu");
GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1"); GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1");
...@@ -1779,11 +1798,11 @@ void utils_update_recent_menu(void) ...@@ -1779,11 +1798,11 @@ void utils_update_recent_menu(void)
children = gtk_container_get_children(GTK_CONTAINER(recent_menu)); children = gtk_container_get_children(GTK_CONTAINER(recent_menu));
if (g_list_length(children) > app->mru_length - 1) if (g_list_length(children) > app->mru_length - 1)
{ {
children = g_list_nth(children, app->mru_length - 1); GList *item = g_list_nth(children, app->mru_length - 1);
while (children != NULL) while (item != NULL)
{ {
if (GTK_IS_WIDGET(children->data)) gtk_widget_destroy(GTK_WIDGET(children->data)); if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data));
children = g_list_next(children); item = g_list_next(item);
} }
} }
...@@ -1796,6 +1815,42 @@ void utils_update_recent_menu(void) ...@@ -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 */ /* 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) 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); ...@@ -167,7 +167,9 @@ gchar *utils_get_initials(gchar *name);
void utils_update_toolbar_icons(GtkIconSize size); 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); gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment