Show Push Dialog after close commit dialog
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob0ca871273e908449465e1d16493cfcea2edab110
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "CommitDlg.h"
22 #include "DirFileEnum.h"
23 //#include "GitConfig.h"
24 #include "ProjectProperties.h"
25 #include "MessageBox.h"
26 #include "AppUtils.h"
27 #include "PathUtils.h"
28 #include "Git.h"
29 #include "Registry.h"
30 #include "GitStatus.h"
31 #include "HistoryDlg.h"
32 #include "Hooks.h"
33 #include "CommonResource.h"
34 #include "UnicodeUtils.h"
35 #include "ProgressDlg.h"
36 #include "ShellUpdater.h"
37 #include "Commands/PushCommand.h"
39 #ifdef _DEBUG
40 #define new DEBUG_NEW
41 #undef THIS_FILE
42 static char THIS_FILE[] = __FILE__;
43 #endif
45 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
47 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
48 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
49 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
50 , m_bRecursive(FALSE)
51 , m_bShowUnversioned(FALSE)
52 , m_bBlock(FALSE)
53 , m_bThreadRunning(FALSE)
54 , m_bRunThread(FALSE)
55 , m_pThread(NULL)
56 , m_bWholeProject(FALSE)
57 , m_bKeepChangeList(TRUE)
58 , m_itemsCount(0)
59 , m_bSelectFilesForCommit(TRUE)
61 this->m_bCommitAmend=FALSE;
62 m_bPushAfterCommit = FALSE;
65 CCommitDlg::~CCommitDlg()
67 if(m_pThread != NULL)
69 delete m_pThread;
73 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
75 CResizableStandAloneDialog::DoDataExchange(pDX);
76 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
77 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
78 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
79 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
80 DDX_Text(pDX, IDC_BUGID, m_sBugID);
81 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
82 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
83 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
84 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
87 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
88 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
89 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
90 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
91 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
92 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
93 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
94 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
95 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
96 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
97 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
98 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
99 ON_WM_TIMER()
100 ON_WM_SIZE()
101 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
102 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
103 ON_STN_CLICKED(IDC_COMMITLABEL, &CCommitDlg::OnStnClickedCommitlabel)
104 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
105 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
106 ON_STN_CLICKED(IDC_BUGIDLABEL, &CCommitDlg::OnStnClickedBugidlabel)
107 END_MESSAGE_MAP()
109 BOOL CCommitDlg::OnInitDialog()
111 CResizableStandAloneDialog::OnInitDialog();
113 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
114 m_bShowUnversioned = m_regAddBeforeCommit;
116 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
118 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
119 m_bKeepChangeList = m_regKeepChangelists;
121 // GitConfig config;
122 // m_bWholeProject = config.KeepLocks();
124 UpdateData(FALSE);
126 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"));
127 m_ListCtrl.SetSelectButton(&m_SelectAll);
128 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
129 m_ListCtrl.SetCancelBool(&m_bCancelled);
130 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
131 m_ListCtrl.EnableFileDrop();
132 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
134 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
135 m_ProjectProperties.ReadPropsPathList(m_pathList);
137 m_cLogMessage.Init(m_ProjectProperties);
138 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
139 m_cLogMessage.RegisterContextMenuHandler(this);
141 OnEnChangeLogmessage();
143 m_tooltips.Create(this);
144 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
145 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
146 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
148 m_SelectAll.SetCheck(BST_INDETERMINATE);
151 CBugTraqAssociations bugtraq_associations;
152 bugtraq_associations.Load();
154 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
156 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
157 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
159 CComPtr<IBugTraqProvider> pProvider;
160 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
161 if (SUCCEEDED(hr))
163 m_BugTraqProvider = pProvider;
164 BSTR temp = NULL;
165 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
167 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
168 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
169 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
172 SysFreeString(temp);
175 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
177 else if (!m_ProjectProperties.sMessage.IsEmpty())
179 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
180 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
181 if (!m_ProjectProperties.sLabel.IsEmpty())
182 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
183 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
184 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
185 GetDlgItem(IDC_BUGID)->SetFocus();
186 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
187 if (!sBugID.IsEmpty())
189 SetDlgItemText(IDC_BUGID, sBugID);
192 else
194 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
195 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
196 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
197 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
198 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
201 if (!m_sLogMessage.IsEmpty())
202 m_cLogMessage.SetText(m_sLogMessage);
204 GetWindowText(m_sWindowTitle);
206 AdjustControlSize(IDC_SHOWUNVERSIONED);
207 AdjustControlSize(IDC_SELECTALL);
208 AdjustControlSize(IDC_WHOLE_PROJECT);
210 GetClientRect(m_DlgOrigRect);
211 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
213 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
214 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
215 AddAnchor(IDC_BUGID, TOP_RIGHT);
216 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
217 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
218 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
219 // AddAnchor(IDC_HISTORY, TOP_LEFT);
220 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
221 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
222 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
223 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
224 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
225 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
226 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
227 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
228 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
229 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
230 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
231 AddAnchor(IDOK, BOTTOM_RIGHT);
232 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
233 AddAnchor(IDHELP, BOTTOM_RIGHT);
234 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
236 if (hWndExplorer)
237 CenterWindow(CWnd::FromHandle(hWndExplorer));
238 EnableSaveRestore(_T("CommitDlg"));
239 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
240 RECT rcDlg, rcLogMsg, rcFileList;
241 GetClientRect(&rcDlg);
242 m_cLogMessage.GetWindowRect(&rcLogMsg);
243 ScreenToClient(&rcLogMsg);
244 m_ListCtrl.GetWindowRect(&rcFileList);
245 ScreenToClient(&rcFileList);
246 if (yPos)
248 RECT rectSplitter;
249 m_wndSplitter.GetWindowRect(&rectSplitter);
250 ScreenToClient(&rectSplitter);
251 int delta = yPos - rectSplitter.top;
252 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
254 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
255 DoSize(delta);
259 // add all directories to the watcher
260 for (int i=0; i<m_pathList.GetCount(); ++i)
262 if (m_pathList[i].IsDirectory())
263 m_pathwatcher.AddPath(m_pathList[i]);
266 m_updatedPathList = m_pathList;
268 //first start a thread to obtain the file list with the status without
269 //blocking the dialog
270 InterlockedExchange(&m_bBlock, TRUE);
271 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
272 if (m_pThread==NULL)
274 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
275 InterlockedExchange(&m_bBlock, FALSE);
277 else
279 m_pThread->m_bAutoDelete = FALSE;
280 m_pThread->ResumeThread();
282 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
283 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
284 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
286 historyhint = TRUE;
287 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
289 err = FALSE;
291 //this->UpdateData(TRUE);
292 //this->m_bCommitAmend=FALSE;
293 //this->UpdateData(FALSE);
295 return FALSE; // return TRUE unless you set the focus to a control
296 // EXCEPTION: OCX Property Pages should return FALSE
299 void CCommitDlg::OnOK()
301 if (m_bBlock)
302 return;
303 if (m_bThreadRunning)
305 m_bCancelled = true;
306 InterlockedExchange(&m_bRunThread, FALSE);
307 WaitForSingleObject(m_pThread->m_hThread, 1000);
308 if (m_bThreadRunning)
310 // we gave the thread a chance to quit. Since the thread didn't
311 // listen to us we have to kill it.
312 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
313 InterlockedExchange(&m_bThreadRunning, FALSE);
316 this->UpdateData();
318 CString id;
319 GetDlgItemText(IDC_BUGID, id);
320 if (!m_ProjectProperties.CheckBugID(id))
322 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
323 return;
325 m_sLogMessage = m_cLogMessage.GetText();
326 if ( m_sLogMessage.IsEmpty() )
328 // no message entered, go round again
329 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
330 return;
332 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
334 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
335 return;
338 #if 0
339 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
340 if (!(DWORD)regUnversionedRecurse)
342 // Find unversioned directories which are marked for commit. The user might expect them
343 // to be added recursively since he cannot the the files. Let's ask the user if he knows
344 // what he is doing.
345 int nListItems = m_ListCtrl.GetItemCount();
346 for (int j=0; j<nListItems; j++)
348 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
349 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
351 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
352 return;
356 #endif
357 m_pathwatcher.Stop();
358 InterlockedExchange(&m_bBlock, TRUE);
359 CDWordArray arDeleted;
360 //first add all the unversioned files the user selected
361 //and check if all versioned files are selected
362 int nchecked = 0;
363 m_bRecursive = true;
364 int nListItems = m_ListCtrl.GetItemCount();
366 CTGitPathList itemsToAdd;
367 CTGitPathList itemsToRemove;
368 //std::set<CString> checkedLists;
369 //std::set<CString> uncheckedLists;
371 //CString checkedfiles;
372 //CString uncheckedfiles;
374 CString cmd;
375 CString out;
377 for (int j=0; j<nListItems; j++)
379 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
380 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
381 if (entry->m_Checked)
383 #if 0
384 if (entry->status == Git_wc_status_unversioned)
386 itemsToAdd.AddPath(entry->GetPath());
388 if (entry->status == Git_wc_status_conflicted)
390 bHasConflicted = true;
392 if (entry->status == Git_wc_status_missing)
394 itemsToRemove.AddPath(entry->GetPath());
396 if (entry->status == Git_wc_status_deleted)
398 arDeleted.Add(j);
400 if (entry->IsInExternal())
402 bCheckedInExternal = true;
404 #endif
405 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
406 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
407 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
408 cmd.Format(_T("git.exe update-index --remove -- \"%s\""),entry->GetGitPathString());
409 else
410 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
412 g_Git.Run(cmd,&out,CP_ACP);
413 nchecked++;
415 //checkedLists.insert(entry->GetGitPathString());
416 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
418 else
420 //uncheckedLists.insert(entry->GetGitPathString());
421 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
422 { //To init git repository, there are not HEAD, so we can use git reset command
423 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
424 g_Git.Run(cmd,&out,CP_ACP);
426 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
428 cmd.Format(_T("git.exe reset -- \"%s\""),entry->GetGitPathString());
429 g_Git.Run(cmd,&out,CP_ACP);
432 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
433 #if 0
434 if ((entry->status != Git_wc_status_unversioned) &&
435 (entry->status != Git_wc_status_ignored))
437 nUnchecked++;
438 uncheckedLists.insert(entry->GetChangeList());
439 if (m_bRecursive)
441 // This algorithm is for the sake of simplicity of the complexity O(N?
442 for (int k=0; k<nListItems; k++)
444 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
445 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
447 // Fall back to a non-recursive commit to prevent items being
448 // committed which aren't checked although its parent is checked
449 // (property change, directory deletion, ... )
450 m_bRecursive = false;
451 break;
456 #endif
459 CShellUpdater::Instance().AddPathForUpdate(*entry);
462 //if(uncheckedfiles.GetLength()>0)
464 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
465 // g_Git.Run(cmd,&out);
468 m_sBugID.Trim();
469 if (!m_sBugID.IsEmpty())
471 m_sBugID.Replace(_T(", "), _T(","));
472 m_sBugID.Replace(_T(" ,"), _T(","));
473 CString sBugID = m_ProjectProperties.sMessage;
474 sBugID.Replace(_T("%BUGID%"), m_sBugID);
475 if (m_ProjectProperties.bAppend)
476 m_sLogMessage += _T("\n") + sBugID + _T("\n");
477 else
478 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
481 BOOL bCloseCommitDlg=true;
482 //if(checkedfiles.GetLength()>0)
483 if(nchecked||m_bCommitAmend)
485 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
486 // g_Git.Run(cmd,&out);
488 CString tempfile=::GetTempFile();
490 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
491 //file.WriteString(m_sLogMessage);
494 out =_T("");
495 CString amend;
496 if(this->m_bCommitAmend)
498 amend=_T("--amend");
500 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
502 CProgressDlg progress;
503 progress.m_GitCmd=cmd;
504 progress.m_bShowCommand = FALSE; // don't show the commit command
505 progress.m_PreText = out; // show any output already generated in log window
506 progress.m_changeAbortButtonOnSuccessTo = "Push";
507 DWORD userResponse = progress.DoModal();
509 if(progress.m_GitStatus)
511 bCloseCommitDlg = false;
512 this->Refresh();
514 else if(userResponse == IDCANCEL)
516 //User pressed 'Push' button after successful commit.
517 m_bPushAfterCommit=true;
520 CFile::Remove(tempfile);
521 }else
522 CMessageBox::Show(this->m_hWnd, _T("Nothing Commit"), _T("Commit Finish"), MB_OK | MB_ICONINFORMATION);
523 #if 0
524 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
526 // There are paths which got changed (touched at least).
527 // We have to find out if this affects the selection in the commit dialog
528 // If it could affect the selection, revert back to a non-recursive commit
529 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
530 changedList.RemoveDuplicates();
531 for (int i=0; i<changedList.GetCount(); ++i)
533 if (changedList[i].IsAdminDir())
535 // something inside an admin dir was changed.
536 // if it's the entries file, then we have to fully refresh because
537 // files may have been added/removed from version control
538 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
539 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
541 m_bRecursive = false;
542 break;
545 else if (!m_ListCtrl.IsPathShown(changedList[i]))
547 // a path which is not shown in the list has changed
548 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
549 if (entry)
551 // check if the changed path would get committed by a recursive commit
552 if ((!entry->IsFromDifferentRepository()) &&
553 (!entry->IsInExternal()) &&
554 (!entry->IsNested()) &&
555 (!entry->IsChecked()))
557 m_bRecursive = false;
558 break;
566 // Now, do all the adds - make sure that the list is sorted so that parents
567 // are added before their children
568 itemsToAdd.SortByPathname();
569 Git Git;
570 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
572 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
573 InterlockedExchange(&m_bBlock, FALSE);
574 Refresh();
575 return;
578 // Remove any missing items
579 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
580 itemsToRemove.SortByPathname();
581 Git.Remove(itemsToRemove, TRUE);
583 //the next step: find all deleted files and check if they're
584 //inside a deleted folder. If that's the case, then remove those
585 //files from the list since they'll get deleted by the parent
586 //folder automatically.
587 m_ListCtrl.Block(TRUE, FALSE);
588 INT_PTR nDeleted = arDeleted.GetCount();
589 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
591 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
593 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
594 if (path.IsDirectory())
596 //now find all children of this directory
597 for (int j=0; j<arDeleted.GetCount(); j++)
599 if (i!=j)
601 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
602 if (childEntry->IsChecked())
604 if (path.IsAncestorOf(childEntry->GetPath()))
606 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
607 nDeleted--;
615 m_ListCtrl.Block(FALSE, FALSE);
617 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
619 //save only the files the user has checked into the temporary file
620 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
622 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
623 // the item count is used in the progress dialog to show the overall commit
624 // progress.
625 // deleted items only send one notification event, all others send two
626 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
628 if ((m_bRecursive)&&(checkedLists.size() == 1))
630 // all checked items belong to the same changelist
631 // find out if there are any unchecked items which belong to that changelist
632 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
633 m_sChangeList = *checkedLists.begin();
635 #endif
636 UpdateData();
637 m_regAddBeforeCommit = m_bShowUnversioned;
638 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
639 m_bWholeProject = FALSE;
640 m_regKeepChangelists = m_bKeepChangeList;
641 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
642 m_bKeepChangeList = FALSE;
643 InterlockedExchange(&m_bBlock, FALSE);
645 m_History.AddEntry(m_sLogMessage);
646 m_History.Save();
648 SaveSplitterPos();
650 if( bCloseCommitDlg )
651 CResizableStandAloneDialog::OnOK();
653 CShellUpdater::Instance().Flush();
656 void CCommitDlg::SaveSplitterPos()
658 if (!IsIconic())
660 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
661 RECT rectSplitter;
662 m_wndSplitter.GetWindowRect(&rectSplitter);
663 ScreenToClient(&rectSplitter);
664 regPos = rectSplitter.top;
668 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
670 return ((CCommitDlg*)pVoid)->StatusThread();
673 UINT CCommitDlg::StatusThread()
675 //get the status of all selected file/folders recursively
676 //and show the ones which have to be committed to the user
677 //in a list control.
678 InterlockedExchange(&m_bBlock, TRUE);
679 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
680 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
681 m_bCancelled = false;
683 DialogEnableWindow(IDOK, false);
684 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
685 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
686 DialogEnableWindow(IDC_SELECTALL, false);
687 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
688 DialogEnableWindow(IDC_EXTERNALWARNING, false);
689 // read the list of recent log entries before querying the WC for status
690 // -> the user may select one and modify / update it while we are crawling the WC
692 if (m_History.GetCount()==0)
694 CString reg;
695 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
696 reg.Replace(_T(':'),_T('_'));
697 m_History.Load(reg, _T("logmsgs"));
700 // Initialise the list control with the status of the files/folders below us
701 m_ListCtrl.Clear();
702 BOOL success;
703 if(m_bWholeProject)
704 success=m_ListCtrl.GetStatus(NULL);
705 else
706 success=m_ListCtrl.GetStatus(&m_pathList);
708 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
709 if(this->m_bShowUnversioned)
710 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,&m_pathList);
712 m_ListCtrl.CheckIfChangelistsArePresent(false);
714 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
715 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
716 if (success)
718 if (m_checkedPathList.GetCount())
719 m_ListCtrl.Show(dwShow, m_checkedPathList);
720 else
722 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
723 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
724 m_ListCtrl.Show(dwShow, dwCheck);
725 m_bSelectFilesForCommit = true;
728 if (m_ListCtrl.HasExternalsFromDifferentRepos())
730 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
731 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
734 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
735 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
737 CString logmsg;
738 GetDlgItemText(IDC_LOGMESSAGE, logmsg);
739 DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);
740 if (!success)
742 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
743 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
744 m_ListCtrl.Show(dwShow);
746 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems()))
748 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
750 m_bShowUnversioned = TRUE;
751 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
752 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
753 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
754 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
758 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
760 if(this->m_bWholeProject)
761 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
762 else
763 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
765 m_autolist.clear();
766 // we don't have to block the commit dialog while we fetch the
767 // auto completion list.
768 m_pathwatcher.ClearChangedPaths();
769 InterlockedExchange(&m_bBlock, FALSE);
770 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
772 m_ListCtrl.Block(TRUE, TRUE);
773 GetAutocompletionList();
774 m_ListCtrl.Block(FALSE, FALSE);
776 if (m_bRunThread)
778 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
779 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
780 DialogEnableWindow(IDC_SELECTALL, true);
781 if (m_ListCtrl.HasChangeLists())
782 DialogEnableWindow(IDC_KEEPLISTS, true);
783 if (m_ListCtrl.HasLocks())
784 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
785 // we have the list, now signal the main thread about it
786 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
789 InterlockedExchange(&m_bRunThread, FALSE);
790 InterlockedExchange(&m_bThreadRunning, FALSE);
791 // force the cursor to normal
792 RefreshCursor();
794 return 0;
797 void CCommitDlg::OnCancel()
799 m_bCancelled = true;
800 if (m_bBlock)
801 return;
802 m_pathwatcher.Stop();
803 if (m_bThreadRunning)
805 InterlockedExchange(&m_bRunThread, FALSE);
806 WaitForSingleObject(m_pThread->m_hThread, 1000);
807 if (m_bThreadRunning)
809 // we gave the thread a chance to quit. Since the thread didn't
810 // listen to us we have to kill it.
811 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
812 InterlockedExchange(&m_bThreadRunning, FALSE);
815 UpdateData();
816 m_sBugID.Trim();
817 m_sLogMessage = m_cLogMessage.GetText();
818 if (!m_sBugID.IsEmpty())
820 m_sBugID.Replace(_T(", "), _T(","));
821 m_sBugID.Replace(_T(" ,"), _T(","));
822 CString sBugID = m_ProjectProperties.sMessage;
823 sBugID.Replace(_T("%BUGID%"), m_sBugID);
824 if (m_ProjectProperties.bAppend)
825 m_sLogMessage += _T("\n") + sBugID + _T("\n");
826 else
827 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
829 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
830 m_History.AddEntry(m_sLogMessage);
831 m_History.Save();
832 SaveSplitterPos();
833 CResizableStandAloneDialog::OnCancel();
836 void CCommitDlg::OnBnClickedSelectall()
838 m_tooltips.Pop(); // hide the tooltips
839 UINT state = (m_SelectAll.GetState() & 0x0003);
840 if (state == BST_INDETERMINATE)
842 // It is not at all useful to manually place the checkbox into the indeterminate state...
843 // We will force this on to the unchecked state
844 state = BST_UNCHECKED;
845 m_SelectAll.SetCheck(state);
847 m_ListCtrl.SelectAll(state == BST_CHECKED);
850 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
852 if (!m_bBlock)
853 m_tooltips.RelayEvent(pMsg);
854 if (pMsg->message == WM_KEYDOWN)
856 switch (pMsg->wParam)
858 case VK_F5:
860 if (m_bBlock)
861 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
862 Refresh();
864 break;
865 case VK_RETURN:
867 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
869 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
871 PostMessage(WM_COMMAND, IDOK);
873 return TRUE;
875 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
877 // Pressing RETURN in the bug id control
878 // moves the focus to the message
879 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
880 return TRUE;
883 break;
887 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
890 void CCommitDlg::Refresh()
892 if (m_bThreadRunning)
893 return;
895 InterlockedExchange(&m_bBlock, TRUE);
896 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
897 if (m_pThread==NULL)
899 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
900 InterlockedExchange(&m_bBlock, FALSE);
902 else
904 m_pThread->m_bAutoDelete = FALSE;
905 m_pThread->ResumeThread();
909 void CCommitDlg::OnBnClickedHelp()
911 OnHelp();
914 void CCommitDlg::OnBnClickedShowunversioned()
916 m_tooltips.Pop(); // hide the tooltips
917 UpdateData();
918 m_regAddBeforeCommit = m_bShowUnversioned;
919 if (!m_bBlock)
921 DWORD dwShow = m_ListCtrl.GetShowFlags();
922 if (DWORD(m_regAddBeforeCommit))
923 dwShow |= SVNSLC_SHOWUNVERSIONED;
924 else
925 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
926 if(dwShow & SVNSLC_SHOWUNVERSIONED)
928 if(m_bWholeProject)
929 m_ListCtrl.GetStatus(NULL,false,false,true);
930 else
931 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
933 m_ListCtrl.Show(dwShow);
937 void CCommitDlg::OnStnClickedExternalwarning()
939 m_tooltips.Popup();
942 void CCommitDlg::OnEnChangeLogmessage()
944 UpdateOKButton();
947 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
949 #if 0
950 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
952 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
954 m_bShowUnversioned = TRUE;
955 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
956 m_ListCtrl.Show(dwShow);
957 UpdateData(FALSE);
960 #endif
961 return 0;
964 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
966 Refresh();
967 return 0;
970 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
972 #if 0
973 BringWindowToTop();
974 SetForegroundWindow();
975 SetActiveWindow();
976 // if multiple files/folders are dropped
977 // this handler is called for every single item
978 // separately.
979 // To avoid creating multiple refresh threads and
980 // causing crashes, we only add the items to the
981 // list control and start a timer.
982 // When the timer expires, we start the refresh thread,
983 // but only if it isn't already running - otherwise we
984 // restart the timer.
985 CTGitPath path;
986 path.SetFromWin((LPCTSTR)lParam);
988 // just add all the items we get here.
989 // if the item is versioned, the add will fail but nothing
990 // more will happen.
991 Git Git;
992 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
994 if (!m_ListCtrl.HasPath(path))
996 if (m_pathList.AreAllPathsFiles())
998 m_pathList.AddPath(path);
999 m_pathList.RemoveDuplicates();
1000 m_updatedPathList.AddPath(path);
1001 m_updatedPathList.RemoveDuplicates();
1003 else
1005 // if the path list contains folders, we have to check whether
1006 // our just (maybe) added path is a child of one of those. If it is
1007 // a child of a folder already in the list, we must not add it. Otherwise
1008 // that path could show up twice in the list.
1009 bool bHasParentInList = false;
1010 for (int i=0; i<m_pathList.GetCount(); ++i)
1012 if (m_pathList[i].IsAncestorOf(path))
1014 bHasParentInList = true;
1015 break;
1018 if (!bHasParentInList)
1020 m_pathList.AddPath(path);
1021 m_pathList.RemoveDuplicates();
1022 m_updatedPathList.AddPath(path);
1023 m_updatedPathList.RemoveDuplicates();
1028 // Always start the timer, since the status of an existing item might have changed
1029 SetTimer(REFRESHTIMER, 200, NULL);
1030 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1031 #endif
1032 return 0;
1035 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1037 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1038 return 0;
1041 //////////////////////////////////////////////////////////////////////////
1042 // functions which run in the status thread
1043 //////////////////////////////////////////////////////////////////////////
1045 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1047 CString strLine;
1050 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1051 while (m_bRunThread && file.ReadString(strLine))
1053 int eqpos = strLine.Find('=');
1054 CString rgx;
1055 rgx = strLine.Mid(eqpos+1).Trim();
1057 int pos = -1;
1058 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1060 mapRegex[strLine.Left(pos)] = rgx;
1061 strLine = strLine.Mid(pos+1).Trim();
1063 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1065 file.Close();
1067 catch (CFileException* pE)
1069 TRACE("CFileException loading auto list regex file\n");
1070 pE->Delete();
1071 return;
1074 void CCommitDlg::GetAutocompletionList()
1076 // the auto completion list is made of strings from each selected files.
1077 // the strings used are extracted from the files with regexes found
1078 // in the file "autolist.txt".
1079 // the format of that file is:
1080 // file extensions separated with commas '=' regular expression to use
1081 // example:
1082 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1083 // .cpp = (?<=[^\s]::)\b\w+\b
1085 std::map<CString, CString> mapRegex;
1086 CString sRegexFile = CPathUtils::GetAppDirectory();
1087 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1088 DWORD timeoutvalue = regtimeout*1000;
1089 sRegexFile += _T("autolist.txt");
1090 if (!m_bRunThread)
1091 return;
1092 ParseRegexFile(sRegexFile, mapRegex);
1093 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1094 sRegexFile.ReleaseBuffer();
1095 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1096 if (PathFileExists(sRegexFile))
1098 ParseRegexFile(sRegexFile, mapRegex);
1100 DWORD starttime = GetTickCount();
1102 // now we have two arrays of strings, where the first array contains all
1103 // file extensions we can use and the second the corresponding regex strings
1104 // to apply to those files.
1106 // the next step is to go over all files shown in the commit dialog
1107 // and scan them for strings we can use
1108 int nListItems = m_ListCtrl.GetItemCount();
1110 for (int i=0; i<nListItems && m_bRunThread; ++i)
1112 // stop parsing after timeout
1113 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1114 return;
1116 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1118 if(path == NULL)
1119 continue;
1121 CString sPartPath =path->GetGitPathString();
1122 m_autolist.insert(sPartPath);
1124 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1125 // if (!entry)
1126 // continue;
1128 // add the path parts to the auto completion list too
1129 // CString sPartPath = entry->GetRelativeGitPath();
1130 // m_autolist.insert(sPartPath);
1133 int pos = 0;
1134 int lastPos = 0;
1135 while ((pos = sPartPath.Find('/', pos)) >= 0)
1137 pos++;
1138 lastPos = pos;
1139 m_autolist.insert(sPartPath.Mid(pos));
1142 // Last inserted entry is a file name.
1143 // Some users prefer to also list file name without extension.
1144 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1146 int dotPos = sPartPath.ReverseFind('.');
1147 if ((dotPos >= 0) && (dotPos > lastPos))
1148 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1150 #if 0
1151 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1152 continue;
1154 CString sExt = entry->GetPath().GetFileExtension();
1155 sExt.MakeLower();
1156 // find the regex string which corresponds to the file extension
1157 CString rdata = mapRegex[sExt];
1158 if (rdata.IsEmpty())
1159 continue;
1161 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1162 if ((entry->textstatus != Git_wc_status_unversioned) &&
1163 (entry->textstatus != Git_wc_status_none) &&
1164 (entry->textstatus != Git_wc_status_ignored) &&
1165 (entry->textstatus != Git_wc_status_added) &&
1166 (entry->textstatus != Git_wc_status_normal))
1168 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1169 if (!basePath.IsEmpty())
1170 ScanFile(basePath.GetWinPathString(), rdata);
1172 #endif
1174 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1177 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1179 wstring sFileContent;
1180 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1181 if (hFile != INVALID_HANDLE_VALUE)
1183 DWORD size = GetFileSize(hFile, NULL);
1184 if (size > 1000000L)
1186 // no files bigger than 1 Meg
1187 CloseHandle(hFile);
1188 return;
1190 // allocate memory to hold file contents
1191 char * buffer = new char[size];
1192 DWORD readbytes;
1193 ReadFile(hFile, buffer, size, &readbytes, NULL);
1194 CloseHandle(hFile);
1195 int opts = 0;
1196 IsTextUnicode(buffer, readbytes, &opts);
1197 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1199 delete [] buffer;
1200 return;
1202 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1204 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1206 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1208 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1209 wchar_t * pWideBuf = new wchar_t[ret];
1210 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1211 if (ret2 == ret)
1212 sFileContent = wstring(pWideBuf, ret);
1213 delete [] pWideBuf;
1215 delete [] buffer;
1217 if (sFileContent.empty()|| !m_bRunThread)
1219 return;
1224 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1225 const tr1::wsregex_iterator end;
1226 wstring s = sFileContent;
1227 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1229 const tr1::wsmatch match = *it;
1230 for (size_t i=1; i<match.size(); ++i)
1232 if (match[i].second-match[i].first)
1234 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1235 m_autolist.insert(wstring(match[i]).c_str());
1240 catch (exception) {}
1243 // CSciEditContextMenuInterface
1244 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1246 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1247 m_nPopupPasteListCmd = nCmd++;
1248 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1250 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1251 if(m_History.GetCount() > 0)
1253 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1254 m_nPopupPasteLastMessage = nCmd++;
1255 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1260 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1263 if (m_bBlock)
1264 return false;
1265 if (cmd == m_nPopupPasteListCmd)
1267 CString logmsg;
1268 TCHAR buf[MAX_STATUS_STRING_LENGTH];
1269 int nListItems = m_ListCtrl.GetItemCount();
1270 for (int i=0; i<nListItems; ++i)
1272 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1273 if (entry&&entry->m_Checked)
1275 CString line;
1276 CString status = entry->GetActionName();
1277 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1278 status = _T("Add");
1280 //git_wc_status_kind status = entry->status;
1281 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1282 if (m_ProjectProperties.bFileListInEnglish)
1283 langID = 1033;
1285 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1286 logmsg += line;
1289 pSciEdit->InsertText(logmsg);
1290 return true;
1293 if(cmd == m_nPopupPasteLastMessage)
1295 if(m_History.GetCount() ==0 )
1296 return false;
1298 CString logmsg;
1299 logmsg +=m_History.GetEntry(0);
1300 pSciEdit->InsertText(logmsg);
1301 return true;
1303 return false;
1306 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1308 switch (nIDEvent)
1310 case ENDDIALOGTIMER:
1311 KillTimer(ENDDIALOGTIMER);
1312 EndDialog(0);
1313 break;
1314 case REFRESHTIMER:
1315 if (m_bThreadRunning)
1317 SetTimer(REFRESHTIMER, 200, NULL);
1318 ATLTRACE("Wait some more before refreshing\n");
1320 else
1322 KillTimer(REFRESHTIMER);
1323 ATLTRACE("Refreshing after items dropped\n");
1324 Refresh();
1326 break;
1328 __super::OnTimer(nIDEvent);
1331 void CCommitDlg::OnBnClickedHistory()
1333 m_tooltips.Pop(); // hide the tooltips
1334 if (m_pathList.GetCount() == 0)
1335 return;
1336 #if 0
1337 CHistoryDlg historyDlg;
1338 historyDlg.SetHistory(m_History);
1339 if (historyDlg.DoModal() != IDOK)
1340 return;
1342 CString sMsg = historyDlg.GetSelectedText();
1343 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1345 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1346 if (!sBugID.IsEmpty())
1348 SetDlgItemText(IDC_BUGID, sBugID);
1350 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1351 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1352 else
1353 m_cLogMessage.SetText(sMsg);
1356 UpdateOKButton();
1357 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1358 #endif
1361 void CCommitDlg::OnBnClickedBugtraqbutton()
1363 m_tooltips.Pop(); // hide the tooltips
1364 CString sMsg = m_cLogMessage.GetText();
1366 if (m_BugTraqProvider == NULL)
1367 return;
1369 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1370 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1371 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1373 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1374 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1376 BSTR originalMessage = sMsg.AllocSysString();
1377 BSTR temp = NULL;
1378 // m_revProps.clear();
1380 // first try the IBugTraqProvider2 interface
1381 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1382 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1383 if (SUCCEEDED(hr))
1385 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1386 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1387 BSTR bugIDOut = NULL;
1388 GetDlgItemText(IDC_BUGID, m_sBugID);
1389 BSTR bugID = m_sBugID.AllocSysString();
1390 SAFEARRAY * revPropNames = NULL;
1391 SAFEARRAY * revPropValues = NULL;
1392 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1394 CString sErr;
1395 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1396 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1398 else
1400 if (bugIDOut)
1402 m_sBugID = bugIDOut;
1403 SysFreeString(bugIDOut);
1404 SetDlgItemText(IDC_BUGID, m_sBugID);
1406 SysFreeString(bugID);
1407 SysFreeString(repositoryRoot);
1408 m_cLogMessage.SetText(temp);
1409 BSTR HUGEP *pbRevNames;
1410 BSTR HUGEP *pbRevValues;
1412 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1413 if (SUCCEEDED(hr1))
1415 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1416 if (SUCCEEDED(hr2))
1418 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1420 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1422 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1425 SafeArrayUnaccessData(revPropValues);
1427 SafeArrayUnaccessData(revPropNames);
1429 if (revPropNames)
1430 SafeArrayDestroy(revPropNames);
1431 if (revPropValues)
1432 SafeArrayDestroy(revPropValues);
1435 else
1437 // if IBugTraqProvider2 failed, try IBugTraqProvider
1438 CComPtr<IBugTraqProvider> pProvider = NULL;
1439 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1440 if (FAILED(hr))
1442 CString sErr;
1443 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1444 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1445 return;
1448 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1450 CString sErr;
1451 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1452 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1454 else
1455 m_cLogMessage.SetText(temp);
1457 m_sLogMessage = m_cLogMessage.GetText();
1458 if (!m_ProjectProperties.sMessage.IsEmpty())
1460 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1461 if (!sBugID.IsEmpty())
1463 SetDlgItemText(IDC_BUGID, sBugID);
1467 m_cLogMessage.SetFocus();
1469 SysFreeString(parameters);
1470 SysFreeString(commonRoot);
1471 SafeArrayDestroy(pathList);
1472 SysFreeString(originalMessage);
1473 SysFreeString(temp);
1477 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1479 UpdateOKButton();
1480 return 0;
1483 void CCommitDlg::UpdateOKButton()
1485 #if 0
1486 BOOL bValidLogSize = FALSE;
1488 if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)
1489 bValidLogSize = !m_bBlock;
1491 LONG nSelectedItems = m_ListCtrl.GetSelected();
1492 DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);
1493 #endif
1497 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1499 switch (message) {
1500 case WM_NOTIFY:
1501 if (wParam == IDC_SPLITTER)
1503 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1504 DoSize(pHdr->delta);
1506 break;
1509 return __super::DefWindowProc(message, wParam, lParam);
1512 void CCommitDlg::SetSplitterRange()
1514 if ((m_ListCtrl)&&(m_cLogMessage))
1516 CRect rcTop;
1517 m_cLogMessage.GetWindowRect(rcTop);
1518 ScreenToClient(rcTop);
1519 CRect rcMiddle;
1520 m_ListCtrl.GetWindowRect(rcMiddle);
1521 ScreenToClient(rcMiddle);
1522 if (rcMiddle.Height() && rcMiddle.Width())
1523 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1527 void CCommitDlg::DoSize(int delta)
1529 RemoveAnchor(IDC_MESSAGEGROUP);
1530 RemoveAnchor(IDC_LOGMESSAGE);
1531 RemoveAnchor(IDC_SPLITTER);
1532 RemoveAnchor(IDC_SIGNOFF);
1533 RemoveAnchor(IDC_COMMIT_AMEND);
1534 RemoveAnchor(IDC_LISTGROUP);
1535 RemoveAnchor(IDC_FILELIST);
1536 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1537 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1538 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1539 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1540 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1541 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1542 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1543 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1544 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1545 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1546 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1547 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1548 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1549 ArrangeLayout();
1550 // adjust the minimum size of the dialog to prevent the resizing from
1551 // moving the list control too far down.
1552 CRect rcLogMsg;
1553 m_cLogMessage.GetClientRect(rcLogMsg);
1554 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1556 SetSplitterRange();
1557 m_cLogMessage.Invalidate();
1558 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1561 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1563 // first, let the resizing take place
1564 __super::OnSize(nType, cx, cy);
1566 //set range
1567 SetSplitterRange();
1571 void CCommitDlg::OnBnClickedSignOff()
1573 // TODO: Add your control notification handler code here
1574 CString str;
1575 CString username;
1576 CString email;
1577 username=g_Git.GetUserName();
1578 email=g_Git.GetUserEmail();
1579 username.Remove(_T('\n'));
1580 email.Remove(_T('\n'));
1581 str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);
1583 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);
1586 void CCommitDlg::OnStnClickedCommitlabel()
1588 // TODO: Add your control notification handler code here
1591 void CCommitDlg::OnBnClickedCommitAmend()
1593 // TODO: Add your control notification handler code here
1594 this->UpdateData();
1595 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1597 GitRev rev;
1598 BYTE_VECTOR vector;
1599 CString head(_T("HEAD"));
1600 g_Git.GetLog(vector,head,NULL,1);
1601 rev.ParserFromLog(vector);
1602 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;
1605 if(this->m_bCommitAmend)
1607 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1608 m_cLogMessage.SetText(m_AmendStr);
1610 }else
1612 this->m_AmendStr=this->m_cLogMessage.GetText();
1613 m_cLogMessage.SetText(m_NoAmendStr);
1619 void CCommitDlg::OnBnClickedWholeProject()
1621 // TODO: Add your control notification handler code here
1622 m_tooltips.Pop(); // hide the tooltips
1623 UpdateData();
1624 m_ListCtrl.Clear();
1625 if (!m_bBlock)
1627 if(m_bWholeProject)
1628 m_ListCtrl.GetStatus(NULL,true,false,true);
1629 else
1630 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1632 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());
1635 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1637 if(this->m_bWholeProject)
1638 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1639 else
1640 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1644 void CCommitDlg::OnStnClickedBugidlabel()
1646 // TODO: Add your control notification handler code here