debug_git(): add a newline after each message
[git-cheetah.git] / menu.c
blobab09699d212b7c03863231d983688ccf3f597e93
1 #include <shlobj.h>
2 #include <stdarg.h>
3 #include <tchar.h>
4 #include "menu.h"
5 #include "ext.h"
6 #include "debug.h"
7 #include "systeminfo.h"
9 /*
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_STRING | MF_BYPOSITION,
24 first_command, _T("Git Gui"));
26 return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 1);
29 static STDMETHODIMP invoke_command(void *p,
30 LPCMINVOKECOMMANDINFO info)
32 struct git_menu *this_menu = p;
33 struct git_data *this_ = this_menu->git_data;
34 int command = LOWORD(info->lpVerb);
36 if (HIWORD(info->lpVerb) != 0)
37 return E_INVALIDARG;
39 if (command == 0)
41 STARTUPINFO si = { sizeof(si) };
42 PROCESS_INFORMATION pi;
44 TCHAR * msysPath = msys_path();
46 if (msysPath)
48 TCHAR command[1024];
49 wsprintf(command, TEXT("sh.exe %s\\bin\\git-gui"),
50 msysPath);
52 if (CreateProcess(
53 NULL,
54 command,
55 NULL,
56 NULL,
57 FALSE,
58 0, NULL, NULL, &si, &pi))
60 CloseHandle(pi.hProcess);
61 CloseHandle(pi.hThread);
63 else
65 debug_git("[ERROR] %s/%s:%d Could not create git gui process (%d)",
66 __FILE__, __FUNCTION__, __LINE__,
67 GetLastError());
70 else
72 debug_git("[ERROR] %s/%s:%d Could not find msysPath",
73 __FILE__, __FUNCTION__, __LINE__);
76 return S_OK;
79 return E_INVALIDARG;
82 static STDMETHODIMP get_command_string(void *p, UINT id,
83 UINT flags, UINT *reserved,
84 LPSTR name, UINT size)
86 struct git_menu *this_menu = p;
87 struct git_data *this_ = this_menu->git_data;
89 if (id == 0)
90 return E_INVALIDARG;
92 #if 0
93 if (flags & GCS_HELPTEXT) {
94 LPCTSTR text = _T("This is the simple shell extension's help");
96 if (flags & GCS_UNICODE)
97 lstrcpynW((LPWSTR)name, mbrtowc(text), size);
98 else
99 lstrcpynA(name, text, size);
101 return S_OK;
103 #endif
105 return E_INVALIDARG;
108 DEFINE_STANDARD_METHODS(git_menu)
110 struct git_menu_virtual_table git_menu_virtual_table = {
111 query_interface_git_menu,
112 add_ref_git_menu,
113 release_git_menu,
114 query_context_menu,
115 invoke_command,
116 get_command_string