7 #include "systeminfo.h"
10 * These are the functions for handling the context menu.
13 static STDMETHODIMP
query_context_menu(void *p
, HMENU menu
,
14 UINT index
, UINT first_command
,
15 UINT last_command
, UINT flags
)
17 struct git_menu
*this_menu
= p
;
18 struct git_data
*this_
= this_menu
->git_data
;
20 if (flags
& CMF_DEFAULTONLY
)
21 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
23 InsertMenu(menu
, index
, MF_SEPARATOR
| MF_BYPOSITION
,
25 InsertMenu(menu
, index
+1, MF_STRING
| MF_BYPOSITION
,
26 first_command
+1, _T("&Git Gui"));
28 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 2);
32 * Perform a couple of transformations, such that a directory
33 * C:\Program Files\Bunch of stuff\in\A dir
35 * /C/Program\ Files/Bunch\ of\ stuff/in/A\ dir
37 * Assumes path is initially a correctly formed Windows-style path.
38 * Returns a new string.
40 static char * convert_directory_format(const char * path
)
45 /* Figure out how much extra space we need to escape spaces */
46 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
50 char * converted
= (char *)calloc(size_incr
+ i
+ 1, sizeof(char));
51 char * dst
= converted
;
57 for (i
= 0; i
< MAX_PATH
&& path
[i
] != '\0'; ++i
)
76 converted
[1] = converted
[0];
82 static void adjust_path_for_git(const char *msys_path
)
84 static int initialized
= 0;
87 const char *old_path
= getenv("PATH");
88 int old_len
= strlen(old_path
);
89 int msys_path_len
= strlen(msys_path
);
90 char *new_path
= malloc(old_len
+ 2 * msys_path_len
+ 23);
93 sprintf(new_path
, "PATH=%s\\bin;%s\\mingw\\bin;%s",
94 old_path
, msys_path
, msys_path
);
100 static STDMETHODIMP
invoke_command(void *p
,
101 LPCMINVOKECOMMANDINFO info
)
103 struct git_menu
*this_menu
= p
;
104 struct git_data
*this_
= this_menu
->git_data
;
105 int command
= LOWORD(info
->lpVerb
);
107 if (HIWORD(info
->lpVerb
) != 0)
112 STARTUPINFO si
= { sizeof(si
) };
113 PROCESS_INFORMATION pi
;
115 TCHAR
* msysPath
= msys_path();
121 adjust_path_for_git(msysPath
);
122 wsprintf(command
, TEXT("wish.exe \"%s/bin/git-gui\""),
126 const char *wd
= this_
->name
;
127 if (wd
== NULL
|| strlen(wd
) == 0)
128 wd
= info
->lpDirectory
;
130 DWORD dwAttr
= FILE_ATTRIBUTE_DIRECTORY
;
131 DWORD fa
= GetFileAttributes(wd
);
133 wd
= info
->lpDirectory
;
135 debug_git("Trying to spawn '%s' in working directory '%s'\n", command
, wd
);
142 0, NULL
, wd
, &si
, &pi
))
144 CloseHandle(pi
.hProcess
);
145 CloseHandle(pi
.hThread
);
149 debug_git("[ERROR] %s/%s:%d Could not create git gui process (%d) Command: %s",
150 __FILE__
, __FUNCTION__
, __LINE__
,
151 GetLastError(), command
);
156 debug_git("[ERROR] %s/%s:%d Could not find msysPath",
157 __FILE__
, __FUNCTION__
, __LINE__
);
166 static STDMETHODIMP
get_command_string(void *p
, UINT id
,
167 UINT flags
, UINT
*reserved
,
168 LPSTR name
, UINT size
)
171 struct git_menu
*this_menu
= p
;
172 struct git_data
*this_
= this_menu
->git_data
;
178 if (flags
& GCS_HELPTEXT
) {
179 LPCTSTR text
= _T("Launch the GIT Gui in the local or chosen directory.");
180 LPWSTR tw
= malloc((strlen(text
)+1)*sizeof(wchar_t));
181 mbstowcs(tw
, text
, strlen(text
));
182 if (flags
& GCS_UNICODE
)
183 lstrcpynW((LPWSTR
)name
, tw
, size
);
185 lstrcpynA(name
, text
, size
);
194 DEFINE_STANDARD_METHODS(git_menu
)
196 struct git_menu_virtual_table git_menu_virtual_table
= {
197 query_interface_git_menu
,