SF.net SVN: geany: [680] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Aug 7 14:54:06 UTC 2006


Revision: 680
Author:   ntrel
Date:     2006-08-07 07:53:58 -0700 (Mon, 07 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=680&view=rev

Log Message:
-----------
Move recent file item to the top when it is clicked on

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/document.c
    trunk/src/utils.c
    trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-08-07 11:11:05 UTC (rev 679)
+++ trunk/ChangeLog	2006-08-07 14:53:58 UTC (rev 680)
@@ -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 at btinternet.com>

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2006-08-07 11:11:05 UTC (rev 679)
+++ trunk/src/callbacks.c	2006-08-07 14:53:58 UTC (rev 680)
@@ -930,15 +930,7 @@
 		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 @@
 	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);
 }

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-08-07 11:11:05 UTC (rev 679)
+++ trunk/src/document.c	2006-08-07 14:53:58 UTC (rev 680)
@@ -642,16 +642,7 @@
 
 
 	// 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);

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2006-08-07 11:11:05 UTC (rev 679)
+++ trunk/src/utils.c	2006-08-07 14:53:58 UTC (rev 680)
@@ -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,8 +1762,22 @@
 }
 
 
-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");
 	GtkWidget *tmp;
@@ -1779,11 +1798,11 @@
 	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 @@
 }
 
 
+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)
 {

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2006-08-07 11:11:05 UTC (rev 679)
+++ trunk/src/utils.h	2006-08-07 14:53:58 UTC (rev 680)
@@ -167,8 +167,10 @@
 
 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);
 
 gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list