File: gnome-panel-recently-used-apps.patch

package info (click to toggle)
gnome-main-menu 1.8.0-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,748 kB
  • ctags: 724
  • sloc: ansic: 4,394; makefile: 150; sh: 17; xml: 2
file content (197 lines) | stat: -rw-r--r-- 4,997 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
diff -uprN gnome-panel-2.16.1-pristine/gnome-panel/panel-run-dialog.c gnome-panel-2.16.1/gnome-panel/panel-run-dialog.c
--- gnome-panel-2.16.1-pristine/gnome-panel/panel-run-dialog.c	2006-08-07 17:07:46.000000000 -0400
+++ gnome-panel-2.16.1/gnome-panel/panel-run-dialog.c	2006-10-23 18:11:16.000000000 -0400
@@ -59,6 +59,14 @@
 #include "panel-lockdown.h"
 #include "panel-xutils.h"
 
+#include <gtk/gtkversion.h>
+#if GTK_CHECK_VERSION (2,10,0)
+#	define USE_GTK_RECENT_MANAGER
+#	include <gtk/gtkrecentmanager.h>
+#else
+#	include "egg-recent-model.h"
+#endif
+
 #define ICON_SIZE 48.0
 
 typedef struct {
@@ -112,6 +120,8 @@ enum {
 
 static PanelRunDialog *static_dialog = NULL;
 
+static void panel_run_dialog_update_recent_apps (PanelRunDialog *dialog, const gchar *cmd);
+
 static void
 panel_run_dialog_destroy (PanelRunDialog *dialog)
 {
@@ -420,6 +430,8 @@ panel_run_dialog_execute (PanelRunDialog
 		gnome_entry_prepend_history (GNOME_ENTRY (dialog->gnome_entry),
 					     TRUE, /* save item in history */
 					     command);
+
+		panel_run_dialog_update_recent_apps (dialog, command);
 		
 		/* only close the dialog if we successfully showed or launched something */
 		gtk_widget_destroy (dialog->run_dialog);
@@ -672,6 +684,160 @@ panel_run_dialog_find_command_idle (Pane
 	return FALSE;
 }
 
+static void
+panel_run_dialog_update_recent_apps (PanelRunDialog *dialog, const gchar *cmd)
+{
+	GtkTreeIter   iter;
+	GtkTreeModel *model = NULL;
+	GtkTreePath  *path  = NULL;
+
+	gchar *found_ditem_path = NULL;
+	gchar *found_ditem_uri  = NULL;
+	gchar *found_cmd        = NULL;
+
+	gchar *cmd_i;
+	gchar *ditem_path_i;
+
+	gboolean fuzzy;
+
+#ifdef USE_GTK_RECENT_MANAGER
+	GtkRecentManager *recent_manager;
+	GtkRecentData     recent_data;
+#else
+	EggRecentModel *recent_model;
+	EggRecentItem  *recent_item;
+#endif
+
+	GError *error = NULL;
+
+	
+	if (! cmd)
+		return;
+
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->program_list));
+	path  = gtk_tree_path_new_first ();
+	
+	if (! path || ! gtk_tree_model_get_iter (model, & iter, path)) {
+		if (path)
+			gtk_tree_path_free (path);
+
+		return;
+	}
+
+	do {
+		cmd_i        = NULL;
+		ditem_path_i = NULL;
+
+		gtk_tree_model_get (
+			model, & iter,
+			COLUMN_EXEC, & cmd_i,
+			COLUMN_PATH, & ditem_path_i,
+			-1
+		);
+
+        	if (cmd_i && ditem_path_i) {
+			fuzzy = FALSE;
+
+			if (fuzzy_command_match (sure_string (cmd), cmd_i, & fuzzy)) {
+				g_free (found_ditem_path);
+				
+				found_ditem_path = g_strdup (ditem_path_i);
+				found_cmd        = g_strdup (cmd_i);
+				
+				if (! fuzzy) {
+					/*
+					 * if not fuzzy then we have a precise
+					 * match and we can quit, else keep
+					 * searching for a better match
+					 */
+					g_free (cmd_i);
+					g_free (ditem_path_i);
+
+					break;
+				}
+			}
+		}
+
+		g_free (cmd_i);
+		g_free (ditem_path_i);
+
+	} while (gtk_tree_model_iter_next (model, & iter));
+
+	gtk_tree_path_free (path);
+
+#ifdef USE_GTK_RECENT_MANAGER
+	recent_manager = gtk_recent_manager_get_default ();
+
+	if (! recent_manager)
+		goto exit;
+#else
+	recent_model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_NONE);
+
+	if (! recent_model)
+		goto exit;
+#endif
+
+	if (found_ditem_path) {
+		found_ditem_uri = g_filename_to_uri (found_ditem_path, NULL, & error);
+
+		if (! error) {
+#ifdef USE_GTK_RECENT_MANAGER
+			recent_data.display_name = NULL;
+			recent_data.description  = NULL;
+			recent_data.mime_type    = g_strdup ("application/x-desktop");
+			recent_data.is_private   = TRUE;
+
+			recent_data.app_name = g_strdup (g_get_application_name ());
+			if (! recent_data.app_name)
+				recent_data.app_name = g_strdup ("gnome-panel run dialog");
+
+			recent_data.app_exec = g_strdup (g_strdup (found_cmd));
+			if (! recent_data.app_exec)
+				recent_data.app_exec = g_strdup ("gnome-open %u");
+
+			recent_data.groups     = g_new0 (gchar *, 2);
+			recent_data.groups [0] = g_strdup ("recently-used-apps");
+			recent_data.groups [1] = NULL;
+
+			gtk_recent_manager_add_full (recent_manager, found_ditem_uri, & recent_data);
+
+			g_free (recent_data.mime_type);
+			g_free (recent_data.app_name);
+			g_free (recent_data.app_exec);
+			g_free (recent_data.groups [0]);
+			g_free (recent_data.groups);
+
+#else
+
+			recent_item = egg_recent_item_new_from_uri (found_ditem_uri);
+			egg_recent_item_add_group (recent_item, "recently-used-apps");
+			egg_recent_item_set_private (recent_item, TRUE);
+
+			egg_recent_model_add_full (recent_model, recent_item);
+
+			if (recent_item)
+				egg_recent_item_unref (recent_item);
+#endif
+		}
+		else {
+			g_warning ("unable to create uri from [%s] to insert into recent file list.\n",
+				found_ditem_path);
+
+			g_error_free (error);
+		}
+	}
+
+#ifndef USE_GTK_RECENT_MANAGER
+	g_object_unref (recent_model);
+#endif
+
+exit:
+
+	g_free (found_ditem_path);
+	g_free (found_ditem_uri);
+	g_free (found_cmd);
+}
+
 static gboolean
 panel_run_dialog_add_icon_idle (PanelRunDialog *dialog)
 {