8 #include "systeminfo.h"
11 #define LONGEST_MENU_ITEM 40
14 * These are the functions for handling the context menu.
17 static STDMETHODIMP
query_context_menu(void *p
, HMENU menu
,
18 UINT index
, UINT first_command
,
19 UINT last_command
, UINT flags
)
21 struct git_menu
*this_menu
= p
;
22 struct git_data
*this_
= this_menu
->git_data
;
24 BOOL bDirSelected
= TRUE
;
26 UINT original_first
= first_command
;
27 char menu_item
[LONGEST_MENU_ITEM
];
31 if (flags
& CMF_DEFAULTONLY
)
32 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
34 /* figure out the directory */
35 wd
= strdup(this_
->name
);
36 if (!(FILE_ATTRIBUTE_DIRECTORY
& GetFileAttributes(wd
))) {
37 char *c
= strrchr(wd
, '\\');
44 status
= exec_program(wd
, NULL
, NULL
, WAITMODE
,
45 "git", "rev-parse", "--show-cdup", NULL
);
48 /* something really bad happened, could run git */
50 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
53 * TODO: the following big, ugly code needs to be something like
55 * It's left as is to signify the preview nature of the patch
57 if (status
) { /* this is not a repository */
59 strcpy(menu_item
, "&Git Clone Here");
61 strcpy(menu_item
, "&Git Init Here");
63 strcpy(menu_item
, "&Git");
65 InsertMenu(menu
, index
, MF_SEPARATOR
| MF_BYPOSITION
,
67 InsertMenu(menu
, index
+1, MF_STRING
| MF_BYPOSITION
,
68 first_command
++, menu_item
);
71 * TODO: when the above block is fixed, we'll just have
72 * return MAKE_RESULT(..., build_menu_items());
74 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
,
75 first_command
- original_first
);
79 * Perform a couple of transformations, such that a directory
80 * C:\Program Files\Bunch of stuff\in\A dir
82 * /C/Program\ Files/Bunch\ of\ stuff/in/A\ dir
84 * Assumes path is initially a correctly formed Windows-style path.
85 * Returns a new string.
87 static char *convert_directory_format(const char *path
)
94 /* Figure out how much extra space we need to escape spaces */
95 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
99 converted
= (char *)calloc(size_incr
+ i
+ 1, sizeof(char));
106 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
125 converted
[1] = converted
[0];
131 static STDMETHODIMP
invoke_command(void *p
,
132 LPCMINVOKECOMMANDINFO info
)
134 struct git_menu
*this_menu
= p
;
135 struct git_data
*this_
= this_menu
->git_data
;
136 int command
= LOWORD(info
->lpVerb
);
138 if (HIWORD(info
->lpVerb
) != 0)
147 if (wd
== NULL
|| strlen(wd
) == 0)
148 wd
= info
->lpDirectory
;
150 dwAttr
= FILE_ATTRIBUTE_DIRECTORY
;
151 fa
= GetFileAttributes(wd
);
153 wd
= info
->lpDirectory
;
155 exec_program(wd
, NULL
, NULL
, NORMALMODE
,
164 static STDMETHODIMP
get_command_string(void *p
, UINT id
,
165 UINT flags
, UINT
*reserved
,
166 LPSTR name
, UINT size
)
169 struct git_menu
*this_menu
= p
;
170 struct git_data
*this_
= this_menu
->git_data
;
176 if (flags
& GCS_HELPTEXT
) {
177 LPCTSTR text
= _T("Launch the GIT Gui in the local or chosen directory.");
178 size_t len
= strlen(text
) + 1;
179 LPWSTR tw
= malloc(len
* sizeof(wchar_t));
180 /* need to convert terminating NULL as well */
181 mbstowcs(tw
, text
, len
);
182 /* use Win32 lstrcpyn to [automatically] avoid buffer overflow */
183 if (flags
& GCS_UNICODE
)
184 lstrcpynW((LPWSTR
)name
, tw
, size
);
186 lstrcpynA(name
, text
, size
);
195 DEFINE_STANDARD_METHODS(git_menu
)
197 struct git_menu_virtual_table git_menu_virtual_table
= {
198 query_interface_git_menu
,