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 int 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
);
56 static int menu_init(struct git_data
*this_
, UINT id
)
58 char *wd
= wd_from_path(this_
->name
, NULL
);
61 free_func_t argv_free
;
64 const char *generic_argv
[] = { "git", "init", NULL
};
66 argv
= menu_get_platform_argv(MENU_INIT
, NULL
,
67 &argv_free
, &argv_data
);
71 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
| WAITMODE
, argv
);
80 static int menu_history(struct git_data
*this_
, unsigned int id
)
83 char *wd
= wd_from_path(this_
->name
, &is_directory
);
87 free_func_t argv_free
;
90 const char *generic_argv
[] = { "gitk", "HEAD", "--",
94 name
= this_
->name
+ strlen(wd
) + 1;
95 generic_argv
[3] = name
;
97 argv
= menu_get_platform_argv(MENU_HISTORY
, name
,
98 &argv_free
, &argv_data
);
102 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
105 argv_free(argv_data
);
111 static int menu_bash(struct git_data
*this_
, UINT id
)
113 char *wd
= wd_from_path(this_
->name
, NULL
);
116 free_func_t argv_free
;
119 argv
= menu_get_platform_argv(MENU_BASH
, wd
,
120 &argv_free
, &argv_data
);
121 /* There is no generic implementation for this item */
123 debug_git("Error: Got no platform terminal for bash");
127 exec_program_v(wd
, NULL
, NULL
, NORMALMODE
, argv
);
130 argv_free(argv_data
);
136 static int menu_blame(struct git_data
*this_
, UINT id
)
139 char *wd
= wd_from_path(this_
->name
, &is_directory
);
143 free_func_t argv_free
= NULL
;
146 const char *generic_argv
[] = { "git", "gui", "blame",
150 name
= this_
->name
+ strlen(wd
) + 1;
151 generic_argv
[3] = name
;
153 argv
= menu_get_platform_argv(MENU_BLAME
, name
,
154 &argv_free
, &argv_data
);
158 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
162 argv_free(argv_data
);
168 static int menu_citool(struct git_data
*this_
, UINT id
)
170 char *wd
= wd_from_path(this_
->name
, NULL
);
173 free_func_t argv_free
;
176 const char *generic_argv
[] = { "git", "citool", NULL
};
178 argv
= menu_get_platform_argv(MENU_CITOOL
, NULL
,
179 &argv_free
, &argv_data
);
183 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
186 argv_free(argv_data
);
192 static int menu_addall(struct git_data
*this_
, UINT id
)
194 char *wd
= wd_from_path(this_
->name
, NULL
);
197 free_func_t argv_free
;
200 const char *generic_argv
[] = { "git", "add", "--all", NULL
};
202 argv
= menu_get_platform_argv(MENU_ADDALL
, NULL
,
203 &argv_free
, &argv_data
);
207 exec_program_v(wd
, NULL
, NULL
, HIDDENMODE
, argv
);
210 argv_free(argv_data
);
216 static int menu_branch(struct git_data
*this_
, UINT id
)
219 char *wd
= wd_from_path(this_
->name
, NULL
);
221 const char *menu_item_text
;
224 free_func_t argv_free
;
227 const char *generic_argv
[] = { "git", "checkout", NULL
, NULL
};
229 menu_item_text
= get_menu_item_text(id
);
230 generic_argv
[2] = menu_item_text
;
232 argv
= menu_get_platform_argv(MENU_BRANCH
, menu_item_text
,
233 &argv_free
, &argv_data
);
237 strbuf_init(&err
, 0);
239 status
= exec_program_v(wd
, NULL
, &err
, HIDDENMODE
| WAITMODE
, argv
);
241 /* if nothing, terribly wrong happened, show the confirmation */
243 /* strangely enough even success message is on stderr */
244 debug_git_mbox(err
.buf
);
247 argv_free(argv_data
);
253 static BOOL
build_branch_menu(struct git_data
*data
,
254 const struct menu_item
*item
,
260 char *wd
= wd_from_path(data
->name
, NULL
);
262 struct strbuf output
;
263 struct strbuf
**lines
, **it
;
264 strbuf_init(&output
, 0);
266 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
267 "git", "branch", NULL
);
272 submenu
= start_submenu(data
, item
, platform
);
274 lines
= strbuf_split(&output
, '\n');
275 for (it
= lines
; *it
; it
++) {
276 struct menu_item item
= {
277 MENU_ITEM_CLEANUP
, 0,
283 item
.string
= strdup((*it
)->buf
+ 2);
284 item
.helptext
= strdup((*it
)->buf
+ 2);
285 item
.flags
= '*' == (*it
)->buf
[0] ?
286 MI_CHECKED
| MI_DISABLED
: 0;
287 if (build_item(data
, &item
, submenu
))
288 append_active_menu(&item
);
291 * if the platform failed to create an item
292 * there is no point to try other items
297 end_submenu(platform
, submenu
);
299 /* technically, there is nothing to track for the menu engine */
303 UINT
cheetah_menu_mask(struct git_data
*this_
)
306 char *wd
= wd_from_path(this_
->name
, &is_directory
);
307 UINT selection
= is_directory
? MENU_ITEM_DIR
: MENU_ITEM_FILE
;
310 struct strbuf output
;
312 strbuf_init(&output
, 0);
314 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
315 "git", "rev-parse", "--show-prefix", NULL
);
316 eol
= strchr(output
.buf
, '\n');
320 if (status
< 0) /* something went terribly wrong */
321 selection
= MENU_ITEM_LAST
;
323 selection
|= MENU_ITEM_NOREPO
;
325 char head_path
[MAX_PATH
] = "HEAD";
327 sprintf(head_path
, "HEAD:%s%s",
329 this_
->name
+ strlen(wd
) + 1);
331 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
332 "git", "rev-parse", "--verify", head_path
, NULL
);
333 if (status
< 0) /* something went terribly wrong */
334 selection
= MENU_ITEM_LAST
;
336 selection
|= MENU_ITEM_REPO
|
338 MENU_ITEM_NOTRACK
: MENU_ITEM_TRACK
);
341 strbuf_release(&output
);
346 const struct menu_item cheetah_menu
[] = {
347 { MENU_ITEM_ALWAYS
, 0, NULL
, NULL
, build_separator
, NULL
},
349 { MENU_ITEM_REPO
, 0, "Git &Add all files now",
350 "Add all files from this folder now",
351 build_item
, menu_addall
},
352 { MENU_ITEM_REPO
, 0, "Git &Commit Tool",
353 "Launch the GIT commit tool in the local or chosen directory.",
354 build_item
, menu_citool
},
355 { MENU_ITEM_TRACK
, 0, "Git &History",
356 "Show GIT history of the chosen file or directory.",
359 { MENU_ITEM_TRACK
| MENU_ITEM_FILE
, 0, "Git &Blame",
360 "Start a blame viewer on the specified file.",
361 build_item
, menu_blame
},
363 { MENU_ITEM_REPO
, 0, "Git &Gui",
364 "Launch the GIT Gui in the local or chosen directory.",
365 build_item
, menu_gui
},
367 { MENU_ITEM_REPO
, 0, "Git Bra&nch",
369 build_branch_menu
, NULL
},
371 { MENU_ITEM_NOREPO
, 0, "Git I&nit Here",
372 "Initialize GIT repo in the local directory.",
373 build_item
, menu_init
},
374 { MENU_ITEM_NOREPO
| MENU_ITEM_DIR
, 0, "Git &Gui",
375 "Launch the GIT Gui in the local or chosen directory.",
376 build_item
, menu_gui
},
378 { MENU_ITEM_ALWAYS
, 0, "Git Ba&sh",
379 "Start GIT shell in the local or chosen directory",
380 build_item
, menu_bash
},
381 { MENU_ITEM_ALWAYS
, 0, NULL
, NULL
, build_separator
, NULL
},
384 void build_cheetah_menu(struct git_data
*data
, void *platform_data
)
386 reset_platform(platform_data
);
387 build_menu_items(data
, cheetah_menu_mask
,
389 sizeof(cheetah_menu
) / sizeof(cheetah_menu
[0]),