OSDN Git Service

Commit DialogBox compile Okay
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / CommitDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "CommitDlg.h"\r
22 #include "DirFileEnum.h"\r
23 //#include "GitConfig.h"\r
24 //#include "GitProperties.h"\r
25 #include "MessageBox.h"\r
26 #include "AppUtils.h"\r
27 #include "PathUtils.h"\r
28 //#include "Git.h"\r
29 #include "Registry.h"\r
30 #include "GitStatus.h"\r
31 #include "HistoryDlg.h"\r
32 #include "Hooks.h"\r
33 \r
34 #ifdef _DEBUG\r
35 #define new DEBUG_NEW\r
36 #undef THIS_FILE\r
37 static char THIS_FILE[] = __FILE__;\r
38 #endif\r
39 \r
40 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));\r
41 \r
42 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)\r
43 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)\r
44         : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)\r
45         , m_bRecursive(FALSE)\r
46         , m_bShowUnversioned(FALSE)\r
47         , m_bBlock(FALSE)\r
48         , m_bThreadRunning(FALSE)\r
49         , m_bRunThread(FALSE)\r
50         , m_pThread(NULL)\r
51         , m_bKeepLocks(FALSE)\r
52         , m_bKeepChangeList(TRUE)\r
53         , m_itemsCount(0)\r
54         , m_bSelectFilesForCommit(TRUE)\r
55 {\r
56 }\r
57 \r
58 CCommitDlg::~CCommitDlg()\r
59 {\r
60         if(m_pThread != NULL)\r
61         {\r
62                 delete m_pThread;\r
63         }\r
64 }\r
65 \r
66 void CCommitDlg::DoDataExchange(CDataExchange* pDX)\r
67 {\r
68         CResizableStandAloneDialog::DoDataExchange(pDX);\r
69         DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);\r
70         DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);\r
71         DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);\r
72         DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);\r
73         DDX_Text(pDX, IDC_BUGID, m_sBugID);\r
74         DDX_Check(pDX, IDC_KEEPLOCK, m_bKeepLocks);\r
75         DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);\r
76         DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);\r
77 }\r
78 \r
79 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)\r
80         ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)\r
81         ON_BN_CLICKED(IDHELP, OnBnClickedHelp)\r
82         ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)\r
83 //      ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)\r
84         ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)\r
85         ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)\r
86 //      ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)\r
87 //      ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)\r
88 //      ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)\r
89 //      ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)\r
90         ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady) \r
91         ON_WM_TIMER()\r
92     ON_WM_SIZE()\r
93         ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)\r
94 END_MESSAGE_MAP()\r
95 \r
96 BOOL CCommitDlg::OnInitDialog()\r
97 {\r
98         CResizableStandAloneDialog::OnInitDialog();\r
99         \r
100         m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);\r
101         m_bShowUnversioned = m_regAddBeforeCommit;\r
102 \r
103         m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));\r
104 \r
105         m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);\r
106         m_bKeepChangeList = m_regKeepChangelists;\r
107 \r
108 //      GitConfig config;\r
109 //      m_bKeepLocks = config.KeepLocks();\r
110 \r
111         UpdateData(FALSE);\r
112         \r
113 //      m_ListCtrl.Init(GitSLC_COLEXT | GitSLC_COLTEXTSTATUS | GitSLC_COLPROPSTATUS | GitSLC_COLLOCK, _T("CommitDlg"));\r
114 //      m_ListCtrl.SetSelectButton(&m_SelectAll);\r
115 //      m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));\r
116 //      m_ListCtrl.SetCancelBool(&m_bCancelled);\r
117 //      m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);\r
118 //      m_ListCtrl.EnableFileDrop();\r
119 //      m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);\r
120         \r
121 //      m_ProjectProperties.ReadPropsPathList(m_pathList);\r
122         m_cLogMessage.Init(m_ProjectProperties);\r
123         m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));\r
124         m_cLogMessage.RegisterContextMenuHandler(this);\r
125 \r
126         OnEnChangeLogmessage();\r
127 \r
128         m_tooltips.Create(this);\r
129         m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);\r
130 //      m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);\r
131         \r
132         m_SelectAll.SetCheck(BST_INDETERMINATE);\r
133 \r
134 #if 0\r
135         CBugTraqAssociations bugtraq_associations;\r
136         bugtraq_associations.Load();\r
137 \r
138         if (bugtraq_associations.FindProvider(m_pathList, &m_bugtraq_association))\r
139         {\r
140                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
141                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
142 \r
143                 CComPtr<IBugTraqProvider> pProvider;\r
144                 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());\r
145                 if (SUCCEEDED(hr))\r
146                 {\r
147                         m_BugTraqProvider = pProvider;\r
148                         BSTR temp = NULL;\r
149                         if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))\r
150                         {\r
151                                 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);\r
152                                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);\r
153                                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);\r
154                         }\r
155 \r
156                         SysFreeString(temp);\r
157                 }\r
158 \r
159                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
160         }\r
161         else if (!m_ProjectProperties.sMessage.IsEmpty())\r
162         {\r
163                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);\r
164                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);\r
165                 if (!m_ProjectProperties.sLabel.IsEmpty())\r
166                         SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);\r
167                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
168                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
169                 GetDlgItem(IDC_BUGID)->SetFocus();\r
170                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);\r
171                 if (!sBugID.IsEmpty())\r
172                 {\r
173                         SetDlgItemText(IDC_BUGID, sBugID);\r
174                 }\r
175         }\r
176         else\r
177         {\r
178                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
179                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
180                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
181                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
182                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
183         }\r
184 #endif\r
185         if (!m_sLogMessage.IsEmpty())\r
186                 m_cLogMessage.SetText(m_sLogMessage);\r
187                 \r
188         GetWindowText(m_sWindowTitle);\r
189         \r
190         AdjustControlSize(IDC_SHOWUNVERSIONED);\r
191         AdjustControlSize(IDC_SELECTALL);\r
192         AdjustControlSize(IDC_KEEPLOCK);\r
193 \r
194         GetClientRect(m_DlgOrigRect);\r
195         m_cLogMessage.GetClientRect(m_LogMsgOrigRect);\r
196 \r
197         AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);\r
198         AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);\r
199         AddAnchor(IDC_BUGID, TOP_RIGHT);\r
200         AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);\r
201         AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);\r
202         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
203 //      AddAnchor(IDC_HISTORY, TOP_LEFT);\r
204         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
205         \r
206         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
207         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
208         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
209         AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);\r
210         AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);\r
211         AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);\r
212         AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
213         AddAnchor(IDC_KEEPLOCK, BOTTOM_LEFT);\r
214         AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);\r
215         AddAnchor(IDOK, BOTTOM_RIGHT);\r
216         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
217         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
218         if (hWndExplorer)\r
219                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
220         EnableSaveRestore(_T("CommitDlg"));\r
221         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
222         RECT rcDlg, rcLogMsg, rcFileList;\r
223         GetClientRect(&rcDlg);\r
224         m_cLogMessage.GetWindowRect(&rcLogMsg);\r
225         ScreenToClient(&rcLogMsg);\r
226         m_ListCtrl.GetWindowRect(&rcFileList);\r
227         ScreenToClient(&rcFileList);\r
228         if (yPos)\r
229         {\r
230                 RECT rectSplitter;\r
231                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
232                 ScreenToClient(&rectSplitter);\r
233                 int delta = yPos - rectSplitter.top;\r
234                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
235                 {\r
236                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
237                         DoSize(delta);\r
238                 }\r
239         }\r
240 \r
241         // add all directories to the watcher\r
242         for (int i=0; i<m_pathList.GetCount(); ++i)\r
243         {\r
244                 if (m_pathList[i].IsDirectory())\r
245                         m_pathwatcher.AddPath(m_pathList[i]);\r
246         }\r
247 \r
248         m_updatedPathList = m_pathList;\r
249 \r
250         //first start a thread to obtain the file list with the status without\r
251         //blocking the dialog\r
252         InterlockedExchange(&m_bBlock, TRUE);\r
253         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
254         if (m_pThread==NULL)\r
255         {\r
256                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
257                 InterlockedExchange(&m_bBlock, FALSE);\r
258         }\r
259         else\r
260         {\r
261                 m_pThread->m_bAutoDelete = FALSE;\r
262                 m_pThread->ResumeThread();\r
263         }\r
264         CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);\r
265         CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);\r
266         if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))\r
267         {\r
268                 historyhint = TRUE;\r
269 //              ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);\r
270         }\r
271         err = FALSE;\r
272 \r
273 \r
274         return FALSE;  // return TRUE unless you set the focus to a control\r
275         // EXCEPTION: OCX Property Pages should return FALSE\r
276 }\r
277 \r
278 void CCommitDlg::OnOK()\r
279 {\r
280         if (m_bBlock)\r
281                 return;\r
282         if (m_bThreadRunning)\r
283         {\r
284                 m_bCancelled = true;\r
285                 InterlockedExchange(&m_bRunThread, FALSE);\r
286                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
287                 if (m_bThreadRunning)\r
288                 {\r
289                         // we gave the thread a chance to quit. Since the thread didn't\r
290                         // listen to us we have to kill it.\r
291                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
292                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
293                 }\r
294         }\r
295         CString id;\r
296         GetDlgItemText(IDC_BUGID, id);\r
297         if (!m_ProjectProperties.CheckBugID(id))\r
298         {\r
299                 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);\r
300                 return;\r
301         }\r
302         m_sLogMessage = m_cLogMessage.GetText();\r
303         if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))\r
304         {\r
305                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
306                         return;\r
307         }\r
308 \r
309 #if 0\r
310         CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);\r
311         if (!(DWORD)regUnversionedRecurse)\r
312         {\r
313                 // Find unversioned directories which are marked for commit. The user might expect them\r
314                 // to be added recursively since he cannot the the files. Let's ask the user if he knows\r
315                 // what he is doing.\r
316                 int nListItems = m_ListCtrl.GetItemCount();\r
317                 for (int j=0; j<nListItems; j++)\r
318                 {\r
319                         const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
320                         if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )\r
321                         {\r
322                                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
323                                         return;\r
324                         }\r
325                 }\r
326         }\r
327 #endif\r
328         m_pathwatcher.Stop();\r
329         InterlockedExchange(&m_bBlock, TRUE);\r
330         CDWordArray arDeleted;\r
331         //first add all the unversioned files the user selected\r
332         //and check if all versioned files are selected\r
333         int nUnchecked = 0;\r
334         m_bRecursive = true;\r
335         int nListItems = m_ListCtrl.GetItemCount();\r
336 \r
337         CTGitPathList itemsToAdd;\r
338         CTGitPathList itemsToRemove;\r
339         bool bCheckedInExternal = false;\r
340         bool bHasConflicted = false;\r
341         std::set<CString> checkedLists;\r
342         std::set<CString> uncheckedLists;\r
343 #if 0\r
344         for (int j=0; j<nListItems; j++)\r
345         {\r
346                 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
347                 if (entry->IsChecked())\r
348                 {\r
349                         if (entry->status == Git_wc_status_unversioned)\r
350                         {\r
351                                 itemsToAdd.AddPath(entry->GetPath());\r
352                         }\r
353                         if (entry->status == Git_wc_status_conflicted)\r
354                         {\r
355                                 bHasConflicted = true;\r
356                         }\r
357                         if (entry->status == Git_wc_status_missing)\r
358                         {\r
359                                 itemsToRemove.AddPath(entry->GetPath());\r
360                         }\r
361                         if (entry->status == Git_wc_status_deleted)\r
362                         {\r
363                                 arDeleted.Add(j);\r
364                         }\r
365                         if (entry->IsInExternal())\r
366                         {\r
367                                 bCheckedInExternal = true;\r
368                         }\r
369                         checkedLists.insert(entry->GetChangeList());\r
370                 }\r
371                 else\r
372                 {\r
373                         if ((entry->status != Git_wc_status_unversioned)        &&\r
374                                 (entry->status != Git_wc_status_ignored))\r
375                         {\r
376                                 nUnchecked++;\r
377                                 uncheckedLists.insert(entry->GetChangeList());\r
378                                 if (m_bRecursive)\r
379                                 {\r
380                                         // This algorithm is for the sake of simplicity of the complexity O(N?\r
381                                         for (int k=0; k<nListItems; k++)\r
382                                         {\r
383                                                 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);\r
384                                                 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath())  )\r
385                                                 {\r
386                                                         // Fall back to a non-recursive commit to prevent items being\r
387                                                         // committed which aren't checked although its parent is checked\r
388                                                         // (property change, directory deletion, ... )\r
389                                                         m_bRecursive = false;\r
390                                                         break;\r
391                                                 }\r
392                                         }\r
393                                 }\r
394                         }\r
395                 }\r
396         }\r
397 #endif\r
398 \r
399 #if 0\r
400         if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)\r
401         {\r
402                 // There are paths which got changed (touched at least).\r
403                 // We have to find out if this affects the selection in the commit dialog\r
404                 // If it could affect the selection, revert back to a non-recursive commit\r
405                 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();\r
406                 changedList.RemoveDuplicates();\r
407                 for (int i=0; i<changedList.GetCount(); ++i)\r
408                 {\r
409                         if (changedList[i].IsAdminDir())\r
410                         {\r
411                                 // something inside an admin dir was changed.\r
412                                 // if it's the entries file, then we have to fully refresh because\r
413                                 // files may have been added/removed from version control\r
414                                 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&\r
415                                         (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))\r
416                                 {\r
417                                         m_bRecursive = false;\r
418                                         break;\r
419                                 }\r
420                         }\r
421                         else if (!m_ListCtrl.IsPathShown(changedList[i]))\r
422                         {\r
423                                 // a path which is not shown in the list has changed\r
424                                 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);\r
425                                 if (entry)\r
426                                 {\r
427                                         // check if the changed path would get committed by a recursive commit\r
428                                         if ((!entry->IsFromDifferentRepository()) &&\r
429                                                 (!entry->IsInExternal()) &&\r
430                                                 (!entry->IsNested()) && \r
431                                                 (!entry->IsChecked()))\r
432                                         {\r
433                                                 m_bRecursive = false;\r
434                                                 break;\r
435                                         }\r
436                                 }\r
437                         }\r
438                 }\r
439         }\r
440 \r
441 \r
442         // Now, do all the adds - make sure that the list is sorted so that parents \r
443         // are added before their children\r
444         itemsToAdd.SortByPathname();\r
445         Git Git;\r
446         if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))\r
447         {\r
448                 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
449                 InterlockedExchange(&m_bBlock, FALSE);\r
450                 Refresh();\r
451                 return;\r
452         }\r
453 \r
454         // Remove any missing items\r
455         // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point\r
456         itemsToRemove.SortByPathname();\r
457         Git.Remove(itemsToRemove, TRUE);\r
458 \r
459         //the next step: find all deleted files and check if they're \r
460         //inside a deleted folder. If that's the case, then remove those\r
461         //files from the list since they'll get deleted by the parent\r
462         //folder automatically.\r
463         m_ListCtrl.Block(TRUE, FALSE);\r
464         INT_PTR nDeleted = arDeleted.GetCount();\r
465         for (INT_PTR i=0; i<arDeleted.GetCount(); i++)\r
466         {\r
467                 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))\r
468                 {\r
469                         const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();\r
470                         if (path.IsDirectory())\r
471                         {\r
472                                 //now find all children of this directory\r
473                                 for (int j=0; j<arDeleted.GetCount(); j++)\r
474                                 {\r
475                                         if (i!=j)\r
476                                         {\r
477                                                 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));\r
478                                                 if (childEntry->IsChecked())\r
479                                                 {\r
480                                                         if (path.IsAncestorOf(childEntry->GetPath()))\r
481                                                         {\r
482                                                                 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);\r
483                                                                 nDeleted--;\r
484                                                         }\r
485                                                 }\r
486                                         }\r
487                                 }\r
488                         }\r
489                 }\r
490         } \r
491         m_ListCtrl.Block(FALSE, FALSE);\r
492 \r
493         if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))\r
494         {\r
495                 //save only the files the user has checked into the temporary file\r
496                 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);\r
497         }\r
498         m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);\r
499         // the item count is used in the progress dialog to show the overall commit\r
500         // progress.\r
501         // deleted items only send one notification event, all others send two\r
502         m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();\r
503 \r
504         if ((m_bRecursive)&&(checkedLists.size() == 1))\r
505         {\r
506                 // all checked items belong to the same changelist\r
507                 // find out if there are any unchecked items which belong to that changelist\r
508                 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())\r
509                         m_sChangeList = *checkedLists.begin();\r
510         }\r
511 #endif\r
512         UpdateData();\r
513         m_regAddBeforeCommit = m_bShowUnversioned;\r
514         if (!GetDlgItem(IDC_KEEPLOCK)->IsWindowEnabled())\r
515                 m_bKeepLocks = FALSE;\r
516         m_regKeepChangelists = m_bKeepChangeList;\r
517         if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())\r
518                 m_bKeepChangeList = FALSE;\r
519         InterlockedExchange(&m_bBlock, FALSE);\r
520         m_sBugID.Trim();\r
521         if (!m_sBugID.IsEmpty())\r
522         {\r
523                 m_sBugID.Replace(_T(", "), _T(","));\r
524                 m_sBugID.Replace(_T(" ,"), _T(","));\r
525                 CString sBugID = m_ProjectProperties.sMessage;\r
526                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
527                 if (m_ProjectProperties.bAppend)\r
528                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
529                 else\r
530                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
531         }\r
532         m_History.AddEntry(m_sLogMessage);\r
533         m_History.Save();\r
534 \r
535         SaveSplitterPos();\r
536 \r
537         CResizableStandAloneDialog::OnOK();\r
538 }\r
539 \r
540 void CCommitDlg::SaveSplitterPos()\r
541 {\r
542         if (!IsIconic())\r
543         {\r
544                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
545                 RECT rectSplitter;\r
546                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
547                 ScreenToClient(&rectSplitter);\r
548                 regPos = rectSplitter.top;\r
549         }\r
550 }\r
551 \r
552 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)\r
553 {\r
554         return ((CCommitDlg*)pVoid)->StatusThread();\r
555 }\r
556 \r
557 UINT CCommitDlg::StatusThread()\r
558 {\r
559         //get the status of all selected file/folders recursively\r
560         //and show the ones which have to be committed to the user\r
561         //in a list control. \r
562         InterlockedExchange(&m_bBlock, TRUE);\r
563         InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running\r
564         InterlockedExchange(&m_bRunThread, TRUE);       // if this is set to FALSE, the thread should stop\r
565         m_bCancelled = false;\r
566 \r
567         DialogEnableWindow(IDOK, false);\r
568         DialogEnableWindow(IDC_SHOWUNVERSIONED, false);\r
569         DialogEnableWindow(IDC_SELECTALL, false);\r
570         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);\r
571         DialogEnableWindow(IDC_EXTERNALWARNING, false);\r
572 \r
573     // read the list of recent log entries before querying the WC for status\r
574     // -> the user may select one and modify / update it while we are crawling the WC\r
575 #if 0\r
576         if (m_History.GetCount()==0)\r
577         {\r
578                 CString reg;\r
579                 if (m_ListCtrl.m_sUUID.IsEmpty() && m_pathList.GetCount()>0)\r
580                 {\r
581                         Git Git;\r
582                         reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)Git.GetUUIDFromPath(m_pathList[0]));\r
583                 }\r
584                 else\r
585                         reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);\r
586                 m_History.Load(reg, _T("logmsgs"));\r
587         }\r
588 \r
589     // Initialise the list control with the status of the files/folders below us\r
590         BOOL success = m_ListCtrl.GetStatus(m_pathList);\r
591         m_ListCtrl.CheckIfChangelistsArePresent(false);\r
592 \r
593         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWLOCKS | GitSLC_SHOWINCHANGELIST;\r
594         dwShow |= DWORD(m_regAddBeforeCommit) ? GitSLC_SHOWUNVERSIONED : 0;\r
595         if (success)\r
596         {\r
597                 if (m_checkedPathList.GetCount())\r
598                         m_ListCtrl.Show(dwShow, m_checkedPathList);\r
599                 else\r
600                 {\r
601                         DWORD dwCheck = m_bSelectFilesForCommit ? GitSLC_SHOWDIRECTS|GitSLC_SHOWMODIFIED|GitSLC_SHOWADDED|GitSLC_SHOWREMOVED|GitSLC_SHOWREPLACED|GitSLC_SHOWMERGED|GitSLC_SHOWLOCKS : 0;\r
602                         m_ListCtrl.Show(dwShow, dwCheck);\r
603                         m_bSelectFilesForCommit = true;\r
604                 }\r
605 \r
606                 if (m_ListCtrl.HasExternalsFromDifferentRepos())\r
607                 {\r
608                         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);\r
609                         DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);\r
610                 }\r
611                 SetDlgItemText(IDC_COMMIT_TO, m_ListCtrl.m_sURL);\r
612                 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());\r
613         }\r
614         CString logmsg;\r
615         GetDlgItemText(IDC_LOGMESSAGE, logmsg);\r
616         DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);\r
617         if (!success)\r
618         {\r
619                 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())\r
620                         m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());\r
621                 m_ListCtrl.Show(dwShow);\r
622         }\r
623         if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems()))\r
624         {\r
625                 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
626                 {\r
627                         m_bShowUnversioned = TRUE;\r
628                         GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);\r
629                         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;\r
630                         m_ListCtrl.Show(dwShow);\r
631                 }\r
632         }\r
633 \r
634         CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);\r
635         SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
636 \r
637         m_autolist.clear();\r
638         // we don't have to block the commit dialog while we fetch the\r
639         // auto completion list.\r
640         m_pathwatcher.ClearChangedPaths();\r
641         InterlockedExchange(&m_bBlock, FALSE);\r
642         if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)\r
643         {\r
644                 m_ListCtrl.Block(TRUE, TRUE);\r
645                 GetAutocompletionList();\r
646                 m_ListCtrl.Block(FALSE, FALSE);\r
647         }\r
648         if (m_bRunThread)\r
649         {\r
650                 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);\r
651                 DialogEnableWindow(IDC_SELECTALL, true);\r
652                 if (m_ListCtrl.HasChangeLists())\r
653                         DialogEnableWindow(IDC_KEEPLISTS, true);\r
654                 if (m_ListCtrl.HasLocks())\r
655                         DialogEnableWindow(IDC_KEEPLOCK, true);\r
656                 // we have the list, now signal the main thread about it\r
657                 SendMessage(WM_AUTOLISTREADY);  // only send the message if the thread wasn't told to quit!\r
658         }\r
659         InterlockedExchange(&m_bRunThread, FALSE);\r
660         InterlockedExchange(&m_bThreadRunning, FALSE);\r
661         // force the cursor to normal\r
662         RefreshCursor();\r
663 #endif\r
664         return 0;\r
665 }\r
666 \r
667 void CCommitDlg::OnCancel()\r
668 {\r
669         m_bCancelled = true;\r
670         if (m_bBlock)\r
671                 return;\r
672         m_pathwatcher.Stop();\r
673         if (m_bThreadRunning)\r
674         {\r
675                 InterlockedExchange(&m_bRunThread, FALSE);\r
676                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
677                 if (m_bThreadRunning)\r
678                 {\r
679                         // we gave the thread a chance to quit. Since the thread didn't\r
680                         // listen to us we have to kill it.\r
681                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
682                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
683                 }\r
684         }\r
685         UpdateData();\r
686         m_sBugID.Trim();\r
687         m_sLogMessage = m_cLogMessage.GetText();\r
688         if (!m_sBugID.IsEmpty())\r
689         {\r
690                 m_sBugID.Replace(_T(", "), _T(","));\r
691                 m_sBugID.Replace(_T(" ,"), _T(","));\r
692                 CString sBugID = m_ProjectProperties.sMessage;\r
693                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
694                 if (m_ProjectProperties.bAppend)\r
695                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
696                 else\r
697                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
698         }\r
699         if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)\r
700                 m_History.AddEntry(m_sLogMessage);\r
701         m_History.Save();\r
702         SaveSplitterPos();\r
703         CResizableStandAloneDialog::OnCancel();\r
704 }\r
705 \r
706 void CCommitDlg::OnBnClickedSelectall()\r
707 {\r
708         m_tooltips.Pop();       // hide the tooltips\r
709         UINT state = (m_SelectAll.GetState() & 0x0003);\r
710         if (state == BST_INDETERMINATE)\r
711         {\r
712                 // It is not at all useful to manually place the checkbox into the indeterminate state...\r
713                 // We will force this on to the unchecked state\r
714                 state = BST_UNCHECKED;\r
715                 m_SelectAll.SetCheck(state);\r
716         }\r
717 //      m_ListCtrl.SelectAll(state == BST_CHECKED);\r
718 }\r
719 \r
720 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)\r
721 {\r
722         if (!m_bBlock)\r
723                 m_tooltips.RelayEvent(pMsg);\r
724         if (pMsg->message == WM_KEYDOWN)\r
725         {\r
726                 switch (pMsg->wParam)\r
727                 {\r
728                 case VK_F5:\r
729                         {\r
730                                 if (m_bBlock)\r
731                                         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
732                                 Refresh();\r
733                         }\r
734                         break;\r
735                 case VK_RETURN:\r
736                         {\r
737                                 if (GetAsyncKeyState(VK_CONTROL)&0x8000)\r
738                                 {\r
739                                         if ( GetDlgItem(IDOK)->IsWindowEnabled() )\r
740                                         {\r
741                                                 PostMessage(WM_COMMAND, IDOK);\r
742                                         }\r
743                                         return TRUE;\r
744                                 }\r
745                                 if ( GetFocus()==GetDlgItem(IDC_BUGID) )\r
746                                 {\r
747                                         // Pressing RETURN in the bug id control\r
748                                         // moves the focus to the message\r
749                                         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
750                                         return TRUE;\r
751                                 }\r
752                         }\r
753                         break;\r
754                 }\r
755         }\r
756 \r
757         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
758 }\r
759 \r
760 void CCommitDlg::Refresh()\r
761 {\r
762         if (m_bThreadRunning)\r
763                 return;\r
764 \r
765         InterlockedExchange(&m_bBlock, TRUE);\r
766         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
767         if (m_pThread==NULL)\r
768         {\r
769                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
770                 InterlockedExchange(&m_bBlock, FALSE);\r
771         }\r
772         else\r
773         {\r
774                 m_pThread->m_bAutoDelete = FALSE;\r
775                 m_pThread->ResumeThread();\r
776         }\r
777 }\r
778 \r
779 void CCommitDlg::OnBnClickedHelp()\r
780 {\r
781         OnHelp();\r
782 }\r
783 \r
784 void CCommitDlg::OnBnClickedShowunversioned()\r
785 {\r
786 #if 0\r
787         m_tooltips.Pop();       // hide the tooltips\r
788         UpdateData();\r
789         m_regAddBeforeCommit = m_bShowUnversioned;\r
790         if (!m_bBlock)\r
791         {\r
792                 DWORD dwShow = m_ListCtrl.GetShowFlags();\r
793                 if (DWORD(m_regAddBeforeCommit))\r
794                         dwShow |= GitSLC_SHOWUNVERSIONED;\r
795                 else\r
796                         dwShow &= ~GitSLC_SHOWUNVERSIONED;\r
797                 m_ListCtrl.Show(dwShow);\r
798         }\r
799 #endif\r
800 }\r
801 \r
802 void CCommitDlg::OnStnClickedExternalwarning()\r
803 {\r
804         m_tooltips.Popup();\r
805 }\r
806 \r
807 void CCommitDlg::OnEnChangeLogmessage()\r
808 {\r
809         UpdateOKButton();\r
810 }\r
811 \r
812 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)\r
813 {\r
814 #if 0\r
815         if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))\r
816         {\r
817                 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
818                 {\r
819                         m_bShowUnversioned = TRUE;\r
820                         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;\r
821                         m_ListCtrl.Show(dwShow);\r
822                         UpdateData(FALSE);\r
823                 }\r
824         }\r
825 #endif\r
826         return 0;\r
827 }\r
828 \r
829 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)\r
830 {\r
831         Refresh();\r
832         return 0;\r
833 }\r
834 \r
835 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam)\r
836 {\r
837 #if 0\r
838         BringWindowToTop();\r
839         SetForegroundWindow();\r
840         SetActiveWindow();\r
841         // if multiple files/folders are dropped\r
842         // this handler is called for every single item\r
843         // separately.\r
844         // To avoid creating multiple refresh threads and\r
845         // causing crashes, we only add the items to the\r
846         // list control and start a timer.\r
847         // When the timer expires, we start the refresh thread,\r
848         // but only if it isn't already running - otherwise we\r
849         // restart the timer.\r
850         CTGitPath path;\r
851         path.SetFromWin((LPCTSTR)lParam);\r
852 \r
853         // just add all the items we get here.\r
854         // if the item is versioned, the add will fail but nothing\r
855         // more will happen.\r
856         Git Git;\r
857         Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);\r
858 \r
859         if (!m_ListCtrl.HasPath(path))\r
860         {\r
861                 if (m_pathList.AreAllPathsFiles())\r
862                 {\r
863                         m_pathList.AddPath(path);\r
864                         m_pathList.RemoveDuplicates();\r
865                         m_updatedPathList.AddPath(path);\r
866                         m_updatedPathList.RemoveDuplicates();\r
867                 }\r
868                 else\r
869                 {\r
870                         // if the path list contains folders, we have to check whether\r
871                         // our just (maybe) added path is a child of one of those. If it is\r
872                         // a child of a folder already in the list, we must not add it. Otherwise\r
873                         // that path could show up twice in the list.\r
874                         bool bHasParentInList = false;\r
875                         for (int i=0; i<m_pathList.GetCount(); ++i)\r
876                         {\r
877                                 if (m_pathList[i].IsAncestorOf(path))\r
878                                 {\r
879                                         bHasParentInList = true;\r
880                                         break;\r
881                                 }\r
882                         }\r
883                         if (!bHasParentInList)\r
884                         {\r
885                                 m_pathList.AddPath(path);\r
886                                 m_pathList.RemoveDuplicates();\r
887                                 m_updatedPathList.AddPath(path);\r
888                                 m_updatedPathList.RemoveDuplicates();\r
889                         }\r
890                 }\r
891         }\r
892         \r
893         // Always start the timer, since the status of an existing item might have changed\r
894         SetTimer(REFRESHTIMER, 200, NULL);\r
895         ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());\r
896 #endif\r
897         return 0;\r
898 }\r
899 \r
900 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)\r
901 {\r
902         m_cLogMessage.SetAutoCompletionList(m_autolist, '*');\r
903         return 0;\r
904 }\r
905 \r
906 //////////////////////////////////////////////////////////////////////////\r
907 // functions which run in the status thread\r
908 //////////////////////////////////////////////////////////////////////////\r
909 \r
910 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)\r
911 {\r
912         CString strLine;\r
913         try\r
914         {\r
915                 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);\r
916                 while (m_bRunThread && file.ReadString(strLine))\r
917                 {\r
918                         int eqpos = strLine.Find('=');\r
919                         CString rgx;\r
920                         rgx = strLine.Mid(eqpos+1).Trim();\r
921 \r
922                         int pos = -1;\r
923                         while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))\r
924                         {\r
925                                 mapRegex[strLine.Left(pos)] = rgx;\r
926                                 strLine = strLine.Mid(pos+1).Trim();\r
927                         }\r
928                         mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;\r
929                 }\r
930                 file.Close();\r
931         }\r
932         catch (CFileException* pE)\r
933         {\r
934                 TRACE("CFileException loading auto list regex file\n");\r
935                 pE->Delete();\r
936                 return;\r
937         }\r
938 }\r
939 void CCommitDlg::GetAutocompletionList()\r
940 {\r
941         // the auto completion list is made of strings from each selected files.\r
942         // the strings used are extracted from the files with regexes found\r
943         // in the file "autolist.txt".\r
944         // the format of that file is:\r
945         // file extensions separated with commas '=' regular expression to use\r
946         // example:\r
947         // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))\r
948         // .cpp = (?<=[^\s]::)\b\w+\b\r
949         \r
950         std::map<CString, CString> mapRegex;\r
951         CString sRegexFile = CPathUtils::GetAppDirectory();\r
952         CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);\r
953         DWORD timeoutvalue = regtimeout*1000;\r
954         sRegexFile += _T("autolist.txt");\r
955         if (!m_bRunThread)\r
956                 return;\r
957         ParseRegexFile(sRegexFile, mapRegex);\r
958         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));\r
959         sRegexFile.ReleaseBuffer();\r
960         sRegexFile += _T("\\TortoiseGit\\autolist.txt");\r
961         if (PathFileExists(sRegexFile))\r
962         {\r
963                 ParseRegexFile(sRegexFile, mapRegex);\r
964         }\r
965         DWORD starttime = GetTickCount();\r
966 \r
967         // now we have two arrays of strings, where the first array contains all\r
968         // file extensions we can use and the second the corresponding regex strings\r
969         // to apply to those files.\r
970 \r
971         // the next step is to go over all files shown in the commit dialog\r
972         // and scan them for strings we can use\r
973         int nListItems = m_ListCtrl.GetItemCount();\r
974 \r
975         for (int i=0; i<nListItems && m_bRunThread; ++i)\r
976         {\r
977                 // stop parsing after timeout\r
978                 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))\r
979                         return;\r
980 \r
981 //              const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
982 //              if (!entry)\r
983 //                      continue;\r
984                 \r
985                 // add the path parts to the auto completion list too\r
986 //              CString sPartPath = entry->GetRelativeGitPath();\r
987 //              m_autolist.insert(sPartPath);\r
988 \r
989 #if 0\r
990                 int pos = 0;\r
991                 int lastPos = 0;\r
992                 while ((pos = sPartPath.Find('/', pos)) >= 0)\r
993                 {\r
994                         pos++;\r
995                         lastPos = pos;\r
996                         m_autolist.insert(sPartPath.Mid(pos));\r
997                 }\r
998 \r
999                 // Last inserted entry is a file name.\r
1000                 // Some users prefer to also list file name without extension.\r
1001                 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))\r
1002                 {\r
1003                         int dotPos = sPartPath.ReverseFind('.');\r
1004                         if ((dotPos >= 0) && (dotPos > lastPos))\r
1005                                 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));\r
1006                 }\r
1007 \r
1008                 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))\r
1009                         continue;\r
1010 \r
1011                 CString sExt = entry->GetPath().GetFileExtension();\r
1012                 sExt.MakeLower();\r
1013                 // find the regex string which corresponds to the file extension\r
1014                 CString rdata = mapRegex[sExt];\r
1015                 if (rdata.IsEmpty())\r
1016                         continue;\r
1017 \r
1018                 ScanFile(entry->GetPath().GetWinPathString(), rdata);\r
1019                 if ((entry->textstatus != Git_wc_status_unversioned) &&\r
1020                         (entry->textstatus != Git_wc_status_none) &&\r
1021                         (entry->textstatus != Git_wc_status_ignored) &&\r
1022                         (entry->textstatus != Git_wc_status_added) &&\r
1023                         (entry->textstatus != Git_wc_status_normal))\r
1024                 {\r
1025                         CTGitPath basePath = Git::GetPristinePath(entry->GetPath());\r
1026                         if (!basePath.IsEmpty())\r
1027                                 ScanFile(basePath.GetWinPathString(), rdata);\r
1028                 }\r
1029 #endif\r
1030         }\r
1031         ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);\r
1032 }\r
1033 \r
1034 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)\r
1035 {\r
1036         wstring sFileContent;\r
1037         HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);\r
1038         if (hFile != INVALID_HANDLE_VALUE)\r
1039         {\r
1040                 DWORD size = GetFileSize(hFile, NULL);\r
1041                 if (size > 1000000L)\r
1042                 {\r
1043                         // no files bigger than 1 Meg\r
1044                         CloseHandle(hFile);\r
1045                         return;\r
1046                 }\r
1047                 // allocate memory to hold file contents\r
1048                 char * buffer = new char[size];\r
1049                 DWORD readbytes;\r
1050                 ReadFile(hFile, buffer, size, &readbytes, NULL);\r
1051                 CloseHandle(hFile);\r
1052                 int opts = 0;\r
1053                 IsTextUnicode(buffer, readbytes, &opts);\r
1054                 if (opts & IS_TEXT_UNICODE_NULL_BYTES)\r
1055                 {\r
1056                         delete [] buffer;\r
1057                         return;\r
1058                 }\r
1059                 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)\r
1060                 {\r
1061                         sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));\r
1062                 }\r
1063                 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))\r
1064                 {\r
1065                         int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);\r
1066                         wchar_t * pWideBuf = new wchar_t[ret];\r
1067                         int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);\r
1068                         if (ret2 == ret)\r
1069                                 sFileContent = wstring(pWideBuf, ret);\r
1070                         delete [] pWideBuf;\r
1071                 }\r
1072                 delete [] buffer;\r
1073         }\r
1074         if (sFileContent.empty()|| !m_bRunThread)\r
1075         {\r
1076                 return;\r
1077         }\r
1078 \r
1079         try\r
1080         {\r
1081                 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
1082                 const tr1::wsregex_iterator end;\r
1083                 wstring s = sFileContent;\r
1084                 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)\r
1085                 {\r
1086                         const tr1::wsmatch match = *it;\r
1087                         for (size_t i=1; i<match.size(); ++i)\r
1088                         {\r
1089                                 if (match[i].second-match[i].first)\r
1090                                 {\r
1091                                         ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());\r
1092                                         m_autolist.insert(wstring(match[i]).c_str());\r
1093                                 }\r
1094                         }\r
1095                 }\r
1096         }\r
1097         catch (exception) {}\r
1098 }\r
1099 \r
1100 // CSciEditContextMenuInterface\r
1101 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)\r
1102 {\r
1103         CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));\r
1104         m_nPopupPasteListCmd = nCmd++;\r
1105         mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);\r
1106 }\r
1107 \r
1108 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)\r
1109 {\r
1110 #if 0\r
1111         if (m_bBlock)\r
1112                 return false;\r
1113         if (cmd == m_nPopupPasteListCmd)\r
1114         {\r
1115                 CString logmsg;\r
1116                 TCHAR buf[MAX_STATUS_STRING_LENGTH];\r
1117                 int nListItems = m_ListCtrl.GetItemCount();\r
1118                 for (int i=0; i<nListItems; ++i)\r
1119                 {\r
1120                         CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1121                         if (entry->IsChecked())\r
1122                         {\r
1123                                 CString line;\r
1124                                 Git_wc_status_kind status = entry->status;\r
1125                                 if (status == Git_wc_status_unversioned)\r
1126                                         status = Git_wc_status_added;\r
1127                                 if (status == Git_wc_status_missing)\r
1128                                         status = Git_wc_status_deleted;\r
1129                                 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());\r
1130                                 if (m_ProjectProperties.bFileListInEnglish)\r
1131                                         langID = 1033;\r
1132                                 GitStatus::GetStatusString(AfxGetResourceHandle(), status, buf, sizeof(buf)/sizeof(TCHAR), langID);\r
1133                                 line.Format(_T("%-10s %s\r\n"), buf, (LPCTSTR)m_ListCtrl.GetItemText(i,0));\r
1134                                 logmsg += line;\r
1135                         }\r
1136                 }\r
1137                 pSciEdit->InsertText(logmsg);\r
1138                 return true;\r
1139         }\r
1140 #endif\r
1141         return false;\r
1142 }\r
1143 \r
1144 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)\r
1145 {\r
1146         switch (nIDEvent)\r
1147         {\r
1148         case ENDDIALOGTIMER:\r
1149                 KillTimer(ENDDIALOGTIMER);\r
1150                 EndDialog(0);\r
1151                 break;\r
1152         case REFRESHTIMER:\r
1153                 if (m_bThreadRunning)\r
1154                 {\r
1155                         SetTimer(REFRESHTIMER, 200, NULL);\r
1156                         ATLTRACE("Wait some more before refreshing\n");\r
1157                 }\r
1158                 else\r
1159                 {\r
1160                         KillTimer(REFRESHTIMER);\r
1161                         ATLTRACE("Refreshing after items dropped\n");\r
1162                         Refresh();\r
1163                 }\r
1164                 break;\r
1165         }\r
1166         __super::OnTimer(nIDEvent);\r
1167 }\r
1168 \r
1169 void CCommitDlg::OnBnClickedHistory()\r
1170 {\r
1171         m_tooltips.Pop();       // hide the tooltips\r
1172         if (m_pathList.GetCount() == 0)\r
1173                 return;\r
1174 #if 0\r
1175         CHistoryDlg historyDlg;\r
1176         historyDlg.SetHistory(m_History);\r
1177         if (historyDlg.DoModal() != IDOK)\r
1178                 return;\r
1179 \r
1180         CString sMsg = historyDlg.GetSelectedText();\r
1181         if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))\r
1182         {\r
1183                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);\r
1184                 if (!sBugID.IsEmpty())\r
1185                 {\r
1186                         SetDlgItemText(IDC_BUGID, sBugID);\r
1187                 }\r
1188                 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)\r
1189                         m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());\r
1190                 else\r
1191                         m_cLogMessage.SetText(sMsg);\r
1192         }\r
1193 \r
1194         UpdateOKButton();\r
1195         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
1196 #endif\r
1197 }\r
1198 \r
1199 void CCommitDlg::OnBnClickedBugtraqbutton()\r
1200 {\r
1201 #if 0\r
1202         m_tooltips.Pop();       // hide the tooltips\r
1203         CString sMsg = m_cLogMessage.GetText();\r
1204 \r
1205         if (m_BugTraqProvider == NULL)\r
1206                 return;\r
1207 \r
1208         BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
1209         BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());\r
1210         SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());\r
1211 \r
1212         for (LONG index = 0; index < m_pathList.GetCount(); ++index)\r
1213                 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());\r
1214 \r
1215         BSTR originalMessage = sMsg.AllocSysString();\r
1216         BSTR temp = NULL;\r
1217 \r
1218         // first try the IBugTraqProvider2 interface\r
1219         CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
1220         HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
1221         if (SUCCEEDED(hr))\r
1222         {\r
1223                 CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
1224                 BSTR repositoryRoot = common.AllocSysString();\r
1225                 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, &temp)))\r
1226                 {\r
1227                         CString sErr;\r
1228                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1229                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1230                 }\r
1231                 else\r
1232                         m_cLogMessage.SetText(temp);\r
1233         }\r
1234         else\r
1235         {\r
1236                 // if IBugTraqProvider2 failed, try IBugTraqProvider\r
1237                 CComPtr<IBugTraqProvider> pProvider = NULL;\r
1238                 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
1239                 if (FAILED(hr))\r
1240                 {\r
1241                         CString sErr;\r
1242                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1243                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1244                         return;\r
1245                 }\r
1246 \r
1247                 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))\r
1248                 {\r
1249                         CString sErr;\r
1250                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1251                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1252                 }\r
1253                 else\r
1254                         m_cLogMessage.SetText(temp);\r
1255         }\r
1256 \r
1257         m_cLogMessage.SetFocus();\r
1258 \r
1259         SysFreeString(temp);\r
1260 #endif\r
1261 }\r
1262 \r
1263 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)\r
1264 {\r
1265         UpdateOKButton();\r
1266         return 0;\r
1267 }\r
1268 \r
1269 void CCommitDlg::UpdateOKButton()\r
1270 {\r
1271 #if 0\r
1272         BOOL bValidLogSize = FALSE;\r
1273 \r
1274     if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)\r
1275                 bValidLogSize = !m_bBlock;\r
1276 \r
1277         LONG nSelectedItems = m_ListCtrl.GetSelected();\r
1278         DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);\r
1279 #endif\r
1280 }\r
1281 \r
1282 \r
1283 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
1284 {\r
1285         switch (message) {\r
1286         case WM_NOTIFY:\r
1287                 if (wParam == IDC_SPLITTER)\r
1288                 { \r
1289                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
1290                         DoSize(pHdr->delta);\r
1291                 }\r
1292                 break;\r
1293         }\r
1294 \r
1295         return __super::DefWindowProc(message, wParam, lParam);\r
1296 }\r
1297 \r
1298 void CCommitDlg::SetSplitterRange()\r
1299 {\r
1300         if ((m_ListCtrl)&&(m_cLogMessage))\r
1301         {\r
1302                 CRect rcTop;\r
1303                 m_cLogMessage.GetWindowRect(rcTop);\r
1304                 ScreenToClient(rcTop);\r
1305                 CRect rcMiddle;\r
1306                 m_ListCtrl.GetWindowRect(rcMiddle);\r
1307                 ScreenToClient(rcMiddle);\r
1308                 if (rcMiddle.Height() && rcMiddle.Width())\r
1309                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
1310         }\r
1311 }\r
1312 \r
1313 void CCommitDlg::DoSize(int delta)\r
1314 {\r
1315         RemoveAnchor(IDC_MESSAGEGROUP);\r
1316         RemoveAnchor(IDC_LOGMESSAGE);\r
1317         RemoveAnchor(IDC_SPLITTER);\r
1318         RemoveAnchor(IDC_LISTGROUP);\r
1319         RemoveAnchor(IDC_FILELIST);\r
1320         CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);\r
1321         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);\r
1322         CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);\r
1323         CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);\r
1324         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
1325         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
1326         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
1327         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
1328         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
1329         ArrangeLayout();\r
1330         // adjust the minimum size of the dialog to prevent the resizing from\r
1331         // moving the list control too far down.\r
1332         CRect rcLogMsg;\r
1333         m_cLogMessage.GetClientRect(rcLogMsg);\r
1334         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));\r
1335 \r
1336         SetSplitterRange();\r
1337         m_cLogMessage.Invalidate();\r
1338         GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
1339 }\r
1340 \r
1341 void CCommitDlg::OnSize(UINT nType, int cx, int cy)\r
1342 {\r
1343     // first, let the resizing take place\r
1344     __super::OnSize(nType, cx, cy);\r
1345 \r
1346     //set range\r
1347     SetSplitterRange();\r
1348 }\r
1349 \r