-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmdopts.cpp
executable file
·181 lines (171 loc) · 4.68 KB
/
cmdopts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* UI to control options for plugin commands and the plugin itself.
*/
#include "stdafx.h"
static SCCRTN LGitOptionsCaps(enum SCCCOMMAND cmd)
{
switch (cmd)
{
/*
* We support commit (checkin, add, remove) and get for remote operations.
*/
case SCC_COMMAND_GET:
case SCC_COMMAND_ADD:
case SCC_COMMAND_REMOVE:
case SCC_COMMAND_CHECKIN:
case SCC_COMMAND_OPTIONS:
return SCC_I_ADV_SUPPORT;
default:
return SCC_E_OPNOTSUPPORTED;
}
}
static BOOL CALLBACK CommitOptsDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitContext *param;
/* TODO: We should try to derive a path from the URL until overriden */
switch (iMsg) {
case WM_INITDIALOG:
param = (LGitContext*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
CheckDlgButton(hwnd, IDC_OPTIONS_COMMIT_PUSH, param->commitOpts.push);
LGitLog(" ! Push is %d\n", param->commitOpts.push);
return TRUE;
case WM_COMMAND:
param = (LGitContext*)GetWindowLong(hwnd, GWL_USERDATA);
switch (LOWORD(wParam)) {
case IDOK:
param->commitOpts.push = IsDlgButtonChecked(hwnd, IDC_OPTIONS_COMMIT_PUSH);
LGitLog(" ! Push is now %d\n", param->commitOpts.push);
EndDialog(hwnd, 2);
return TRUE;
case IDCANCEL:
EndDialog(hwnd, 1);
return TRUE;
}
return FALSE;
default:
return FALSE;
}
}
static SCCRTN SetCommitOptions(LGitContext *ctx, HWND hWnd, LPCMDOPTS *opts)
{
if (opts != NULL && *opts == NULL) {
*opts = &ctx->commitOpts;
ZeroMemory(&ctx->commitOpts, sizeof(LGitCommitOpts));
}
switch (DialogBoxParamW(ctx->dllInst,
MAKEINTRESOURCEW(IDD_OPTIONS_COMMIT),
hWnd,
CommitOptsDialogProc,
(LPARAM)ctx)) {
case 0:
case -1:
LGitLog(" ! Uh-oh, dialog error\n");
break;
case 1:
return SCC_I_OPERATIONCANCELED;
case 2:
return SCC_OK;
}
return SCC_E_NONSPECIFICERROR;
}
static BOOL CALLBACK GetOptsDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitContext *param;
/* TODO: We should try to derive a path from the URL until overriden */
switch (iMsg) {
case WM_INITDIALOG:
param = (LGitContext*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
CheckDlgButton(hwnd, IDC_OPTIONS_COMMIT_PULL, param->getOpts.pull);
LGitLog(" ! Pull is %d\n", param->getOpts.pull);
return TRUE;
case WM_COMMAND:
param = (LGitContext*)GetWindowLong(hwnd, GWL_USERDATA);
switch (LOWORD(wParam)) {
case IDOK:
param->getOpts.pull = IsDlgButtonChecked(hwnd, IDC_OPTIONS_COMMIT_PULL);
LGitLog(" ! Pull is now %d\n", param->getOpts.pull);
EndDialog(hwnd, 2);
return TRUE;
case IDCANCEL:
EndDialog(hwnd, 1);
return TRUE;
}
return FALSE;
default:
return FALSE;
}
}
static SCCRTN SetGetOptions(LGitContext *ctx, HWND hWnd, LPCMDOPTS *opts)
{
if (opts != NULL && *opts == NULL) {
*opts = &ctx->getOpts;
ZeroMemory(&ctx->commitOpts, sizeof(LGitGetOpts));
}
switch (DialogBoxParamW(ctx->dllInst,
MAKEINTRESOURCEW(IDD_OPTIONS_GET),
hWnd,
GetOptsDialogProc,
(LPARAM)ctx)) {
case 0:
case -1:
LGitLog(" ! Uh-oh, dialog error\n");
break;
case 1:
return SCC_I_OPERATIONCANCELED;
case 2:
return SCC_OK;
}
return SCC_E_NONSPECIFICERROR;
}
static SCCRTN SetPluginOptions(LGitContext *ctx, HWND hWnd)
{
/* The provided options aren't useful since this is our responsibility. */
MessageBox(hWnd, "Not supported.", "Visual Git Options", MB_ICONERROR);
return SCC_E_OPNOTSUPPORTED;
}
SCCRTN SccGetCommandOptions (LPVOID context,
HWND hWnd,
enum SCCCOMMAND nCommand,
LPCMDOPTS * ppvOptions)
{
LGitLog("**SccGetCommandOptions** Context=%p\n", context);
LGitLog(" command %s\n", LGitCommandName(nCommand));
LGitLog(" options %p\n", ppvOptions);
if (ppvOptions != NULL) {
LGitLog(" *options %p\n", *ppvOptions);
}
LGitContext *ctx = (LGitContext*)context;
/* IDE calls first with NULL to see if we support this option */
if (ppvOptions == NULL) {
return LGitOptionsCaps(nCommand);
}
/* Context may not be open. Don't do things needing repos from dialogs. */
/* Dispatch to shared dialogs. */
SCCRTN ret;
switch (nCommand) {;
case SCC_COMMAND_GET:
ret = SetGetOptions(ctx, hWnd, ppvOptions);
break;
case SCC_COMMAND_ADD:
case SCC_COMMAND_REMOVE:
case SCC_COMMAND_CHECKIN:
ret = SetCommitOptions(ctx, hWnd, ppvOptions);
break;
case SCC_COMMAND_OPTIONS:
ret = SetPluginOptions(ctx, hWnd);
break;
default:
ret = SCC_E_OPNOTSUPPORTED;
break;
}
LGitLog(" ! New ptr %p rc %d\n", *ppvOptions, ret);
return ret;
}