4 #include "menuengine.h"
5 #include "cheetahmenu.h"
7 char *wd_from_path(const char *path
, BOOL
*is_path_dir
)
9 BOOL is_directory
= TRUE
;
10 char *cheetah_wd
= strdup(path
);
11 if (!(FILE_ATTRIBUTE_DIRECTORY
& GetFileAttributes(cheetah_wd
))) {
12 char *c
= strrchr(cheetah_wd
, '\\');
13 if (c
) /* sanity check in case it's a weird directory */
20 *is_path_dir
= is_directory
;
26 * Cheetah-specific menu
29 static void menu_gui(struct git_data
*this_
, UINT id
)
31 char *wd
= wd_from_path(this_
->name
, NULL
);
32 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "gui", NULL
);
36 static void menu_init(struct git_data
*this_
, UINT id
)
38 char *wd
= wd_from_path(this_
->name
, NULL
);
39 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "init", NULL
);
43 static void menu_history(struct git_data
*this_
, unsigned int id
)
46 char *wd
= wd_from_path(this_
->name
, &is_directory
);
50 name
= this_
->name
+ strlen(wd
) + 1;
52 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "sh", "--login", "-i",
53 "/bin/gitk", "HEAD", "--", name
, NULL
);
57 static void menu_bash(struct git_data
*this_
, UINT id
)
59 char *wd
= wd_from_path(this_
->name
, NULL
);
60 /* start is required because exec_program does not create a window */
61 exec_program(wd
, NULL
, NULL
, NORMALMODE
,
62 "start", "sh", "--login", "-i", NULL
);
66 static void menu_blame(struct git_data
*this_
, UINT id
)
69 char *wd
= wd_from_path(this_
->name
, &is_directory
);
73 name
= this_
->name
+ strlen(wd
) + 1;
74 exec_program(wd
, NULL
, NULL
, HIDDENMODE
,
75 "git", "gui", "blame", name
, NULL
);
81 static void menu_citool(struct git_data
*this_
, UINT id
)
83 char *wd
= wd_from_path(this_
->name
, NULL
);
84 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "citool", NULL
);
88 static void menu_addall(struct git_data
*this_
, UINT id
)
90 char *wd
= wd_from_path(this_
->name
, NULL
);
91 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "git", "add", "--all", NULL
);
95 UINT
cheetah_menu_mask(struct git_data
*this_
)
98 char *wd
= wd_from_path(this_
->name
, &is_directory
);
99 UINT selection
= is_directory
? MENU_ITEM_DIR
: MENU_ITEM_FILE
;
102 struct strbuf output
;
104 strbuf_init(&output
, 0);
106 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
107 "git", "rev-parse", "--show-prefix", NULL
);
108 eol
= strchr(output
.buf
, '\n');
112 if (status
< 0) /* something went terribly wrong */
113 selection
= MENU_ITEM_LAST
;
115 selection
|= MENU_ITEM_NOREPO
;
117 char head_path
[MAX_PATH
] = "HEAD";
119 sprintf(head_path
, "HEAD:%s%s",
121 this_
->name
+ strlen(wd
) + 1);
123 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
124 "git", "rev-parse", "--verify", head_path
, NULL
);
125 if (status
< 0) /* something went terribly wrong */
126 selection
= MENU_ITEM_LAST
;
128 selection
|= MENU_ITEM_REPO
|
130 MENU_ITEM_NOTRACK
: MENU_ITEM_TRACK
);
133 strbuf_release(&output
);
138 const struct menu_item cheetah_menu
[] = {
139 { MENU_ITEM_ALWAYS
, NULL
, NULL
, build_separator
, NULL
},
141 { MENU_ITEM_REPO
, "Git &Add all files now",
142 "Add all files from this folder now",
143 build_item
, menu_addall
},
144 { MENU_ITEM_REPO
, "Git &Commit Tool",
145 "Launch the GIT commit tool in the local or chosen directory.",
146 build_item
, menu_citool
},
147 { MENU_ITEM_TRACK
, "Git &History",
148 "Show GIT history of the chosen file or directory.",
151 { MENU_ITEM_TRACK
| MENU_ITEM_FILE
, "Git &Blame",
152 "Start a blame viewer on the specified file.",
153 build_item
, menu_blame
},
155 { MENU_ITEM_REPO
, "Git &Gui",
156 "Launch the GIT Gui in the local or chosen directory.",
157 build_item
, menu_gui
},
159 { MENU_ITEM_NOREPO
, "Git I&nit Here",
160 "Initialize GIT repo in the local directory.",
161 build_item
, menu_init
},
162 { MENU_ITEM_NOREPO
| MENU_ITEM_DIR
, "Git &Gui",
163 "Launch the GIT Gui in the local or chosen directory.",
164 build_item
, menu_gui
},
166 { MENU_ITEM_ALWAYS
, "Git Ba&sh",
167 "Start GIT shell in the local or chosen directory",
168 build_item
, menu_bash
},
169 { MENU_ITEM_ALWAYS
, NULL
, NULL
, build_separator
, NULL
},
172 void build_cheetah_menu(struct git_data
*data
, void *platform_data
)
174 reset_platform(platform_data
);
175 build_menu_items(data
, cheetah_menu_mask
,
177 sizeof(cheetah_menu
) / sizeof(cheetah_menu
[0]),