Added checkbox to commit dialog to disable autoselection of submodules
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob3859ee7362549bca5aed26618cc9210aae9d970f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "CommitDlg.h"
23 #include "DirFileEnum.h"
24 //#include "GitConfig.h"
25 #include "ProjectProperties.h"
26 #include "MessageBox.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "Git.h"
30 #include "Registry.h"
31 #include "GitStatus.h"
32 #include "HistoryDlg.h"
33 #include "Hooks.h"
34 #include "CommonResource.h"
35 #include "UnicodeUtils.h"
36 #include "ProgressDlg.h"
37 #include "ShellUpdater.h"
38 #include "Commands/PushCommand.h"
39 #include "PatchViewDlg.h"
40 #include "COMError.h"
41 #include "Globals.h"
43 #ifdef _DEBUG
44 #define new DEBUG_NEW
45 #undef THIS_FILE
46 static char THIS_FILE[] = __FILE__;
47 #endif
49 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
51 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
52 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
53 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
54 , m_bRecursive(FALSE)
55 , m_bShowUnversioned(FALSE)
56 , m_bBlock(FALSE)
57 , m_bThreadRunning(FALSE)
58 , m_bRunThread(FALSE)
59 , m_pThread(NULL)
60 , m_bWholeProject(FALSE)
61 , m_bKeepChangeList(TRUE)
62 , m_bDoNotAutoselectSubmodules(FALSE)
63 , m_itemsCount(0)
64 , m_bSelectFilesForCommit(TRUE)
65 , m_bNoPostActions(FALSE)
66 , m_bAutoClose(false)
68 this->m_bCommitAmend=FALSE;
69 m_bPushAfterCommit = FALSE;
72 CCommitDlg::~CCommitDlg()
74 if(m_pThread != NULL)
76 delete m_pThread;
80 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
82 CResizableStandAloneDialog::DoDataExchange(pDX);
83 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
84 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
85 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
86 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
87 DDX_Text(pDX, IDC_BUGID, m_sBugID);
88 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
89 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
90 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
91 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
92 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
93 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
94 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
97 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
98 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
99 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
100 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
101 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
102 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
103 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
104 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
105 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
106 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
107 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
108 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
109 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
111 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
112 ON_WM_TIMER()
113 ON_WM_SIZE()
114 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
115 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
116 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
117 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
118 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
119 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
120 ON_WM_MOVE()
121 ON_WM_MOVING()
122 ON_WM_SIZING()
123 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
124 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
125 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
126 END_MESSAGE_MAP()
128 BOOL CCommitDlg::OnInitDialog()
130 CResizableStandAloneDialog::OnInitDialog();
132 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
134 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG")))
136 CStdioFile file;
137 if(file.Open(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG"), CFile::modeRead))
139 CString str;
140 while(file.ReadString(str))
142 m_sLogMessage += str;
143 str.Empty();
144 m_sLogMessage += _T("\n");
148 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
149 m_bShowUnversioned = m_regAddBeforeCommit;
151 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
153 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
154 m_bKeepChangeList = m_regKeepChangelists;
156 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
157 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
159 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
161 // GitConfig config;
162 // m_bWholeProject = config.KeepLocks();
164 if(this->m_pathList.GetCount() == 0)
165 m_bWholeProject =true;
167 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
168 m_bWholeProject =true;
170 UpdateData(FALSE);
172 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"),(SVNSLC_POPALL ^ (SVNSLC_POPCOMMIT | SVNSLC_POPSAVEAS)));
173 m_ListCtrl.SetSelectButton(&m_SelectAll);
174 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
175 m_ListCtrl.SetCancelBool(&m_bCancelled);
176 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
177 m_ListCtrl.EnableFileDrop();
178 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
180 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
181 m_ProjectProperties.ReadPropsPathList(m_pathList);
183 m_cLogMessage.Init(m_ProjectProperties);
184 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
185 m_cLogMessage.RegisterContextMenuHandler(this);
187 OnEnChangeLogmessage();
189 m_tooltips.Create(this);
190 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
191 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
192 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
194 m_SelectAll.SetCheck(BST_INDETERMINATE);
196 CBugTraqAssociations bugtraq_associations;
197 bugtraq_associations.Load();
199 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
201 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
202 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
204 CComPtr<IBugTraqProvider> pProvider;
205 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
206 if (SUCCEEDED(hr))
208 m_BugTraqProvider = pProvider;
209 BSTR temp = NULL;
210 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
212 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
213 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
214 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
217 SysFreeString(temp);
220 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
222 else if (!m_ProjectProperties.sMessage.IsEmpty())
224 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
225 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
226 if (!m_ProjectProperties.sLabel.IsEmpty())
227 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
228 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
229 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
230 GetDlgItem(IDC_BUGID)->SetFocus();
231 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
232 if (!sBugID.IsEmpty())
234 SetDlgItemText(IDC_BUGID, sBugID);
237 else
239 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
240 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
241 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
242 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
243 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
246 if (!m_sLogMessage.IsEmpty())
247 m_cLogMessage.SetText(m_sLogMessage);
249 GetWindowText(m_sWindowTitle);
251 AdjustControlSize(IDC_SHOWUNVERSIONED);
252 AdjustControlSize(IDC_SELECTALL);
253 AdjustControlSize(IDC_WHOLE_PROJECT);
255 GetClientRect(m_DlgOrigRect);
256 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
258 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
259 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
260 AddAnchor(IDC_BUGID, TOP_RIGHT);
261 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
262 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
263 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
264 // AddAnchor(IDC_HISTORY, TOP_LEFT);
265 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
266 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
267 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
268 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
269 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
270 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
271 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
272 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
273 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
274 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
275 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
276 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
277 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
278 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
279 AddAnchor(IDOK, BOTTOM_RIGHT);
280 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
281 AddAnchor(IDHELP, BOTTOM_RIGHT);
282 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
283 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
285 if (hWndExplorer)
286 CenterWindow(CWnd::FromHandle(hWndExplorer));
287 EnableSaveRestore(_T("CommitDlg"));
288 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
289 RECT rcDlg, rcLogMsg, rcFileList;
290 GetClientRect(&rcDlg);
291 m_cLogMessage.GetWindowRect(&rcLogMsg);
292 ScreenToClient(&rcLogMsg);
293 m_ListCtrl.GetWindowRect(&rcFileList);
294 ScreenToClient(&rcFileList);
295 if (yPos)
297 RECT rectSplitter;
298 m_wndSplitter.GetWindowRect(&rectSplitter);
299 ScreenToClient(&rectSplitter);
300 int delta = yPos - rectSplitter.top;
301 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
303 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
304 DoSize(delta);
308 // add all directories to the watcher
310 for (int i=0; i<m_pathList.GetCount(); ++i)
312 if (m_pathList[i].IsDirectory())
313 m_pathwatcher.AddPath(m_pathList[i]);
316 m_updatedPathList = m_pathList;
318 //first start a thread to obtain the file list with the status without
319 //blocking the dialog
320 InterlockedExchange(&m_bBlock, TRUE);
321 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
322 if (m_pThread==NULL)
324 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
325 InterlockedExchange(&m_bBlock, FALSE);
327 else
329 m_pThread->m_bAutoDelete = FALSE;
330 m_pThread->ResumeThread();
332 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
333 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
334 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
336 historyhint = TRUE;
337 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
339 err = FALSE;
341 if(m_bCommitAmend)
343 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(FALSE);
344 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
347 this->m_ctrlShowPatch.SetURL(CString());
349 return FALSE; // return TRUE unless you set the focus to a control
350 // EXCEPTION: OCX Property Pages should return FALSE
353 void CCommitDlg::OnOK()
355 if (m_bBlock)
356 return;
357 if (m_bThreadRunning)
359 m_bCancelled = true;
360 InterlockedExchange(&m_bRunThread, FALSE);
361 WaitForSingleObject(m_pThread->m_hThread, 1000);
362 if (m_bThreadRunning)
364 // we gave the thread a chance to quit. Since the thread didn't
365 // listen to us we have to kill it.
366 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
367 InterlockedExchange(&m_bThreadRunning, FALSE);
370 this->UpdateData();
372 CString id;
373 GetDlgItemText(IDC_BUGID, id);
374 if (!m_ProjectProperties.CheckBugID(id))
376 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
377 return;
379 m_sLogMessage = m_cLogMessage.GetText();
380 if ( m_sLogMessage.IsEmpty() )
382 // no message entered, go round again
383 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
384 return;
386 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
388 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
389 return;
392 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
393 #if 0
394 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
395 if (!(DWORD)regUnversionedRecurse)
397 // Find unversioned directories which are marked for commit. The user might expect them
398 // to be added recursively since he cannot the the files. Let's ask the user if he knows
399 // what he is doing.
400 int nListItems = m_ListCtrl.GetItemCount();
401 for (int j=0; j<nListItems; j++)
403 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
404 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
406 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
407 return;
411 #endif
412 m_pathwatcher.Stop();
413 InterlockedExchange(&m_bBlock, TRUE);
414 CDWordArray arDeleted;
415 //first add all the unversioned files the user selected
416 //and check if all versioned files are selected
417 int nchecked = 0;
418 m_bRecursive = true;
419 int nListItems = m_ListCtrl.GetItemCount();
421 CTGitPathList itemsToAdd;
422 CTGitPathList itemsToRemove;
423 //std::set<CString> checkedLists;
424 //std::set<CString> uncheckedLists;
426 // now let the bugtraq plugin check the commit message
427 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
428 if (m_BugTraqProvider)
430 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
431 if (SUCCEEDED(hr))
433 BSTR temp = NULL;
434 CString common = g_Git.m_CurrentDir;
435 BSTR repositoryRoot = common.AllocSysString();
436 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
437 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
438 BSTR commitMessage = m_sLogMessage.AllocSysString();
439 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
441 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
442 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
444 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
446 COMError ce(hr);
447 CString sErr;
448 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
449 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
451 else
453 CString sError = temp;
454 if (!sError.IsEmpty())
456 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
457 return;
459 SysFreeString(temp);
464 //CString checkedfiles;
465 //CString uncheckedfiles;
467 CString cmd;
468 CString out;
470 bool bAddSuccess=true;
471 bool bCloseCommitDlg=false;
473 for (int j=0; j<nListItems; j++)
475 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
476 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
477 if (entry->m_Checked)
479 #if 0
480 if (entry->status == Git_wc_status_unversioned)
482 itemsToAdd.AddPath(entry->GetPath());
484 if (entry->status == Git_wc_status_conflicted)
486 bHasConflicted = true;
488 if (entry->status == Git_wc_status_missing)
490 itemsToRemove.AddPath(entry->GetPath());
492 if (entry->status == Git_wc_status_deleted)
494 arDeleted.Add(j);
496 if (entry->IsInExternal())
498 bCheckedInExternal = true;
500 #endif
501 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
502 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
503 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
504 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
505 else
506 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
508 if(g_Git.Run(cmd,&out,CP_ACP))
510 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
511 bAddSuccess = false ;
512 break;
515 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
516 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
518 g_Git.Run(cmd,&out,CP_ACP);
520 nchecked++;
522 //checkedLists.insert(entry->GetGitPathString());
523 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
525 else
527 //uncheckedLists.insert(entry->GetGitPathString());
528 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
529 { //To init git repository, there are not HEAD, so we can use git reset command
530 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
531 if(g_Git.Run(cmd,&out,CP_ACP))
533 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
534 bAddSuccess = false ;
535 bCloseCommitDlg=false;
536 break;
540 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
542 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
544 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
546 else
548 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
550 if(g_Git.Run(cmd,&out,CP_ACP))
552 /* when reset a unstage file will report error.
553 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
554 bAddSuccess = false ;
555 bCloseCommitDlg=false;
556 break;
559 // && !entry->IsDirectory()
560 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
561 continue;
564 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
565 #if 0
566 if ((entry->status != Git_wc_status_unversioned) &&
567 (entry->status != Git_wc_status_ignored))
569 nUnchecked++;
570 uncheckedLists.insert(entry->GetChangeList());
571 if (m_bRecursive)
573 // This algorithm is for the sake of simplicity of the complexity O(N?
574 for (int k=0; k<nListItems; k++)
576 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
577 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
579 // Fall back to a non-recursive commit to prevent items being
580 // committed which aren't checked although its parent is checked
581 // (property change, directory deletion, ... )
582 m_bRecursive = false;
583 break;
588 #endif
591 CShellUpdater::Instance().AddPathForUpdate(*entry);
594 //if(uncheckedfiles.GetLength()>0)
596 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
597 // g_Git.Run(cmd,&out);
600 m_sBugID.Trim();
601 if (!m_sBugID.IsEmpty())
603 m_sBugID.Replace(_T(", "), _T(","));
604 m_sBugID.Replace(_T(" ,"), _T(","));
605 CString sBugID = m_ProjectProperties.sMessage;
606 sBugID.Replace(_T("%BUGID%"), m_sBugID);
607 if (m_ProjectProperties.bAppend)
608 m_sLogMessage += _T("\n") + sBugID + _T("\n");
609 else
610 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
613 BOOL bIsMerge=false;
614 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
616 bIsMerge=true;
618 //if(checkedfiles.GetLength()>0)
619 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
621 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
622 // g_Git.Run(cmd,&out);
624 bCloseCommitDlg = true;
626 CString tempfile=::GetTempFile();
628 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
629 //file.WriteString(m_sLogMessage);
631 CTGitPath path=g_Git.m_CurrentDir;
633 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
635 out =_T("");
636 CString amend;
637 if(this->m_bCommitAmend)
639 amend=_T("--amend");
641 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
643 CheckHeadDetach();
645 CCommitProgressDlg progress;
646 progress.m_bBufferAll=true; // improve show speed when there are many file added.
647 progress.m_GitCmd=cmd;
648 progress.m_bShowCommand = FALSE; // don't show the commit command
649 progress.m_PreText = out; // show any output already generated in log window
650 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
652 if (!m_bNoPostActions || !m_bAutoClose)
654 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
655 progress.m_PostCmdList.Add(_T("&ReCommit"));
658 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
660 DWORD userResponse = progress.DoModal();
662 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1+1))
664 bCloseCommitDlg = false;
665 if( userResponse == (IDC_PROGRESS_BUTTON1+1 ))
667 this->m_sLogMessage.Empty();
668 m_cLogMessage.SetText(m_sLogMessage);
671 this->Refresh();
673 else if(userResponse == IDC_PROGRESS_BUTTON1)
675 //User pressed 'Push' button after successful commit.
676 m_bPushAfterCommit=true;
679 CFile::Remove(tempfile);
681 if (m_BugTraqProvider && progress.m_GitStatus == 0)
683 CComPtr<IBugTraqProvider2> pProvider = NULL;
684 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
685 if (SUCCEEDED(hr))
687 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
688 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
690 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
691 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
693 BSTR logMessage = m_sLogMessage.AllocSysString();
695 CGitHash hash=g_Git.GetHash(_T("HEAD"));
696 LONG version = g_Git.Hash2int(hash);
698 BSTR temp = NULL;
699 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
700 commonRoot,
701 pathList,
702 logMessage,
703 (LONG)version,
704 &temp)))
706 CString sErr = temp;
707 if (!sErr.IsEmpty())
708 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
709 else
711 COMError ce(hr);
712 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
713 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
717 SysFreeString(temp);
721 }else if(bAddSuccess)
723 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
724 bCloseCommitDlg=false;
726 #if 0
727 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
729 // There are paths which got changed (touched at least).
730 // We have to find out if this affects the selection in the commit dialog
731 // If it could affect the selection, revert back to a non-recursive commit
732 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
733 changedList.RemoveDuplicates();
734 for (int i=0; i<changedList.GetCount(); ++i)
736 if (changedList[i].IsAdminDir())
738 // something inside an admin dir was changed.
739 // if it's the entries file, then we have to fully refresh because
740 // files may have been added/removed from version control
741 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
742 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
744 m_bRecursive = false;
745 break;
748 else if (!m_ListCtrl.IsPathShown(changedList[i]))
750 // a path which is not shown in the list has changed
751 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
752 if (entry)
754 // check if the changed path would get committed by a recursive commit
755 if ((!entry->IsFromDifferentRepository()) &&
756 (!entry->IsInExternal()) &&
757 (!entry->IsNested()) &&
758 (!entry->IsChecked()))
760 m_bRecursive = false;
761 break;
769 // Now, do all the adds - make sure that the list is sorted so that parents
770 // are added before their children
771 itemsToAdd.SortByPathname();
772 Git Git;
773 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
775 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
776 InterlockedExchange(&m_bBlock, FALSE);
777 Refresh();
778 return;
781 // Remove any missing items
782 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
783 itemsToRemove.SortByPathname();
784 Git.Remove(itemsToRemove, TRUE);
786 //the next step: find all deleted files and check if they're
787 //inside a deleted folder. If that's the case, then remove those
788 //files from the list since they'll get deleted by the parent
789 //folder automatically.
790 m_ListCtrl.Block(TRUE, FALSE);
791 INT_PTR nDeleted = arDeleted.GetCount();
792 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
794 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
796 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
797 if (path.IsDirectory())
799 //now find all children of this directory
800 for (int j=0; j<arDeleted.GetCount(); j++)
802 if (i!=j)
804 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
805 if (childEntry->IsChecked())
807 if (path.IsAncestorOf(childEntry->GetPath()))
809 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
810 nDeleted--;
818 m_ListCtrl.Block(FALSE, FALSE);
820 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
822 //save only the files the user has checked into the temporary file
823 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
826 // the item count is used in the progress dialog to show the overall commit
827 // progress.
828 // deleted items only send one notification event, all others send two
829 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
831 if ((m_bRecursive)&&(checkedLists.size() == 1))
833 // all checked items belong to the same changelist
834 // find out if there are any unchecked items which belong to that changelist
835 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
836 m_sChangeList = *checkedLists.begin();
838 #endif
839 UpdateData();
840 m_regAddBeforeCommit = m_bShowUnversioned;
841 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
842 m_bWholeProject = FALSE;
843 m_regKeepChangelists = m_bKeepChangeList;
844 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
845 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
846 m_bKeepChangeList = FALSE;
847 InterlockedExchange(&m_bBlock, FALSE);
849 m_History.AddEntry(m_sLogMessage);
850 m_History.Save();
852 SaveSplitterPos();
854 if( bCloseCommitDlg )
855 CResizableStandAloneDialog::OnOK();
857 CShellUpdater::Instance().Flush();
860 void CCommitDlg::SaveSplitterPos()
862 if (!IsIconic())
864 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
865 RECT rectSplitter;
866 m_wndSplitter.GetWindowRect(&rectSplitter);
867 ScreenToClient(&rectSplitter);
868 regPos = rectSplitter.top;
872 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
874 return ((CCommitDlg*)pVoid)->StatusThread();
877 UINT CCommitDlg::StatusThread()
879 //get the status of all selected file/folders recursively
880 //and show the ones which have to be committed to the user
881 //in a list control.
882 InterlockedExchange(&m_bBlock, TRUE);
883 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
884 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
886 m_pathwatcher.Stop();
888 g_Git.RefreshGitIndex();
890 m_bCancelled = false;
892 DialogEnableWindow(IDOK, false);
893 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
894 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
895 DialogEnableWindow(IDC_SELECTALL, false);
896 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
897 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
898 DialogEnableWindow(IDC_EXTERNALWARNING, false);
899 // read the list of recent log entries before querying the WC for status
900 // -> the user may select one and modify / update it while we are crawling the WC
902 if (m_History.GetCount()==0)
904 CString reg;
905 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
906 reg.Replace(_T(':'),_T('_'));
907 m_History.Load(reg, _T("logmsgs"));
910 // Initialise the list control with the status of the files/folders below us
911 m_ListCtrl.Clear();
912 BOOL success;
913 CTGitPathList *pList;
914 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
915 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
917 if(m_bWholeProject)
918 pList=NULL;
919 else
920 pList = &m_pathList;
922 success=m_ListCtrl.GetStatus(pList);
924 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
925 if(this->m_bShowUnversioned)
926 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
928 m_ListCtrl.CheckIfChangelistsArePresent(false);
930 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
931 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
932 if (success)
934 if (m_checkedPathList.GetCount())
935 m_ListCtrl.Show(dwShow, m_checkedPathList);
936 else
938 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
939 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
940 m_ListCtrl.Show(dwShow, dwCheck);
941 m_bSelectFilesForCommit = true;
944 if (m_ListCtrl.HasExternalsFromDifferentRepos())
946 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
947 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
950 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
951 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
953 CString logmsg;
954 GetDlgItemText(IDC_LOGMESSAGE, logmsg);
955 DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);
956 if (!success)
958 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
959 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
960 m_ListCtrl.Show(dwShow);
962 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
963 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
965 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
967 m_bShowUnversioned = TRUE;
968 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
969 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
970 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
971 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
975 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
977 if(this->m_bWholeProject)
978 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T(" (Whole Project)")));
979 else
980 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
982 m_autolist.clear();
983 // we don't have to block the commit dialog while we fetch the
984 // auto completion list.
985 m_pathwatcher.ClearChangedPaths();
986 InterlockedExchange(&m_bBlock, FALSE);
987 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
989 m_ListCtrl.Block(TRUE, TRUE);
990 GetAutocompletionList();
991 m_ListCtrl.Block(FALSE, FALSE);
993 if (m_bRunThread)
995 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
996 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
997 DialogEnableWindow(IDC_SELECTALL, true);
998 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
999 if (m_ListCtrl.HasChangeLists())
1000 DialogEnableWindow(IDC_KEEPLISTS, true);
1001 if (m_ListCtrl.HasLocks())
1002 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1003 // we have the list, now signal the main thread about it
1004 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1007 InterlockedExchange(&m_bRunThread, FALSE);
1008 InterlockedExchange(&m_bThreadRunning, FALSE);
1009 // force the cursor to normal
1010 RefreshCursor();
1012 return 0;
1015 void CCommitDlg::OnCancel()
1017 m_bCancelled = true;
1018 m_pathwatcher.Stop();
1020 if (m_bBlock)
1021 return;
1023 if (m_bThreadRunning)
1025 InterlockedExchange(&m_bRunThread, FALSE);
1026 WaitForSingleObject(m_pThread->m_hThread, 1000);
1027 if (m_bThreadRunning)
1029 // we gave the thread a chance to quit. Since the thread didn't
1030 // listen to us we have to kill it.
1031 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1032 InterlockedExchange(&m_bThreadRunning, FALSE);
1035 UpdateData();
1036 m_sBugID.Trim();
1037 m_sLogMessage = m_cLogMessage.GetText();
1038 if (!m_sBugID.IsEmpty())
1040 m_sBugID.Replace(_T(", "), _T(","));
1041 m_sBugID.Replace(_T(" ,"), _T(","));
1042 CString sBugID = m_ProjectProperties.sMessage;
1043 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1044 if (m_ProjectProperties.bAppend)
1045 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1046 else
1047 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1049 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1050 m_History.AddEntry(m_sLogMessage);
1051 m_History.Save();
1052 SaveSplitterPos();
1053 CResizableStandAloneDialog::OnCancel();
1056 void CCommitDlg::OnBnClickedSelectall()
1058 m_tooltips.Pop(); // hide the tooltips
1059 UINT state = (m_SelectAll.GetState() & 0x0003);
1060 if (state == BST_INDETERMINATE)
1062 // It is not at all useful to manually place the checkbox into the indeterminate state...
1063 // We will force this on to the unchecked state
1064 state = BST_UNCHECKED;
1065 m_SelectAll.SetCheck(state);
1067 m_ListCtrl.SelectAll(state == BST_CHECKED);
1070 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1072 if (!m_bBlock)
1073 m_tooltips.RelayEvent(pMsg);
1075 if (m_hAccel)
1077 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1078 if (ret)
1079 return TRUE;
1082 if (pMsg->message == WM_KEYDOWN)
1084 switch (pMsg->wParam)
1086 case VK_F5:
1088 if (m_bBlock)
1089 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1090 Refresh();
1092 break;
1093 case VK_RETURN:
1095 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1097 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1099 PostMessage(WM_COMMAND, IDOK);
1101 return TRUE;
1103 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1105 // Pressing RETURN in the bug id control
1106 // moves the focus to the message
1107 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1108 return TRUE;
1111 break;
1115 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1118 void CCommitDlg::Refresh()
1120 if (m_bThreadRunning)
1121 return;
1123 InterlockedExchange(&m_bBlock, TRUE);
1124 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1125 if (m_pThread==NULL)
1127 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1128 InterlockedExchange(&m_bBlock, FALSE);
1130 else
1132 m_pThread->m_bAutoDelete = FALSE;
1133 m_pThread->ResumeThread();
1137 void CCommitDlg::OnBnClickedHelp()
1139 OnHelp();
1142 void CCommitDlg::OnBnClickedShowunversioned()
1144 m_tooltips.Pop(); // hide the tooltips
1145 UpdateData();
1146 m_regAddBeforeCommit = m_bShowUnversioned;
1147 if (!m_bBlock)
1149 DWORD dwShow = m_ListCtrl.GetShowFlags();
1150 if (DWORD(m_regAddBeforeCommit))
1151 dwShow |= SVNSLC_SHOWUNVERSIONED;
1152 else
1153 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1154 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1156 if(m_bWholeProject)
1157 m_ListCtrl.GetStatus(NULL,false,false,true);
1158 else
1159 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1161 m_ListCtrl.Show(dwShow,0,true,0,true);
1165 void CCommitDlg::OnStnClickedExternalwarning()
1167 m_tooltips.Popup();
1170 void CCommitDlg::OnEnChangeLogmessage()
1172 UpdateOKButton();
1175 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1177 #if 0
1178 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1180 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1182 m_bShowUnversioned = TRUE;
1183 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1184 m_ListCtrl.Show(dwShow);
1185 UpdateData(FALSE);
1188 #endif
1189 return 0;
1192 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1194 Refresh();
1195 return 0;
1198 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1200 #if 0
1201 BringWindowToTop();
1202 SetForegroundWindow();
1203 SetActiveWindow();
1204 // if multiple files/folders are dropped
1205 // this handler is called for every single item
1206 // separately.
1207 // To avoid creating multiple refresh threads and
1208 // causing crashes, we only add the items to the
1209 // list control and start a timer.
1210 // When the timer expires, we start the refresh thread,
1211 // but only if it isn't already running - otherwise we
1212 // restart the timer.
1213 CTGitPath path;
1214 path.SetFromWin((LPCTSTR)lParam);
1216 // just add all the items we get here.
1217 // if the item is versioned, the add will fail but nothing
1218 // more will happen.
1219 Git Git;
1220 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1222 if (!m_ListCtrl.HasPath(path))
1224 if (m_pathList.AreAllPathsFiles())
1226 m_pathList.AddPath(path);
1227 m_pathList.RemoveDuplicates();
1228 m_updatedPathList.AddPath(path);
1229 m_updatedPathList.RemoveDuplicates();
1231 else
1233 // if the path list contains folders, we have to check whether
1234 // our just (maybe) added path is a child of one of those. If it is
1235 // a child of a folder already in the list, we must not add it. Otherwise
1236 // that path could show up twice in the list.
1237 bool bHasParentInList = false;
1238 for (int i=0; i<m_pathList.GetCount(); ++i)
1240 if (m_pathList[i].IsAncestorOf(path))
1242 bHasParentInList = true;
1243 break;
1246 if (!bHasParentInList)
1248 m_pathList.AddPath(path);
1249 m_pathList.RemoveDuplicates();
1250 m_updatedPathList.AddPath(path);
1251 m_updatedPathList.RemoveDuplicates();
1256 // Always start the timer, since the status of an existing item might have changed
1257 SetTimer(REFRESHTIMER, 200, NULL);
1258 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1259 #endif
1260 return 0;
1263 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1265 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1266 return 0;
1269 //////////////////////////////////////////////////////////////////////////
1270 // functions which run in the status thread
1271 //////////////////////////////////////////////////////////////////////////
1273 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1275 CString strLine;
1278 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1279 while (m_bRunThread && file.ReadString(strLine))
1281 int eqpos = strLine.Find('=');
1282 CString rgx;
1283 rgx = strLine.Mid(eqpos+1).Trim();
1285 int pos = -1;
1286 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1288 mapRegex[strLine.Left(pos)] = rgx;
1289 strLine = strLine.Mid(pos+1).Trim();
1291 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1293 file.Close();
1295 catch (CFileException* pE)
1297 TRACE("CFileException loading auto list regex file\n");
1298 pE->Delete();
1299 return;
1302 void CCommitDlg::GetAutocompletionList()
1304 // the auto completion list is made of strings from each selected files.
1305 // the strings used are extracted from the files with regexes found
1306 // in the file "autolist.txt".
1307 // the format of that file is:
1308 // file extensions separated with commas '=' regular expression to use
1309 // example:
1310 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1311 // .cpp = (?<=[^\s]::)\b\w+\b
1313 std::map<CString, CString> mapRegex;
1314 CString sRegexFile = CPathUtils::GetAppDirectory();
1315 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1316 DWORD timeoutvalue = regtimeout*1000;
1317 sRegexFile += _T("autolist.txt");
1318 if (!m_bRunThread)
1319 return;
1320 ParseRegexFile(sRegexFile, mapRegex);
1321 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1322 sRegexFile.ReleaseBuffer();
1323 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1324 if (PathFileExists(sRegexFile))
1326 ParseRegexFile(sRegexFile, mapRegex);
1328 DWORD starttime = GetTickCount();
1330 // now we have two arrays of strings, where the first array contains all
1331 // file extensions we can use and the second the corresponding regex strings
1332 // to apply to those files.
1334 // the next step is to go over all files shown in the commit dialog
1335 // and scan them for strings we can use
1336 int nListItems = m_ListCtrl.GetItemCount();
1338 for (int i=0; i<nListItems && m_bRunThread; ++i)
1340 // stop parsing after timeout
1341 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1342 return;
1344 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1346 if(path == NULL)
1347 continue;
1349 CString sPartPath =path->GetGitPathString();
1350 m_autolist.insert(sPartPath);
1352 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1353 // if (!entry)
1354 // continue;
1356 // add the path parts to the auto completion list too
1357 // CString sPartPath = entry->GetRelativeGitPath();
1358 // m_autolist.insert(sPartPath);
1361 int pos = 0;
1362 int lastPos = 0;
1363 while ((pos = sPartPath.Find('/', pos)) >= 0)
1365 pos++;
1366 lastPos = pos;
1367 m_autolist.insert(sPartPath.Mid(pos));
1370 // Last inserted entry is a file name.
1371 // Some users prefer to also list file name without extension.
1372 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1374 int dotPos = sPartPath.ReverseFind('.');
1375 if ((dotPos >= 0) && (dotPos > lastPos))
1376 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1378 #if 0
1379 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1380 continue;
1382 CString sExt = entry->GetPath().GetFileExtension();
1383 sExt.MakeLower();
1384 // find the regex string which corresponds to the file extension
1385 CString rdata = mapRegex[sExt];
1386 if (rdata.IsEmpty())
1387 continue;
1389 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1390 if ((entry->textstatus != Git_wc_status_unversioned) &&
1391 (entry->textstatus != Git_wc_status_none) &&
1392 (entry->textstatus != Git_wc_status_ignored) &&
1393 (entry->textstatus != Git_wc_status_added) &&
1394 (entry->textstatus != Git_wc_status_normal))
1396 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1397 if (!basePath.IsEmpty())
1398 ScanFile(basePath.GetWinPathString(), rdata);
1400 #endif
1402 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1405 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1407 wstring sFileContent;
1408 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1409 if (hFile != INVALID_HANDLE_VALUE)
1411 DWORD size = GetFileSize(hFile, NULL);
1412 if (size > 1000000L)
1414 // no files bigger than 1 Meg
1415 CloseHandle(hFile);
1416 return;
1418 // allocate memory to hold file contents
1419 char * buffer = new char[size];
1420 DWORD readbytes;
1421 ReadFile(hFile, buffer, size, &readbytes, NULL);
1422 CloseHandle(hFile);
1423 int opts = 0;
1424 IsTextUnicode(buffer, readbytes, &opts);
1425 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1427 delete [] buffer;
1428 return;
1430 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1432 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1434 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1436 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1437 wchar_t * pWideBuf = new wchar_t[ret];
1438 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1439 if (ret2 == ret)
1440 sFileContent = wstring(pWideBuf, ret);
1441 delete [] pWideBuf;
1443 delete [] buffer;
1445 if (sFileContent.empty()|| !m_bRunThread)
1447 return;
1452 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1453 const tr1::wsregex_iterator end;
1454 wstring s = sFileContent;
1455 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1457 const tr1::wsmatch match = *it;
1458 for (size_t i=1; i<match.size(); ++i)
1460 if (match[i].second-match[i].first)
1462 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1463 m_autolist.insert(wstring(match[i]).c_str());
1468 catch (exception) {}
1471 // CSciEditContextMenuInterface
1472 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1474 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1475 m_nPopupPasteListCmd = nCmd++;
1476 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1478 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1479 if(m_History.GetCount() > 0)
1481 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1482 m_nPopupPasteLastMessage = nCmd++;
1483 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1485 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1486 m_nPopupRecentMessage = nCmd++;
1487 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1493 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1496 if (m_bBlock)
1497 return false;
1498 if (cmd == m_nPopupPasteListCmd)
1500 CString logmsg;
1501 int nListItems = m_ListCtrl.GetItemCount();
1502 for (int i=0; i<nListItems; ++i)
1504 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1505 if (entry&&entry->m_Checked)
1507 CString line;
1508 CString status = entry->GetActionName();
1509 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1510 status = _T("Add");
1512 //git_wc_status_kind status = entry->status;
1513 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1514 if (m_ProjectProperties.bFileListInEnglish)
1515 langID = 1033;
1517 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1518 logmsg += line;
1521 pSciEdit->InsertText(logmsg);
1522 return true;
1525 if(cmd == m_nPopupPasteLastMessage)
1527 if(m_History.GetCount() ==0 )
1528 return false;
1530 CString logmsg;
1531 logmsg +=m_History.GetEntry(0);
1532 pSciEdit->InsertText(logmsg);
1533 return true;
1536 if(cmd == m_nPopupRecentMessage )
1538 OnBnClickedHistory();
1539 return true;
1541 return false;
1544 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1546 switch (nIDEvent)
1548 case ENDDIALOGTIMER:
1549 KillTimer(ENDDIALOGTIMER);
1550 EndDialog(0);
1551 break;
1552 case REFRESHTIMER:
1553 if (m_bThreadRunning)
1555 SetTimer(REFRESHTIMER, 200, NULL);
1556 ATLTRACE("Wait some more before refreshing\n");
1558 else
1560 KillTimer(REFRESHTIMER);
1561 ATLTRACE("Refreshing after items dropped\n");
1562 Refresh();
1564 break;
1566 __super::OnTimer(nIDEvent);
1569 void CCommitDlg::OnBnClickedHistory()
1571 m_tooltips.Pop(); // hide the tooltips
1572 if (m_pathList.GetCount() == 0)
1573 return;
1575 CHistoryDlg historyDlg;
1576 historyDlg.SetHistory(m_History);
1577 if (historyDlg.DoModal() != IDOK)
1578 return;
1580 CString sMsg = historyDlg.GetSelectedText();
1581 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1583 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1584 if (!sBugID.IsEmpty())
1586 SetDlgItemText(IDC_BUGID, sBugID);
1588 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1589 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1590 else
1591 m_cLogMessage.SetText(sMsg);
1594 UpdateOKButton();
1595 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1599 void CCommitDlg::OnBnClickedBugtraqbutton()
1601 m_tooltips.Pop(); // hide the tooltips
1602 CString sMsg = m_cLogMessage.GetText();
1604 if (m_BugTraqProvider == NULL)
1605 return;
1607 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1608 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1609 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1611 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1612 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1614 BSTR originalMessage = sMsg.AllocSysString();
1615 BSTR temp = NULL;
1616 // m_revProps.clear();
1618 // first try the IBugTraqProvider2 interface
1619 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1620 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1621 if (SUCCEEDED(hr))
1623 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1624 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1625 BSTR bugIDOut = NULL;
1626 GetDlgItemText(IDC_BUGID, m_sBugID);
1627 BSTR bugID = m_sBugID.AllocSysString();
1628 SAFEARRAY * revPropNames = NULL;
1629 SAFEARRAY * revPropValues = NULL;
1630 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1632 CString sErr;
1633 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1634 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1636 else
1638 if (bugIDOut)
1640 m_sBugID = bugIDOut;
1641 SysFreeString(bugIDOut);
1642 SetDlgItemText(IDC_BUGID, m_sBugID);
1644 SysFreeString(bugID);
1645 SysFreeString(repositoryRoot);
1646 m_cLogMessage.SetText(temp);
1647 BSTR HUGEP *pbRevNames;
1648 BSTR HUGEP *pbRevValues;
1650 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1651 if (SUCCEEDED(hr1))
1653 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1654 if (SUCCEEDED(hr2))
1656 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1658 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1660 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1663 SafeArrayUnaccessData(revPropValues);
1665 SafeArrayUnaccessData(revPropNames);
1667 if (revPropNames)
1668 SafeArrayDestroy(revPropNames);
1669 if (revPropValues)
1670 SafeArrayDestroy(revPropValues);
1673 else
1675 // if IBugTraqProvider2 failed, try IBugTraqProvider
1676 CComPtr<IBugTraqProvider> pProvider = NULL;
1677 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1678 if (FAILED(hr))
1680 CString sErr;
1681 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1682 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1683 return;
1686 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1688 CString sErr;
1689 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1690 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1692 else
1693 m_cLogMessage.SetText(temp);
1695 m_sLogMessage = m_cLogMessage.GetText();
1696 if (!m_ProjectProperties.sMessage.IsEmpty())
1698 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1699 if (!sBugID.IsEmpty())
1701 SetDlgItemText(IDC_BUGID, sBugID);
1705 m_cLogMessage.SetFocus();
1707 SysFreeString(parameters);
1708 SysFreeString(commonRoot);
1709 SafeArrayDestroy(pathList);
1710 SysFreeString(originalMessage);
1711 SysFreeString(temp);
1715 void CCommitDlg::FillPatchView()
1717 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1719 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1721 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1722 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1723 CString cmd,out;
1725 while(pos)
1727 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1728 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1729 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1731 CString head;
1732 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1733 head = _T("HEAD~1 ");
1734 cmd.Format(_T("git.exe diff %s-- \"%s\""), head, p->GetGitPathString());
1735 g_Git.Run(cmd,&out,CP_ACP);
1739 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1740 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1741 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1744 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1746 this->FillPatchView();
1747 return 0;
1751 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1753 UpdateOKButton();
1754 return 0;
1757 void CCommitDlg::UpdateOKButton()
1759 #if 0
1760 BOOL bValidLogSize = FALSE;
1762 if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)
1763 bValidLogSize = !m_bBlock;
1765 LONG nSelectedItems = m_ListCtrl.GetSelected();
1766 DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);
1767 #endif
1770 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1772 switch (message) {
1773 case WM_NOTIFY:
1774 if (wParam == IDC_SPLITTER)
1776 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1777 DoSize(pHdr->delta);
1779 break;
1782 return __super::DefWindowProc(message, wParam, lParam);
1785 void CCommitDlg::SetSplitterRange()
1787 if ((m_ListCtrl)&&(m_cLogMessage))
1789 CRect rcTop;
1790 m_cLogMessage.GetWindowRect(rcTop);
1791 ScreenToClient(rcTop);
1792 CRect rcMiddle;
1793 m_ListCtrl.GetWindowRect(rcMiddle);
1794 ScreenToClient(rcMiddle);
1795 if (rcMiddle.Height() && rcMiddle.Width())
1796 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1800 void CCommitDlg::DoSize(int delta)
1802 RemoveAnchor(IDC_MESSAGEGROUP);
1803 RemoveAnchor(IDC_LOGMESSAGE);
1804 RemoveAnchor(IDC_SPLITTER);
1805 RemoveAnchor(IDC_SIGNOFF);
1806 RemoveAnchor(IDC_COMMIT_AMEND);
1807 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
1808 RemoveAnchor(IDC_LISTGROUP);
1809 RemoveAnchor(IDC_FILELIST);
1810 RemoveAnchor(IDC_TEXT_INFO);
1811 RemoveAnchor(IDC_VIEW_PATCH);
1813 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1814 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1815 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1816 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1817 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1818 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1819 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
1820 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1821 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1823 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1824 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1825 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1826 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1827 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1828 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1829 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1830 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1831 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
1832 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1833 ArrangeLayout();
1834 // adjust the minimum size of the dialog to prevent the resizing from
1835 // moving the list control too far down.
1836 CRect rcLogMsg;
1837 m_cLogMessage.GetClientRect(rcLogMsg);
1838 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1840 SetSplitterRange();
1841 m_cLogMessage.Invalidate();
1842 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1845 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1847 // first, let the resizing take place
1848 __super::OnSize(nType, cx, cy);
1850 //set range
1851 SetSplitterRange();
1855 void CCommitDlg::OnBnClickedSignOff()
1857 CString str;
1858 CString username;
1859 CString email;
1860 username=g_Git.GetUserName();
1861 email=g_Git.GetUserEmail();
1862 username.Remove(_T('\n'));
1863 email.Remove(_T('\n'));
1864 str.Format(_T("Signed-off-by: %s <%s>"),username,email);
1866 if (m_cLogMessage.GetText().Find(str) == -1) {
1867 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
1868 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
1869 int foundByLine = -1;
1870 if (lastNewline > 0)
1871 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
1873 if (foundByLine == -1 || foundByLine < lastNewline)
1874 str = _T("\r\n") + str;
1876 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
1880 void CCommitDlg::OnBnClickedCommitAmend()
1882 this->UpdateData();
1883 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1885 GitRev rev;
1886 rev.GetCommit(CString(_T("HEAD")));
1887 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
1890 if(this->m_bCommitAmend)
1892 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1893 m_cLogMessage.SetText(m_AmendStr);
1894 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1896 else
1898 this->m_AmendStr=this->m_cLogMessage.GetText();
1899 m_cLogMessage.SetText(m_NoAmendStr);
1900 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
1902 Refresh();
1905 void CCommitDlg::OnBnClickedWholeProject()
1907 m_tooltips.Pop(); // hide the tooltips
1908 UpdateData();
1909 m_ListCtrl.Clear();
1910 if (!m_bBlock)
1912 if(m_bWholeProject)
1913 m_ListCtrl.GetStatus(NULL,true,false,true);
1914 else
1915 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1917 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());
1920 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1922 if(this->m_bWholeProject)
1923 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1924 else
1925 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1929 void CCommitDlg::OnFocusMessage()
1931 m_cLogMessage.SetFocus();
1934 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1936 UNREFERENCED_PARAMETER(pNMHDR);
1937 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1938 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1939 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1941 CString str;
1942 str.Format(_T("%d/%d"),line+1,column+1);
1943 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1945 if(*pResult)
1946 *pResult=0;
1948 void CCommitDlg::OnStnClickedViewPatch()
1950 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1951 m_patchViewdlg.m_ParentCommitDlg = this;
1952 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1954 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1955 CRect rect;
1956 this->GetWindowRect(&rect);
1958 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1959 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1961 m_patchViewdlg.m_ctrlPatchView.MoveWindow(0,0,rect.Width(),rect.Height());
1962 m_patchViewdlg.ShowWindow(SW_SHOW);
1964 ShowViewPatchText(false);
1965 FillPatchView();
1967 else
1969 m_patchViewdlg.ShowWindow(SW_HIDE);
1970 m_patchViewdlg.DestroyWindow();
1971 ShowViewPatchText(true);
1973 this->m_ctrlShowPatch.Invalidate();
1976 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
1978 __super::OnMoving(fwSide, pRect);
1980 if (::IsWindow(m_patchViewdlg.m_hWnd))
1982 RECT patchrect;
1983 m_patchViewdlg.GetWindowRect(&patchrect);
1984 if (::IsWindow(m_hWnd))
1986 RECT thisrect;
1987 GetWindowRect(&thisrect);
1988 if (patchrect.left == thisrect.right)
1990 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
1991 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
1998 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2000 __super::OnSizing(fwSide, pRect);
2002 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2004 CRect thisrect, patchrect;
2005 this->GetWindowRect(thisrect);
2006 this->m_patchViewdlg.GetWindowRect(patchrect);
2007 if(thisrect.right==patchrect.left)
2009 patchrect.left -= (thisrect.right - pRect->right);
2010 patchrect.right-= (thisrect.right - pRect->right);
2012 if( patchrect.bottom == thisrect.bottom)
2014 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2016 if( patchrect.top == thisrect.top)
2018 patchrect.top -= thisrect.top-pRect->top;
2020 m_patchViewdlg.MoveWindow(patchrect);
2025 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2027 UNREFERENCED_PARAMETER(pNMHDR);
2028 *pResult = 0;
2029 TRACE("Item Changed\r\n");
2032 int CCommitDlg::CheckHeadDetach()
2034 CString output;
2035 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2037 if(CMessageBox::Show(NULL,_T("<ct=0x0000FF>Current HEAD Detached</ct>, you are working on (no branch)\nDo you want create branch now?"),
2038 _T("TortoiseGit"),MB_YESNO|MB_ICONWARNING) == IDYES)
2040 CAppUtils::CreateBranchTag(FALSE,NULL,true);
2043 return 0;
2046 void CCommitDlg::OnBnClickedCommitAmenddiff()
2048 UpdateData();
2049 Refresh();
2052 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2054 UpdateData();
2055 Refresh();