4 #include "menuengine.h"
5 #include "cheetahmenu.h"
7 #include "systeminfo.h"
9 char *wd_from_path(const char *path
, BOOL
*is_path_dir
)
11 BOOL directory
= TRUE
;
12 char *cheetah_wd
= strdup(path
);
13 if (!is_directory(cheetah_wd
)) {
14 char *c
= strrchr(cheetah_wd
, PATH_SEPERATOR
);
15 if (c
) /* sanity check in case it's a weird directory */
22 *is_path_dir
= directory
;
28 * Cheetah-specific menu
31 static void menu_gui(struct git_data
*this_
, UINT id
)
33 char *wd
= wd_from_path(this_
->name
, NULL
);
36 free_func_t argv_free
;
39 const char *generic_argv
[] = { "git", "gui", NULL
};
41 argv
= menu_get_platform_argv(MENU_GUI
, NULL
,
42 &argv_free
, &argv_data
);
47 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
54 static void menu_init(struct git_data
*this_
, UINT id
)
56 char *wd
= wd_from_path(this_
->name
, NULL
);
59 free_func_t argv_free
;
62 const char *generic_argv
[] = { "git", "init", NULL
};
64 argv
= menu_get_platform_argv(MENU_INIT
, NULL
,
65 &argv_free
, &argv_data
);
69 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
76 static void menu_history(struct git_data
*this_
, unsigned int id
)
79 char *wd
= wd_from_path(this_
->name
, &is_directory
);
83 free_func_t argv_free
;
86 const char *generic_argv
[] = { "gitk", "HEAD", "--",
90 name
= this_
->name
+ strlen(wd
) + 1;
91 generic_argv
[3] = name
;
93 argv
= menu_get_platform_argv(MENU_HISTORY
, name
,
94 &argv_free
, &argv_data
);
98 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
101 argv_free(argv_data
);
105 static void menu_bash(struct git_data
*this_
, UINT id
)
107 char *wd
= wd_from_path(this_
->name
, NULL
);
110 free_func_t argv_free
;
113 argv
= menu_get_platform_argv(MENU_BASH
, wd
,
114 &argv_free
, &argv_data
);
115 /* There is no generic implementation for this item */
117 debug_git("Error: Got no platform terminal for bash");
121 exec_program_v(wd
, NULL
, NULL
, NORMALMODE
, argv
);
124 argv_free(argv_data
);
128 static void menu_blame(struct git_data
*this_
, UINT id
)
131 char *wd
= wd_from_path(this_
->name
, &is_directory
);
135 free_func_t argv_free
= NULL
;
138 const char *generic_argv
[] = { "git", "gui", "blame",
142 name
= this_
->name
+ strlen(wd
) + 1;
143 generic_argv
[3] = name
;
145 argv
= menu_get_platform_argv(MENU_BLAME
, name
,
146 &argv_free
, &argv_data
);
150 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
154 argv_free(argv_data
);
158 static void menu_citool(struct git_data
*this_
, UINT id
)
160 char *wd
= wd_from_path(this_
->name
, NULL
);
163 free_func_t argv_free
;
166 const char *generic_argv
[] = { "git", "citool", NULL
};
168 argv
= menu_get_platform_argv(MENU_CITOOL
, NULL
,
169 &argv_free
, &argv_data
);
173 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
176 argv_free(argv_data
);
180 static void menu_addall(struct git_data
*this_
, UINT id
)
182 char *wd
= wd_from_path(this_
->name
, NULL
);
185 free_func_t argv_free
;
188 const char *generic_argv
[] = { "git", "add", "--all", NULL
};
190 argv
= menu_get_platform_argv(MENU_ADDALL
, NULL
,
191 &argv_free
, &argv_data
);
195 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
198 argv_free(argv_data
);
202 static void menu_branch(struct git_data
*this_
, UINT id
)
205 char *wd
= wd_from_path(this_
->name
, NULL
);
207 const char *menu_item_text
;
210 free_func_t argv_free
;
213 const char *generic_argv
[] = { "git", "checkout", NULL
, NULL
};
215 menu_item_text
= get_menu_item_text(id
);
216 generic_argv
[2] = menu_item_text
;
218 argv
= menu_get_platform_argv(MENU_BRANCH
, menu_item_text
,
219 &argv_free
, &argv_data
);
223 strbuf_init(&err
, 0);
225 status
= exec_program_v(wd
, NULL
, &err
, HIDDENMODE
, argv
);
227 /* if nothing, terribly wrong happened, show the confirmation */
229 /* strangely enough even success message is on stderr */
230 debug_git_mbox(err
.buf
);
233 argv_free(argv_data
);
237 static BOOL
build_branch_menu(struct git_data
*data
,
238 const struct menu_item
*item
,
244 char *wd
= wd_from_path(data
->name
, NULL
);
246 struct strbuf output
;
247 struct strbuf
**lines
, **it
;
248 strbuf_init(&output
, 0);
250 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
251 "git", "branch", NULL
);
256 submenu
= start_submenu(data
, item
, platform
);
258 lines
= strbuf_split(&output
, '\n');
259 for (it
= lines
; *it
; it
++) {
260 struct menu_item item
= {
261 MENU_ITEM_CLEANUP
, 0,
267 item
.string
= strdup((*it
)->buf
+ 2);
268 item
.helptext
= strdup((*it
)->buf
+ 2);
269 item
.flags
= '*' == (*it
)->buf
[0] ? MI_CHECKED
: 0;
270 if (build_item(data
, &item
, submenu
))
271 append_active_menu(&item
);
274 * if the platform failed to create an item
275 * there is no point to try other items
280 end_submenu(platform
, submenu
);
282 /* technically, there is nothing to track for the menu engine */
286 UINT
cheetah_menu_mask(struct git_data
*this_
)
289 char *wd
= wd_from_path(this_
->name
, &is_directory
);
290 UINT selection
= is_directory
? MENU_ITEM_DIR
: MENU_ITEM_FILE
;
293 struct strbuf output
;
295 strbuf_init(&output
, 0);
297 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
298 "git", "rev-parse", "--show-prefix", NULL
);
299 eol
= strchr(output
.buf
, '\n');
303 if (status
< 0) /* something went terribly wrong */
304 selection
= MENU_ITEM_LAST
;
306 selection
|= MENU_ITEM_NOREPO
;
308 char head_path
[MAX_PATH
] = "HEAD";
310 sprintf(head_path
, "HEAD:%s%s",
312 this_
->name
+ strlen(wd
) + 1);
314 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
315 "git", "rev-parse", "--verify", head_path
, NULL
);
316 if (status
< 0) /* something went terribly wrong */
317 selection
= MENU_ITEM_LAST
;
319 selection
|= MENU_ITEM_REPO
|
321 MENU_ITEM_NOTRACK
: MENU_ITEM_TRACK
);
324 strbuf_release(&output
);
329 const struct menu_item cheetah_menu
[] = {
330 { MENU_ITEM_ALWAYS
, 0, NULL
, NULL
, build_separator
, NULL
},
332 { MENU_ITEM_REPO
, 0, "Git &Add all files now",
333 "Add all files from this folder now",
334 build_item
, menu_addall
},
335 { MENU_ITEM_REPO
, 0, "Git &Commit Tool",
336 "Launch the GIT commit tool in the local or chosen directory.",
337 build_item
, menu_citool
},
338 { MENU_ITEM_TRACK
, 0, "Git &History",
339 "Show GIT history of the chosen file or directory.",
342 { MENU_ITEM_TRACK
| MENU_ITEM_FILE
, 0, "Git &Blame",
343 "Start a blame viewer on the specified file.",
344 build_item
, menu_blame
},
346 { MENU_ITEM_REPO
, 0, "Git &Gui",
347 "Launch the GIT Gui in the local or chosen directory.",
348 build_item
, menu_gui
},
350 { MENU_ITEM_REPO
, 0, "Git Bra&nch",
352 build_branch_menu
, NULL
},
354 { MENU_ITEM_NOREPO
, 0, "Git I&nit Here",
355 "Initialize GIT repo in the local directory.",
356 build_item
, menu_init
},
357 { MENU_ITEM_NOREPO
| MENU_ITEM_DIR
, 0, "Git &Gui",
358 "Launch the GIT Gui in the local or chosen directory.",
359 build_item
, menu_gui
},
361 { MENU_ITEM_ALWAYS
, 0, "Git Ba&sh",
362 "Start GIT shell in the local or chosen directory",
363 build_item
, menu_bash
},
364 { MENU_ITEM_ALWAYS
, 0, NULL
, NULL
, build_separator
, NULL
},
367 void build_cheetah_menu(struct git_data
*data
, void *platform_data
)
369 reset_platform(platform_data
);
370 build_menu_items(data
, cheetah_menu_mask
,
372 sizeof(cheetah_menu
) / sizeof(cheetah_menu
[0]),