Fixed issue #1205: Add "Last modified" column to commit dialog
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
bloba106b657f6667b138669fb5bb781ebfd98d8eb1a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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 "UnicodeUtils.h"
35 #include "../TGitCache/CacheInterface.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"
42 #include "SysProgressDlg.h"
43 #include "MassiveGitTask.h"
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
51 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
53 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
54 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
55 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
56 , m_bRecursive(FALSE)
57 , m_bShowUnversioned(FALSE)
58 , m_bBlock(FALSE)
59 , m_bThreadRunning(FALSE)
60 , m_bRunThread(FALSE)
61 , m_pThread(NULL)
62 , m_bWholeProject(FALSE)
63 , m_bKeepChangeList(TRUE)
64 , m_bDoNotAutoselectSubmodules(FALSE)
65 , m_itemsCount(0)
66 , m_bSelectFilesForCommit(TRUE)
67 , m_bNoPostActions(FALSE)
68 , m_bAutoClose(false)
69 , m_bSetCommitDateTime(FALSE)
70 , m_bCreateNewBranch(FALSE)
71 , m_bCreateTagAfterCommit(FALSE)
72 , m_bForceCommitAmend(false)
74 this->m_bCommitAmend=FALSE;
75 m_bPushAfterCommit = FALSE;
78 CCommitDlg::~CCommitDlg()
80 if(m_pThread != NULL)
82 delete m_pThread;
86 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
88 CResizableStandAloneDialog::DoDataExchange(pDX);
89 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
90 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
91 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
92 DDX_Check(pDX, IDC_COMMIT_SETDATETIME, m_bSetCommitDateTime);
93 DDX_Check(pDX, IDC_CHECK_NEWBRANCH, m_bCreateNewBranch);
94 DDX_Text(pDX, IDC_NEWBRANCH, m_sCreateNewBranch);
95 DDX_Text(pDX, IDC_BUGID, m_sBugID);
96 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
97 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
98 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
99 DDX_Check(pDX, IDC_NOAUTOSELECTSUBMODULES, m_bDoNotAutoselectSubmodules);
100 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
101 DDX_Check(pDX,IDC_COMMIT_AMENDDIFF,m_bAmendDiffToLastCommit);
102 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
103 DDX_Control(pDX, IDC_COMMIT_DATEPICKER, m_CommitDate);
104 DDX_Control(pDX, IDC_COMMIT_TIMEPICKER, m_CommitTime);
107 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
108 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
109 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
110 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
111 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
112 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
113 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
114 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
115 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
116 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
117 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
118 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
120 ON_REGISTERED_MESSAGE(CLinkControl::LK_LINKITEMCLICKED, &CCommitDlg::OnCheck)
121 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
122 ON_WM_TIMER()
123 ON_WM_SIZE()
124 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
125 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
126 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
127 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
128 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
129 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
130 ON_WM_MOVE()
131 ON_WM_MOVING()
132 ON_WM_SIZING()
133 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
134 ON_BN_CLICKED(IDC_COMMIT_AMENDDIFF, &CCommitDlg::OnBnClickedCommitAmenddiff)
135 ON_BN_CLICKED(IDC_NOAUTOSELECTSUBMODULES, &CCommitDlg::OnBnClickedNoautoselectsubmodules)
136 ON_BN_CLICKED(IDC_COMMIT_SETDATETIME, &CCommitDlg::OnBnClickedCommitSetDateTime)
137 ON_BN_CLICKED(IDC_CHECK_NEWBRANCH, &CCommitDlg::OnBnClickedCheckNewBranch)
138 END_MESSAGE_MAP()
140 BOOL CCommitDlg::OnInitDialog()
142 CResizableStandAloneDialog::OnInitDialog();
143 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
145 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
147 CString dotGitPath;
148 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath);
149 if(PathFileExists(dotGitPath + _T("MERGE_MSG")))
151 CStdioFile file;
152 if(file.Open(dotGitPath + _T("MERGE_MSG"), CFile::modeRead))
154 CString str;
155 while(file.ReadString(str))
157 m_sLogMessage += str;
158 str.Empty();
159 m_sLogMessage += _T("\n");
164 if (CTGitPath(g_Git.m_CurrentDir).IsMergeActive())
165 DialogEnableWindow(IDC_CHECK_NEWBRANCH, FALSE);
167 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
168 m_bShowUnversioned = m_regAddBeforeCommit;
170 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
172 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
173 m_bKeepChangeList = m_regKeepChangelists;
175 m_regDoNotAutoselectSubmodules = CRegDWORD(_T("Software\\TortoiseGit\\DoNotAutoselectSubmodules"), FALSE);
176 m_bDoNotAutoselectSubmodules = m_regDoNotAutoselectSubmodules;
178 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
180 // GitConfig config;
181 // m_bWholeProject = config.KeepLocks();
183 if(this->m_pathList.GetCount() == 0)
184 m_bWholeProject =true;
186 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
187 m_bWholeProject =true;
189 SetDlgTitle();
191 UpdateData(FALSE);
193 m_ListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS | GITSLC_COLADD | GITSLC_COLDEL, _T("CommitDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT | GITSLC_POPSAVEAS)), true, true);
194 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
195 m_ListCtrl.SetCancelBool(&m_bCancelled);
196 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
197 m_ListCtrl.EnableFileDrop();
198 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
200 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
201 m_ProjectProperties.ReadPropsPathList(m_pathList);
203 m_cLogMessage.Init(m_ProjectProperties);
204 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
205 m_cLogMessage.RegisterContextMenuHandler(this);
207 OnEnChangeLogmessage();
209 m_tooltips.Create(this);
210 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
211 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
212 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
214 CBugTraqAssociations bugtraq_associations;
215 bugtraq_associations.Load();
217 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
219 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
220 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
222 CComPtr<IBugTraqProvider> pProvider;
223 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
224 if (SUCCEEDED(hr))
226 m_BugTraqProvider = pProvider;
227 BSTR temp = NULL;
228 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
230 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
231 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
232 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
235 SysFreeString(temp);
238 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
240 else if (!m_ProjectProperties.sMessage.IsEmpty())
242 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
243 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
244 if (!m_ProjectProperties.sLabel.IsEmpty())
245 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
246 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
247 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
248 GetDlgItem(IDC_BUGID)->SetFocus();
249 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
250 if (!sBugID.IsEmpty())
252 SetDlgItemText(IDC_BUGID, sBugID);
255 else
257 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
258 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
259 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
260 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
261 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
264 if (!m_sLogMessage.IsEmpty())
265 m_cLogMessage.SetText(m_sLogMessage);
267 GetWindowText(m_sWindowTitle);
269 AdjustControlSize(IDC_SHOWUNVERSIONED);
270 AdjustControlSize(IDC_WHOLE_PROJECT);
271 AdjustControlSize(IDC_CHECK_NEWBRANCH);
272 AdjustControlSize(IDC_COMMIT_AMEND);
273 AdjustControlSize(IDC_COMMIT_AMENDDIFF);
274 AdjustControlSize(IDC_COMMIT_SETDATETIME);
275 AdjustControlSize(IDC_NOAUTOSELECTSUBMODULES);
276 AdjustControlSize(IDC_KEEPLISTS);
278 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKALL);
279 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKNONE);
280 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKUNVERSIONED);
281 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKVERSIONED);
282 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKADDED);
283 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKDELETED);
284 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKMODIFIED);
285 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKFILES);
286 m_linkControl.ConvertStaticToLink(m_hWnd, IDC_CHECKSUBMODULES);
288 // line up all controls and adjust their sizes.
289 #define LINKSPACING 9
290 RECT rc = AdjustControlSize(IDC_SELECTLABEL);
291 rc.right -= 15; // AdjustControlSize() adds 20 pixels for the checkbox/radio button bitmap, but this is a label...
292 rc = AdjustStaticSize(IDC_CHECKALL, rc, LINKSPACING);
293 rc = AdjustStaticSize(IDC_CHECKNONE, rc, LINKSPACING);
294 rc = AdjustStaticSize(IDC_CHECKUNVERSIONED, rc, LINKSPACING);
295 rc = AdjustStaticSize(IDC_CHECKVERSIONED, rc, LINKSPACING);
296 rc = AdjustStaticSize(IDC_CHECKADDED, rc, LINKSPACING);
297 rc = AdjustStaticSize(IDC_CHECKDELETED, rc, LINKSPACING);
298 rc = AdjustStaticSize(IDC_CHECKMODIFIED, rc, LINKSPACING);
299 rc = AdjustStaticSize(IDC_CHECKFILES, rc, LINKSPACING);
300 rc = AdjustStaticSize(IDC_CHECKSUBMODULES, rc, LINKSPACING);
302 GetClientRect(m_DlgOrigRect);
303 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
305 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
306 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
307 AddAnchor(IDC_BUGID, TOP_RIGHT);
308 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
309 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
310 AddAnchor(IDC_CHECK_NEWBRANCH, TOP_RIGHT);
311 AddAnchor(IDC_NEWBRANCH, TOP_LEFT, TOP_RIGHT);
312 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
313 // AddAnchor(IDC_HISTORY, TOP_LEFT);
314 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
315 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
316 AddAnchor(IDC_VIEW_PATCH, BOTTOM_RIGHT);
317 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
318 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
319 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
320 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
321 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
322 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
323 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
324 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
325 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
326 AddAnchor(IDC_NOAUTOSELECTSUBMODULES, BOTTOM_LEFT);
327 AddAnchor(IDOK, BOTTOM_RIGHT);
328 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
329 AddAnchor(IDHELP, BOTTOM_RIGHT);
330 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
331 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
332 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
333 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
334 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
336 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
337 AddAnchor(IDC_CHECKALL, TOP_LEFT);
338 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
339 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
340 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
341 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
342 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
343 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
344 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
345 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
347 if (hWndExplorer)
348 CenterWindow(CWnd::FromHandle(hWndExplorer));
349 EnableSaveRestore(_T("CommitDlg"));
350 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
351 RECT rcDlg, rcLogMsg, rcFileList;
352 GetClientRect(&rcDlg);
353 m_cLogMessage.GetWindowRect(&rcLogMsg);
354 ScreenToClient(&rcLogMsg);
355 m_ListCtrl.GetWindowRect(&rcFileList);
356 ScreenToClient(&rcFileList);
357 if (yPos)
359 RECT rectSplitter;
360 m_wndSplitter.GetWindowRect(&rectSplitter);
361 ScreenToClient(&rectSplitter);
362 int delta = yPos - rectSplitter.top;
363 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
365 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
366 DoSize(delta);
370 // add all directories to the watcher
372 for (int i=0; i<m_pathList.GetCount(); ++i)
374 if (m_pathList[i].IsDirectory())
375 m_pathwatcher.AddPath(m_pathList[i]);
378 m_updatedPathList = m_pathList;
380 //first start a thread to obtain the file list with the status without
381 //blocking the dialog
382 InterlockedExchange(&m_bBlock, TRUE);
383 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
384 if (m_pThread==NULL)
386 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
387 InterlockedExchange(&m_bBlock, FALSE);
389 else
391 m_pThread->m_bAutoDelete = FALSE;
392 m_pThread->ResumeThread();
394 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
395 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
396 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
398 historyhint = TRUE;
399 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
401 err = FALSE;
403 this->m_ctrlShowPatch.SetURL(CString());
405 BOOL viewPatchEnabled = FALSE;
406 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
407 if (viewPatchEnabled)
408 OnStnClickedViewPatch();
410 return FALSE; // return TRUE unless you set the focus to a control
411 // EXCEPTION: OCX Property Pages should return FALSE
414 void CCommitDlg::OnOK()
416 if (m_bBlock)
417 return;
418 if (m_bThreadRunning)
420 m_bCancelled = true;
421 InterlockedExchange(&m_bRunThread, FALSE);
422 WaitForSingleObject(m_pThread->m_hThread, 1000);
423 if (m_bThreadRunning)
425 // we gave the thread a chance to quit. Since the thread didn't
426 // listen to us we have to kill it.
427 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
428 InterlockedExchange(&m_bThreadRunning, FALSE);
431 this->UpdateData();
433 if (m_bCreateNewBranch)
435 if (!g_Git.IsBranchNameValid(m_sCreateNewBranch))
437 ShowEditBalloon(IDC_NEWBRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
438 return;
440 if (g_Git.BranchTagExists(m_sCreateNewBranch))
442 // branch already exists
443 CString msg;
444 msg.LoadString(IDS_B_EXISTS);
445 msg += _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DELETEORDIFFERENTNAME));
446 ShowEditBalloon(IDC_NEWBRANCH, msg, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
447 return;
449 if (g_Git.BranchTagExists(m_sCreateNewBranch, false))
451 // tag with the same name exists -> shortref is ambiguous
452 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
453 return;
457 CString id;
458 GetDlgItemText(IDC_BUGID, id);
459 if (!m_ProjectProperties.CheckBugID(id))
461 ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, TTI_ERROR);
462 return;
464 m_sLogMessage = m_cLogMessage.GetText();
465 if ( m_sLogMessage.IsEmpty() )
467 // no message entered, go round again
468 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
469 return;
471 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
473 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
474 return;
477 BOOL bWarnNoSignedOffBy = FALSE;
478 ProjectProperties::GetBOOLProps(bWarnNoSignedOffBy, _T("tgit.warnnosignedoffby"));
479 if (bWarnNoSignedOffBy == TRUE && m_cLogMessage.GetText().Find(GetSignedOffByLine()) == -1)
481 UINT retval = CMessageBox::Show(this->m_hWnd, IDS_PROC_COMMIT_NOSIGNOFFLINE, IDS_APPNAME, 1, IDI_WARNING, IDS_PROC_COMMIT_ADDSIGNOFFBUTTON, IDS_PROC_COMMIT_NOADDSIGNOFFBUTTON, IDS_ABORTBUTTON);
482 if (retval == 1)
484 OnBnClickedSignOff();
485 m_sLogMessage = m_cLogMessage.GetText();
487 else if (retval == 3)
488 return;
491 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
492 m_pathwatcher.Stop();
493 InterlockedExchange(&m_bBlock, TRUE);
494 CDWordArray arDeleted;
495 //first add all the unversioned files the user selected
496 //and check if all versioned files are selected
497 int nchecked = 0;
498 m_bRecursive = true;
499 int nListItems = m_ListCtrl.GetItemCount();
501 CTGitPathList itemsToAdd;
502 CTGitPathList itemsToRemove;
503 CMassiveGitTask mgtReAddAfterCommit(_T("add --ignore-errors -f"));
504 //std::set<CString> checkedLists;
505 //std::set<CString> uncheckedLists;
507 // now let the bugtraq plugin check the commit message
508 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
509 if (m_BugTraqProvider)
511 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
512 if (SUCCEEDED(hr))
514 BSTR temp = NULL;
515 CString common = g_Git.m_CurrentDir;
516 BSTR repositoryRoot = common.AllocSysString();
517 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
518 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
519 BSTR commitMessage = m_sLogMessage.AllocSysString();
520 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
522 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
523 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
525 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
527 COMError ce(hr);
528 CString sErr;
529 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
530 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
532 else
534 CString sError = temp;
535 if (!sError.IsEmpty())
537 CMessageBox::Show(m_hWnd, sError, _T("TortoiseGit"), MB_ICONERROR);
538 return;
540 SysFreeString(temp);
545 //CString checkedfiles;
546 //CString uncheckedfiles;
548 CString cmd;
549 CString out;
551 bool bAddSuccess=true;
552 bool bCloseCommitDlg=false;
554 CSysProgressDlg sysProgressDlg;
555 if (nListItems >= 25 && sysProgressDlg.IsValid())
557 sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PREPARECOMMIT)));
558 sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_UPDATEINDEX)));
559 sysProgressDlg.SetTime(true);
560 sysProgressDlg.SetShowProgressBar(true);
561 sysProgressDlg.ShowModal(this, true);
564 CBlockCacheForPath cacheBlock(g_Git.m_CurrentDir);
565 DWORD currentTicks = GetTickCount();
567 for (int j=0; j<nListItems; j++)
569 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
570 if (sysProgressDlg.IsValid())
572 if (GetTickCount() - currentTicks > 1000 || j == nListItems - 1 || j == 0)
574 sysProgressDlg.SetLine(2, entry->GetGitPathString(), true);
575 sysProgressDlg.SetProgress(j, nListItems);
576 AfxGetThread()->PumpMessage(); // process messages, in order to avoid freezing; do not call this too: this takes time!
577 currentTicks = GetTickCount();
580 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
581 if (entry->m_Checked)
583 #if 0
584 if (entry->status == Git_wc_status_unversioned)
586 itemsToAdd.AddPath(entry->GetPath());
588 if (entry->status == Git_wc_status_conflicted)
590 bHasConflicted = true;
592 if (entry->status == Git_wc_status_missing)
594 itemsToRemove.AddPath(entry->GetPath());
596 if (entry->status == Git_wc_status_deleted)
598 arDeleted.Add(j);
600 if (entry->IsInExternal())
602 bCheckedInExternal = true;
604 #endif
605 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
606 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
607 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
608 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
609 else
610 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
612 if (g_Git.Run(cmd, &out, CP_UTF8))
614 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
615 bAddSuccess = false ;
616 break;
619 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
620 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
622 g_Git.Run(cmd, &out, CP_UTF8);
624 nchecked++;
626 //checkedLists.insert(entry->GetGitPathString());
627 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
629 else
631 //uncheckedLists.insert(entry->GetGitPathString());
632 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
633 { //To init git repository, there are not HEAD, so we can use git reset command
634 cmd.Format(_T("git.exe rm -f --cache -- \"%s\""),entry->GetGitPathString());
635 if (g_Git.Run(cmd, &out, CP_UTF8))
637 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
638 bAddSuccess = false ;
639 bCloseCommitDlg=false;
640 break;
642 mgtReAddAfterCommit.AddFile(*entry);
644 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
646 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
648 cmd.Format(_T("git.exe reset HEAD~2 -- \"%s\""), entry->GetGitPathString());
650 else
652 cmd.Format(_T("git.exe reset -- \"%s\""), entry->GetGitPathString());
654 if (g_Git.Run(cmd, &out, CP_UTF8))
656 /* when reset a unstage file will report error.
657 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
658 bAddSuccess = false ;
659 bCloseCommitDlg=false;
660 break;
663 // && !entry->IsDirectory()
664 if (m_bCommitAmend && !m_bAmendDiffToLastCommit)
665 continue;
668 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
669 #if 0
670 if ((entry->status != Git_wc_status_unversioned) &&
671 (entry->status != Git_wc_status_ignored))
673 nUnchecked++;
674 uncheckedLists.insert(entry->GetChangeList());
675 if (m_bRecursive)
677 // This algorithm is for the sake of simplicity of the complexity O(N?
678 for (int k=0; k<nListItems; k++)
680 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
681 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
683 // Fall back to a non-recursive commit to prevent items being
684 // committed which aren't checked although its parent is checked
685 // (property change, directory deletion, ... )
686 m_bRecursive = false;
687 break;
692 #endif
695 if (sysProgressDlg.IsValid() && sysProgressDlg.HasUserCancelled())
697 bAddSuccess = false;
698 break;
701 CShellUpdater::Instance().AddPathForUpdate(*entry);
704 if (sysProgressDlg.IsValid())
705 sysProgressDlg.Stop();
707 if (bAddSuccess && m_bCreateNewBranch)
709 if (g_Git.Run(_T("git branch ") + m_sCreateNewBranch, &out, CP_UTF8))
711 MessageBox(_T("Creating new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
712 bAddSuccess = false;
714 if (g_Git.Run(_T("git checkout ") + m_sCreateNewBranch, &out, CP_UTF8))
716 MessageBox(_T("Switching to new branch failed:\n") + out, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
717 bAddSuccess = false;
721 if (bAddSuccess && CheckHeadDetach())
722 bAddSuccess = false;
724 //if(uncheckedfiles.GetLength()>0)
726 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
727 // g_Git.Run(cmd,&out);
730 m_sBugID.Trim();
731 if (!m_sBugID.IsEmpty())
733 m_sBugID.Replace(_T(", "), _T(","));
734 m_sBugID.Replace(_T(" ,"), _T(","));
735 CString sBugID = m_ProjectProperties.sMessage;
736 sBugID.Replace(_T("%BUGID%"), m_sBugID);
737 if (m_ProjectProperties.bAppend)
738 m_sLogMessage += _T("\n") + sBugID + _T("\n");
739 else
740 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
743 //if(checkedfiles.GetLength()>0)
744 if (bAddSuccess && (nchecked || m_bCommitAmend || CTGitPath(g_Git.m_CurrentDir).IsMergeActive()))
746 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
747 // g_Git.Run(cmd,&out);
749 bCloseCommitDlg = true;
751 CString tempfile=::GetTempFile();
753 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
754 //file.WriteString(m_sLogMessage);
756 CTGitPath path=g_Git.m_CurrentDir;
758 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
760 out =_T("");
761 CString amend;
762 if(this->m_bCommitAmend)
764 amend=_T("--amend");
766 CString dateTime;
767 if (m_bSetCommitDateTime)
769 CTime date, time;
770 m_CommitDate.GetTime(date);
771 m_CommitTime.GetTime(time);
772 dateTime.Format(_T("--date=%sT%s"), date.Format(_T("%Y-%m-%d")), time.Format(_T("%H:%M:%S")));
774 cmd.Format(_T("git.exe commit %s %s -F \"%s\""), dateTime, amend, tempfile);
776 CCommitProgressDlg progress;
777 progress.m_bBufferAll=true; // improve show speed when there are many file added.
778 progress.m_GitCmd=cmd;
779 progress.m_bShowCommand = FALSE; // don't show the commit command
780 progress.m_PreText = out; // show any output already generated in log window
781 progress.m_bAutoCloseOnSuccess = m_bAutoClose;
783 int indexReCommit = -1;
784 int indexTag = -1;
786 if (!m_bNoPostActions && !m_bAutoClose)
788 if (IsGitSVN)
789 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUSVNDCOMMIT)));
790 progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUPUSH)));
791 indexReCommit = progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_RECOMMIT)));
792 indexTag = progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENUTAG)));
795 DWORD userResponse = progress.DoModal();
797 if(progress.m_GitStatus || userResponse == (IDC_PROGRESS_BUTTON1 + indexReCommit))
799 bCloseCommitDlg = false;
800 if (userResponse == IDC_PROGRESS_BUTTON1 + indexReCommit)
802 this->m_sLogMessage.Empty();
803 m_cLogMessage.SetText(m_sLogMessage);
806 this->Refresh();
808 else if (userResponse == IDC_PROGRESS_BUTTON1 + indexTag)
810 m_bCreateTagAfterCommit=true;
812 else if (userResponse >= IDC_PROGRESS_BUTTON1 && userResponse < IDC_PROGRESS_BUTTON1 + indexReCommit)
814 // User pressed 'DCommit' or 'Push' button after successful commit.
815 m_bPushAfterCommit=true;
816 if (userResponse == IDC_PROGRESS_BUTTON1 && IsGitSVN)
817 m_PostCmd = GIT_POST_CMD_DCOMMIT;
818 else
819 m_PostCmd = GIT_POST_CMD_PUSH;
822 CFile::Remove(tempfile);
824 if (m_BugTraqProvider && progress.m_GitStatus == 0)
826 CComPtr<IBugTraqProvider2> pProvider = NULL;
827 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
828 if (SUCCEEDED(hr))
830 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
831 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
833 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
834 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
836 BSTR logMessage = m_sLogMessage.AllocSysString();
838 CGitHash hash=g_Git.GetHash(_T("HEAD"));
839 LONG version = g_Git.Hash2int(hash);
841 BSTR temp = NULL;
842 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
843 commonRoot,
844 pathList,
845 logMessage,
846 (LONG)version,
847 &temp)))
849 CString sErr = temp;
850 if (!sErr.IsEmpty())
851 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
852 else
854 COMError ce(hr);
855 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
856 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
860 SysFreeString(temp);
863 RestoreFiles(progress.m_GitStatus == 0);
864 if (((DWORD)CRegStdDWORD(_T("Software\\TortoiseGit\\ReaddUnselectedAddedFilesAfterCommit"), TRUE)) == TRUE)
866 BOOL cancel;
867 mgtReAddAfterCommit.Execute(cancel);
870 else if(bAddSuccess)
872 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
873 bCloseCommitDlg=false;
875 #if 0
876 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
878 // There are paths which got changed (touched at least).
879 // We have to find out if this affects the selection in the commit dialog
880 // If it could affect the selection, revert back to a non-recursive commit
881 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
882 changedList.RemoveDuplicates();
883 for (int i=0; i<changedList.GetCount(); ++i)
885 if (changedList[i].IsAdminDir())
887 // something inside an admin dir was changed.
888 // if it's the entries file, then we have to fully refresh because
889 // files may have been added/removed from version control
890 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
891 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
893 m_bRecursive = false;
894 break;
897 else if (!m_ListCtrl.IsPathShown(changedList[i]))
899 // a path which is not shown in the list has changed
900 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
901 if (entry)
903 // check if the changed path would get committed by a recursive commit
904 if ((!entry->IsFromDifferentRepository()) &&
905 (!entry->IsInExternal()) &&
906 (!entry->IsNested()) &&
907 (!entry->IsChecked()))
909 m_bRecursive = false;
910 break;
918 // Now, do all the adds - make sure that the list is sorted so that parents
919 // are added before their children
920 itemsToAdd.SortByPathname();
921 Git Git;
922 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
924 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
925 InterlockedExchange(&m_bBlock, FALSE);
926 Refresh();
927 return;
930 // Remove any missing items
931 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
932 itemsToRemove.SortByPathname();
933 Git.Remove(itemsToRemove, TRUE);
935 //the next step: find all deleted files and check if they're
936 //inside a deleted folder. If that's the case, then remove those
937 //files from the list since they'll get deleted by the parent
938 //folder automatically.
939 m_ListCtrl.Block(TRUE, FALSE);
940 INT_PTR nDeleted = arDeleted.GetCount();
941 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
943 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
945 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
946 if (path.IsDirectory())
948 //now find all children of this directory
949 for (int j=0; j<arDeleted.GetCount(); j++)
951 if (i!=j)
953 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
954 if (childEntry->IsChecked())
956 if (path.IsAncestorOf(childEntry->GetPath()))
958 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
959 nDeleted--;
967 m_ListCtrl.Block(FALSE, FALSE);
969 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
971 //save only the files the user has checked into the temporary file
972 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
975 // the item count is used in the progress dialog to show the overall commit
976 // progress.
977 // deleted items only send one notification event, all others send two
978 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
980 if ((m_bRecursive)&&(checkedLists.size() == 1))
982 // all checked items belong to the same changelist
983 // find out if there are any unchecked items which belong to that changelist
984 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
985 m_sChangeList = *checkedLists.begin();
987 #endif
988 UpdateData();
989 m_regAddBeforeCommit = m_bShowUnversioned;
990 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
991 m_bWholeProject = FALSE;
992 m_regKeepChangelists = m_bKeepChangeList;
993 m_regDoNotAutoselectSubmodules = m_bDoNotAutoselectSubmodules;
994 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
995 m_bKeepChangeList = FALSE;
996 InterlockedExchange(&m_bBlock, FALSE);
998 m_History.AddEntry(m_sLogMessage);
999 m_History.Save();
1001 SaveSplitterPos();
1003 if( bCloseCommitDlg )
1004 CResizableStandAloneDialog::OnOK();
1006 CShellUpdater::Instance().Flush();
1009 void CCommitDlg::SaveSplitterPos()
1011 if (!IsIconic())
1013 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
1014 RECT rectSplitter;
1015 m_wndSplitter.GetWindowRect(&rectSplitter);
1016 ScreenToClient(&rectSplitter);
1017 regPos = rectSplitter.top;
1021 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
1023 return ((CCommitDlg*)pVoid)->StatusThread();
1026 UINT CCommitDlg::StatusThread()
1028 //get the status of all selected file/folders recursively
1029 //and show the ones which have to be committed to the user
1030 //in a list control.
1031 InterlockedExchange(&m_bBlock, TRUE);
1032 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
1033 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
1035 m_pathwatcher.Stop();
1037 g_Git.RefreshGitIndex();
1039 m_bCancelled = false;
1041 DialogEnableWindow(IDOK, false);
1042 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
1043 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
1044 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, false);
1045 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
1046 DialogEnableWindow(IDC_EXTERNALWARNING, false);
1047 DialogEnableWindow(IDC_COMMIT_AMEND, FALSE);
1048 DialogEnableWindow(IDC_COMMIT_AMENDDIFF, FALSE);
1049 // read the list of recent log entries before querying the WC for status
1050 // -> the user may select one and modify / update it while we are crawling the WC
1052 DialogEnableWindow(IDC_CHECKALL, false);
1053 DialogEnableWindow(IDC_CHECKNONE, false);
1054 DialogEnableWindow(IDC_CHECKUNVERSIONED, false);
1055 DialogEnableWindow(IDC_CHECKVERSIONED, false);
1056 DialogEnableWindow(IDC_CHECKADDED, false);
1057 DialogEnableWindow(IDC_CHECKDELETED, false);
1058 DialogEnableWindow(IDC_CHECKMODIFIED, false);
1059 DialogEnableWindow(IDC_CHECKFILES, false);
1060 DialogEnableWindow(IDC_CHECKSUBMODULES, false);
1062 if (m_History.GetCount()==0)
1064 CString reg;
1065 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
1066 reg.Replace(_T(':'),_T('_'));
1067 m_History.Load(reg, _T("logmsgs"));
1070 // Initialise the list control with the status of the files/folders below us
1071 m_ListCtrl.Clear();
1072 BOOL success;
1073 CTGitPathList *pList;
1074 m_ListCtrl.m_amend = (m_bCommitAmend==TRUE) && (m_bAmendDiffToLastCommit==FALSE);
1075 m_ListCtrl.m_bDoNotAutoselectSubmodules = (m_bDoNotAutoselectSubmodules == TRUE);
1077 if(m_bWholeProject)
1078 pList=NULL;
1079 else
1080 pList = &m_pathList;
1082 success=m_ListCtrl.GetStatus(pList);
1084 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
1085 if(this->m_bShowUnversioned)
1086 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,pList);
1088 m_ListCtrl.CheckIfChangelistsArePresent(false);
1090 DWORD dwShow = GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWLOCKS | GITSLC_SHOWINCHANGELIST;
1091 dwShow |= DWORD(m_regAddBeforeCommit) ? GITSLC_SHOWUNVERSIONED : 0;
1092 if (success)
1094 if (m_checkedPathList.GetCount())
1095 m_ListCtrl.Show(dwShow, m_checkedPathList);
1096 else
1098 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
1099 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
1100 m_ListCtrl.Show(dwShow, dwCheck);
1101 m_bSelectFilesForCommit = true;
1104 if (m_ListCtrl.HasExternalsFromDifferentRepos())
1106 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
1107 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
1110 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
1111 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
1113 if (!success)
1115 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
1116 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
1117 m_ListCtrl.Show(dwShow);
1120 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
1121 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
1123 CString temp;
1124 temp.LoadString(IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED);
1125 if (CMessageBox::ShowCheck(m_hWnd, temp, _T("TortoiseGit"), MB_ICONINFORMATION | MB_YESNO, _T("NothingToCommitShowUnversioned"), NULL)==IDYES)
1127 m_bShowUnversioned = TRUE;
1128 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
1129 DWORD dwShow = (DWORD)(GITSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GITSLC_SHOWUNVERSIONED | GITSLC_SHOWLOCKS);
1130 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
1131 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
1135 SetDlgTitle();
1137 m_autolist.clear();
1138 // we don't have to block the commit dialog while we fetch the
1139 // auto completion list.
1140 m_pathwatcher.ClearChangedPaths();
1141 InterlockedExchange(&m_bBlock, FALSE);
1142 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
1144 m_ListCtrl.Block(TRUE, TRUE);
1145 GetAutocompletionList();
1146 m_ListCtrl.Block(FALSE, FALSE);
1148 UpdateOKButton();
1149 if (m_bRunThread)
1151 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
1152 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1153 DialogEnableWindow(IDC_NOAUTOSELECTSUBMODULES, true);
1154 if (m_ListCtrl.HasChangeLists())
1155 DialogEnableWindow(IDC_KEEPLISTS, true);
1156 if (m_ListCtrl.HasLocks())
1157 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
1159 // activate amend checkbox (if necessary)
1160 if (g_Git.IsInitRepos())
1162 m_bCommitAmend = FALSE;
1163 UpdateData(FALSE);
1165 else
1167 if (m_bForceCommitAmend)
1169 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
1170 m_bCommitAmend = TRUE;
1171 UpdateData(FALSE);
1173 else
1174 GetDlgItem(IDC_COMMIT_AMEND)->EnableWindow(TRUE);
1176 CGitHash hash;
1179 hash = g_Git.GetHash(_T("HEAD"));
1181 catch (char* msg)
1183 CString err(msg);
1184 MessageBox(_T("Could not get HEAD hash.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
1186 if (!hash.IsEmpty())
1188 GitRev headRevision;
1189 headRevision.GetParentFromHash(hash);
1190 // do not allow to show diff to "last" revision if it has more that one parent
1191 if (headRevision.ParentsCount() != 1)
1193 m_bAmendDiffToLastCommit = true;
1194 UpdateData(FALSE);
1196 else
1197 GetDlgItem(IDC_COMMIT_AMENDDIFF)->EnableWindow(TRUE);
1201 UpdateCheckLinks();
1203 // we have the list, now signal the main thread about it
1204 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
1207 InterlockedExchange(&m_bRunThread, FALSE);
1208 InterlockedExchange(&m_bThreadRunning, FALSE);
1209 // force the cursor to normal
1210 RefreshCursor();
1212 return 0;
1215 void CCommitDlg::SetDlgTitle()
1217 if (m_sTitle.IsEmpty())
1218 GetWindowText(m_sTitle);
1220 if (m_bWholeProject)
1221 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
1222 else
1224 if (m_pathList.GetCount() == 1)
1225 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList[0].GetUIPathString()).TrimRight('\\'), m_sTitle);
1226 else
1227 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir + _T("\\") + m_ListCtrl.GetCommonDirectory(false), m_sTitle);
1231 void CCommitDlg::OnCancel()
1233 m_bCancelled = true;
1234 m_pathwatcher.Stop();
1236 if (m_bThreadRunning)
1238 InterlockedExchange(&m_bRunThread, FALSE);
1239 WaitForSingleObject(m_pThread->m_hThread, 1000);
1240 if (m_bThreadRunning)
1242 // we gave the thread a chance to quit. Since the thread didn't
1243 // listen to us we have to kill it.
1244 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1245 InterlockedExchange(&m_bThreadRunning, FALSE);
1248 UpdateData();
1249 m_sBugID.Trim();
1250 m_sLogMessage = m_cLogMessage.GetText();
1251 if (!m_sBugID.IsEmpty())
1253 m_sBugID.Replace(_T(", "), _T(","));
1254 m_sBugID.Replace(_T(" ,"), _T(","));
1255 CString sBugID = m_ProjectProperties.sMessage;
1256 sBugID.Replace(_T("%BUGID%"), m_sBugID);
1257 if (m_ProjectProperties.bAppend)
1258 m_sLogMessage += _T("\n") + sBugID + _T("\n");
1259 else
1260 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1262 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1263 m_History.AddEntry(m_sLogMessage);
1264 m_History.Save();
1265 RestoreFiles();
1266 SaveSplitterPos();
1267 CResizableStandAloneDialog::OnCancel();
1270 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1272 if (!m_bBlock)
1273 m_tooltips.RelayEvent(pMsg);
1275 if (m_hAccel)
1277 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1278 if (ret)
1279 return TRUE;
1282 if (pMsg->message == WM_KEYDOWN)
1284 switch (pMsg->wParam)
1286 case VK_F5:
1288 if (m_bBlock)
1289 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1290 Refresh();
1292 break;
1293 case VK_RETURN:
1295 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1297 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1299 PostMessage(WM_COMMAND, IDOK);
1301 return TRUE;
1303 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1305 // Pressing RETURN in the bug id control
1306 // moves the focus to the message
1307 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1308 return TRUE;
1311 break;
1315 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1318 void CCommitDlg::Refresh()
1320 if (m_bThreadRunning)
1321 return;
1323 InterlockedExchange(&m_bBlock, TRUE);
1324 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1325 if (m_pThread==NULL)
1327 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1328 InterlockedExchange(&m_bBlock, FALSE);
1330 else
1332 m_pThread->m_bAutoDelete = FALSE;
1333 m_pThread->ResumeThread();
1337 void CCommitDlg::OnBnClickedHelp()
1339 OnHelp();
1342 void CCommitDlg::OnBnClickedShowunversioned()
1344 m_tooltips.Pop(); // hide the tooltips
1345 UpdateData();
1346 m_regAddBeforeCommit = m_bShowUnversioned;
1347 if (!m_bBlock)
1349 DWORD dwShow = m_ListCtrl.GetShowFlags();
1350 if (DWORD(m_regAddBeforeCommit))
1351 dwShow |= GITSLC_SHOWUNVERSIONED;
1352 else
1353 dwShow &= ~GITSLC_SHOWUNVERSIONED;
1354 if(dwShow & GITSLC_SHOWUNVERSIONED)
1356 if(m_bWholeProject)
1357 m_ListCtrl.GetStatus(NULL,false,false,true);
1358 else
1359 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1361 m_ListCtrl.Show(dwShow, 0, true, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
1362 UpdateCheckLinks();
1366 void CCommitDlg::OnStnClickedExternalwarning()
1368 m_tooltips.Popup();
1371 void CCommitDlg::OnEnChangeLogmessage()
1373 UpdateOKButton();
1376 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1378 #if 0
1379 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1381 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1383 m_bShowUnversioned = TRUE;
1384 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1385 m_ListCtrl.Show(dwShow);
1386 UpdateData(FALSE);
1389 #endif
1390 return 0;
1393 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1395 Refresh();
1396 return 0;
1399 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1401 #if 0
1402 BringWindowToTop();
1403 SetForegroundWindow();
1404 SetActiveWindow();
1405 // if multiple files/folders are dropped
1406 // this handler is called for every single item
1407 // separately.
1408 // To avoid creating multiple refresh threads and
1409 // causing crashes, we only add the items to the
1410 // list control and start a timer.
1411 // When the timer expires, we start the refresh thread,
1412 // but only if it isn't already running - otherwise we
1413 // restart the timer.
1414 CTGitPath path;
1415 path.SetFromWin((LPCTSTR)lParam);
1417 // just add all the items we get here.
1418 // if the item is versioned, the add will fail but nothing
1419 // more will happen.
1420 Git Git;
1421 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1423 if (!m_ListCtrl.HasPath(path))
1425 if (m_pathList.AreAllPathsFiles())
1427 m_pathList.AddPath(path);
1428 m_pathList.RemoveDuplicates();
1429 m_updatedPathList.AddPath(path);
1430 m_updatedPathList.RemoveDuplicates();
1432 else
1434 // if the path list contains folders, we have to check whether
1435 // our just (maybe) added path is a child of one of those. If it is
1436 // a child of a folder already in the list, we must not add it. Otherwise
1437 // that path could show up twice in the list.
1438 bool bHasParentInList = false;
1439 for (int i=0; i<m_pathList.GetCount(); ++i)
1441 if (m_pathList[i].IsAncestorOf(path))
1443 bHasParentInList = true;
1444 break;
1447 if (!bHasParentInList)
1449 m_pathList.AddPath(path);
1450 m_pathList.RemoveDuplicates();
1451 m_updatedPathList.AddPath(path);
1452 m_updatedPathList.RemoveDuplicates();
1457 // Always start the timer, since the status of an existing item might have changed
1458 SetTimer(REFRESHTIMER, 200, NULL);
1459 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1460 #endif
1461 return 0;
1464 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1466 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1467 return 0;
1470 //////////////////////////////////////////////////////////////////////////
1471 // functions which run in the status thread
1472 //////////////////////////////////////////////////////////////////////////
1474 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1476 CString strLine;
1479 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1480 while (m_bRunThread && file.ReadString(strLine))
1482 int eqpos = strLine.Find('=');
1483 CString rgx;
1484 rgx = strLine.Mid(eqpos+1).Trim();
1486 int pos = -1;
1487 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1489 mapRegex[strLine.Left(pos)] = rgx;
1490 strLine = strLine.Mid(pos+1).Trim();
1492 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1494 file.Close();
1496 catch (CFileException* pE)
1498 TRACE("CFileException loading auto list regex file\n");
1499 pE->Delete();
1500 return;
1503 void CCommitDlg::GetAutocompletionList()
1505 // the auto completion list is made of strings from each selected files.
1506 // the strings used are extracted from the files with regexes found
1507 // in the file "autolist.txt".
1508 // the format of that file is:
1509 // file extensions separated with commas '=' regular expression to use
1510 // example:
1511 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1512 // .cpp = (?<=[^\s]::)\b\w+\b
1514 std::map<CString, CString> mapRegex;
1515 CString sRegexFile = CPathUtils::GetAppDirectory();
1516 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1517 DWORD timeoutvalue = regtimeout*1000;
1518 sRegexFile += _T("autolist.txt");
1519 if (!m_bRunThread)
1520 return;
1521 ParseRegexFile(sRegexFile, mapRegex);
1522 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1523 sRegexFile.ReleaseBuffer();
1524 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1525 if (PathFileExists(sRegexFile))
1527 ParseRegexFile(sRegexFile, mapRegex);
1529 DWORD starttime = GetTickCount();
1531 // now we have two arrays of strings, where the first array contains all
1532 // file extensions we can use and the second the corresponding regex strings
1533 // to apply to those files.
1535 // the next step is to go over all files shown in the commit dialog
1536 // and scan them for strings we can use
1537 int nListItems = m_ListCtrl.GetItemCount();
1539 for (int i=0; i<nListItems && m_bRunThread; ++i)
1541 // stop parsing after timeout
1542 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1543 return;
1545 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1547 if(path == NULL)
1548 continue;
1550 CString sPartPath =path->GetGitPathString();
1551 m_autolist.insert(sPartPath);
1553 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1554 // if (!entry)
1555 // continue;
1557 // add the path parts to the auto completion list too
1558 // CString sPartPath = entry->GetRelativeGitPath();
1559 // m_autolist.insert(sPartPath);
1562 int pos = 0;
1563 int lastPos = 0;
1564 while ((pos = sPartPath.Find('/', pos)) >= 0)
1566 pos++;
1567 lastPos = pos;
1568 m_autolist.insert(sPartPath.Mid(pos));
1571 // Last inserted entry is a file name.
1572 // Some users prefer to also list file name without extension.
1573 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1575 int dotPos = sPartPath.ReverseFind('.');
1576 if ((dotPos >= 0) && (dotPos > lastPos))
1577 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1579 #if 0
1580 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1581 continue;
1583 CString sExt = entry->GetPath().GetFileExtension();
1584 sExt.MakeLower();
1585 // find the regex string which corresponds to the file extension
1586 CString rdata = mapRegex[sExt];
1587 if (rdata.IsEmpty())
1588 continue;
1590 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1591 if ((entry->textstatus != Git_wc_status_unversioned) &&
1592 (entry->textstatus != Git_wc_status_none) &&
1593 (entry->textstatus != Git_wc_status_ignored) &&
1594 (entry->textstatus != Git_wc_status_added) &&
1595 (entry->textstatus != Git_wc_status_normal))
1597 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1598 if (!basePath.IsEmpty())
1599 ScanFile(basePath.GetWinPathString(), rdata);
1601 #endif
1603 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1606 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1608 wstring sFileContent;
1609 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1610 if (hFile != INVALID_HANDLE_VALUE)
1612 DWORD size = GetFileSize(hFile, NULL);
1613 if (size > 1000000L)
1615 // no files bigger than 1 Meg
1616 CloseHandle(hFile);
1617 return;
1619 // allocate memory to hold file contents
1620 char * buffer = new char[size];
1621 DWORD readbytes;
1622 ReadFile(hFile, buffer, size, &readbytes, NULL);
1623 CloseHandle(hFile);
1624 int opts = 0;
1625 IsTextUnicode(buffer, readbytes, &opts);
1626 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1628 delete [] buffer;
1629 return;
1631 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1633 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1635 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1637 int ret = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1638 wchar_t * pWideBuf = new wchar_t[ret];
1639 int ret2 = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1640 if (ret2 == ret)
1641 sFileContent = wstring(pWideBuf, ret);
1642 delete [] pWideBuf;
1644 delete [] buffer;
1646 if (sFileContent.empty()|| !m_bRunThread)
1648 return;
1653 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1654 const tr1::wsregex_iterator end;
1655 wstring s = sFileContent;
1656 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1658 const tr1::wsmatch match = *it;
1659 for (size_t i=1; i<match.size(); ++i)
1661 if (match[i].second-match[i].first)
1663 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1664 m_autolist.insert(wstring(match[i]).c_str());
1669 catch (exception) {}
1672 // CSciEditContextMenuInterface
1673 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1675 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1676 m_nPopupPasteListCmd = nCmd++;
1677 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1679 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1680 if(m_History.GetCount() > 0)
1682 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1683 m_nPopupPasteLastMessage = nCmd++;
1684 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1686 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1687 m_nPopupRecentMessage = nCmd++;
1688 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1694 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1697 if (m_bBlock)
1698 return false;
1699 if (cmd == m_nPopupPasteListCmd)
1701 CString logmsg;
1702 int nListItems = m_ListCtrl.GetItemCount();
1703 for (int i=0; i<nListItems; ++i)
1705 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1706 if (entry&&entry->m_Checked)
1708 CString line;
1709 CString status = entry->GetActionName();
1710 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1711 status = _T("Add"); // I18N TODO
1713 //git_wc_status_kind status = entry->status;
1714 WORD langID = (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1715 if (m_ProjectProperties.bFileListInEnglish)
1716 langID = 1033;
1718 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1719 logmsg += line;
1722 pSciEdit->InsertText(logmsg);
1723 return true;
1726 if(cmd == m_nPopupPasteLastMessage)
1728 if(m_History.GetCount() ==0 )
1729 return false;
1731 CString logmsg;
1732 logmsg +=m_History.GetEntry(0);
1733 pSciEdit->InsertText(logmsg);
1734 return true;
1737 if(cmd == m_nPopupRecentMessage )
1739 OnBnClickedHistory();
1740 return true;
1742 return false;
1745 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1747 switch (nIDEvent)
1749 case ENDDIALOGTIMER:
1750 KillTimer(ENDDIALOGTIMER);
1751 EndDialog(0);
1752 break;
1753 case REFRESHTIMER:
1754 if (m_bThreadRunning)
1756 SetTimer(REFRESHTIMER, 200, NULL);
1757 ATLTRACE("Wait some more before refreshing\n");
1759 else
1761 KillTimer(REFRESHTIMER);
1762 ATLTRACE("Refreshing after items dropped\n");
1763 Refresh();
1765 break;
1767 __super::OnTimer(nIDEvent);
1770 void CCommitDlg::OnBnClickedHistory()
1772 m_tooltips.Pop(); // hide the tooltips
1773 if (m_pathList.GetCount() == 0)
1774 return;
1776 CHistoryDlg historyDlg;
1777 historyDlg.SetHistory(m_History);
1778 if (historyDlg.DoModal() != IDOK)
1779 return;
1781 CString sMsg = historyDlg.GetSelectedText();
1782 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1784 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1785 if (!sBugID.IsEmpty())
1787 SetDlgItemText(IDC_BUGID, sBugID);
1789 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1790 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1791 else
1792 m_cLogMessage.SetText(sMsg);
1795 UpdateOKButton();
1796 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1800 void CCommitDlg::OnBnClickedBugtraqbutton()
1802 m_tooltips.Pop(); // hide the tooltips
1803 CString sMsg = m_cLogMessage.GetText();
1805 if (m_BugTraqProvider == NULL)
1806 return;
1808 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1809 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1810 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1812 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1813 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1815 BSTR originalMessage = sMsg.AllocSysString();
1816 BSTR temp = NULL;
1817 // m_revProps.clear();
1819 // first try the IBugTraqProvider2 interface
1820 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1821 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1822 if (SUCCEEDED(hr))
1824 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1825 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1826 BSTR bugIDOut = NULL;
1827 GetDlgItemText(IDC_BUGID, m_sBugID);
1828 BSTR bugID = m_sBugID.AllocSysString();
1829 SAFEARRAY * revPropNames = NULL;
1830 SAFEARRAY * revPropValues = NULL;
1831 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1833 CString sErr;
1834 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1835 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1837 else
1839 if (bugIDOut)
1841 m_sBugID = bugIDOut;
1842 SysFreeString(bugIDOut);
1843 SetDlgItemText(IDC_BUGID, m_sBugID);
1845 SysFreeString(bugID);
1846 SysFreeString(repositoryRoot);
1847 m_cLogMessage.SetText(temp);
1848 BSTR HUGEP *pbRevNames;
1849 BSTR HUGEP *pbRevValues;
1851 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1852 if (SUCCEEDED(hr1))
1854 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1855 if (SUCCEEDED(hr2))
1857 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1859 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1861 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1864 SafeArrayUnaccessData(revPropValues);
1866 SafeArrayUnaccessData(revPropNames);
1868 if (revPropNames)
1869 SafeArrayDestroy(revPropNames);
1870 if (revPropValues)
1871 SafeArrayDestroy(revPropValues);
1874 else
1876 // if IBugTraqProvider2 failed, try IBugTraqProvider
1877 CComPtr<IBugTraqProvider> pProvider = NULL;
1878 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1879 if (FAILED(hr))
1881 CString sErr;
1882 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1883 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1884 return;
1887 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1889 CString sErr;
1890 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1891 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1893 else
1894 m_cLogMessage.SetText(temp);
1896 m_sLogMessage = m_cLogMessage.GetText();
1897 if (!m_ProjectProperties.sMessage.IsEmpty())
1899 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1900 if (!sBugID.IsEmpty())
1902 SetDlgItemText(IDC_BUGID, sBugID);
1906 m_cLogMessage.SetFocus();
1908 SysFreeString(parameters);
1909 SysFreeString(commonRoot);
1910 SafeArrayDestroy(pathList);
1911 SysFreeString(originalMessage);
1912 SysFreeString(temp);
1916 void CCommitDlg::FillPatchView()
1918 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1920 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1922 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1923 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1924 CString cmd,out;
1926 while(pos)
1928 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1929 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1930 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1932 CString head = _T("HEAD");
1933 if(m_bCommitAmend==TRUE && m_bAmendDiffToLastCommit==FALSE)
1934 head = _T("HEAD~1");
1935 cmd.Format(_T("git.exe diff %s -- \"%s\""), head, p->GetGitPathString());
1936 g_Git.Run(cmd, &out, CP_UTF8);
1940 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1941 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1942 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1943 CRect rect;
1944 m_patchViewdlg.m_ctrlPatchView.GetClientRect(rect);
1945 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTH, rect.Width() - 4);
1948 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM /*wparam*/, LPARAM /*lparam*/)
1950 this->FillPatchView();
1951 return 0;
1955 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1957 UpdateOKButton();
1958 return 0;
1961 LRESULT CCommitDlg::OnCheck(WPARAM wnd, LPARAM)
1963 HWND hwnd = (HWND)wnd;
1964 if (hwnd == GetDlgItem(IDC_CHECKALL)->GetSafeHwnd())
1965 m_ListCtrl.Check(GITSLC_SHOWEVERYTHING, true);
1966 else if (hwnd == GetDlgItem(IDC_CHECKNONE)->GetSafeHwnd())
1967 m_ListCtrl.Check(0, true);
1968 else if (hwnd == GetDlgItem(IDC_CHECKUNVERSIONED)->GetSafeHwnd())
1969 m_ListCtrl.Check(GITSLC_SHOWUNVERSIONED, false);
1970 else if (hwnd == GetDlgItem(IDC_CHECKVERSIONED)->GetSafeHwnd())
1971 m_ListCtrl.Check(GITSLC_SHOWVERSIONED, false);
1972 else if (hwnd == GetDlgItem(IDC_CHECKADDED)->GetSafeHwnd())
1973 m_ListCtrl.Check(GITSLC_SHOWADDED, false);
1974 else if (hwnd == GetDlgItem(IDC_CHECKDELETED)->GetSafeHwnd())
1975 m_ListCtrl.Check(GITSLC_SHOWREMOVED, false);
1976 else if (hwnd == GetDlgItem(IDC_CHECKMODIFIED)->GetSafeHwnd())
1977 m_ListCtrl.Check(GITSLC_SHOWMODIFIED, false);
1978 else if (hwnd == GetDlgItem(IDC_CHECKFILES)->GetSafeHwnd())
1979 m_ListCtrl.Check(GITSLC_SHOWFILES, false);
1980 else if (hwnd == GetDlgItem(IDC_CHECKSUBMODULES)->GetSafeHwnd())
1981 m_ListCtrl.Check(GITSLC_SHOWSUBMODULES, false);
1983 return 0;
1986 void CCommitDlg::UpdateOKButton()
1988 if (m_bBlock)
1989 return;
1991 bool bValidLogSize = m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize && m_cLogMessage.GetText().GetLength() > 0;
1992 bool bAmendOrSelectFilesOrMerge = m_ListCtrl.GetSelected() > 0 || (m_bCommitAmend && m_bAmendDiffToLastCommit) || CTGitPath(g_Git.m_CurrentDir).IsMergeActive();
1994 DialogEnableWindow(IDOK, bValidLogSize && bAmendOrSelectFilesOrMerge);
1997 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1999 switch (message) {
2000 case WM_NOTIFY:
2001 if (wParam == IDC_SPLITTER)
2003 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
2004 DoSize(pHdr->delta);
2006 break;
2009 return __super::DefWindowProc(message, wParam, lParam);
2012 void CCommitDlg::SetSplitterRange()
2014 if ((m_ListCtrl)&&(m_cLogMessage))
2016 CRect rcTop;
2017 m_cLogMessage.GetWindowRect(rcTop);
2018 ScreenToClient(rcTop);
2019 CRect rcMiddle;
2020 m_ListCtrl.GetWindowRect(rcMiddle);
2021 ScreenToClient(rcMiddle);
2022 if (rcMiddle.Height() && rcMiddle.Width())
2023 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
2027 void CCommitDlg::DoSize(int delta)
2029 RemoveAnchor(IDC_MESSAGEGROUP);
2030 RemoveAnchor(IDC_LOGMESSAGE);
2031 RemoveAnchor(IDC_SPLITTER);
2032 RemoveAnchor(IDC_SIGNOFF);
2033 RemoveAnchor(IDC_COMMIT_AMEND);
2034 RemoveAnchor(IDC_COMMIT_AMENDDIFF);
2035 RemoveAnchor(IDC_COMMIT_SETDATETIME);
2036 RemoveAnchor(IDC_COMMIT_DATEPICKER);
2037 RemoveAnchor(IDC_COMMIT_TIMEPICKER);
2038 RemoveAnchor(IDC_LISTGROUP);
2039 RemoveAnchor(IDC_FILELIST);
2040 RemoveAnchor(IDC_TEXT_INFO);
2041 RemoveAnchor(IDC_SELECTLABEL);
2042 RemoveAnchor(IDC_CHECKALL);
2043 RemoveAnchor(IDC_CHECKNONE);
2044 RemoveAnchor(IDC_CHECKUNVERSIONED);
2045 RemoveAnchor(IDC_CHECKVERSIONED);
2046 RemoveAnchor(IDC_CHECKADDED);
2047 RemoveAnchor(IDC_CHECKDELETED);
2048 RemoveAnchor(IDC_CHECKMODIFIED);
2049 RemoveAnchor(IDC_CHECKFILES);
2050 RemoveAnchor(IDC_CHECKSUBMODULES);
2052 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
2053 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
2054 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
2055 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
2056 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
2057 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
2058 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMENDDIFF),0,delta);
2059 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_SETDATETIME),0,delta);
2060 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_DATEPICKER),0,delta);
2061 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_TIMEPICKER),0,delta);
2062 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
2063 CSplitterControl::ChangePos(GetDlgItem(IDC_SELECTLABEL), 0, delta);
2064 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKALL), 0, delta);
2065 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKNONE), 0, delta);
2066 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKUNVERSIONED), 0, delta);
2067 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKVERSIONED), 0, delta);
2068 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKADDED), 0, delta);
2069 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKDELETED), 0, delta);
2070 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKMODIFIED), 0, delta);
2071 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKFILES), 0, delta);
2072 CSplitterControl::ChangePos(GetDlgItem(IDC_CHECKSUBMODULES), 0, delta);
2074 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
2075 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
2076 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
2077 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
2078 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
2079 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
2080 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
2081 AddAnchor(IDC_COMMIT_AMENDDIFF,TOP_LEFT);
2082 AddAnchor(IDC_COMMIT_SETDATETIME,TOP_LEFT);
2083 AddAnchor(IDC_COMMIT_DATEPICKER,TOP_LEFT);
2084 AddAnchor(IDC_COMMIT_TIMEPICKER,TOP_LEFT);
2085 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
2086 AddAnchor(IDC_SELECTLABEL, TOP_LEFT);
2087 AddAnchor(IDC_CHECKALL, TOP_LEFT);
2088 AddAnchor(IDC_CHECKNONE, TOP_LEFT);
2089 AddAnchor(IDC_CHECKUNVERSIONED, TOP_LEFT);
2090 AddAnchor(IDC_CHECKVERSIONED, TOP_LEFT);
2091 AddAnchor(IDC_CHECKADDED, TOP_LEFT);
2092 AddAnchor(IDC_CHECKDELETED, TOP_LEFT);
2093 AddAnchor(IDC_CHECKMODIFIED, TOP_LEFT);
2094 AddAnchor(IDC_CHECKFILES, TOP_LEFT);
2095 AddAnchor(IDC_CHECKSUBMODULES, TOP_LEFT);
2096 ArrangeLayout();
2097 // adjust the minimum size of the dialog to prevent the resizing from
2098 // moving the list control too far down.
2099 CRect rcLogMsg;
2100 m_cLogMessage.GetClientRect(rcLogMsg);
2101 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
2103 SetSplitterRange();
2104 m_cLogMessage.Invalidate();
2105 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
2108 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
2110 // first, let the resizing take place
2111 __super::OnSize(nType, cx, cy);
2113 //set range
2114 SetSplitterRange();
2117 CString CCommitDlg::GetSignedOffByLine()
2119 CString str;
2121 CString username = g_Git.GetUserName();
2122 CString email = g_Git.GetUserEmail();
2123 username.Remove(_T('\n'));
2124 email.Remove(_T('\n'));
2126 str.Format(_T("Signed-off-by: %s <%s>"), username, email);
2128 return str;
2131 void CCommitDlg::OnBnClickedSignOff()
2133 CString str = GetSignedOffByLine();
2135 if (m_cLogMessage.GetText().Find(str) == -1) {
2136 m_cLogMessage.SetText(m_cLogMessage.GetText().TrimRight());
2137 int lastNewline = m_cLogMessage.GetText().ReverseFind(_T('\n'));
2138 int foundByLine = -1;
2139 if (lastNewline > 0)
2140 foundByLine = m_cLogMessage.GetText().Find(_T("-by: "), lastNewline);
2142 if (foundByLine == -1 || foundByLine < lastNewline)
2143 str = _T("\r\n") + str;
2145 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n")+str+_T("\r\n"));
2149 void CCommitDlg::OnBnClickedCommitAmend()
2151 this->UpdateData();
2152 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
2154 GitRev rev;
2155 rev.GetCommit(CString(_T("HEAD")));
2156 m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody();
2159 if(this->m_bCommitAmend)
2161 this->m_NoAmendStr=this->m_cLogMessage.GetText();
2162 m_cLogMessage.SetText(m_AmendStr);
2163 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_SHOW);
2165 else
2167 this->m_AmendStr=this->m_cLogMessage.GetText();
2168 m_cLogMessage.SetText(m_NoAmendStr);
2169 GetDlgItem(IDC_COMMIT_AMENDDIFF)->ShowWindow(SW_HIDE);
2172 OnBnClickedCommitSetDateTime(); // to update the commit date and time
2174 Refresh();
2177 void CCommitDlg::OnBnClickedWholeProject()
2179 m_tooltips.Pop(); // hide the tooltips
2180 UpdateData();
2181 m_ListCtrl.Clear();
2182 if (!m_bBlock)
2184 if(m_bWholeProject)
2185 m_ListCtrl.GetStatus(NULL,true,false,true);
2186 else
2187 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
2189 DWORD dwShow = m_ListCtrl.GetShowFlags();
2190 if (DWORD(m_regAddBeforeCommit))
2191 dwShow |= GITSLC_SHOWUNVERSIONED;
2192 else
2193 dwShow &= ~GITSLC_SHOWUNVERSIONED;
2195 m_ListCtrl.Show(dwShow, dwShow & ~(CTGitPath::LOGACTIONS_UNVER), true);
2196 UpdateCheckLinks();
2199 SetDlgTitle();
2202 void CCommitDlg::OnFocusMessage()
2204 m_cLogMessage.SetFocus();
2207 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
2209 UNREFERENCED_PARAMETER(pNMHDR);
2210 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
2211 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
2212 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
2214 CString str;
2215 str.Format(_T("%d/%d"),line+1,column+1);
2216 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
2218 if(*pResult)
2219 *pResult=0;
2221 void CCommitDlg::OnStnClickedViewPatch()
2223 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
2224 m_patchViewdlg.m_ParentCommitDlg = this;
2225 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
2227 BOOL viewPatchEnabled = FALSE;
2228 m_ProjectProperties.GetBOOLProps(viewPatchEnabled, _T("tgit.commitshowpatch"));
2229 if (viewPatchEnabled == FALSE)
2230 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("true"));
2231 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
2232 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETSCROLLWIDTHTRACKING, TRUE);
2233 CRect rect;
2234 this->GetWindowRect(&rect);
2236 m_patchViewdlg.ShowWindow(SW_SHOW);
2238 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
2239 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
2241 ShowViewPatchText(false);
2242 FillPatchView();
2244 else
2246 g_Git.SetConfigValue(_T("tgit.commitshowpatch"), _T("false"));
2247 m_patchViewdlg.ShowWindow(SW_HIDE);
2248 m_patchViewdlg.DestroyWindow();
2249 ShowViewPatchText(true);
2251 this->m_ctrlShowPatch.Invalidate();
2254 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
2256 __super::OnMoving(fwSide, pRect);
2258 if (::IsWindow(m_patchViewdlg.m_hWnd))
2260 RECT patchrect;
2261 m_patchViewdlg.GetWindowRect(&patchrect);
2262 if (::IsWindow(m_hWnd))
2264 RECT thisrect;
2265 GetWindowRect(&thisrect);
2266 if (patchrect.left == thisrect.right)
2268 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
2269 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
2276 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
2278 __super::OnSizing(fwSide, pRect);
2280 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
2282 CRect thisrect, patchrect;
2283 this->GetWindowRect(thisrect);
2284 this->m_patchViewdlg.GetWindowRect(patchrect);
2285 if(thisrect.right==patchrect.left)
2287 patchrect.left -= (thisrect.right - pRect->right);
2288 patchrect.right-= (thisrect.right - pRect->right);
2290 if( patchrect.bottom == thisrect.bottom)
2292 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
2294 if( patchrect.top == thisrect.top)
2296 patchrect.top -= thisrect.top-pRect->top;
2298 m_patchViewdlg.MoveWindow(patchrect);
2303 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
2305 UNREFERENCED_PARAMETER(pNMHDR);
2306 *pResult = 0;
2307 TRACE("Item Changed\r\n");
2310 int CCommitDlg::CheckHeadDetach()
2312 CString output;
2313 if(g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir,output))
2315 int retval = CMessageBox::Show(NULL, IDS_PROC_COMMIT_DETACHEDWARNING, IDS_APPNAME, MB_YESNOCANCEL | MB_ICONWARNING);
2316 if(retval == IDYES)
2318 if (CAppUtils::CreateBranchTag(FALSE, NULL, true) == FALSE)
2319 return 1;
2321 else if (retval == IDCANCEL)
2322 return 1;
2324 return 0;
2327 void CCommitDlg::OnBnClickedCommitAmenddiff()
2329 UpdateData();
2330 Refresh();
2333 void CCommitDlg::OnBnClickedNoautoselectsubmodules()
2335 UpdateData();
2336 Refresh();
2339 void CCommitDlg::OnBnClickedCommitSetDateTime()
2341 UpdateData();
2343 if (m_bSetCommitDateTime)
2345 CTime authordate = CTime::GetCurrentTime();
2346 if (m_bCommitAmend)
2348 GitRev headRevision;
2349 headRevision.GetCommit(_T("HEAD"));
2350 authordate = headRevision.GetAuthorDate();
2353 m_CommitDate.SetTime(&authordate);
2354 m_CommitTime.SetTime(&authordate);
2356 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_SHOW);
2357 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_SHOW);
2359 else
2361 GetDlgItem(IDC_COMMIT_DATEPICKER)->ShowWindow(SW_HIDE);
2362 GetDlgItem(IDC_COMMIT_TIMEPICKER)->ShowWindow(SW_HIDE);
2366 void CCommitDlg::OnBnClickedCheckNewBranch()
2368 UpdateData();
2369 if (m_bCreateNewBranch)
2371 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_HIDE);
2372 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_SHOW);
2374 else
2376 GetDlgItem(IDC_NEWBRANCH)->ShowWindow(SW_HIDE);
2377 GetDlgItem(IDC_COMMIT_TO)->ShowWindow(SW_SHOW);
2381 void CCommitDlg::RestoreFiles(bool doNotAsk)
2383 if (m_ListCtrl.m_restorepaths.size() && (doNotAsk || CMessageBox::Show(m_hWnd, IDS_PROC_COMMIT_RESTOREFILES, IDS_APPNAME, 2, IDI_QUESTION, IDS_PROC_COMMIT_RESTOREFILES_RESTORE, IDS_PROC_COMMIT_RESTOREFILES_KEEP) == 1))
2385 for (std::map<CString, CString>::iterator it = m_ListCtrl.m_restorepaths.begin(); it != m_ListCtrl.m_restorepaths.end(); ++it)
2386 CopyFile(it->second, g_Git.m_CurrentDir + _T("\\") + it->first, FALSE);
2387 m_ListCtrl.m_restorepaths.clear();
2391 void CCommitDlg::UpdateCheckLinks()
2393 DialogEnableWindow(IDC_CHECKALL, true);
2394 DialogEnableWindow(IDC_CHECKNONE, true);
2395 DialogEnableWindow(IDC_CHECKUNVERSIONED, m_ListCtrl.GetUnversionedCount() > 0);
2396 DialogEnableWindow(IDC_CHECKVERSIONED, m_ListCtrl.GetItemCount() > m_ListCtrl.GetUnversionedCount());
2397 DialogEnableWindow(IDC_CHECKADDED, m_ListCtrl.GetAddedCount() > 0);
2398 DialogEnableWindow(IDC_CHECKDELETED, m_ListCtrl.GetDeletedCount() > 0);
2399 DialogEnableWindow(IDC_CHECKMODIFIED, m_ListCtrl.GetModifiedCount() > 0);
2400 DialogEnableWindow(IDC_CHECKFILES, m_ListCtrl.GetFileCount() > 0);
2401 DialogEnableWindow(IDC_CHECKSUBMODULES, m_ListCtrl.GetSubmoduleCount() > 0);