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_history(struct git_data
*this_
, unsigned int id
)
39 char *wd
= wd_from_path(this_
->name
, &is_directory
);
43 name
= this_
->name
+ strlen(wd
) + 1;
45 exec_program(wd
, NULL
, NULL
, HIDDENMODE
, "sh", "--login", "-i",
46 "/bin/gitk", "HEAD", "--", name
, NULL
);
50 UINT
cheetah_menu_mask(struct git_data
*this_
)
53 char *wd
= wd_from_path(this_
->name
, &is_directory
);
54 UINT selection
= is_directory
? MENU_ITEM_DIR
: MENU_ITEM_FILE
;
59 strbuf_init(&output
, 0);
61 status
= exec_program(wd
, &output
, NULL
, WAITMODE
,
62 "git", "rev-parse", "--show-prefix", NULL
);
63 eol
= strchr(output
.buf
, '\n');
67 if (status
< 0) /* something went terribly wrong */
68 selection
= MENU_ITEM_LAST
;
70 selection
|= MENU_ITEM_NOREPO
;
72 char head_path
[MAX_PATH
] = "HEAD";
74 sprintf(head_path
, "HEAD:%s%s",
76 this_
->name
+ strlen(wd
) + 1);
78 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
79 "git", "rev-parse", "--verify", head_path
, NULL
);
80 if (status
< 0) /* something went terribly wrong */
81 selection
= MENU_ITEM_LAST
;
83 selection
|= MENU_ITEM_REPO
|
85 MENU_ITEM_NOTRACK
: MENU_ITEM_TRACK
);
88 strbuf_release(&output
);
93 const struct menu_item cheetah_menu
[] = {
94 { MENU_ITEM_ALWAYS
, NULL
, NULL
, build_separator
, NULL
},
96 { MENU_ITEM_TRACK
, "Git &History",
97 "Show GIT history of the chosen file or directory.",
101 { MENU_ITEM_REPO
, "&Git",
102 "Launch the GIT Gui in the local or chosen directory.",
103 build_item
, menu_gui
},
105 { MENU_ITEM_NOREPO
| MENU_ITEM_FILE
, "&Git Init Here",
106 "Initialize GIT repo in the local directory.",
107 build_item
, menu_gui
},
108 { MENU_ITEM_NOREPO
| MENU_ITEM_DIR
, "&Git Clone Here",
109 "Clone GIT repo into the local or chosen directory.",
110 build_item
, menu_gui
},
113 void build_cheetah_menu(struct git_data
*data
, void *platform_data
)
115 reset_platform(platform_data
);
116 build_menu_items(data
, cheetah_menu_mask
,
118 sizeof(cheetah_menu
) / sizeof(cheetah_menu
[0]),