OSDN Git Service

Fixed issue #112: (6) Low hanging GUI fruits during Commit and Push
[tortoisegit/TortoiseGitJp.git] / src / 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 "ProjectProperties.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 #include "CommonResource.h"\r
34 #include "UnicodeUtils.h"\r
35 #include "ProgressDlg.h"\r
36 #include "ShellUpdater.h"\r
37 #include "Commands/PushCommand.h"\r
38 \r
39 #ifdef _DEBUG\r
40 #define new DEBUG_NEW\r
41 #undef THIS_FILE\r
42 static char THIS_FILE[] = __FILE__;\r
43 #endif\r
44 \r
45 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));\r
46 \r
47 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)\r
48 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)\r
49         : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)\r
50         , m_bRecursive(FALSE)\r
51         , m_bShowUnversioned(FALSE)\r
52         , m_bBlock(FALSE)\r
53         , m_bThreadRunning(FALSE)\r
54         , m_bRunThread(FALSE)\r
55         , m_pThread(NULL)\r
56         , m_bWholeProject(FALSE)\r
57         , m_bKeepChangeList(TRUE)\r
58         , m_itemsCount(0)\r
59         , m_bSelectFilesForCommit(TRUE)\r
60 {\r
61         this->m_bCommitAmend=FALSE;\r
62         m_bPushAfterCommit = FALSE;\r
63 }\r
64 \r
65 CCommitDlg::~CCommitDlg()\r
66 {\r
67         if(m_pThread != NULL)\r
68         {\r
69                 delete m_pThread;\r
70         }\r
71 }\r
72 \r
73 void CCommitDlg::DoDataExchange(CDataExchange* pDX)\r
74 {\r
75         CResizableStandAloneDialog::DoDataExchange(pDX);\r
76         DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);\r
77         DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);\r
78         DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);\r
79         DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);\r
80         DDX_Text(pDX, IDC_BUGID, m_sBugID);\r
81         DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);\r
82         DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);\r
83         DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);\r
84         DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);\r
85 }\r
86 \r
87 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)\r
88         ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)\r
89         ON_BN_CLICKED(IDHELP, OnBnClickedHelp)\r
90         ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)\r
91 //      ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)\r
92         ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)\r
93         ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)\r
94         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)\r
95         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)\r
96         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)\r
97         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)\r
98         ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady) \r
99         ON_WM_TIMER()\r
100     ON_WM_SIZE()\r
101         ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)\r
102         ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)\r
103         ON_STN_CLICKED(IDC_COMMITLABEL, &CCommitDlg::OnStnClickedCommitlabel)\r
104     ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)\r
105     ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)\r
106         ON_STN_CLICKED(IDC_BUGIDLABEL, &CCommitDlg::OnStnClickedBugidlabel)\r
107         ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)\r
108 END_MESSAGE_MAP()\r
109 \r
110 BOOL CCommitDlg::OnInitDialog()\r
111 {\r
112         CResizableStandAloneDialog::OnInitDialog();\r
113         \r
114         m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);\r
115         m_bShowUnversioned = m_regAddBeforeCommit;\r
116 \r
117         m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));\r
118 \r
119         m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);\r
120         m_bKeepChangeList = m_regKeepChangelists;\r
121 \r
122         m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));\r
123 \r
124 //      GitConfig config;\r
125 //      m_bWholeProject = config.KeepLocks();\r
126 \r
127         if(this->m_pathList.GetCount() == 0)\r
128                 m_bWholeProject =true;\r
129         \r
130         if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())\r
131                 m_bWholeProject =true;\r
132 \r
133         UpdateData(FALSE);\r
134         \r
135         m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"));\r
136         m_ListCtrl.SetSelectButton(&m_SelectAll);\r
137         m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));\r
138         m_ListCtrl.SetCancelBool(&m_bCancelled);\r
139         m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);\r
140         m_ListCtrl.EnableFileDrop();\r
141         m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);\r
142         \r
143         //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);\r
144         m_ProjectProperties.ReadPropsPathList(m_pathList);\r
145 \r
146         m_cLogMessage.Init(m_ProjectProperties);\r
147         m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));\r
148         m_cLogMessage.RegisterContextMenuHandler(this);\r
149 \r
150         OnEnChangeLogmessage();\r
151 \r
152         m_tooltips.Create(this);\r
153         m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);\r
154         m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);\r
155 //      m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);\r
156         \r
157         m_SelectAll.SetCheck(BST_INDETERMINATE);\r
158 \r
159 \r
160         CBugTraqAssociations bugtraq_associations;\r
161         bugtraq_associations.Load();\r
162 \r
163         if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))\r
164         {\r
165                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
166                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
167 \r
168                 CComPtr<IBugTraqProvider> pProvider;\r
169                 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());\r
170                 if (SUCCEEDED(hr))\r
171                 {\r
172                         m_BugTraqProvider = pProvider;\r
173                         BSTR temp = NULL;\r
174                         if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))\r
175                         {\r
176                                 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);\r
177                                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);\r
178                                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);\r
179                         }\r
180 \r
181                         SysFreeString(temp);\r
182                 }\r
183 \r
184                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
185         }\r
186         else if (!m_ProjectProperties.sMessage.IsEmpty())\r
187         {\r
188                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);\r
189                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);\r
190                 if (!m_ProjectProperties.sLabel.IsEmpty())\r
191                         SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);\r
192                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
193                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
194                 GetDlgItem(IDC_BUGID)->SetFocus();\r
195                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);\r
196                 if (!sBugID.IsEmpty())\r
197                 {\r
198                         SetDlgItemText(IDC_BUGID, sBugID);\r
199                 }\r
200         }\r
201         else\r
202         {\r
203                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
204                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
205                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
206                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
207                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
208         }\r
209 \r
210         if (!m_sLogMessage.IsEmpty())\r
211                 m_cLogMessage.SetText(m_sLogMessage);\r
212                 \r
213         GetWindowText(m_sWindowTitle);\r
214         \r
215         AdjustControlSize(IDC_SHOWUNVERSIONED);\r
216         AdjustControlSize(IDC_SELECTALL);\r
217         AdjustControlSize(IDC_WHOLE_PROJECT);\r
218 \r
219         GetClientRect(m_DlgOrigRect);\r
220         m_cLogMessage.GetClientRect(m_LogMsgOrigRect);\r
221 \r
222         AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);\r
223         AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);\r
224         AddAnchor(IDC_BUGID, TOP_RIGHT);\r
225         AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);\r
226         AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);\r
227         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
228 //      AddAnchor(IDC_HISTORY, TOP_LEFT);\r
229         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
230         AddAnchor(IDC_SIGNOFF,   TOP_RIGHT);\r
231         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
232         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
233         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
234         AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);\r
235         AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);\r
236         AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);\r
237         AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
238         AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);\r
239         AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);\r
240         AddAnchor(IDOK, BOTTOM_RIGHT);\r
241         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
242         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
243         AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);\r
244         \r
245         if (hWndExplorer)\r
246                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
247         EnableSaveRestore(_T("CommitDlg"));\r
248         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
249         RECT rcDlg, rcLogMsg, rcFileList;\r
250         GetClientRect(&rcDlg);\r
251         m_cLogMessage.GetWindowRect(&rcLogMsg);\r
252         ScreenToClient(&rcLogMsg);\r
253         m_ListCtrl.GetWindowRect(&rcFileList);\r
254         ScreenToClient(&rcFileList);\r
255         if (yPos)\r
256         {\r
257                 RECT rectSplitter;\r
258                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
259                 ScreenToClient(&rectSplitter);\r
260                 int delta = yPos - rectSplitter.top;\r
261                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
262                 {\r
263                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
264                         DoSize(delta);\r
265                 }\r
266         }\r
267 \r
268         // add all directories to the watcher\r
269         for (int i=0; i<m_pathList.GetCount(); ++i)\r
270         {\r
271                 if (m_pathList[i].IsDirectory())\r
272                         m_pathwatcher.AddPath(m_pathList[i]);\r
273         }\r
274 \r
275         m_updatedPathList = m_pathList;\r
276 \r
277         //first start a thread to obtain the file list with the status without\r
278         //blocking the dialog\r
279         InterlockedExchange(&m_bBlock, TRUE);\r
280         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
281         if (m_pThread==NULL)\r
282         {\r
283                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
284                 InterlockedExchange(&m_bBlock, FALSE);\r
285         }\r
286         else\r
287         {\r
288                 m_pThread->m_bAutoDelete = FALSE;\r
289                 m_pThread->ResumeThread();\r
290         }\r
291         CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);\r
292         CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);\r
293         if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))\r
294         {\r
295                 historyhint = TRUE;\r
296 //              ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);\r
297         }\r
298         err = FALSE;\r
299 \r
300         //this->UpdateData(TRUE);\r
301         //this->m_bCommitAmend=FALSE;\r
302         //this->UpdateData(FALSE);\r
303 \r
304         return FALSE;  // return TRUE unless you set the focus to a control\r
305         // EXCEPTION: OCX Property Pages should return FALSE\r
306 }\r
307 \r
308 void CCommitDlg::OnOK()\r
309 {\r
310         if (m_bBlock)\r
311                 return;\r
312         if (m_bThreadRunning)\r
313         {\r
314                 m_bCancelled = true;\r
315                 InterlockedExchange(&m_bRunThread, FALSE);\r
316                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
317                 if (m_bThreadRunning)\r
318                 {\r
319                         // we gave the thread a chance to quit. Since the thread didn't\r
320                         // listen to us we have to kill it.\r
321                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
322                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
323                 }\r
324         }\r
325         this->UpdateData();\r
326 \r
327         CString id;\r
328         GetDlgItemText(IDC_BUGID, id);\r
329         if (!m_ProjectProperties.CheckBugID(id))\r
330         {\r
331                 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);\r
332                 return;\r
333         }\r
334         m_sLogMessage = m_cLogMessage.GetText();\r
335         if ( m_sLogMessage.IsEmpty() )\r
336         {\r
337                 // no message entered, go round again\r
338                 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
339                 return;\r
340         }\r
341         if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))\r
342         {\r
343                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
344                         return;\r
345         }\r
346 \r
347 #if 0\r
348         CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);\r
349         if (!(DWORD)regUnversionedRecurse)\r
350         {\r
351                 // Find unversioned directories which are marked for commit. The user might expect them\r
352                 // to be added recursively since he cannot the the files. Let's ask the user if he knows\r
353                 // what he is doing.\r
354                 int nListItems = m_ListCtrl.GetItemCount();\r
355                 for (int j=0; j<nListItems; j++)\r
356                 {\r
357                         const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
358                         if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )\r
359                         {\r
360                                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
361                                         return;\r
362                         }\r
363                 }\r
364         }\r
365 #endif\r
366         m_pathwatcher.Stop();\r
367         InterlockedExchange(&m_bBlock, TRUE);\r
368         CDWordArray arDeleted;\r
369         //first add all the unversioned files the user selected\r
370         //and check if all versioned files are selected\r
371         int nchecked = 0;\r
372         m_bRecursive = true;\r
373         int nListItems = m_ListCtrl.GetItemCount();\r
374 \r
375         CTGitPathList itemsToAdd;\r
376         CTGitPathList itemsToRemove;\r
377         //std::set<CString> checkedLists;\r
378         //std::set<CString> uncheckedLists;\r
379 \r
380         //CString checkedfiles;\r
381         //CString uncheckedfiles;\r
382 \r
383         CString cmd;\r
384         CString out;\r
385 \r
386         for (int j=0; j<nListItems; j++)\r
387         {\r
388                 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
389                 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);\r
390                 if (entry->m_Checked)\r
391                 {\r
392 #if 0\r
393                         if (entry->status == Git_wc_status_unversioned)\r
394                         {\r
395                                 itemsToAdd.AddPath(entry->GetPath());\r
396                         }\r
397                         if (entry->status == Git_wc_status_conflicted)\r
398                         {\r
399                                 bHasConflicted = true;\r
400                         }\r
401                         if (entry->status == Git_wc_status_missing)\r
402                         {\r
403                                 itemsToRemove.AddPath(entry->GetPath());\r
404                         }\r
405                         if (entry->status == Git_wc_status_deleted)\r
406                         {\r
407                                 arDeleted.Add(j);\r
408                         }\r
409                         if (entry->IsInExternal())\r
410                         {\r
411                                 bCheckedInExternal = true;\r
412                         }\r
413 #endif\r
414                         if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)\r
415                                 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());\r
416                         else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)\r
417                                 cmd.Format(_T("git.exe update-index --remove -- \"%s\""),entry->GetGitPathString());\r
418                         else\r
419                                 cmd.Format(_T("git.exe update-index  -- \"%s\""),entry->GetGitPathString());\r
420 \r
421                         g_Git.Run(cmd,&out,CP_ACP);\r
422                         nchecked++;\r
423 \r
424                         //checkedLists.insert(entry->GetGitPathString());\r
425 //                      checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
426                 }\r
427                 else\r
428                 {\r
429                         //uncheckedLists.insert(entry->GetGitPathString());\r
430                         if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)\r
431                         {       //To init git repository, there are not HEAD, so we can use git reset command\r
432                                 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());\r
433                                 g_Git.Run(cmd,&out,CP_ACP);     \r
434                         }\r
435                         else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )\r
436                         {\r
437                                 cmd.Format(_T("git.exe reset -- \"%s\""),entry->GetGitPathString());\r
438                                 g_Git.Run(cmd,&out,CP_ACP);\r
439                         }\r
440 \r
441                 //      uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
442 #if 0\r
443                         if ((entry->status != Git_wc_status_unversioned)        &&\r
444                                 (entry->status != Git_wc_status_ignored))\r
445                         {\r
446                                 nUnchecked++;\r
447                                 uncheckedLists.insert(entry->GetChangeList());\r
448                                 if (m_bRecursive)\r
449                                 {\r
450                                         // This algorithm is for the sake of simplicity of the complexity O(N?\r
451                                         for (int k=0; k<nListItems; k++)\r
452                                         {\r
453                                                 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);\r
454                                                 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath())  )\r
455                                                 {\r
456                                                         // Fall back to a non-recursive commit to prevent items being\r
457                                                         // committed which aren't checked although its parent is checked\r
458                                                         // (property change, directory deletion, ... )\r
459                                                         m_bRecursive = false;\r
460                                                         break;\r
461                                                 }\r
462                                         }\r
463                                 }\r
464                         }\r
465 #endif\r
466                 }\r
467 \r
468                 CShellUpdater::Instance().AddPathForUpdate(*entry);\r
469         }\r
470 \r
471         //if(uncheckedfiles.GetLength()>0)\r
472         //{\r
473         //      cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);\r
474         //      g_Git.Run(cmd,&out);\r
475         //}\r
476         \r
477         m_sBugID.Trim();\r
478         if (!m_sBugID.IsEmpty())\r
479         {\r
480                 m_sBugID.Replace(_T(", "), _T(","));\r
481                 m_sBugID.Replace(_T(" ,"), _T(","));\r
482                 CString sBugID = m_ProjectProperties.sMessage;\r
483                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
484                 if (m_ProjectProperties.bAppend)\r
485                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
486                 else\r
487                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
488         }\r
489 \r
490         BOOL bCloseCommitDlg=true;\r
491         //if(checkedfiles.GetLength()>0)\r
492         if(nchecked||m_bCommitAmend)\r
493         {\r
494         //      cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);\r
495         //      g_Git.Run(cmd,&out);\r
496 \r
497                 CString tempfile=::GetTempFile();\r
498                 \r
499                 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);\r
500                 //file.WriteString(m_sLogMessage);\r
501                                 \r
502         \r
503                 out =_T("");\r
504                 CString amend;\r
505                 if(this->m_bCommitAmend)\r
506                 {\r
507                         amend=_T("--amend");\r
508                 }\r
509                 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);\r
510                 \r
511                 CProgressDlg progress;\r
512                 progress.m_GitCmd=cmd;\r
513                 progress.m_bShowCommand = FALSE;        // don't show the commit command\r
514                 progress.m_PreText = out;                       // show any output already generated in log window\r
515                 progress.m_changeAbortButtonOnSuccessTo = "Push";\r
516                 DWORD userResponse = progress.DoModal();\r
517                 \r
518                 if(progress.m_GitStatus)\r
519                 {\r
520                         bCloseCommitDlg = false;\r
521                         this->Refresh();\r
522                 }\r
523                 else if(userResponse == IDCANCEL)\r
524                 {\r
525                         //User pressed 'Push' button after successful commit.\r
526                         m_bPushAfterCommit=true;\r
527                 }\r
528 \r
529                 CFile::Remove(tempfile);\r
530         }else\r
531         {\r
532                 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);\r
533                 bCloseCommitDlg=false;\r
534         }\r
535 #if 0\r
536         if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)\r
537         {\r
538                 // There are paths which got changed (touched at least).\r
539                 // We have to find out if this affects the selection in the commit dialog\r
540                 // If it could affect the selection, revert back to a non-recursive commit\r
541                 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();\r
542                 changedList.RemoveDuplicates();\r
543                 for (int i=0; i<changedList.GetCount(); ++i)\r
544                 {\r
545                         if (changedList[i].IsAdminDir())\r
546                         {\r
547                                 // something inside an admin dir was changed.\r
548                                 // if it's the entries file, then we have to fully refresh because\r
549                                 // files may have been added/removed from version control\r
550                                 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&\r
551                                         (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))\r
552                                 {\r
553                                         m_bRecursive = false;\r
554                                         break;\r
555                                 }\r
556                         }\r
557                         else if (!m_ListCtrl.IsPathShown(changedList[i]))\r
558                         {\r
559                                 // a path which is not shown in the list has changed\r
560                                 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);\r
561                                 if (entry)\r
562                                 {\r
563                                         // check if the changed path would get committed by a recursive commit\r
564                                         if ((!entry->IsFromDifferentRepository()) &&\r
565                                                 (!entry->IsInExternal()) &&\r
566                                                 (!entry->IsNested()) && \r
567                                                 (!entry->IsChecked()))\r
568                                         {\r
569                                                 m_bRecursive = false;\r
570                                                 break;\r
571                                         }\r
572                                 }\r
573                         }\r
574                 }\r
575         }\r
576 \r
577 \r
578         // Now, do all the adds - make sure that the list is sorted so that parents \r
579         // are added before their children\r
580         itemsToAdd.SortByPathname();\r
581         Git Git;\r
582         if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))\r
583         {\r
584                 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
585                 InterlockedExchange(&m_bBlock, FALSE);\r
586                 Refresh();\r
587                 return;\r
588         }\r
589 \r
590         // Remove any missing items\r
591         // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point\r
592         itemsToRemove.SortByPathname();\r
593         Git.Remove(itemsToRemove, TRUE);\r
594 \r
595         //the next step: find all deleted files and check if they're \r
596         //inside a deleted folder. If that's the case, then remove those\r
597         //files from the list since they'll get deleted by the parent\r
598         //folder automatically.\r
599         m_ListCtrl.Block(TRUE, FALSE);\r
600         INT_PTR nDeleted = arDeleted.GetCount();\r
601         for (INT_PTR i=0; i<arDeleted.GetCount(); i++)\r
602         {\r
603                 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))\r
604                 {\r
605                         const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();\r
606                         if (path.IsDirectory())\r
607                         {\r
608                                 //now find all children of this directory\r
609                                 for (int j=0; j<arDeleted.GetCount(); j++)\r
610                                 {\r
611                                         if (i!=j)\r
612                                         {\r
613                                                 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));\r
614                                                 if (childEntry->IsChecked())\r
615                                                 {\r
616                                                         if (path.IsAncestorOf(childEntry->GetPath()))\r
617                                                         {\r
618                                                                 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);\r
619                                                                 nDeleted--;\r
620                                                         }\r
621                                                 }\r
622                                         }\r
623                                 }\r
624                         }\r
625                 }\r
626         } \r
627         m_ListCtrl.Block(FALSE, FALSE);\r
628 \r
629         if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))\r
630         {\r
631                 //save only the files the user has checked into the temporary file\r
632                 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);\r
633         }\r
634         m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);\r
635         // the item count is used in the progress dialog to show the overall commit\r
636         // progress.\r
637         // deleted items only send one notification event, all others send two\r
638         m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();\r
639 \r
640         if ((m_bRecursive)&&(checkedLists.size() == 1))\r
641         {\r
642                 // all checked items belong to the same changelist\r
643                 // find out if there are any unchecked items which belong to that changelist\r
644                 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())\r
645                         m_sChangeList = *checkedLists.begin();\r
646         }\r
647 #endif\r
648         UpdateData();\r
649         m_regAddBeforeCommit = m_bShowUnversioned;\r
650         if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())\r
651                 m_bWholeProject = FALSE;\r
652         m_regKeepChangelists = m_bKeepChangeList;\r
653         if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())\r
654                 m_bKeepChangeList = FALSE;\r
655         InterlockedExchange(&m_bBlock, FALSE);\r
656 \r
657         m_History.AddEntry(m_sLogMessage);\r
658         m_History.Save();\r
659 \r
660         SaveSplitterPos();\r
661 \r
662         if( bCloseCommitDlg )\r
663                 CResizableStandAloneDialog::OnOK();\r
664 \r
665         CShellUpdater::Instance().Flush();\r
666 }\r
667 \r
668 void CCommitDlg::SaveSplitterPos()\r
669 {\r
670         if (!IsIconic())\r
671         {\r
672                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
673                 RECT rectSplitter;\r
674                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
675                 ScreenToClient(&rectSplitter);\r
676                 regPos = rectSplitter.top;\r
677         }\r
678 }\r
679 \r
680 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)\r
681 {\r
682         return ((CCommitDlg*)pVoid)->StatusThread();\r
683 }\r
684 \r
685 UINT CCommitDlg::StatusThread()\r
686 {\r
687         //get the status of all selected file/folders recursively\r
688         //and show the ones which have to be committed to the user\r
689         //in a list control. \r
690         InterlockedExchange(&m_bBlock, TRUE);\r
691         InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running\r
692         InterlockedExchange(&m_bRunThread, TRUE);       // if this is set to FALSE, the thread should stop\r
693         m_bCancelled = false;\r
694 \r
695         DialogEnableWindow(IDOK, false);\r
696         DialogEnableWindow(IDC_SHOWUNVERSIONED, false);\r
697     DialogEnableWindow(IDC_WHOLE_PROJECT, false);\r
698         DialogEnableWindow(IDC_SELECTALL, false);\r
699         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);\r
700         DialogEnableWindow(IDC_EXTERNALWARNING, false);\r
701     // read the list of recent log entries before querying the WC for status\r
702     // -> the user may select one and modify / update it while we are crawling the WC\r
703 \r
704         if (m_History.GetCount()==0)\r
705         {\r
706                 CString reg;\r
707                 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);\r
708                 reg.Replace(_T(':'),_T('_'));\r
709                 m_History.Load(reg, _T("logmsgs"));\r
710         }\r
711 \r
712     // Initialise the list control with the status of the files/folders below us\r
713         m_ListCtrl.Clear();\r
714         BOOL success;\r
715     if(m_bWholeProject)\r
716         success=m_ListCtrl.GetStatus(NULL);\r
717     else\r
718         success=m_ListCtrl.GetStatus(&m_pathList);\r
719 \r
720         //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));\r
721         if(this->m_bShowUnversioned)\r
722                 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,&m_pathList);\r
723         \r
724         m_ListCtrl.CheckIfChangelistsArePresent(false);\r
725 \r
726         DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;\r
727         dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;\r
728         if (success)\r
729         {\r
730                 if (m_checkedPathList.GetCount())\r
731                         m_ListCtrl.Show(dwShow, m_checkedPathList);\r
732                 else\r
733                 {\r
734                         DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;\r
735                         dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default. \r
736                         m_ListCtrl.Show(dwShow, dwCheck);\r
737                         m_bSelectFilesForCommit = true;\r
738                 }\r
739 \r
740                 if (m_ListCtrl.HasExternalsFromDifferentRepos())\r
741                 {\r
742                         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);\r
743                         DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);\r
744                 }\r
745                 \r
746                 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());\r
747                 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());\r
748         }\r
749         CString logmsg;\r
750         GetDlgItemText(IDC_LOGMESSAGE, logmsg);\r
751         DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);\r
752         if (!success)\r
753         {\r
754                 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())\r
755                         m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());\r
756                 m_ListCtrl.Show(dwShow);\r
757         }\r
758         if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems()))\r
759         {\r
760                 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
761                 {\r
762                         m_bShowUnversioned = TRUE;\r
763                         GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);\r
764                         DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);\r
765                         m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);\r
766                         m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));\r
767                 }\r
768         }\r
769 \r
770         CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);\r
771 \r
772     if(this->m_bWholeProject)   \r
773         SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));\r
774     else\r
775             SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
776 \r
777         m_autolist.clear();\r
778         // we don't have to block the commit dialog while we fetch the\r
779         // auto completion list.\r
780         m_pathwatcher.ClearChangedPaths();\r
781         InterlockedExchange(&m_bBlock, FALSE);\r
782         if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)\r
783         {\r
784                 m_ListCtrl.Block(TRUE, TRUE);\r
785                 GetAutocompletionList();\r
786                 m_ListCtrl.Block(FALSE, FALSE);\r
787         }\r
788         if (m_bRunThread)\r
789         {\r
790                 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);\r
791         DialogEnableWindow(IDC_WHOLE_PROJECT, true);\r
792                 DialogEnableWindow(IDC_SELECTALL, true);\r
793                 if (m_ListCtrl.HasChangeLists())\r
794                         DialogEnableWindow(IDC_KEEPLISTS, true);\r
795                 if (m_ListCtrl.HasLocks())\r
796                         DialogEnableWindow(IDC_WHOLE_PROJECT, true);\r
797                 // we have the list, now signal the main thread about it\r
798                 SendMessage(WM_AUTOLISTREADY);  // only send the message if the thread wasn't told to quit!\r
799         }\r
800 \r
801         InterlockedExchange(&m_bRunThread, FALSE);\r
802         InterlockedExchange(&m_bThreadRunning, FALSE);\r
803         // force the cursor to normal\r
804         RefreshCursor();\r
805 \r
806         return 0;\r
807 }\r
808 \r
809 void CCommitDlg::OnCancel()\r
810 {\r
811         m_bCancelled = true;\r
812         if (m_bBlock)\r
813                 return;\r
814         m_pathwatcher.Stop();\r
815         if (m_bThreadRunning)\r
816         {\r
817                 InterlockedExchange(&m_bRunThread, FALSE);\r
818                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
819                 if (m_bThreadRunning)\r
820                 {\r
821                         // we gave the thread a chance to quit. Since the thread didn't\r
822                         // listen to us we have to kill it.\r
823                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
824                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
825                 }\r
826         }\r
827         UpdateData();\r
828         m_sBugID.Trim();\r
829         m_sLogMessage = m_cLogMessage.GetText();\r
830         if (!m_sBugID.IsEmpty())\r
831         {\r
832                 m_sBugID.Replace(_T(", "), _T(","));\r
833                 m_sBugID.Replace(_T(" ,"), _T(","));\r
834                 CString sBugID = m_ProjectProperties.sMessage;\r
835                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
836                 if (m_ProjectProperties.bAppend)\r
837                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
838                 else\r
839                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
840         }\r
841         if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)\r
842                 m_History.AddEntry(m_sLogMessage);\r
843         m_History.Save();\r
844         SaveSplitterPos();\r
845         CResizableStandAloneDialog::OnCancel();\r
846 }\r
847 \r
848 void CCommitDlg::OnBnClickedSelectall()\r
849 {\r
850         m_tooltips.Pop();       // hide the tooltips\r
851         UINT state = (m_SelectAll.GetState() & 0x0003);\r
852         if (state == BST_INDETERMINATE)\r
853         {\r
854                 // It is not at all useful to manually place the checkbox into the indeterminate state...\r
855                 // We will force this on to the unchecked state\r
856                 state = BST_UNCHECKED;\r
857                 m_SelectAll.SetCheck(state);\r
858         }\r
859         m_ListCtrl.SelectAll(state == BST_CHECKED);\r
860 }\r
861 \r
862 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)\r
863 {\r
864         if (!m_bBlock)\r
865                 m_tooltips.RelayEvent(pMsg);\r
866         \r
867         if (m_hAccel)\r
868         {\r
869                 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);\r
870                 if (ret)\r
871                         return TRUE;\r
872         }\r
873 \r
874         if (pMsg->message == WM_KEYDOWN)\r
875         {\r
876                 switch (pMsg->wParam)\r
877                 {\r
878                 case VK_F5:\r
879                         {\r
880                                 if (m_bBlock)\r
881                                         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
882                                 Refresh();\r
883                         }\r
884                         break;\r
885                 case VK_RETURN:\r
886                         {\r
887                                 if (GetAsyncKeyState(VK_CONTROL)&0x8000)\r
888                                 {\r
889                                         if ( GetDlgItem(IDOK)->IsWindowEnabled() )\r
890                                         {\r
891                                                 PostMessage(WM_COMMAND, IDOK);\r
892                                         }\r
893                                         return TRUE;\r
894                                 }\r
895                                 if ( GetFocus()==GetDlgItem(IDC_BUGID) )\r
896                                 {\r
897                                         // Pressing RETURN in the bug id control\r
898                                         // moves the focus to the message\r
899                                         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
900                                         return TRUE;\r
901                                 }\r
902                         }\r
903                         break;\r
904                 }\r
905         }\r
906 \r
907         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
908 }\r
909 \r
910 void CCommitDlg::Refresh()\r
911 {\r
912         if (m_bThreadRunning)\r
913                 return;\r
914 \r
915         InterlockedExchange(&m_bBlock, TRUE);\r
916         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
917         if (m_pThread==NULL)\r
918         {\r
919                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
920                 InterlockedExchange(&m_bBlock, FALSE);\r
921         }\r
922         else\r
923         {\r
924                 m_pThread->m_bAutoDelete = FALSE;\r
925                 m_pThread->ResumeThread();\r
926         }\r
927 }\r
928 \r
929 void CCommitDlg::OnBnClickedHelp()\r
930 {\r
931         OnHelp();\r
932 }\r
933 \r
934 void CCommitDlg::OnBnClickedShowunversioned()\r
935 {\r
936         m_tooltips.Pop();       // hide the tooltips\r
937         UpdateData();\r
938         m_regAddBeforeCommit = m_bShowUnversioned;\r
939         if (!m_bBlock)\r
940         {\r
941                 DWORD dwShow = m_ListCtrl.GetShowFlags();\r
942                 if (DWORD(m_regAddBeforeCommit))\r
943                         dwShow |= SVNSLC_SHOWUNVERSIONED;\r
944                 else\r
945                         dwShow &= ~SVNSLC_SHOWUNVERSIONED;\r
946                 if(dwShow & SVNSLC_SHOWUNVERSIONED)\r
947                 {\r
948             if(m_bWholeProject)\r
949                 m_ListCtrl.GetStatus(NULL,false,false,true);\r
950             else\r
951                             m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);\r
952                 }\r
953                 m_ListCtrl.Show(dwShow);\r
954         }\r
955 }\r
956 \r
957 void CCommitDlg::OnStnClickedExternalwarning()\r
958 {\r
959         m_tooltips.Popup();\r
960 }\r
961 \r
962 void CCommitDlg::OnEnChangeLogmessage()\r
963 {\r
964         UpdateOKButton();\r
965 }\r
966 \r
967 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)\r
968 {\r
969 #if 0\r
970         if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))\r
971         {\r
972                 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
973                 {\r
974                         m_bShowUnversioned = TRUE;\r
975                         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;\r
976                         m_ListCtrl.Show(dwShow);\r
977                         UpdateData(FALSE);\r
978                 }\r
979         }\r
980 #endif\r
981         return 0;\r
982 }\r
983 \r
984 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)\r
985 {\r
986         Refresh();\r
987         return 0;\r
988 }\r
989 \r
990 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)\r
991 {\r
992 #if 0\r
993         BringWindowToTop();\r
994         SetForegroundWindow();\r
995         SetActiveWindow();\r
996         // if multiple files/folders are dropped\r
997         // this handler is called for every single item\r
998         // separately.\r
999         // To avoid creating multiple refresh threads and\r
1000         // causing crashes, we only add the items to the\r
1001         // list control and start a timer.\r
1002         // When the timer expires, we start the refresh thread,\r
1003         // but only if it isn't already running - otherwise we\r
1004         // restart the timer.\r
1005         CTGitPath path;\r
1006         path.SetFromWin((LPCTSTR)lParam);\r
1007 \r
1008         // just add all the items we get here.\r
1009         // if the item is versioned, the add will fail but nothing\r
1010         // more will happen.\r
1011         Git Git;\r
1012         Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);\r
1013 \r
1014         if (!m_ListCtrl.HasPath(path))\r
1015         {\r
1016                 if (m_pathList.AreAllPathsFiles())\r
1017                 {\r
1018                         m_pathList.AddPath(path);\r
1019                         m_pathList.RemoveDuplicates();\r
1020                         m_updatedPathList.AddPath(path);\r
1021                         m_updatedPathList.RemoveDuplicates();\r
1022                 }\r
1023                 else\r
1024                 {\r
1025                         // if the path list contains folders, we have to check whether\r
1026                         // our just (maybe) added path is a child of one of those. If it is\r
1027                         // a child of a folder already in the list, we must not add it. Otherwise\r
1028                         // that path could show up twice in the list.\r
1029                         bool bHasParentInList = false;\r
1030                         for (int i=0; i<m_pathList.GetCount(); ++i)\r
1031                         {\r
1032                                 if (m_pathList[i].IsAncestorOf(path))\r
1033                                 {\r
1034                                         bHasParentInList = true;\r
1035                                         break;\r
1036                                 }\r
1037                         }\r
1038                         if (!bHasParentInList)\r
1039                         {\r
1040                                 m_pathList.AddPath(path);\r
1041                                 m_pathList.RemoveDuplicates();\r
1042                                 m_updatedPathList.AddPath(path);\r
1043                                 m_updatedPathList.RemoveDuplicates();\r
1044                         }\r
1045                 }\r
1046         }\r
1047         \r
1048         // Always start the timer, since the status of an existing item might have changed\r
1049         SetTimer(REFRESHTIMER, 200, NULL);\r
1050         ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());\r
1051 #endif\r
1052         return 0;\r
1053 }\r
1054 \r
1055 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)\r
1056 {\r
1057         m_cLogMessage.SetAutoCompletionList(m_autolist, '*');\r
1058         return 0;\r
1059 }\r
1060 \r
1061 //////////////////////////////////////////////////////////////////////////\r
1062 // functions which run in the status thread\r
1063 //////////////////////////////////////////////////////////////////////////\r
1064 \r
1065 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)\r
1066 {\r
1067         CString strLine;\r
1068         try\r
1069         {\r
1070                 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);\r
1071                 while (m_bRunThread && file.ReadString(strLine))\r
1072                 {\r
1073                         int eqpos = strLine.Find('=');\r
1074                         CString rgx;\r
1075                         rgx = strLine.Mid(eqpos+1).Trim();\r
1076 \r
1077                         int pos = -1;\r
1078                         while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))\r
1079                         {\r
1080                                 mapRegex[strLine.Left(pos)] = rgx;\r
1081                                 strLine = strLine.Mid(pos+1).Trim();\r
1082                         }\r
1083                         mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;\r
1084                 }\r
1085                 file.Close();\r
1086         }\r
1087         catch (CFileException* pE)\r
1088         {\r
1089                 TRACE("CFileException loading auto list regex file\n");\r
1090                 pE->Delete();\r
1091                 return;\r
1092         }\r
1093 }\r
1094 void CCommitDlg::GetAutocompletionList()\r
1095 {\r
1096         // the auto completion list is made of strings from each selected files.\r
1097         // the strings used are extracted from the files with regexes found\r
1098         // in the file "autolist.txt".\r
1099         // the format of that file is:\r
1100         // file extensions separated with commas '=' regular expression to use\r
1101         // example:\r
1102         // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))\r
1103         // .cpp = (?<=[^\s]::)\b\w+\b\r
1104         \r
1105         std::map<CString, CString> mapRegex;\r
1106         CString sRegexFile = CPathUtils::GetAppDirectory();\r
1107         CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);\r
1108         DWORD timeoutvalue = regtimeout*1000;\r
1109         sRegexFile += _T("autolist.txt");\r
1110         if (!m_bRunThread)\r
1111                 return;\r
1112         ParseRegexFile(sRegexFile, mapRegex);\r
1113         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));\r
1114         sRegexFile.ReleaseBuffer();\r
1115         sRegexFile += _T("\\TortoiseGit\\autolist.txt");\r
1116         if (PathFileExists(sRegexFile))\r
1117         {\r
1118                 ParseRegexFile(sRegexFile, mapRegex);\r
1119         }\r
1120         DWORD starttime = GetTickCount();\r
1121 \r
1122         // now we have two arrays of strings, where the first array contains all\r
1123         // file extensions we can use and the second the corresponding regex strings\r
1124         // to apply to those files.\r
1125 \r
1126         // the next step is to go over all files shown in the commit dialog\r
1127         // and scan them for strings we can use\r
1128         int nListItems = m_ListCtrl.GetItemCount();\r
1129 \r
1130         for (int i=0; i<nListItems && m_bRunThread; ++i)\r
1131         {\r
1132                 // stop parsing after timeout\r
1133                 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))\r
1134                         return;\r
1135 \r
1136                 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
1137 \r
1138                 if(path == NULL)\r
1139                         continue;\r
1140 \r
1141                 CString sPartPath =path->GetGitPathString();\r
1142                 m_autolist.insert(sPartPath);\r
1143 \r
1144 //              const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1145 //              if (!entry)\r
1146 //                      continue;\r
1147                 \r
1148                 // add the path parts to the auto completion list too\r
1149 //              CString sPartPath = entry->GetRelativeGitPath();\r
1150 //              m_autolist.insert(sPartPath);\r
1151 \r
1152 \r
1153                 int pos = 0;\r
1154                 int lastPos = 0;\r
1155                 while ((pos = sPartPath.Find('/', pos)) >= 0)\r
1156                 {\r
1157                         pos++;\r
1158                         lastPos = pos;\r
1159                         m_autolist.insert(sPartPath.Mid(pos));\r
1160                 }\r
1161 \r
1162                 // Last inserted entry is a file name.\r
1163                 // Some users prefer to also list file name without extension.\r
1164                 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))\r
1165                 {\r
1166                         int dotPos = sPartPath.ReverseFind('.');\r
1167                         if ((dotPos >= 0) && (dotPos > lastPos))\r
1168                                 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));\r
1169                 }\r
1170 #if 0\r
1171                 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))\r
1172                         continue;\r
1173 \r
1174                 CString sExt = entry->GetPath().GetFileExtension();\r
1175                 sExt.MakeLower();\r
1176                 // find the regex string which corresponds to the file extension\r
1177                 CString rdata = mapRegex[sExt];\r
1178                 if (rdata.IsEmpty())\r
1179                         continue;\r
1180 \r
1181                 ScanFile(entry->GetPath().GetWinPathString(), rdata);\r
1182                 if ((entry->textstatus != Git_wc_status_unversioned) &&\r
1183                         (entry->textstatus != Git_wc_status_none) &&\r
1184                         (entry->textstatus != Git_wc_status_ignored) &&\r
1185                         (entry->textstatus != Git_wc_status_added) &&\r
1186                         (entry->textstatus != Git_wc_status_normal))\r
1187                 {\r
1188                         CTGitPath basePath = Git::GetPristinePath(entry->GetPath());\r
1189                         if (!basePath.IsEmpty())\r
1190                                 ScanFile(basePath.GetWinPathString(), rdata);\r
1191                 }\r
1192 #endif\r
1193         }\r
1194         ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);\r
1195 }\r
1196 \r
1197 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)\r
1198 {\r
1199         wstring sFileContent;\r
1200         HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);\r
1201         if (hFile != INVALID_HANDLE_VALUE)\r
1202         {\r
1203                 DWORD size = GetFileSize(hFile, NULL);\r
1204                 if (size > 1000000L)\r
1205                 {\r
1206                         // no files bigger than 1 Meg\r
1207                         CloseHandle(hFile);\r
1208                         return;\r
1209                 }\r
1210                 // allocate memory to hold file contents\r
1211                 char * buffer = new char[size];\r
1212                 DWORD readbytes;\r
1213                 ReadFile(hFile, buffer, size, &readbytes, NULL);\r
1214                 CloseHandle(hFile);\r
1215                 int opts = 0;\r
1216                 IsTextUnicode(buffer, readbytes, &opts);\r
1217                 if (opts & IS_TEXT_UNICODE_NULL_BYTES)\r
1218                 {\r
1219                         delete [] buffer;\r
1220                         return;\r
1221                 }\r
1222                 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)\r
1223                 {\r
1224                         sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));\r
1225                 }\r
1226                 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))\r
1227                 {\r
1228                         int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);\r
1229                         wchar_t * pWideBuf = new wchar_t[ret];\r
1230                         int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);\r
1231                         if (ret2 == ret)\r
1232                                 sFileContent = wstring(pWideBuf, ret);\r
1233                         delete [] pWideBuf;\r
1234                 }\r
1235                 delete [] buffer;\r
1236         }\r
1237         if (sFileContent.empty()|| !m_bRunThread)\r
1238         {\r
1239                 return;\r
1240         }\r
1241 \r
1242         try\r
1243         {\r
1244                 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
1245                 const tr1::wsregex_iterator end;\r
1246                 wstring s = sFileContent;\r
1247                 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)\r
1248                 {\r
1249                         const tr1::wsmatch match = *it;\r
1250                         for (size_t i=1; i<match.size(); ++i)\r
1251                         {\r
1252                                 if (match[i].second-match[i].first)\r
1253                                 {\r
1254                                         ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());\r
1255                                         m_autolist.insert(wstring(match[i]).c_str());\r
1256                                 }\r
1257                         }\r
1258                 }\r
1259         }\r
1260         catch (exception) {}\r
1261 }\r
1262 \r
1263 // CSciEditContextMenuInterface\r
1264 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)\r
1265 {\r
1266         CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));\r
1267         m_nPopupPasteListCmd = nCmd++;\r
1268         mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);\r
1269 \r
1270         //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));\r
1271         if(m_History.GetCount() > 0)\r
1272         {\r
1273                 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);\r
1274                 m_nPopupPasteLastMessage = nCmd++;\r
1275                 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);\r
1276 \r
1277                 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);\r
1278                 m_nPopupRecentMessage = nCmd++;\r
1279                 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);\r
1280 \r
1281         }\r
1282         \r
1283 }\r
1284 \r
1285 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)\r
1286 {\r
1287 \r
1288         if (m_bBlock)\r
1289                 return false;\r
1290         if (cmd == m_nPopupPasteListCmd)\r
1291         {\r
1292                 CString logmsg;\r
1293                 TCHAR buf[MAX_STATUS_STRING_LENGTH];\r
1294                 int nListItems = m_ListCtrl.GetItemCount();\r
1295                 for (int i=0; i<nListItems; ++i)\r
1296                 {\r
1297                         CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
1298                         if (entry&&entry->m_Checked)\r
1299                         {\r
1300                                 CString line;\r
1301                                 CString status = entry->GetActionName();\r
1302                                 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)\r
1303                                         status = _T("Add");\r
1304 \r
1305                                 //git_wc_status_kind status = entry->status;\r
1306                                 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());\r
1307                                 if (m_ProjectProperties.bFileListInEnglish)\r
1308                                         langID = 1033;\r
1309                                 \r
1310                                 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));\r
1311                                 logmsg += line;\r
1312                         }\r
1313                 }\r
1314                 pSciEdit->InsertText(logmsg);\r
1315                 return true;\r
1316         }\r
1317 \r
1318         if(cmd == m_nPopupPasteLastMessage)\r
1319         {\r
1320                 if(m_History.GetCount() ==0 )\r
1321                         return false;\r
1322 \r
1323                 CString logmsg;\r
1324                 logmsg +=m_History.GetEntry(0);\r
1325                 pSciEdit->InsertText(logmsg);\r
1326                 return true;\r
1327         }\r
1328 \r
1329         if(cmd == m_nPopupRecentMessage )\r
1330         {\r
1331                 OnBnClickedHistory();\r
1332                 return true;\r
1333         }\r
1334         return false;\r
1335 }\r
1336 \r
1337 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)\r
1338 {\r
1339         switch (nIDEvent)\r
1340         {\r
1341         case ENDDIALOGTIMER:\r
1342                 KillTimer(ENDDIALOGTIMER);\r
1343                 EndDialog(0);\r
1344                 break;\r
1345         case REFRESHTIMER:\r
1346                 if (m_bThreadRunning)\r
1347                 {\r
1348                         SetTimer(REFRESHTIMER, 200, NULL);\r
1349                         ATLTRACE("Wait some more before refreshing\n");\r
1350                 }\r
1351                 else\r
1352                 {\r
1353                         KillTimer(REFRESHTIMER);\r
1354                         ATLTRACE("Refreshing after items dropped\n");\r
1355                         Refresh();\r
1356                 }\r
1357                 break;\r
1358         }\r
1359         __super::OnTimer(nIDEvent);\r
1360 }\r
1361 \r
1362 void CCommitDlg::OnBnClickedHistory()\r
1363 {\r
1364         m_tooltips.Pop();       // hide the tooltips\r
1365         if (m_pathList.GetCount() == 0)\r
1366                 return;\r
1367 \r
1368         CHistoryDlg historyDlg;\r
1369         historyDlg.SetHistory(m_History);\r
1370         if (historyDlg.DoModal() != IDOK)\r
1371                 return;\r
1372 \r
1373         CString sMsg = historyDlg.GetSelectedText();\r
1374         if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))\r
1375         {\r
1376                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);\r
1377                 if (!sBugID.IsEmpty())\r
1378                 {\r
1379                         SetDlgItemText(IDC_BUGID, sBugID);\r
1380                 }\r
1381                 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)\r
1382                         m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());\r
1383                 else\r
1384                         m_cLogMessage.SetText(sMsg);\r
1385         }\r
1386 \r
1387         UpdateOKButton();\r
1388         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
1389 \r
1390 }\r
1391 \r
1392 void CCommitDlg::OnBnClickedBugtraqbutton()\r
1393 {\r
1394         m_tooltips.Pop();       // hide the tooltips\r
1395         CString sMsg = m_cLogMessage.GetText();\r
1396 \r
1397         if (m_BugTraqProvider == NULL)\r
1398                 return;\r
1399 \r
1400         BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
1401         BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);\r
1402         SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());\r
1403 \r
1404         for (LONG index = 0; index < m_pathList.GetCount(); ++index)\r
1405                 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());\r
1406 \r
1407         BSTR originalMessage = sMsg.AllocSysString();\r
1408         BSTR temp = NULL;\r
1409 //      m_revProps.clear();\r
1410 \r
1411         // first try the IBugTraqProvider2 interface\r
1412         CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
1413         HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
1414         if (SUCCEEDED(hr))\r
1415         {\r
1416                 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
1417                 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();\r
1418                 BSTR bugIDOut = NULL;\r
1419                 GetDlgItemText(IDC_BUGID, m_sBugID);\r
1420                 BSTR bugID = m_sBugID.AllocSysString();\r
1421                 SAFEARRAY * revPropNames = NULL;\r
1422                 SAFEARRAY * revPropValues = NULL;\r
1423                 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))\r
1424                 {\r
1425                         CString sErr;\r
1426                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1427                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1428                 }\r
1429                 else\r
1430                 {\r
1431                         if (bugIDOut)\r
1432                         {\r
1433                                 m_sBugID = bugIDOut;\r
1434                                 SysFreeString(bugIDOut);\r
1435                                 SetDlgItemText(IDC_BUGID, m_sBugID);\r
1436                         }\r
1437                         SysFreeString(bugID);\r
1438                         SysFreeString(repositoryRoot);\r
1439                         m_cLogMessage.SetText(temp);\r
1440                         BSTR HUGEP *pbRevNames;\r
1441                         BSTR HUGEP *pbRevValues;\r
1442 \r
1443                         HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);\r
1444                         if (SUCCEEDED(hr1))\r
1445                         {\r
1446                                 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);\r
1447                                 if (SUCCEEDED(hr2))\r
1448                                 {\r
1449                                         if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)\r
1450                                         {\r
1451                                                 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)\r
1452                                                 {\r
1453 //                                                      m_revProps[pbRevNames[i]] = pbRevValues[i];\r
1454                                                 }\r
1455                                         }\r
1456                                         SafeArrayUnaccessData(revPropValues);\r
1457                                 }\r
1458                                 SafeArrayUnaccessData(revPropNames);\r
1459                         }\r
1460                         if (revPropNames)\r
1461                                 SafeArrayDestroy(revPropNames);\r
1462                         if (revPropValues)\r
1463                                 SafeArrayDestroy(revPropValues);\r
1464                 }\r
1465         }\r
1466         else\r
1467         {\r
1468                 // if IBugTraqProvider2 failed, try IBugTraqProvider\r
1469                 CComPtr<IBugTraqProvider> pProvider = NULL;\r
1470                 hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
1471                 if (FAILED(hr))\r
1472                 {\r
1473                         CString sErr;\r
1474                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1475                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1476                         return;\r
1477                 }\r
1478 \r
1479                 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))\r
1480                 {\r
1481                         CString sErr;\r
1482                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1483                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1484                 }\r
1485                 else\r
1486                         m_cLogMessage.SetText(temp);\r
1487         }\r
1488         m_sLogMessage = m_cLogMessage.GetText();\r
1489         if (!m_ProjectProperties.sMessage.IsEmpty())\r
1490         {\r
1491                 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);\r
1492                 if (!sBugID.IsEmpty())\r
1493                 {\r
1494                         SetDlgItemText(IDC_BUGID, sBugID);\r
1495                 }\r
1496         }\r
1497 \r
1498         m_cLogMessage.SetFocus();\r
1499 \r
1500         SysFreeString(parameters);\r
1501         SysFreeString(commonRoot);\r
1502         SafeArrayDestroy(pathList);\r
1503         SysFreeString(originalMessage);\r
1504         SysFreeString(temp);\r
1505 \r
1506 }\r
1507 \r
1508 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)\r
1509 {\r
1510         UpdateOKButton();\r
1511         return 0;\r
1512 }\r
1513 \r
1514 void CCommitDlg::UpdateOKButton()\r
1515 {\r
1516 #if 0\r
1517         BOOL bValidLogSize = FALSE;\r
1518 \r
1519     if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)\r
1520                 bValidLogSize = !m_bBlock;\r
1521 \r
1522         LONG nSelectedItems = m_ListCtrl.GetSelected();\r
1523         DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);\r
1524 #endif\r
1525 }\r
1526 \r
1527 \r
1528 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
1529 {\r
1530         switch (message) {\r
1531         case WM_NOTIFY:\r
1532                 if (wParam == IDC_SPLITTER)\r
1533                 { \r
1534                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
1535                         DoSize(pHdr->delta);\r
1536                 }\r
1537                 break;\r
1538         }\r
1539 \r
1540         return __super::DefWindowProc(message, wParam, lParam);\r
1541 }\r
1542 \r
1543 void CCommitDlg::SetSplitterRange()\r
1544 {\r
1545         if ((m_ListCtrl)&&(m_cLogMessage))\r
1546         {\r
1547                 CRect rcTop;\r
1548                 m_cLogMessage.GetWindowRect(rcTop);\r
1549                 ScreenToClient(rcTop);\r
1550                 CRect rcMiddle;\r
1551                 m_ListCtrl.GetWindowRect(rcMiddle);\r
1552                 ScreenToClient(rcMiddle);\r
1553                 if (rcMiddle.Height() && rcMiddle.Width())\r
1554                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
1555         }\r
1556 }\r
1557 \r
1558 void CCommitDlg::DoSize(int delta)\r
1559 {\r
1560         RemoveAnchor(IDC_MESSAGEGROUP);\r
1561         RemoveAnchor(IDC_LOGMESSAGE);\r
1562         RemoveAnchor(IDC_SPLITTER);\r
1563         RemoveAnchor(IDC_SIGNOFF);\r
1564         RemoveAnchor(IDC_COMMIT_AMEND);\r
1565         RemoveAnchor(IDC_LISTGROUP);\r
1566         RemoveAnchor(IDC_FILELIST);\r
1567         CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);\r
1568         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);\r
1569         CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);\r
1570         CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);\r
1571         CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);\r
1572         CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);\r
1573         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
1574         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
1575         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
1576         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
1577         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
1578         AddAnchor(IDC_SIGNOFF,TOP_RIGHT);\r
1579         AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);\r
1580         ArrangeLayout();\r
1581         // adjust the minimum size of the dialog to prevent the resizing from\r
1582         // moving the list control too far down.\r
1583         CRect rcLogMsg;\r
1584         m_cLogMessage.GetClientRect(rcLogMsg);\r
1585         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));\r
1586 \r
1587         SetSplitterRange();\r
1588         m_cLogMessage.Invalidate();\r
1589         GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
1590 }\r
1591 \r
1592 void CCommitDlg::OnSize(UINT nType, int cx, int cy)\r
1593 {\r
1594     // first, let the resizing take place\r
1595     __super::OnSize(nType, cx, cy);\r
1596 \r
1597     //set range\r
1598     SetSplitterRange();\r
1599 }\r
1600 \r
1601 \r
1602 void CCommitDlg::OnBnClickedSignOff()\r
1603 {\r
1604         // TODO: Add your control notification handler code here\r
1605         CString str;\r
1606         CString username;\r
1607         CString email;\r
1608         username=g_Git.GetUserName();\r
1609         email=g_Git.GetUserEmail();\r
1610         username.Remove(_T('\n'));\r
1611         email.Remove(_T('\n'));\r
1612         str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);\r
1613 \r
1614         m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);\r
1615 }\r
1616 \r
1617 void CCommitDlg::OnStnClickedCommitlabel()\r
1618 {\r
1619         // TODO: Add your control notification handler code here\r
1620 }\r
1621 \r
1622 void CCommitDlg::OnBnClickedCommitAmend()\r
1623 {\r
1624     // TODO: Add your control notification handler code here\r
1625         this->UpdateData();\r
1626         if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())\r
1627         {\r
1628                 GitRev rev;\r
1629                 BYTE_VECTOR vector;\r
1630                 CString head(_T("HEAD"));\r
1631                 g_Git.GetLog(vector,head,NULL,1);\r
1632                 rev.ParserFromLog(vector);\r
1633                 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;\r
1634         }\r
1635 \r
1636         if(this->m_bCommitAmend)\r
1637         {\r
1638                 this->m_NoAmendStr=this->m_cLogMessage.GetText();\r
1639                 m_cLogMessage.SetText(m_AmendStr);\r
1640 \r
1641         }else\r
1642         {\r
1643                 this->m_AmendStr=this->m_cLogMessage.GetText();\r
1644                 m_cLogMessage.SetText(m_NoAmendStr);\r
1645 \r
1646         }\r
1647 \r
1648 }\r
1649 \r
1650 void CCommitDlg::OnBnClickedWholeProject()\r
1651 {\r
1652     // TODO: Add your control notification handler code here\r
1653     m_tooltips.Pop();   // hide the tooltips\r
1654         UpdateData();\r
1655     m_ListCtrl.Clear();\r
1656         if (!m_bBlock)\r
1657         {\r
1658             if(m_bWholeProject)\r
1659             m_ListCtrl.GetStatus(NULL,true,false,true);\r
1660         else\r
1661                     m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);\r
1662                 \r
1663                 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());\r
1664         }\r
1665 \r
1666         CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);\r
1667 \r
1668     if(this->m_bWholeProject)   \r
1669         SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));\r
1670     else\r
1671             SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
1672 \r
1673 }\r
1674 \r
1675 void CCommitDlg::OnStnClickedBugidlabel()\r
1676 {\r
1677         // TODO: Add your control notification handler code here\r
1678 }\r
1679 \r
1680 void CCommitDlg::OnFocusMessage()\r
1681 {\r
1682         m_cLogMessage.SetFocus();\r
1683 }