Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: added copy hook to warn user before deleting .hg directory

Changeset b2bbf1aee6bb

Parent 273b179a0014

by David Golub

Changes to 11 files · Browse files at b2bbf1aee6bb Showing diff from parent 273b179a0014 Diff from another changeset...

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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
 
 
 
 
 
 
 
 
 
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
 // Copyright (C) 2011 Fog Creek Software  //  // This program is free software: you can redistribute it and/or modify  // it under the terms of the GNU General Public License as published by  // the Free Software Foundation, either version 2 of the License, or  // (at your option) any later version.  //  // This program is distributed in the hope that it will be useful,  // but WITHOUT ANY WARRANTY; without even the implied warranty of  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  // GNU General Public License for more details.  //  // You should have received a copy of the GNU General Public License  // along with this program. If not, see <http://www.gnu.org/licenses/>.    #include "stdafx.h"    #include "GlobalData.h"    // According to http://msdn.microsoft.com/en-us/library/bb776094%28VS.85%29.aspx  // the help texts for the commands should be reasonably short (under 40 characters)    const CMenuDescription MenuDescList[] =  {   { "commit", L"Commit...",   L"Commits changes in repository.",   "menucommit.ico", 0},   { "init", L"Create Repository Here",   L"Creates a new repository.",   "menucreaterepos.ico", 0},   { "clone", L"Clone...",   L"Creates a clone of a repository.",   "menuclone.ico", 0},   { "shelve", L"Shelve Changes",   L"Shelves or unshelves file changes.",   "shelve.ico", 0},   { "status", L"View File Status",   L"Shows repository status and changes.",   "menushowchanged.ico", 0},   { "add", L"Add Files...",   L"Adds files to version control.",   "menuadd.ico", 0},   { "revert", L"Revert Files...",   L"Reverts file changes.",   "menurevert.ico", 0},   { "remove", L"Remove Files...",   L"Removes files from version control.",   "menudelete.ico", 0},   { "rename", L"Rename File...",   L"Renames the file or directory.",   "general.ico", 0},   { "workbench", L"Workbench",   L"Shows the change history of the repository.",   "menulog.ico", 0},   { "log", L"Revision History",   L"Shows the change history of the selected files.",   "menulog.ico", 0},   { "synch", L"Synchronize",   L"Synchronizes with a remote repository.",   "menusynch.ico", 0},   { "serve", L"Web Server",   L"Starts the web server for this repository.",   "proxy.ico", 0},   { "update", L"Update...",   L"Updates the working directory.",   "menucheckout.ico", 0},   { "thgstatus", L"Update Icons",   L"Updates icons for this repository.",   "refresh_overlays.ico", 0},   { "userconf", L"Global Settings",   L"Configures user wide settings.",   "settings_user.ico", 0},   { "repoconf", L"Repository Settings",   L"Configures repository settings.",   "settings_repo.ico", 0},   { "about", L"About TortoiseHg",   L"Shows the about dialog.",   "menuabout.ico", 0},   { "annotate", L"Annotate Files",   L"Shows changeset information per file line.",   "menublame.ico", 0},   { "vdiff", L"Visual Diff",   L"Shows changes using the GUI diff tool.",   "TortoiseMerge.ico", 0},   { "hgignore", L"Edit Ignore Filter",   L"Edits the repository ignore filter.",   "ignore.ico", 0},   { "guess", L"Guess Renames",   L"Detects renames and copies.",   "detect_rename.ico", 0},   { "grep", L"Search History",   L"Searches file revisions for patterns.",   "menurepobrowse.ico", 0},   { "forget", L"Forget Files...",   L"Removes files from version control.",   "menudelete.ico", 0},   { "shellconf", L"Explorer Extension Settings",   L"Configures the Explorer extension.",   "settings_repo.ico", 0},   { "kiln", L"Kiln",   L"Opens the current repository in Kiln.",   "kiln.ico", 0 },   { "kilnfiles", L"Kiln",   L"Opens the selected files in Kiln.",   "kiln.ico", 0 },   { "keyboard", L"Keyboard Help",   L"Displays a list of keyboard shortcuts.",   "", 0 },     // Add new items here.   // Template:   // { "cmdname", L"Display Name",   // L"Status bar prompt.",   // "iconfile.ico", 0 },  };  const int MenuDescListCount = sizeof(MenuDescList) / sizeof(CMenuDescription);    // Menu commands shown when the folder is in a repository but no files are selected  const LPCTSTR RepoNoFilesMenu[] =  {   "commit",   "status",   "shelve",   "vdiff",   NULL,   "add",   "revert",   "rename",   "forget",   "remove",   NULL,   "workbench",   "update",   "grep",   NULL,   "kiln",   NULL,   "synch",   "serve",   "clone",   "init"   "thgstatus",   NULL,   "hgignore",   "guess",   NULL,   "shellconf",   "repoconf",   "userconf",   NULL,   "keyboard",   "about",  };  const int RepoNoFilesMenuCount = sizeof(RepoNoFilesMenu) / sizeof(LPCTSTR);    // Menu commands shown when the folder is in a repository and files are selected  const LPCTSTR RepoFilesMenu[] =  {   "commit",   "status",   "vdiff",   NULL,   "add",   "revert",   "rename",   "forget",   "remove",   NULL,   "log",   "annotate",   NULL,   "kilnfiles",   NULL,   "keyboard",   "about",  };  const int RepoFilesMenuCount = sizeof(RepoFilesMenu) / sizeof(LPCTSTR);    // Menu commands shown when the folder is not in a repository  const LPCTSTR NoRepoMenu[] =  {   "clone",   "init",   "shellconf",   "userconf",   "thgstatus",   NULL,   "workbench",   NULL,   "keyboard",   "about",  };  const int NoRepoMenuCount = sizeof(NoRepoMenu) / sizeof(LPCTSTR);    const LPCTSTR DefaultPromotedString = "commit,workbench,kiln,kilnfiles";    // List of all keyboard shortcuts  const CKeyShortcut KeyShortcutList[] =  {   { "add", VK_INSERT, KSF_ALT },   { "remove", VK_DELETE, KSF_ALT },   { "commit", 'C', KSF_CONTROL | KSF_SHIFT },   { "forget", 'F', KSF_CONTROL | KSF_SHIFT },   { "rename", 'M', KSF_CONTROL | KSF_SHIFT },   { "synch", 'S', KSF_CONTROL | KSF_SHIFT },   { "update", 'U', KSF_CONTROL | KSF_SHIFT },   { "revert", 'V', KSF_CONTROL | KSF_SHIFT },   { "workbench", 'W', KSF_CONTROL | KSF_SHIFT },  };  const int KeyShortcutListCount = sizeof(KeyShortcutList) / sizeof(CKeyShortcut); + +// Message displayed if the user tries to delete the internal .hg directory +const LPCTSTR DeleteHgMessage = "The folder you are attempting to delete, .hg, is used " + "internally by Mercurial to store the history of this repository. If you delete " + "this folder, your code will no longer be treated as a source code control " + "repository by Mercurial. If you do no have a backup copy of the repository " + "elsewhere, its history will be lost permanently. Are you sure that you want to " + "delete the .hg folder?"; +const LPCTSTR DeleteHgTitle = "TortoiseHg Warning";
 
50
51
52
 
 
 
 
 
50
51
52
53
54
55
56
@@ -50,3 +50,7 @@
 // Keyboard shortcut data  extern const CKeyShortcut KeyShortcutList[];  extern const int KeyShortcutListCount; + +// Warning messages displayed by the copy hook +extern const LPCTSTR DeleteHgMessage; +extern const LPCTSTR DeleteHgTitle;
 
24
25
26
 
27
28
29
 
35
36
37
 
38
39
40
 
24
25
26
27
28
29
30
 
36
37
38
39
40
41
42
@@ -24,6 +24,7 @@
 #include "TortoiseHgDropHandler.h"  #include "TortoiseHgOverlay.h"  #include "TortoiseHgKeyboard.h" +#include "TortoiseHgCopyHook.h"    CComModule _Module;   @@ -35,6 +36,7 @@
  OBJECT_ENTRY(CLSID_TortoiseHgModified, CTortoiseHgModified)   OBJECT_ENTRY(CLSID_TortoiseHgUnversioned, CTortoiseHgUnversioned)   OBJECT_ENTRY(CLSID_TortoiseHgKeyboard, CTortoiseHgKeyboard) + OBJECT_ENTRY(CLSID_TortoiseHgCopyHook, CTortoiseHgCopyHook)  END_OBJECT_MAP()    BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 
63
64
65
 
 
 
 
 
 
66
 
63
64
65
66
67
68
69
70
71
72
@@ -63,4 +63,10 @@
  {   [default] interface IObjectWithSite;   } + + [uuid(61047697-7E8B-46FE-9CF8-2CE603EB3017)] + coclass TortoiseHgCopyHook + { + [default] interface IUnknown; + }  }
 
30
31
32
 
33
34
35
 
30
31
32
33
34
35
36
@@ -30,6 +30,7 @@
 IDR_MODIFIED REGISTRY "TortoiseHgModified.rgs"  IDR_UNVERSIONED REGISTRY "TortoiseHgUnversioned.rgs"  IDR_KEYBOARD REGISTRY "TortoiseHgKeyboard.rgs" +IDR_COPYHOOK REGISTRY "TortoiseHgCopyHook.rgs"    #ifdef APSTUDIO_INVOKED  /////////////////////////////////////////////////////////////////////////////
 
232
233
234
 
235
236
237
 
260
261
262
 
263
264
265
 
272
273
274
 
275
276
277
 
232
233
234
235
236
237
238
 
261
262
263
264
265
266
267
 
274
275
276
277
278
279
280
@@ -232,6 +232,7 @@
  <ClCompile Include="THgStatus.cpp" />   <ClCompile Include="THgVersion.cpp" />   <ClCompile Include="TortoiseHgCmenu.cpp" /> + <ClCompile Include="TortoiseHgCopyHook.cpp" />   <ClCompile Include="TortoiseHgDropHandler.cpp" />   <ClCompile Include="TortoiseHgKeyboard.cpp" />   <ClCompile Include="TortoiseHgOverlay.cpp" /> @@ -260,6 +261,7 @@
  <ClInclude Include="THgVersion.h" />   <ClInclude Include="TlsPtr.h" />   <ClInclude Include="TortoiseHgCmenu.h" /> + <ClInclude Include="TortoiseHgCopyHook.h" />   <ClInclude Include="TortoiseHgDropHandler.h" />   <ClInclude Include="TortoiseHgKeyboard.h" />   <ClInclude Include="TortoiseHgOverlay.h" /> @@ -272,6 +274,7 @@
  <None Include="THgShell.rc2" />   <None Include="TortoiseHgAdded.rgs" />   <None Include="TortoiseHgCmenu.rgs" /> + <None Include="TortoiseHgCopyHook.rgs" />   <None Include="TortoiseHgDropHandler.rgs" />   <None Include="TortoiseHgKeyboard.rgs" />   <None Include="TortoiseHgModified.rgs" />
 
90
91
92
 
 
 
93
94
95
 
170
171
172
 
 
 
173
174
175
 
199
200
201
 
 
 
202
203
204
 
90
91
92
93
94
95
96
97
98
 
173
174
175
176
177
178
179
180
181
 
205
206
207
208
209
210
211
212
213
@@ -90,6 +90,9 @@
  <ClCompile Include="GlobalData.cpp">   <Filter>Source Files</Filter>   </ClCompile> + <ClCompile Include="TortoiseHgCopyHook.cpp"> + <Filter>Source Files</Filter> + </ClCompile>   </ItemGroup>   <ItemGroup>   <ClInclude Include="Directory.h"> @@ -170,6 +173,9 @@
  <ClInclude Include="TlsPtr.h">   <Filter>Header Files</Filter>   </ClInclude> + <ClInclude Include="TortoiseHgCopyHook.h"> + <Filter>Header Files</Filter> + </ClInclude>   </ItemGroup>   <ItemGroup>   <None Include="THgShell.def"> @@ -199,6 +205,9 @@
  <None Include="TortoiseHgKeyboard.rgs">   <Filter>Resource Files</Filter>   </None> + <None Include="TortoiseHgCopyHook.rgs"> + <Filter>Resource Files</Filter> + </None>   </ItemGroup>   <ItemGroup>   <ResourceCompile Include="THgShell.rc">
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgCopyHook.cpp Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,51 @@
+// Copyright (C) 2011 Fog Creek Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#include "stdafx.h" +#include "THgShell_h.h" + +#include "TortoiseHgCopyHook.h" +#include "RegistryConfig.h" +#include "GlobalData.h" + +CTortoiseHgCopyHook::CTortoiseHgCopyHook() +{ +} + +STDMETHODIMP_(UINT) CTortoiseHgCopyHook::CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, + LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs) +{ + if (wFunc != FO_DELETE || !(dwSrcAttribs & FILE_ATTRIBUTE_DIRECTORY)) return IDYES; + + CString strDirName = pszSrcFile; + if (strDirName.Right(4) != "\\.hg") return IDYES; + + CStringW strMenuText = DeleteHgTitle; + CStringW strHelpText = DeleteHgMessage; + + // Attempt to load localized message and title strings if they exist. + CString strLang; + GetRegistryConfig("CMenuLang", strLang); + if (!strLang.IsEmpty()) + { + CStringW strMenuText2; + CStringW strHelpText2; + GetCMenuTranslation(strLang, "hgwarning", strMenuText, strHelpText); + if (!strMenuText2.IsEmpty()) strMenuText = strMenuText2; + if (!strHelpText2.IsEmpty()) strHelpText = strHelpText2; + } + return ::MessageBoxW(hWnd, strHelpText, strMenuText, + MB_YESNOCANCEL | MB_ICONWARNING); +}
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgCopyHook.h Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,36 @@
+// Copyright (C) 2011 Fog Creek Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#pragma once + +class CTortoiseHgCopyHook : + public CComObjectRootEx<CComMultiThreadModel>, + public CComCoClass<CTortoiseHgCopyHook, &CLSID_TortoiseHgCopyHook>, + public ICopyHook +{ +public: + CTortoiseHgCopyHook(); + + BEGIN_COM_MAP(CTortoiseHgCopyHook) + COM_INTERFACE_ENTRY(ICopyHook) + END_COM_MAP() + + DECLARE_REGISTRY_RESOURCEID(IDR_COPYHOOK) + + // ICopyHook + STDMETHOD_(UINT, CopyCallback)(HWND hWnd, UINT wFunc, UINT wFlags, + LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, + DWORD dwDestAttribs); +};
Change 1 of 1 Show Entire File win32/​shellext/​TortoiseHgCopyHook.rgs Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,45 @@
+HKCR +{ + NoRemove 'CLSID' + { + ForceRemove '{61047697-7E8B-46FE-9CF8-2CE603EB3017}' = s 'TortoiseHg' + { + 'InprocServer32' = s '%MODULE%' + { + val 'ThreadingModel' = s 'Apartment' + } + } + } + 'Directory' + { + 'shellex' + { + 'CopyHookHandlers' + { + 'TortoiseCopyHook' = s '{61047697-7E8B-46FE-9CF8-2CE603EB3017}' + } + } + } +} +HKLM +{ + NoRemove 'Software' + { + NoRemove 'Microsoft' + { + NoRemove 'Windows' + { + NoRemove 'CurrentVersion' + { + NoRemove 'Shell Extensions' + { + NoRemove 'Approved' + { + val '{61047697-7E8B-46FE-9CF8-2CE603EB3017}' = s 'TortoiseHg' + } + } + } + } + } + } +}
 
10
11
12
 
13
14
15
 
17
18
19
20
 
21
22
23
 
10
11
12
13
14
15
16
 
18
19
20
 
21
22
23
24
@@ -10,6 +10,7 @@
 #define IDR_UNVERSIONED 106  #define IDR_KEYBOARD 107  #define IDD_KEYBOARDHELP 108 +#define IDR_COPYHOOK 109  #define IDC_KEYLIST 1000  #define IDC_TOPTEXT 1001   @@ -17,7 +18,7 @@
 //  #ifdef APSTUDIO_INVOKED  #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 109 +#define _APS_NEXT_RESOURCE_VALUE 110  #define _APS_NEXT_COMMAND_VALUE 40001  #define _APS_NEXT_CONTROL_VALUE 1002  #define _APS_NEXT_SYMED_VALUE 101