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

fogcreek shellext: move RunDialog into a separate file

Changeset 1f51c7f62171

Parent 0b8f7055dad4

by David Golub

Changes to 10 files · Browse files at 1f51c7f62171 Showing diff from parent 0b8f7055dad4 Diff from another changeset...

 
54
55
56
57
 
58
59
60
 
67
68
69
70
 
 
71
 
72
73
 
74
75
76
 
54
55
56
 
57
58
59
60
 
67
68
69
 
70
71
72
73
74
 
75
76
77
78
@@ -54,7 +54,7 @@
  }  }   -void KilnOpenFiles(HWND hWnd, const CString& strPath, const CAtlArray<CString>& arrFiles) +void KilnOpenFiles(HWND hWnd, const CString& strPath, const CAtlList<CString>& listFiles)  {   CString strKilnUrl;   if (KilnGetUrl(strPath, &strKilnUrl)) @@ -67,10 +67,12 @@
  GetHgRoot(strPath, strHgRoot);     // Open each file in the default web browser - for (int i = 0; i < arrFiles.GetCount(); i++) + POSITION position = listFiles.GetHeadPosition(); + while (position != NULL)   { + CString strFile = listFiles.GetNext(position);   CString strRelPath; - GetRelPath(strHgRoot, arrFiles[i], strRelPath); + GetRelPath(strHgRoot, strFile, strRelPath);   ::ShellExecute(hWnd, NULL, strKilnUrl + strRelPath, NULL, NULL, SW_SHOW);   }   }
 
18
19
20
21
 
 
18
19
20
 
21
@@ -18,4 +18,4 @@
 bool KilnGetUrl(const CString& strPath, CString* pstrKilnUrl = NULL);  void KilnOpenRepo(HWND hWnd, const CString& strPath);  void KilnOpenFiles(HWND hWnd, const CString& strPath, - const CAtlArray<CString>& arrFiles); + const CAtlList<CString>& arrFiles);
Change 1 of 1 Show Entire File win32/​shellext/​RunDialog.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
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
@@ -0,0 +1,134 @@
+// 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 "RunDialog.h" +#include "TortoiseUtils.h" +#include "StringUtils.h" +#include "THgStatus.h" +#include "Kiln.h" + +void RunDialog(HWND hWnd, const CString& strCmd, const CAtlList<CString>& listFiles, + const CString& strFolder) +{ + CString strDir = GetTHgProgRoot(); + if (strDir.IsEmpty()) + { + ATLTRACE("RunDialog: THG root is empty\n"); + return; + } + CString strHgCmd = strDir + "\\thgw.exe"; + + WIN32_FIND_DATA data; + HANDLE hFind = ::FindFirstFile(strHgCmd, &data); + if (hFind == INVALID_HANDLE_VALUE) + { + strHgCmd = strDir + "\\hgtk.exe"; + hFind = ::FindFirstFile(strHgCmd, &data); + if (hFind == INVALID_HANDLE_VALUE) + { + strHgCmd = strDir + "\\thg.cmd"; + } + else + { + ::FindClose(hFind); + } + } + else + { + ::FindClose(hFind); + } + + strHgCmd = Quote(strHgCmd) + " --nofork " + strCmd; + + CString strCwd; + if (!strFolder.IsEmpty()) + { + strCwd = strFolder; + } + else if (!listFiles.IsEmpty()) + { + strCwd = listFiles.GetHead(); + if (!::PathIsDirectory(strCwd)) strCwd = DirName(strCwd); + } + else + { + ATLTRACE("***** RunDialog: can't get cwd\n"); + return; + } + + if (strCmd == "thgstatus") + { + if (CTHgStatus::Remove(strCwd) != 0) + { + CString strPath = strDir + "\\TortoiseHgOverlayServer.exe"; + LaunchCommand(Quote(strPath), strDir); + } + return; + } + else if (strCmd == "kiln") + { + KilnOpenRepo(hWnd, strCwd); + return; + } + else if (strCmd == "kilnfiles") + { + KilnOpenFiles(hWnd, strCwd, listFiles); + return; + } + + if (!listFiles.IsEmpty()) + { + CString strTempFile = GetTemporaryFile(); + if (strTempFile.IsEmpty()) + { + ATLTRACE("***** RunDialog: error: GetTemporaryFile returned empty string\n"); + return; + } + + ATLTRACE("RunDialog: temp file = %s\n", (LPCTSTR)strTempFile); + HANDLE hTempFile = ::CreateFile(strTempFile, GENERIC_WRITE, FILE_SHARE_READ, 0, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + + if (hTempFile == INVALID_HANDLE_VALUE) + { + ATLTRACE("***** RunDialog: error: failed to create file '%s'\n", + (LPCTSTR)strTempFile); + return; + } + + DWORD dwWritten; + POSITION position = listFiles.GetHeadPosition(); + while (position != NULL) + { + CString strFile = listFiles.GetNext(position); + ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)strFile); + ::WriteFile(hTempFile, (LPCTSTR)strFile, strFile.GetLength(), &dwWritten, 0); + ::WriteFile(hTempFile, "\n", 1, &dwWritten, 0); + } + if (strCmd == "drag_move" || strCmd == "drag_copy") + { + // Append the current directory as the dest. + ::WriteFile(hTempFile, (LPCTSTR)strCwd, strCwd.GetLength(), &dwWritten, 0); + ::WriteFile(hTempFile, "\n", 1, &dwWritten, 0); + } + + ::CloseHandle(hTempFile); + strHgCmd += " --listfile " + Quote(strTempFile); + } + + LaunchCommand(strHgCmd, strCwd); +}
Change 1 of 1 Show Entire File win32/​shellext/​RunDialog.h Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@@ -0,0 +1,19 @@
+// 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 + +void RunDialog(HWND hWnd, const CString& strCmd, const CAtlList<CString>& listFiles, + const CString& strFolder = "");
 
209
210
211
 
212
213
214
 
239
240
241
 
242
243
244
 
209
210
211
212
213
214
215
 
240
241
242
243
244
245
246
@@ -209,6 +209,7 @@
  <ClCompile Include="Kiln.cpp" />   <ClCompile Include="QueryDirstate.cpp" />   <ClCompile Include="RegistryConfig.cpp" /> + <ClCompile Include="RunDialog.cpp" />   <ClCompile Include="stdafx.cpp">   <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>   <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> @@ -239,6 +240,7 @@
  <ClInclude Include="QueryDirstate.h" />   <ClInclude Include="RegistryConfig.h" />   <ClInclude Include="resource.h" /> + <ClInclude Include="RunDialog.h" />   <ClInclude Include="stdafx.h" />   <ClInclude Include="StringUtils.h" />   <ClInclude Include="SysInfo.h" />
 
81
82
83
 
 
 
84
85
86
 
149
150
151
 
 
 
152
153
154
 
81
82
83
84
85
86
87
88
89
 
152
153
154
155
156
157
158
159
160
@@ -81,6 +81,9 @@
  <ClCompile Include="TortoiseHgKeyboard.cpp">   <Filter>Source Files</Filter>   </ClCompile> + <ClCompile Include="RunDialog.cpp"> + <Filter>Source Files</Filter> + </ClCompile>   </ItemGroup>   <ItemGroup>   <ClInclude Include="Directory.h"> @@ -149,6 +152,9 @@
  <ClInclude Include="TortoiseHgKeyboard.h">   <Filter>Header Files</Filter>   </ClInclude> + <ClInclude Include="RunDialog.h"> + <Filter>Header Files</Filter> + </ClInclude>   </ItemGroup>   <ItemGroup>   <None Include="THgShell.def">
 
25
26
27
 
28
29
30
 
490
491
492
493
 
494
495
496
 
499
500
501
502
 
 
503
504
505
 
507
508
509
510
 
511
512
513
514
 
515
516
517
 
633
634
635
636
 
637
638
639
 
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
 
971
972
973
974
 
975
976
977
 
989
990
991
992
 
993
994
995
 
1021
1022
1023
1024
 
1025
1026
1027
 
25
26
27
28
29
30
31
 
491
492
493
 
494
495
496
497
 
500
501
502
 
503
504
505
506
507
 
509
510
511
 
512
513
514
515
 
516
517
518
519
 
635
636
637
 
638
639
640
641
 
823
824
825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
827
828
 
871
872
873
 
874
875
876
877
 
889
890
891
 
892
893
894
895
 
921
922
923
 
924
925
926
927
@@ -25,6 +25,7 @@
 #include "TortoiseIconBitmap.h"  #include "THgVersion.h"  #include "TortoiseHgCmenu.h" +#include "RunDialog.h"  #include "Kiln.h"    #include <msi.h> @@ -490,7 +491,7 @@
  Tokenize(promoted_string, listPromoted, ",");     // Select menu to show - bool bFileMenu = !m_arrFiles.IsEmpty(); + bool bFileMenu = !m_listFiles.IsEmpty();   bool bIsHgRepo = false;   CString strCwd;   if (!m_strFolder.IsEmpty()) @@ -499,7 +500,8 @@
  }   else if (bFileMenu)   { - strCwd = ::PathIsDirectory(m_arrFiles[0]) ? m_arrFiles[0] : DirName(m_arrFiles[0]); + strCwd = m_listFiles.GetHead(); + if (!::PathIsDirectory(strCwd)) strCwd = DirName(strCwd);   }     if (!strCwd.IsEmpty()) @@ -507,11 +509,11 @@
  // check if target directory is a Mercurial repository   CString strRoot = GetHgRepoRoot(strCwd);   bIsHgRepo = !strRoot.IsEmpty(); - if (m_arrFiles.GetCount() == 1 && strRoot == m_arrFiles[0]) + if (m_listFiles.GetCount() == 1 && strRoot == m_listFiles.GetHead())   {   bFileMenu = false;   m_strFolder = strCwd; - m_arrFiles.RemoveAll(); + m_listFiles.RemoveAll();   }   }   @@ -633,7 +635,7 @@
  const CMenuIdCmdMap::CPair* p = m_mapMenuId.Lookup(idCmd);   if (p != NULL)   { - RunDialog(lpcmi->hwnd, p->m_value.strName); + RunDialog(lpcmi->hwnd, p->m_value.strName, m_listFiles, m_strFolder);   hr = S_OK;   }   else @@ -821,108 +823,6 @@
  return S_OK;  }   - -void CTortoiseHgCmenuBase::RunDialog(HWND hWnd, const CString& strCmd) -{ - CString strDir = GetTHgProgRoot(); - if (strDir.IsEmpty()) - { - ATLTRACE("RunDialog: THG root is empty\n"); - return; - } - CString strHgCmd = strDir + "\\thgw.exe"; - - WIN32_FIND_DATA data; - HANDLE hFind = ::FindFirstFile(strHgCmd, &data); - if (hFind == INVALID_HANDLE_VALUE) - { - strHgCmd = strDir + "\\hgtk.exe"; - hFind = ::FindFirstFile(strHgCmd, &data); - if (hFind == INVALID_HANDLE_VALUE) - { - strHgCmd = strDir + "\\thg.cmd"; - } - else - { - ::FindClose(hFind); - } - } - else - { - ::FindClose(hFind); - } - - strHgCmd = Quote(strHgCmd) + " --nofork " + strCmd; - - CString strCwd; - if (!m_strFolder.IsEmpty()) - { - strCwd = m_strFolder; - } - else if (!m_arrFiles.IsEmpty()) - { - strCwd = ::PathIsDirectory(m_arrFiles[0]) ? m_arrFiles[0] : DirName(m_arrFiles[0]); - } - else - { - ATLTRACE("***** RunDialog: can't get cwd\n"); - return; - } - - if (strCmd == "thgstatus") - { - if (CTHgStatus::Remove(strCwd) != 0) - { - CString strPath = strDir + "\\TortoiseHgOverlayServer.exe"; - LaunchCommand(Quote(strPath), strDir); - } - return; - } - else if (strCmd == "kiln") - { - KilnOpenRepo(hWnd, strCwd); - return; - } - else if (strCmd == "kilnfiles") - { - KilnOpenFiles(hWnd, strCwd, m_arrFiles); - return; - } - - if (!m_arrFiles.IsEmpty()) - { - CString strTempFile = GetTemporaryFile(); - if (strTempFile.IsEmpty()) - { - ATLTRACE("***** RunDialog: error: GetTemporaryFile returned empty string\n"); - return; - } - - ATLTRACE("RunDialog: temp file = %s\n", (LPCTSTR)strTempFile); - HANDLE hTempFile = ::CreateFile(strTempFile, GENERIC_WRITE, FILE_SHARE_READ, 0, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (hTempFile == INVALID_HANDLE_VALUE) - { - ATLTRACE("***** RunDialog: error: failed to create file '%s'\n", - (LPCTSTR)strTempFile); - return; - } - - for (int i = 0; i < m_arrFiles.GetCount(); i++) - { - DWORD dwWritten; - ATLTRACE("RunDialog: temp file adding '%s'\n", (LPCTSTR)m_arrFiles[i]); - ::WriteFile(hTempFile, (LPCTSTR)m_arrFiles[i], m_arrFiles[i].GetLength(), &dwWritten, 0); - ::WriteFile(hTempFile, "\n", 1, &dwWritten, 0); - } - ::CloseHandle(hTempFile); - strHgCmd += " --listfile " + Quote(strTempFile); - } - - LaunchCommand(strHgCmd, strCwd); -} -  #ifdef _DEBUG  void CTortoiseHgCmenuBase::PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj)  { @@ -971,7 +871,7 @@
 #endif     m_strFolder.Empty(); - m_arrFiles.RemoveAll(); + m_listFiles.RemoveAll();     if (pDataObj)   { @@ -989,7 +889,7 @@
  if (::DragQueryFile(hDrop, i, szName, MAX_PATH) > 0)   {   ATLTRACE(" DragQueryFile [%d] = '%s'\n", i, szName); - m_arrFiles.Add(szName); + m_listFiles.AddTail(szName);   }   }   } @@ -1021,7 +921,7 @@
    // disable context menu if neither the folder nor the files   // have been found - if (m_strFolder.IsEmpty() && m_arrFiles.IsEmpty()) + if (m_strFolder.IsEmpty() && m_listFiles.IsEmpty())   {   ATLTRACE(" shell extension not available on this object\n");   return E_FAIL;
 
33
34
35
36
 
37
38
39
40
41
42
43
44
45
 
33
34
35
 
36
37
38
39
40
 
 
41
42
43
@@ -33,13 +33,11 @@
  public IShellExtInit  {  protected: - CAtlArray<CString> m_arrFiles; + CAtlList<CString> m_listFiles;   CString m_strFolder;   CMenuDescriptionMap m_mapMenuDesc;   CMenuIdCmdMap m_mapMenuId;   - virtual void RunDialog(HWND hWnd, const CString& strCmd); -   void TweakMenuForVista(HMENU hMenu);   void InitMenuMaps(const CMenuDescription *pMenuDescs, int nCount);   void InsertMenuItemByName(HMENU hMenu, const CString& strName, UINT indexMenu,
 
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
98
99
100
101
 
102
103
104
 
137
138
139
140
 
141
142
143
 
144
145
146
 
164
165
166
167
 
168
169
170
 
79
80
81
 
 
 
 
 
 
 
 
 
82
83
84
 
89
90
91
 
92
93
94
95
 
128
129
130
 
131
132
133
 
134
135
136
137
 
155
156
157
 
158
159
160
161
@@ -79,15 +79,6 @@
  return ResultFromShort(idCmd - idCmdFirst);  }   -void CTortoiseHgDropHandler::RunDialog(HWND hWnd, const CString& strCmd) -{ - if (strCmd == "drag_move" || strCmd == "drag_copy") { - // Append the current directory as the dest. - m_arrFiles.Add(m_strFolder); - } - CTortoiseHgCmenuBase::RunDialog(hWnd, strCmd); -} -  STDMETHODIMP CTortoiseHgDropHandler::Initialize(LPCITEMIDLIST pIDFolder,   LPDATAOBJECT pDataObj, HKEY hRegKey)  { @@ -98,7 +89,7 @@
 #endif     m_strFolder.Empty(); - m_arrFiles.RemoveAll(); + m_listFiles.RemoveAll();     // if a directory background   if (pIDFolder) @@ -137,10 +128,10 @@
  if (GetHgRepoRoot(szName) != strRoot)   {   ATLTRACE(" '%s' isn't in target dir repository\n", szName); - m_arrFiles.RemoveAll(); + m_listFiles.RemoveAll();   break;   } - m_arrFiles.Add(szName); + m_listFiles.AddTail(szName);   }   }   } @@ -164,7 +155,7 @@
    // disable context menu if neither the folder nor the files   // have been found - if (m_arrFiles.IsEmpty()) + if (m_listFiles.IsEmpty())   {   ATLTRACE(" shell extension not available on this object\n");   return E_FAIL;
 
21
22
23
24
25
26
27
28
29
 
21
22
23
 
 
 
24
25
26
@@ -21,9 +21,6 @@
  public CTortoiseHgCmenuBase,   public CComCoClass<CTortoiseHgDropHandler, &CLSID_TortoiseHgDropHandler>  { -protected: - virtual void RunDialog(HWND hWnd, const CString& strCmd); -  public:   CTortoiseHgDropHandler();