4 #include "menuengine.h"
5 #include "cheetahmenu.h"
8 char *wd_from_path(const char *path
, BOOL
*is_path_dir
)
10 BOOL is_directory
= TRUE
;
11 char *cheetah_wd
= strdup(path
);
12 if (!(FILE_ATTRIBUTE_DIRECTORY
& GetFileAttributes(cheetah_wd
))) {
13 char *c
= strrchr(cheetah_wd
, '\\');
14 if (c
) /* sanity check in case it's a weird directory */
21 *is_path_dir
= is_directory
;
27 * Cheetah-specific menu
30 static void menu_gui(struct git_data
*this_
, UINT id
)
32 char *wd
= wd_from_path(this_
->name
, NULL
);
33 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "gui", NULL
);
37 static void menu_init(struct git_data
*this_
, UINT id
)
39 char *wd
= wd_from_path(this_
->name
, NULL
);
40 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "init", NULL
);
44 static void menu_history(struct git_data
*this_
, unsigned int id
)
47 char *wd
= wd_from_path(this_
->name
, &is_directory
);
51 name
= this_
->name
+ strlen(wd
) + 1;
53 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "sh", "--login", "-i",
54 "/bin/gitk", "HEAD", "--", name
, NULL
);
58 static void menu_bash(struct git_data
*this_
, UINT id
)
60 char *wd
= wd_from_path(this_
->name
, NULL
);
61 /* start is required because exec_program does not create a window */
62 exec_program(wd
, NULL
, NULL
, NORMALMODE
,
63 "start", "sh", "--login", "-i", NULL
);
67 static void menu_blame(struct git_data
*this_
, UINT id
)
70 char *wd
= wd_from_path(this_
->name
, &is_directory
);
74 name
= this_
->name
+ strlen(wd
) + 1;
75 exec_program(wd
, NULL
, NULL
, HIDDENMODE
,
76 "git", "gui", "blame", name
, NULL
);
82 static void menu_citool(struct git_data
*this_
, UINT id
)
84 char *wd
= wd_from_path(this_
->name
, NULL
);
85 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "citool", NULL
);
89 static void menu_addall(struct git_data
*this_
, UINT id
)
91 char *wd
= wd_from_path(this_
->name
, NULL
);
92 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "add", "--all", NULL
);
96 static void menu_branch(struct git_data
*this_
, UINT id
)
99 char *wd
= wd_from_path(this_
->name
, NULL
);
101 strbuf_init(&err
, 0);
103 status
= exec_program(wd
, NULL
, &err
, HIDDENMODE
,
104 "git", "checkout", get_menu_item_text(id
), NULL
);
106 /* if nothing, terribly wrong happened, show the confirmation */
108 /* strangely enough even success message is on stderr */
109 debug_git_mbox(err
.buf
);
114 static BOOL
build_branch_menu(struct git_data
*data
,
115 const struct menu_item
*item
,
121 char *wd
= wd_from_path(data
->name
, NULL
);
123 struct strbuf output
;
124 struct strbuf
**lines
, **it
;
125 strbuf_init(&output
, 0);
127 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
128 "git", "branch", NULL
);
133 submenu
= start_submenu(data
, item
, platform
);
135 lines
= strbuf_split(&output
, '\n');
136 for (it
= lines
; *it
; it
++) {
137 struct menu_item item
= {
144 item
.string
= strdup((*it
)->buf
+ 2);
145 item
.helptext
= strdup((*it
)->buf
+ 2);
146 if (build_item(data
, &item
, submenu
)) {
147 check_menu_item(submenu
, '*' == (*it
)->buf
[0]);
148 append_active_menu(item
);
151 * if the platform failed to create an item
152 * there is no point to try other items
157 end_submenu(platform
, submenu
);
159 /* technically, there is nothing to track for the menu engine */
163 UINT
cheetah_menu_mask(struct git_data
*this_
)
166 char *wd
= wd_from_path(this_
->name
, &is_directory
);
167 UINT selection
= is_directory
? MENU_ITEM_DIR
: MENU_ITEM_FILE
;
170 struct strbuf output
;
172 strbuf_init(&output
, 0);
174 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
175 "git", "rev-parse", "--show-prefix", NULL
);
176 eol
= strchr(output
.buf
, '\n');
180 if (status
< 0) /* something went terribly wrong */
181 selection
= MENU_ITEM_LAST
;
183 selection
|= MENU_ITEM_NOREPO
;
185 char head_path
[MAX_PATH
] = "HEAD";
187 sprintf(head_path
, "HEAD:%s%s",
189 this_
->name
+ strlen(wd
) + 1);
191 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
192 "git", "rev-parse", "--verify", head_path
, NULL
);
193 if (status
< 0) /* something went terribly wrong */
194 selection
= MENU_ITEM_LAST
;
196 selection
|= MENU_ITEM_REPO
|
198 MENU_ITEM_NOTRACK
: MENU_ITEM_TRACK
);
201 strbuf_release(&output
);
206 const struct menu_item cheetah_menu
[] = {
207 { MENU_ITEM_ALWAYS
, NULL
, NULL
, build_separator
, NULL
},
209 { MENU_ITEM_REPO
, "Git &Add all files now",
210 "Add all files from this folder now",
211 build_item
, menu_addall
},
212 { MENU_ITEM_REPO
, "Git &Commit Tool",
213 "Launch the GIT commit tool in the local or chosen directory.",
214 build_item
, menu_citool
},
215 { MENU_ITEM_TRACK
, "Git &History",
216 "Show GIT history of the chosen file or directory.",
219 { MENU_ITEM_TRACK
| MENU_ITEM_FILE
, "Git &Blame",
220 "Start a blame viewer on the specified file.",
221 build_item
, menu_blame
},
223 { MENU_ITEM_REPO
, "Git &Gui",
224 "Launch the GIT Gui in the local or chosen directory.",
225 build_item
, menu_gui
},
227 { MENU_ITEM_REPO
, "Git Bra&nch",
229 build_branch_menu
, NULL
},
231 { MENU_ITEM_NOREPO
, "Git I&nit Here",
232 "Initialize GIT repo in the local directory.",
233 build_item
, menu_init
},
234 { MENU_ITEM_NOREPO
| MENU_ITEM_DIR
, "Git &Gui",
235 "Launch the GIT Gui in the local or chosen directory.",
236 build_item
, menu_gui
},
238 { MENU_ITEM_ALWAYS
, "Git Ba&sh",
239 "Start GIT shell in the local or chosen directory",
240 build_item
, menu_bash
},
241 { MENU_ITEM_ALWAYS
, NULL
, NULL
, build_separator
, NULL
},
244 void build_cheetah_menu(struct git_data
*data
, void *platform_data
)
246 reset_platform(platform_data
);
247 build_menu_items(data
, cheetah_menu_mask
,
249 sizeof(cheetah_menu
) / sizeof(cheetah_menu
[0]),