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 struct nautilus_menu_data
*nautilus_data
= platform
;
28 static int not_shown_offset
= 0;
35 if (not_shown_offset
) {
36 nautilus_data
->item_id
+= not_shown_offset
;
40 item_name
= strdup(item
->string
);
42 shortcut_key
= parse_and_remove_shortcuts(item_name
);
44 debug_git("Adding entry: %s", item_name
);
46 snprintf(item_reference_string
, 1024, "GitExtension::%s", item_name
);
47 item_reference_string
[1023] = '\0';
48 one_menu_item
= nautilus_menu_item_new(item_reference_string
,
51 NULL
/* icon name */);
52 g_signal_connect(one_menu_item
, "activate",
53 G_CALLBACK(invoke_command
), nautilus_data
->provider
);
55 g_object_set_data((GObject
*) one_menu_item
, "git_extension_id",
56 (void *) nautilus_data
->item_id
);
57 g_object_set_data((GObject
*) one_menu_item
,
58 "git_extension_git_data", me
);
60 nautilus_data
->menu_items
= g_list_append(nautilus_data
->menu_items
,
63 /* this needs to be uniqe for each item */
64 nautilus_data
->item_id
++;
70 BOOL
build_separator(struct git_data
*me
, const struct menu_item
*item
,
73 /* not implemented, yet */
74 struct nautilus_menu_data
*nautilus_data
= platform
;
75 nautilus_data
->item_id
++;
79 void reset_platform(void *platform
)
81 /* nautilus does not need to reset anything */
84 void *start_submenu(struct git_data
*me
, const struct menu_item
*item
,
87 /* not implemented, yet */
91 void end_submenu(void *parent
, void *submenu
)
93 /* not implemented, yet */
96 static inline char *get_local_filename_from_fileinfo(char *filename
, int n
,
97 NautilusFileInfo
*file
)
100 char locator
[MAX_PATH
];
102 name
= nautilus_file_info_get_uri(file
);
104 /* find out if this is a local file */
105 strncpy(locator
, name
, MAX_PATH
);
107 if (!strcmp(locator
, "file://")) {
108 strncpy(filename
, name
+7, n
);
109 filename
[n
-1] = '\0';
118 GList
*git_extension_get_file_items(NautilusMenuProvider
*provider
,
127 struct nautilus_menu_data nautilus_data
= {
134 git_data
.name
[0] = '\0';
135 for (l
= files
; l
!= NULL
; l
= l
->next
) {
136 get_local_filename_from_fileinfo(git_data
.name
,
137 MAX_PATH
, NAUTILUS_FILE_INFO(l
->data
));
140 /* if we could not get a local file we stop */
141 if (!git_data
.name
[0])
144 debug_git("selected %s\n", git_data
.name
);
146 build_cheetah_menu(&git_data
, &nautilus_data
);
148 return nautilus_data
.menu_items
;
151 GList
*git_extension_get_background_items(NautilusMenuProvider
*provider
,
153 NautilusFileInfo
*current_folder
)
158 struct nautilus_menu_data nautilus_data
= {
164 git_data
.name
[0] = '\0';
165 get_local_filename_from_fileinfo(git_data
.name
,
166 MAX_PATH
, NAUTILUS_FILE_INFO(current_folder
));
168 /* if we could not get a local file we stop */
169 if (!git_data
.name
[0])
172 debug_git("selected %s\n", git_data
.name
);
174 build_cheetah_menu(&git_data
, &nautilus_data
);
176 return nautilus_data
.menu_items
;
179 GList
*git_extension_get_toolbar_items(NautilusMenuProvider
*provider
,
181 NautilusFileInfo
*current_folder
)
183 return git_extension_get_background_items(provider
,
184 window
, current_folder
);
187 void invoke_command(NautilusMenuItem
*item
,
193 id
= (int) g_object_get_data((GObject
*) item
, "git_extension_id");
194 me
= (struct git_data
*) g_object_get_data((GObject
*) item
,
195 "git_extension_git_data");
197 debug_git("invoke_command: %s, id: %i", me
->name
, id
);
199 handle_menu_item(me
, id
);
202 const char **menu_get_platform_argv(menu_commands cmd
, const void *data
,
203 free_func_t
*free_argv
, void **argv_data
)
205 static const char *bash_argv
[] = { "gnome-terminal", NULL
};