3 * Here we implement the functions which feed the cheetah menuengine
6 * Copyright (C) Heiko Voigt, 2009
10 #include "../common/git-compat-util.h"
11 #include "../common/debug.h"
12 #include "../common/strbuf.h"
13 #include "../common/menuengine.h"
14 #include "../common/cheetahmenu.h"
18 static struct git_data git_data
;
20 BOOL
build_item(struct git_data
*me
, const struct menu_item
*item
,
25 char item_reference_string
[1024];
26 NautilusMenuItem
*one_menu_item
;
27 GValue sensitive
= {0};
28 struct nautilus_menu_data
*nautilus_data
= platform
;
33 item_name
= strdup(item
->string
);
35 shortcut_key
= parse_and_remove_shortcuts(item_name
);
37 debug_git("Adding entry: %s", item_name
);
39 snprintf(item_reference_string
, 1024, "GitExtension::%s", item_name
);
40 item_reference_string
[1023] = '\0';
41 one_menu_item
= nautilus_menu_item_new(item_reference_string
,
44 item
->flags
& MI_CHECKED
? GTK_STOCK_YES
: NULL
);
45 g_signal_connect(one_menu_item
, "activate",
46 G_CALLBACK(invoke_command
), nautilus_data
->provider
);
48 g_object_set_data((GObject
*) one_menu_item
, "git_extension_id",
49 (void *)next_active_item
);
50 g_object_set_data((GObject
*) one_menu_item
,
51 "git_extension_git_data", me
);
53 g_value_init(&sensitive
, G_TYPE_BOOLEAN
);
54 g_value_set_boolean(&sensitive
, !(item
->flags
& MI_DISABLED
));
55 g_object_set_property((GObject
*)one_menu_item
, "sensitive",
58 if (nautilus_data
->submenu
)
59 nautilus_menu_append_item(nautilus_data
->submenu
, one_menu_item
);
61 nautilus_data
->menu_items
= g_list_append(nautilus_data
->menu_items
,
68 BOOL
build_separator(struct git_data
*me
, const struct menu_item
*item
,
71 /* not implemented, yet */
75 void reset_platform(void *platform
)
77 /* nautilus does not need to reset anything */
80 void *start_submenu(struct git_data
*me
, const struct menu_item
*item
,
83 struct nautilus_menu_data
*nautilus_data
= platform
;
85 NautilusMenuItem
*submenu_item
;
86 NautilusMenu
*submenu
;
87 char name
[512], *item_name
= strdup(item
->string
), shortcut_key
;
89 shortcut_key
= parse_and_remove_shortcuts(item_name
);
91 snprintf(name
, sizeof(name
), "GitExtension::%s", item_name
);
92 name
[sizeof(name
) - 1] = '\0';
94 debug_git("creating submenu item '%s' '%s' '%s'", item_name
, name
, item
->helptext
);
95 submenu_item
= nautilus_menu_item_new(
103 submenu
= nautilus_menu_new();
105 g_object_set_data((GObject
*)submenu
, "git_menu_parent",
106 (void *)nautilus_data
->submenu
);
108 nautilus_menu_item_set_submenu(submenu_item
, submenu
);
110 if (nautilus_data
->submenu
)
111 nautilus_menu_append_item(nautilus_data
->submenu
, submenu_item
);
113 nautilus_data
->menu_items
= g_list_append(nautilus_data
->menu_items
,
116 nautilus_data
->submenu
= submenu
;
121 void end_submenu(void *parent
, void *submenu
)
123 struct nautilus_menu_data
*nautilus_data
= parent
;
124 nautilus_data
->submenu
= (NautilusMenu
*)g_object_get_data(
125 (GObject
*)nautilus_data
->submenu
,
129 static inline char *get_local_filename_from_fileinfo(char *filename
, int n
,
130 NautilusFileInfo
*file
)
132 char *name
, *uri
= nautilus_file_info_get_uri(file
);
134 /* find out if this is a local file */
135 name
= g_filename_from_uri(uri
, NULL
, NULL
);
137 strncpy(filename
, name
, n
);
139 filename
[n
-1] = '\0';
149 GList
*git_extension_get_file_items(NautilusMenuProvider
*provider
,
158 struct nautilus_menu_data nautilus_data
= {
165 git_data
.name
[0] = '\0';
166 for (l
= files
; l
!= NULL
; l
= l
->next
) {
167 get_local_filename_from_fileinfo(git_data
.name
,
168 MAX_PATH
, NAUTILUS_FILE_INFO(l
->data
));
171 /* if we could not get a local file we stop */
172 if (!git_data
.name
[0])
175 debug_git("selected %s\n", git_data
.name
);
177 build_cheetah_menu(&git_data
, &nautilus_data
);
179 return nautilus_data
.menu_items
;
182 GList
*git_extension_get_background_items(NautilusMenuProvider
*provider
,
184 NautilusFileInfo
*current_folder
)
189 struct nautilus_menu_data nautilus_data
= {
195 git_data
.name
[0] = '\0';
196 get_local_filename_from_fileinfo(git_data
.name
,
197 MAX_PATH
, NAUTILUS_FILE_INFO(current_folder
));
199 /* if we could not get a local file we stop */
200 if (!git_data
.name
[0])
203 debug_git("selected %s\n", git_data
.name
);
205 build_cheetah_menu(&git_data
, &nautilus_data
);
207 return nautilus_data
.menu_items
;
210 GList
*git_extension_get_toolbar_items(NautilusMenuProvider
*provider
,
212 NautilusFileInfo
*current_folder
)
214 return git_extension_get_background_items(provider
,
215 window
, current_folder
);
218 void invoke_command(NautilusMenuItem
*item
,
223 NautilusMenuProvider
*provider
= (NautilusMenuProvider
*)user_data
;
225 id
= (int) g_object_get_data((GObject
*) item
, "git_extension_id");
226 me
= (struct git_data
*) g_object_get_data((GObject
*) item
,
227 "git_extension_git_data");
229 debug_git("invoke_command: %s, id: %i", me
->name
, id
);
231 if (handle_menu_item(me
, id
))
232 nautilus_menu_provider_emit_items_updated_signal(provider
);
235 const char **menu_get_platform_argv(menu_commands cmd
, void *data
,
236 free_func_t
*free_argv
, void **argv_data
)
238 static const char *bash_argv
[] = { "gnome-terminal", NULL
};