Build recent data for GTK ourselves

This prevents GTK of trying to fetch the necessary information like
MIME-type itself, which leads to a significant speedup (> 30%), as
well as using the real MIME-type we use rather than the GIO-guessed
one.
This commit is contained in:
Colomban Wendling 2011-11-03 20:45:52 +01:00
parent 0167f589b3
commit b55a30c2bf
4 changed files with 33 additions and 13 deletions

View File

@ -588,7 +588,7 @@ static gboolean remove_page(guint page_num)
/* Checking real_path makes it likely the file exists on disk */ /* Checking real_path makes it likely the file exists on disk */
if (! main_status.closing_all && doc->real_path != NULL) if (! main_status.closing_all && doc->real_path != NULL)
ui_add_recent_file(doc->file_name); ui_add_recent_document(doc);
doc->is_valid = FALSE; doc->is_valid = FALSE;
@ -1113,7 +1113,7 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename
doc = document_find_by_filename(utf8_filename); doc = document_find_by_filename(utf8_filename);
if (doc != NULL) if (doc != NULL)
{ {
ui_add_recent_file(utf8_filename); /* either add or reorder recent item */ ui_add_recent_document(doc); /* either add or reorder recent item */
/* show the doc before reload dialog */ /* show the doc before reload dialog */
document_show_tab(doc); document_show_tab(doc);
document_check_disk_status(doc, TRUE); /* force a file changed check */ document_check_disk_status(doc, TRUE); /* force a file changed check */
@ -1200,7 +1200,7 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename
/* 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 (! main_status.opening_session_files) if (! main_status.opening_session_files)
ui_add_recent_file(utf8_filename); ui_add_recent_document(doc);
if (reload) if (reload)
{ {
@ -1475,7 +1475,7 @@ gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname)
doc->priv->file_disk_status = FILE_IGNORE; doc->priv->file_disk_status = FILE_IGNORE;
if (ret) if (ret)
ui_add_recent_file(doc->file_name); ui_add_recent_document(doc);
return ret; return ret;
} }

View File

@ -776,7 +776,7 @@ gboolean main_handle_filename(const gchar *locale_filename)
doc = document_open_file(filename, FALSE, NULL, NULL); doc = document_open_file(filename, FALSE, NULL, NULL);
/* add recent file manually if opening_session_files is set */ /* add recent file manually if opening_session_files is set */
if (doc != NULL && main_status.opening_session_files) if (doc != NULL && main_status.opening_session_files)
ui_add_recent_file(doc->file_name); ui_add_recent_document(doc);
g_free(filename); g_free(filename);
return TRUE; return TRUE;
} }
@ -786,7 +786,7 @@ gboolean main_handle_filename(const gchar *locale_filename)
doc = document_new_file(utf8_filename, NULL, NULL); doc = document_new_file(utf8_filename, NULL, NULL);
if (doc != NULL) if (doc != NULL)
ui_add_recent_file(doc->file_name); ui_add_recent_document(doc);
g_free(utf8_filename); g_free(utf8_filename);
g_free(filename); g_free(filename);
return TRUE; return TRUE;

View File

@ -1113,18 +1113,19 @@ static void recent_project_activate_cb(GtkMenuItem *menuitem, G_GNUC_UNUSED gpoi
} }
static void add_recent_file(const gchar *utf8_filename, GeanyRecentFiles *grf) static void add_recent_file(const gchar *utf8_filename, GeanyRecentFiles *grf,
const GtkRecentData *rdata)
{ {
if (g_queue_find_custom(grf->recent_queue, utf8_filename, (GCompareFunc) strcmp) == NULL) if (g_queue_find_custom(grf->recent_queue, utf8_filename, (GCompareFunc) strcmp) == NULL)
{ {
if (grf->type == RECENT_FILE_FILE) if (grf->type == RECENT_FILE_FILE && rdata)
{ {
GtkRecentManager *manager = gtk_recent_manager_get_default(); GtkRecentManager *manager = gtk_recent_manager_get_default();
gchar *uri = g_filename_to_uri(utf8_filename, NULL, NULL); gchar *uri = g_filename_to_uri(utf8_filename, NULL, NULL);
if (uri != NULL) if (uri != NULL)
{ {
gtk_recent_manager_add_item(manager, uri); gtk_recent_manager_add_full(manager, uri, rdata);
g_free(uri); g_free(uri);
} }
} }
@ -1142,15 +1143,34 @@ static void add_recent_file(const gchar *utf8_filename, GeanyRecentFiles *grf)
} }
void ui_add_recent_file(const gchar *utf8_filename) void ui_add_recent_document(GeanyDocument *doc)
{ {
add_recent_file(utf8_filename, recent_get_recent_files()); /* what are the groups for actually? */
static const gchar *groups[2] = {
"geany",
NULL
};
GtkRecentData rdata;
/* Prepare the data for gtk_recent_manager_add_full() */
rdata.display_name = NULL;
rdata.description = NULL;
rdata.mime_type = doc->file_type->mime_type;
/* if we ain't got no mime-type, fallback to plain text */
if (! rdata.mime_type)
rdata.mime_type = (gchar *) "text/plain";
rdata.app_name = (gchar *) "geany";
rdata.app_exec = (gchar *) "geany %u";
rdata.groups = (gchar **) groups;
rdata.is_private = FALSE;
add_recent_file(doc->file_name, recent_get_recent_files(), &rdata);
} }
void ui_add_recent_project_file(const gchar *utf8_filename) void ui_add_recent_project_file(const gchar *utf8_filename)
{ {
add_recent_file(utf8_filename, recent_get_recent_projects()); add_recent_file(utf8_filename, recent_get_recent_projects(), NULL);
} }

View File

@ -292,7 +292,7 @@ GtkWidget *ui_new_image_from_inline(gint img);
void ui_create_recent_menus(void); void ui_create_recent_menus(void);
void ui_add_recent_file(const gchar *utf8_filename); void ui_add_recent_document(GeanyDocument *doc);
void ui_add_recent_project_file(const gchar *utf8_filename); void ui_add_recent_project_file(const gchar *utf8_filename);