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_git("rev-parse --show-cdup", wd
, P_WAIT
);
48 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
51 * TODO: the following big, ugly code needs to be something like
53 * It's left as is to signify the preview nature of the patch
55 if (0 != status
) { /* this is not a repository */
57 strcpy(menu_item
, "&Git Clone Here");
59 strcpy(menu_item
, "&Git Init Here");
61 strcpy(menu_item
, "&Git");
63 InsertMenu(menu
, index
, MF_SEPARATOR
| MF_BYPOSITION
,
65 InsertMenu(menu
, index
+1, MF_STRING
| MF_BYPOSITION
,
66 first_command
++, menu_item
);
69 * TODO: when the above block is fixed, we'll just have
70 * return MAKE_RESULT(..., build_menu_items());
72 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
,
73 first_command
- original_first
);
77 * Perform a couple of transformations, such that a directory
78 * C:\Program Files\Bunch of stuff\in\A dir
80 * /C/Program\ Files/Bunch\ of\ stuff/in/A\ dir
82 * Assumes path is initially a correctly formed Windows-style path.
83 * Returns a new string.
85 static char *convert_directory_format(const char *path
)
92 /* Figure out how much extra space we need to escape spaces */
93 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
97 converted
= (char *)calloc(size_incr
+ i
+ 1, sizeof(char));
104 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
123 converted
[1] = converted
[0];
129 static STDMETHODIMP
invoke_command(void *p
,
130 LPCMINVOKECOMMANDINFO info
)
132 struct git_menu
*this_menu
= p
;
133 struct git_data
*this_
= this_menu
->git_data
;
134 int command
= LOWORD(info
->lpVerb
);
136 if (HIWORD(info
->lpVerb
) != 0)
145 if (wd
== NULL
|| strlen(wd
) == 0)
146 wd
= info
->lpDirectory
;
148 dwAttr
= FILE_ATTRIBUTE_DIRECTORY
;
149 fa
= GetFileAttributes(wd
);
151 wd
= info
->lpDirectory
;
153 exec_git("gui", wd
, P_NOWAIT
);
161 static STDMETHODIMP
get_command_string(void *p
, UINT id
,
162 UINT flags
, UINT
*reserved
,
163 LPSTR name
, UINT size
)
166 struct git_menu
*this_menu
= p
;
167 struct git_data
*this_
= this_menu
->git_data
;
173 if (flags
& GCS_HELPTEXT
) {
174 LPCTSTR text
= _T("Launch the GIT Gui in the local or chosen directory.");
175 size_t len
= strlen(text
) + 1;
176 LPWSTR tw
= malloc(len
* sizeof(wchar_t));
177 /* need to convert terminating NULL as well */
178 mbstowcs(tw
, text
, len
);
179 /* use Win32 lstrcpyn to [automatically] avoid buffer overflow */
180 if (flags
& GCS_UNICODE
)
181 lstrcpynW((LPWSTR
)name
, tw
, size
);
183 lstrcpynA(name
, text
, size
);
192 DEFINE_STANDARD_METHODS(git_menu
)
194 struct git_menu_virtual_table git_menu_virtual_table
= {
195 query_interface_git_menu
,