Fixed issue #507: Help Spell error and push wrongly link to sync
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blobd1a1839e12fbc5accae989bf760c552b19f4843d
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"
38 #include "PatchViewDlg.h"
39 #include "COMError.h"
40 #include "Globals.h"
42 #ifdef _DEBUG
43 #define new DEBUG_NEW
44 #undef THIS_FILE
45 static char THIS_FILE[] = __FILE__;
46 #endif
48 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));
50 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)
51 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)
52 : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)
53 , m_bRecursive(FALSE)
54 , m_bShowUnversioned(FALSE)
55 , m_bBlock(FALSE)
56 , m_bThreadRunning(FALSE)
57 , m_bRunThread(FALSE)
58 , m_pThread(NULL)
59 , m_bWholeProject(FALSE)
60 , m_bKeepChangeList(TRUE)
61 , m_itemsCount(0)
62 , m_bSelectFilesForCommit(TRUE)
64 this->m_bCommitAmend=FALSE;
65 m_bPushAfterCommit = FALSE;
68 CCommitDlg::~CCommitDlg()
70 if(m_pThread != NULL)
72 delete m_pThread;
76 void CCommitDlg::DoDataExchange(CDataExchange* pDX)
78 CResizableStandAloneDialog::DoDataExchange(pDX);
79 DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);
80 DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);
81 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
82 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
83 DDX_Text(pDX, IDC_BUGID, m_sBugID);
84 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
85 DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);
86 DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);
87 DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);
88 DDX_Control(pDX,IDC_VIEW_PATCH,m_ctrlShowPatch);
91 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
92 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
93 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
94 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
95 ON_NOTIFY(SCN_UPDATEUI, IDC_LOGMESSAGE, OnScnUpdateUI)
96 // ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)
97 ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)
98 ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)
99 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)
100 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)
101 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
102 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)
103 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCHANGED, &CCommitDlg::OnGitStatusListCtrlItemChanged)
105 ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady)
106 ON_WM_TIMER()
107 ON_WM_SIZE()
108 ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)
109 ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)
110 ON_STN_CLICKED(IDC_COMMITLABEL, &CCommitDlg::OnStnClickedCommitlabel)
111 ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)
112 ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)
113 ON_STN_CLICKED(IDC_BUGIDLABEL, &CCommitDlg::OnStnClickedBugidlabel)
114 ON_COMMAND(ID_FOCUS_MESSAGE,&CCommitDlg::OnFocusMessage)
115 ON_STN_CLICKED(IDC_VIEW_PATCH, &CCommitDlg::OnStnClickedViewPatch)
116 ON_WM_MOVE()
117 ON_WM_MOVING()
118 ON_WM_SIZING()
119 ON_NOTIFY(HDN_ITEMCHANGED, 0, &CCommitDlg::OnHdnItemchangedFilelist)
120 END_MESSAGE_MAP()
122 BOOL CCommitDlg::OnInitDialog()
124 CResizableStandAloneDialog::OnInitDialog();
126 CAppUtils::GetCommitTemplate(this->m_sLogMessage);
128 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG")))
130 CStdioFile file;
131 if(file.Open(g_Git.m_CurrentDir+_T("\\.git\\MERGE_MSG"), CFile::modeRead))
133 CString str;
134 while(file.ReadString(str))
136 m_sLogMessage += str;
137 str.Empty();
138 m_sLogMessage += _T("\n");
142 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
143 m_bShowUnversioned = m_regAddBeforeCommit;
145 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
147 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
148 m_bKeepChangeList = m_regKeepChangelists;
150 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
152 // GitConfig config;
153 // m_bWholeProject = config.KeepLocks();
155 if(this->m_pathList.GetCount() == 0)
156 m_bWholeProject =true;
158 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
159 m_bWholeProject =true;
161 UpdateData(FALSE);
163 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"));
164 m_ListCtrl.SetSelectButton(&m_SelectAll);
165 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
166 m_ListCtrl.SetCancelBool(&m_bCancelled);
167 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
168 m_ListCtrl.EnableFileDrop();
169 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
171 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
172 m_ProjectProperties.ReadPropsPathList(m_pathList);
174 m_cLogMessage.Init(m_ProjectProperties);
175 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
176 m_cLogMessage.RegisterContextMenuHandler(this);
178 OnEnChangeLogmessage();
180 m_tooltips.Create(this);
181 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
182 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
183 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
185 m_SelectAll.SetCheck(BST_INDETERMINATE);
188 CBugTraqAssociations bugtraq_associations;
189 bugtraq_associations.Load();
191 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
193 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
194 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
196 CComPtr<IBugTraqProvider> pProvider;
197 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
198 if (SUCCEEDED(hr))
200 m_BugTraqProvider = pProvider;
201 BSTR temp = NULL;
202 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
204 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
205 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
206 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
209 SysFreeString(temp);
212 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
214 else if (!m_ProjectProperties.sMessage.IsEmpty())
216 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
217 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
218 if (!m_ProjectProperties.sLabel.IsEmpty())
219 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
220 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
221 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
222 GetDlgItem(IDC_BUGID)->SetFocus();
223 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
224 if (!sBugID.IsEmpty())
226 SetDlgItemText(IDC_BUGID, sBugID);
229 else
231 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
232 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
233 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
234 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
235 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
238 if (!m_sLogMessage.IsEmpty())
239 m_cLogMessage.SetText(m_sLogMessage);
241 GetWindowText(m_sWindowTitle);
243 AdjustControlSize(IDC_SHOWUNVERSIONED);
244 AdjustControlSize(IDC_SELECTALL);
245 AdjustControlSize(IDC_WHOLE_PROJECT);
247 GetClientRect(m_DlgOrigRect);
248 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
250 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
251 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
252 AddAnchor(IDC_BUGID, TOP_RIGHT);
253 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
254 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
255 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
256 // AddAnchor(IDC_HISTORY, TOP_LEFT);
257 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
258 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
259 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
260 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
261 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
262 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
263 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
264 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
265 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
266 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
267 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
268 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
269 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
270 AddAnchor(IDOK, BOTTOM_RIGHT);
271 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
272 AddAnchor(IDHELP, BOTTOM_RIGHT);
273 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
275 if (hWndExplorer)
276 CenterWindow(CWnd::FromHandle(hWndExplorer));
277 EnableSaveRestore(_T("CommitDlg"));
278 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
279 RECT rcDlg, rcLogMsg, rcFileList;
280 GetClientRect(&rcDlg);
281 m_cLogMessage.GetWindowRect(&rcLogMsg);
282 ScreenToClient(&rcLogMsg);
283 m_ListCtrl.GetWindowRect(&rcFileList);
284 ScreenToClient(&rcFileList);
285 if (yPos)
287 RECT rectSplitter;
288 m_wndSplitter.GetWindowRect(&rectSplitter);
289 ScreenToClient(&rectSplitter);
290 int delta = yPos - rectSplitter.top;
291 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
293 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
294 DoSize(delta);
298 // add all directories to the watcher
299 for (int i=0; i<m_pathList.GetCount(); ++i)
301 if (m_pathList[i].IsDirectory())
302 m_pathwatcher.AddPath(m_pathList[i]);
305 m_updatedPathList = m_pathList;
307 //first start a thread to obtain the file list with the status without
308 //blocking the dialog
309 InterlockedExchange(&m_bBlock, TRUE);
310 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
311 if (m_pThread==NULL)
313 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
314 InterlockedExchange(&m_bBlock, FALSE);
316 else
318 m_pThread->m_bAutoDelete = FALSE;
319 m_pThread->ResumeThread();
321 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
322 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
323 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
325 historyhint = TRUE;
326 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
328 err = FALSE;
330 //this->UpdateData(TRUE);
331 //this->m_bCommitAmend=FALSE;
332 //this->UpdateData(FALSE);
334 this->m_ctrlShowPatch.SetURL(CString());
336 return FALSE; // return TRUE unless you set the focus to a control
337 // EXCEPTION: OCX Property Pages should return FALSE
340 void CCommitDlg::OnOK()
342 if (m_bBlock)
343 return;
344 if (m_bThreadRunning)
346 m_bCancelled = true;
347 InterlockedExchange(&m_bRunThread, FALSE);
348 WaitForSingleObject(m_pThread->m_hThread, 1000);
349 if (m_bThreadRunning)
351 // we gave the thread a chance to quit. Since the thread didn't
352 // listen to us we have to kill it.
353 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
354 InterlockedExchange(&m_bThreadRunning, FALSE);
357 this->UpdateData();
359 CString id;
360 GetDlgItemText(IDC_BUGID, id);
361 if (!m_ProjectProperties.CheckBugID(id))
363 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
364 return;
366 m_sLogMessage = m_cLogMessage.GetText();
367 if ( m_sLogMessage.IsEmpty() )
369 // no message entered, go round again
370 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
371 return;
373 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
375 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
376 return;
379 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
380 #if 0
381 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
382 if (!(DWORD)regUnversionedRecurse)
384 // Find unversioned directories which are marked for commit. The user might expect them
385 // to be added recursively since he cannot the the files. Let's ask the user if he knows
386 // what he is doing.
387 int nListItems = m_ListCtrl.GetItemCount();
388 for (int j=0; j<nListItems; j++)
390 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
391 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
393 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
394 return;
398 #endif
399 m_pathwatcher.Stop();
400 InterlockedExchange(&m_bBlock, TRUE);
401 CDWordArray arDeleted;
402 //first add all the unversioned files the user selected
403 //and check if all versioned files are selected
404 int nchecked = 0;
405 m_bRecursive = true;
406 int nListItems = m_ListCtrl.GetItemCount();
408 CTGitPathList itemsToAdd;
409 CTGitPathList itemsToRemove;
410 //std::set<CString> checkedLists;
411 //std::set<CString> uncheckedLists;
413 // now let the bugtraq plugin check the commit message
414 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
415 if (m_BugTraqProvider)
417 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
418 if (SUCCEEDED(hr))
420 BSTR temp = NULL;
421 CString common = g_Git.m_CurrentDir;
422 BSTR repositoryRoot = common.AllocSysString();
423 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
424 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
425 BSTR commitMessage = m_sLogMessage.AllocSysString();
426 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
428 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
429 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
431 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
433 COMError ce(hr);
434 CString sErr;
435 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
436 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseSVN"), MB_ICONERROR);
438 else
440 CString sError = temp;
441 if (!sError.IsEmpty())
443 CMessageBox::Show(m_hWnd, sError, _T("TortoiseSVN"), MB_ICONERROR);
444 return;
446 SysFreeString(temp);
451 //CString checkedfiles;
452 //CString uncheckedfiles;
454 CString cmd;
455 CString out;
457 bool bAddSuccess=true;
458 bool bCloseCommitDlg=false;
460 for (int j=0; j<nListItems; j++)
462 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
463 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
464 if (entry->m_Checked)
466 #if 0
467 if (entry->status == Git_wc_status_unversioned)
469 itemsToAdd.AddPath(entry->GetPath());
471 if (entry->status == Git_wc_status_conflicted)
473 bHasConflicted = true;
475 if (entry->status == Git_wc_status_missing)
477 itemsToRemove.AddPath(entry->GetPath());
479 if (entry->status == Git_wc_status_deleted)
481 arDeleted.Add(j);
483 if (entry->IsInExternal())
485 bCheckedInExternal = true;
487 #endif
488 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
489 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
490 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
491 cmd.Format(_T("git.exe update-index --force-remove -- \"%s\""),entry->GetGitPathString());
492 else
493 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
495 if(g_Git.Run(cmd,&out,CP_ACP))
497 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
498 bAddSuccess = false ;
499 break;
502 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
503 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
505 g_Git.Run(cmd,&out,CP_ACP);
507 nchecked++;
509 //checkedLists.insert(entry->GetGitPathString());
510 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
512 else
514 //uncheckedLists.insert(entry->GetGitPathString());
515 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
516 { //To init git repository, there are not HEAD, so we can use git reset command
517 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
518 if(g_Git.Run(cmd,&out,CP_ACP))
520 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
521 bAddSuccess = false ;
522 bCloseCommitDlg=false;
523 break;
527 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
529 cmd.Format(_T("git.exe reset -- \"%s\""),entry->GetGitPathString());
530 if(g_Git.Run(cmd,&out,CP_ACP))
532 /* when reset a unstage file will report error.
533 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
534 bAddSuccess = false ;
535 bCloseCommitDlg=false;
536 break;
541 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
542 #if 0
543 if ((entry->status != Git_wc_status_unversioned) &&
544 (entry->status != Git_wc_status_ignored))
546 nUnchecked++;
547 uncheckedLists.insert(entry->GetChangeList());
548 if (m_bRecursive)
550 // This algorithm is for the sake of simplicity of the complexity O(N?
551 for (int k=0; k<nListItems; k++)
553 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
554 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
556 // Fall back to a non-recursive commit to prevent items being
557 // committed which aren't checked although its parent is checked
558 // (property change, directory deletion, ... )
559 m_bRecursive = false;
560 break;
565 #endif
568 CShellUpdater::Instance().AddPathForUpdate(*entry);
571 //if(uncheckedfiles.GetLength()>0)
573 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
574 // g_Git.Run(cmd,&out);
577 m_sBugID.Trim();
578 if (!m_sBugID.IsEmpty())
580 m_sBugID.Replace(_T(", "), _T(","));
581 m_sBugID.Replace(_T(" ,"), _T(","));
582 CString sBugID = m_ProjectProperties.sMessage;
583 sBugID.Replace(_T("%BUGID%"), m_sBugID);
584 if (m_ProjectProperties.bAppend)
585 m_sLogMessage += _T("\n") + sBugID + _T("\n");
586 else
587 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
590 BOOL bIsMerge=false;
591 if(PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
593 bIsMerge=true;
595 //if(checkedfiles.GetLength()>0)
596 if( bAddSuccess && (nchecked||m_bCommitAmend||bIsMerge) )
598 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
599 // g_Git.Run(cmd,&out);
601 bCloseCommitDlg = true;
603 CString tempfile=::GetTempFile();
605 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
606 //file.WriteString(m_sLogMessage);
608 CTGitPath path=g_Git.m_CurrentDir;
610 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
612 out =_T("");
613 CString amend;
614 if(this->m_bCommitAmend)
616 amend=_T("--amend");
618 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
620 CCommitProgressDlg progress;
621 progress.m_bBufferAll=true; // improve show speed when there are many file added.
622 progress.m_GitCmd=cmd;
623 progress.m_bShowCommand = FALSE; // don't show the commit command
624 progress.m_PreText = out; // show any output already generated in log window
626 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
628 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
630 DWORD userResponse = progress.DoModal();
632 if(progress.m_GitStatus)
634 bCloseCommitDlg = false;
635 this->Refresh();
637 else if(userResponse == IDC_PROGRESS_BUTTON1)
639 //User pressed 'Push' button after successful commit.
640 m_bPushAfterCommit=true;
643 CFile::Remove(tempfile);
645 if (m_BugTraqProvider && progress.m_GitStatus == 0)
647 CComPtr<IBugTraqProvider2> pProvider = NULL;
648 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
649 if (SUCCEEDED(hr))
651 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
652 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
654 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
655 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
657 BSTR logMessage = m_sLogMessage.AllocSysString();
659 CString hash=g_Git.GetHash(CString(_T("HEAD")));
660 LONG version = g_Git.Hash2int(hash);
662 BSTR temp = NULL;
663 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
664 commonRoot,
665 pathList,
666 logMessage,
667 (LONG)version,
668 &temp)))
670 CString sErr = temp;
671 if (!sErr.IsEmpty())
672 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
673 else
675 COMError ce(hr);
676 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
677 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
681 SysFreeString(temp);
685 }else if(bAddSuccess)
687 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
688 bCloseCommitDlg=false;
690 #if 0
691 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
693 // There are paths which got changed (touched at least).
694 // We have to find out if this affects the selection in the commit dialog
695 // If it could affect the selection, revert back to a non-recursive commit
696 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
697 changedList.RemoveDuplicates();
698 for (int i=0; i<changedList.GetCount(); ++i)
700 if (changedList[i].IsAdminDir())
702 // something inside an admin dir was changed.
703 // if it's the entries file, then we have to fully refresh because
704 // files may have been added/removed from version control
705 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
706 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
708 m_bRecursive = false;
709 break;
712 else if (!m_ListCtrl.IsPathShown(changedList[i]))
714 // a path which is not shown in the list has changed
715 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
716 if (entry)
718 // check if the changed path would get committed by a recursive commit
719 if ((!entry->IsFromDifferentRepository()) &&
720 (!entry->IsInExternal()) &&
721 (!entry->IsNested()) &&
722 (!entry->IsChecked()))
724 m_bRecursive = false;
725 break;
733 // Now, do all the adds - make sure that the list is sorted so that parents
734 // are added before their children
735 itemsToAdd.SortByPathname();
736 Git Git;
737 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
739 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
740 InterlockedExchange(&m_bBlock, FALSE);
741 Refresh();
742 return;
745 // Remove any missing items
746 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
747 itemsToRemove.SortByPathname();
748 Git.Remove(itemsToRemove, TRUE);
750 //the next step: find all deleted files and check if they're
751 //inside a deleted folder. If that's the case, then remove those
752 //files from the list since they'll get deleted by the parent
753 //folder automatically.
754 m_ListCtrl.Block(TRUE, FALSE);
755 INT_PTR nDeleted = arDeleted.GetCount();
756 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
758 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
760 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
761 if (path.IsDirectory())
763 //now find all children of this directory
764 for (int j=0; j<arDeleted.GetCount(); j++)
766 if (i!=j)
768 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
769 if (childEntry->IsChecked())
771 if (path.IsAncestorOf(childEntry->GetPath()))
773 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
774 nDeleted--;
782 m_ListCtrl.Block(FALSE, FALSE);
784 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
786 //save only the files the user has checked into the temporary file
787 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
790 // the item count is used in the progress dialog to show the overall commit
791 // progress.
792 // deleted items only send one notification event, all others send two
793 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
795 if ((m_bRecursive)&&(checkedLists.size() == 1))
797 // all checked items belong to the same changelist
798 // find out if there are any unchecked items which belong to that changelist
799 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
800 m_sChangeList = *checkedLists.begin();
802 #endif
803 UpdateData();
804 m_regAddBeforeCommit = m_bShowUnversioned;
805 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
806 m_bWholeProject = FALSE;
807 m_regKeepChangelists = m_bKeepChangeList;
808 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
809 m_bKeepChangeList = FALSE;
810 InterlockedExchange(&m_bBlock, FALSE);
812 m_History.AddEntry(m_sLogMessage);
813 m_History.Save();
815 SaveSplitterPos();
817 if( bCloseCommitDlg )
818 CResizableStandAloneDialog::OnOK();
820 CShellUpdater::Instance().Flush();
823 void CCommitDlg::SaveSplitterPos()
825 if (!IsIconic())
827 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
828 RECT rectSplitter;
829 m_wndSplitter.GetWindowRect(&rectSplitter);
830 ScreenToClient(&rectSplitter);
831 regPos = rectSplitter.top;
835 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
837 return ((CCommitDlg*)pVoid)->StatusThread();
840 UINT CCommitDlg::StatusThread()
842 //get the status of all selected file/folders recursively
843 //and show the ones which have to be committed to the user
844 //in a list control.
845 InterlockedExchange(&m_bBlock, TRUE);
846 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
847 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
849 g_Git.RefreshGitIndex();
851 m_bCancelled = false;
853 DialogEnableWindow(IDOK, false);
854 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
855 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
856 DialogEnableWindow(IDC_SELECTALL, false);
857 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
858 DialogEnableWindow(IDC_EXTERNALWARNING, false);
859 // read the list of recent log entries before querying the WC for status
860 // -> the user may select one and modify / update it while we are crawling the WC
862 if (m_History.GetCount()==0)
864 CString reg;
865 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
866 reg.Replace(_T(':'),_T('_'));
867 m_History.Load(reg, _T("logmsgs"));
870 // Initialise the list control with the status of the files/folders below us
871 m_ListCtrl.Clear();
872 BOOL success;
873 if(m_bWholeProject)
874 success=m_ListCtrl.GetStatus(NULL);
875 else
876 success=m_ListCtrl.GetStatus(&m_pathList);
878 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
879 if(this->m_bShowUnversioned)
880 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,&m_pathList);
882 m_ListCtrl.CheckIfChangelistsArePresent(false);
884 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
885 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
886 if (success)
888 if (m_checkedPathList.GetCount())
889 m_ListCtrl.Show(dwShow, m_checkedPathList);
890 else
892 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
893 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
894 m_ListCtrl.Show(dwShow, dwCheck);
895 m_bSelectFilesForCommit = true;
898 if (m_ListCtrl.HasExternalsFromDifferentRepos())
900 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
901 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
904 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
905 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
907 CString logmsg;
908 GetDlgItemText(IDC_LOGMESSAGE, logmsg);
909 DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);
910 if (!success)
912 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
913 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
914 m_ListCtrl.Show(dwShow);
916 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems())
917 && !PathFileExists(g_Git.m_CurrentDir+_T("\\.git\\MERGE_HEAD")))
919 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
921 m_bShowUnversioned = TRUE;
922 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
923 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
924 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
925 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
929 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
931 if(this->m_bWholeProject)
932 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T("(Whole Project)")));
933 else
934 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
936 m_autolist.clear();
937 // we don't have to block the commit dialog while we fetch the
938 // auto completion list.
939 m_pathwatcher.ClearChangedPaths();
940 InterlockedExchange(&m_bBlock, FALSE);
941 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
943 m_ListCtrl.Block(TRUE, TRUE);
944 GetAutocompletionList();
945 m_ListCtrl.Block(FALSE, FALSE);
947 if (m_bRunThread)
949 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
950 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
951 DialogEnableWindow(IDC_SELECTALL, true);
952 if (m_ListCtrl.HasChangeLists())
953 DialogEnableWindow(IDC_KEEPLISTS, true);
954 if (m_ListCtrl.HasLocks())
955 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
956 // we have the list, now signal the main thread about it
957 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
960 InterlockedExchange(&m_bRunThread, FALSE);
961 InterlockedExchange(&m_bThreadRunning, FALSE);
962 // force the cursor to normal
963 RefreshCursor();
965 return 0;
968 void CCommitDlg::OnCancel()
970 m_bCancelled = true;
971 m_pathwatcher.Stop();
973 if (m_bBlock)
974 return;
976 if (m_bThreadRunning)
978 InterlockedExchange(&m_bRunThread, FALSE);
979 WaitForSingleObject(m_pThread->m_hThread, 1000);
980 if (m_bThreadRunning)
982 // we gave the thread a chance to quit. Since the thread didn't
983 // listen to us we have to kill it.
984 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
985 InterlockedExchange(&m_bThreadRunning, FALSE);
988 UpdateData();
989 m_sBugID.Trim();
990 m_sLogMessage = m_cLogMessage.GetText();
991 if (!m_sBugID.IsEmpty())
993 m_sBugID.Replace(_T(", "), _T(","));
994 m_sBugID.Replace(_T(" ,"), _T(","));
995 CString sBugID = m_ProjectProperties.sMessage;
996 sBugID.Replace(_T("%BUGID%"), m_sBugID);
997 if (m_ProjectProperties.bAppend)
998 m_sLogMessage += _T("\n") + sBugID + _T("\n");
999 else
1000 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
1002 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
1003 m_History.AddEntry(m_sLogMessage);
1004 m_History.Save();
1005 SaveSplitterPos();
1006 CResizableStandAloneDialog::OnCancel();
1009 void CCommitDlg::OnBnClickedSelectall()
1011 m_tooltips.Pop(); // hide the tooltips
1012 UINT state = (m_SelectAll.GetState() & 0x0003);
1013 if (state == BST_INDETERMINATE)
1015 // It is not at all useful to manually place the checkbox into the indeterminate state...
1016 // We will force this on to the unchecked state
1017 state = BST_UNCHECKED;
1018 m_SelectAll.SetCheck(state);
1020 m_ListCtrl.SelectAll(state == BST_CHECKED);
1023 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1025 if (!m_bBlock)
1026 m_tooltips.RelayEvent(pMsg);
1028 if (m_hAccel)
1030 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1031 if (ret)
1032 return TRUE;
1035 if (pMsg->message == WM_KEYDOWN)
1037 switch (pMsg->wParam)
1039 case VK_F5:
1041 if (m_bBlock)
1042 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1043 Refresh();
1045 break;
1046 case VK_RETURN:
1048 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1050 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1052 PostMessage(WM_COMMAND, IDOK);
1054 return TRUE;
1056 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1058 // Pressing RETURN in the bug id control
1059 // moves the focus to the message
1060 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1061 return TRUE;
1064 break;
1068 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1071 void CCommitDlg::Refresh()
1073 if (m_bThreadRunning)
1074 return;
1076 InterlockedExchange(&m_bBlock, TRUE);
1077 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1078 if (m_pThread==NULL)
1080 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1081 InterlockedExchange(&m_bBlock, FALSE);
1083 else
1085 m_pThread->m_bAutoDelete = FALSE;
1086 m_pThread->ResumeThread();
1090 void CCommitDlg::OnBnClickedHelp()
1092 OnHelp();
1095 void CCommitDlg::OnBnClickedShowunversioned()
1097 m_tooltips.Pop(); // hide the tooltips
1098 UpdateData();
1099 m_regAddBeforeCommit = m_bShowUnversioned;
1100 if (!m_bBlock)
1102 DWORD dwShow = m_ListCtrl.GetShowFlags();
1103 if (DWORD(m_regAddBeforeCommit))
1104 dwShow |= SVNSLC_SHOWUNVERSIONED;
1105 else
1106 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1107 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1109 if(m_bWholeProject)
1110 m_ListCtrl.GetStatus(NULL,false,false,true);
1111 else
1112 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1114 m_ListCtrl.Show(dwShow,0,true,0,true);
1118 void CCommitDlg::OnStnClickedExternalwarning()
1120 m_tooltips.Popup();
1123 void CCommitDlg::OnEnChangeLogmessage()
1125 UpdateOKButton();
1128 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1130 #if 0
1131 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1133 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1135 m_bShowUnversioned = TRUE;
1136 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1137 m_ListCtrl.Show(dwShow);
1138 UpdateData(FALSE);
1141 #endif
1142 return 0;
1145 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1147 Refresh();
1148 return 0;
1151 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1153 #if 0
1154 BringWindowToTop();
1155 SetForegroundWindow();
1156 SetActiveWindow();
1157 // if multiple files/folders are dropped
1158 // this handler is called for every single item
1159 // separately.
1160 // To avoid creating multiple refresh threads and
1161 // causing crashes, we only add the items to the
1162 // list control and start a timer.
1163 // When the timer expires, we start the refresh thread,
1164 // but only if it isn't already running - otherwise we
1165 // restart the timer.
1166 CTGitPath path;
1167 path.SetFromWin((LPCTSTR)lParam);
1169 // just add all the items we get here.
1170 // if the item is versioned, the add will fail but nothing
1171 // more will happen.
1172 Git Git;
1173 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1175 if (!m_ListCtrl.HasPath(path))
1177 if (m_pathList.AreAllPathsFiles())
1179 m_pathList.AddPath(path);
1180 m_pathList.RemoveDuplicates();
1181 m_updatedPathList.AddPath(path);
1182 m_updatedPathList.RemoveDuplicates();
1184 else
1186 // if the path list contains folders, we have to check whether
1187 // our just (maybe) added path is a child of one of those. If it is
1188 // a child of a folder already in the list, we must not add it. Otherwise
1189 // that path could show up twice in the list.
1190 bool bHasParentInList = false;
1191 for (int i=0; i<m_pathList.GetCount(); ++i)
1193 if (m_pathList[i].IsAncestorOf(path))
1195 bHasParentInList = true;
1196 break;
1199 if (!bHasParentInList)
1201 m_pathList.AddPath(path);
1202 m_pathList.RemoveDuplicates();
1203 m_updatedPathList.AddPath(path);
1204 m_updatedPathList.RemoveDuplicates();
1209 // Always start the timer, since the status of an existing item might have changed
1210 SetTimer(REFRESHTIMER, 200, NULL);
1211 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1212 #endif
1213 return 0;
1216 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1218 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1219 return 0;
1222 //////////////////////////////////////////////////////////////////////////
1223 // functions which run in the status thread
1224 //////////////////////////////////////////////////////////////////////////
1226 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1228 CString strLine;
1231 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1232 while (m_bRunThread && file.ReadString(strLine))
1234 int eqpos = strLine.Find('=');
1235 CString rgx;
1236 rgx = strLine.Mid(eqpos+1).Trim();
1238 int pos = -1;
1239 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1241 mapRegex[strLine.Left(pos)] = rgx;
1242 strLine = strLine.Mid(pos+1).Trim();
1244 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1246 file.Close();
1248 catch (CFileException* pE)
1250 TRACE("CFileException loading auto list regex file\n");
1251 pE->Delete();
1252 return;
1255 void CCommitDlg::GetAutocompletionList()
1257 // the auto completion list is made of strings from each selected files.
1258 // the strings used are extracted from the files with regexes found
1259 // in the file "autolist.txt".
1260 // the format of that file is:
1261 // file extensions separated with commas '=' regular expression to use
1262 // example:
1263 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1264 // .cpp = (?<=[^\s]::)\b\w+\b
1266 std::map<CString, CString> mapRegex;
1267 CString sRegexFile = CPathUtils::GetAppDirectory();
1268 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1269 DWORD timeoutvalue = regtimeout*1000;
1270 sRegexFile += _T("autolist.txt");
1271 if (!m_bRunThread)
1272 return;
1273 ParseRegexFile(sRegexFile, mapRegex);
1274 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1275 sRegexFile.ReleaseBuffer();
1276 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1277 if (PathFileExists(sRegexFile))
1279 ParseRegexFile(sRegexFile, mapRegex);
1281 DWORD starttime = GetTickCount();
1283 // now we have two arrays of strings, where the first array contains all
1284 // file extensions we can use and the second the corresponding regex strings
1285 // to apply to those files.
1287 // the next step is to go over all files shown in the commit dialog
1288 // and scan them for strings we can use
1289 int nListItems = m_ListCtrl.GetItemCount();
1291 for (int i=0; i<nListItems && m_bRunThread; ++i)
1293 // stop parsing after timeout
1294 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1295 return;
1297 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1299 if(path == NULL)
1300 continue;
1302 CString sPartPath =path->GetGitPathString();
1303 m_autolist.insert(sPartPath);
1305 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1306 // if (!entry)
1307 // continue;
1309 // add the path parts to the auto completion list too
1310 // CString sPartPath = entry->GetRelativeGitPath();
1311 // m_autolist.insert(sPartPath);
1314 int pos = 0;
1315 int lastPos = 0;
1316 while ((pos = sPartPath.Find('/', pos)) >= 0)
1318 pos++;
1319 lastPos = pos;
1320 m_autolist.insert(sPartPath.Mid(pos));
1323 // Last inserted entry is a file name.
1324 // Some users prefer to also list file name without extension.
1325 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1327 int dotPos = sPartPath.ReverseFind('.');
1328 if ((dotPos >= 0) && (dotPos > lastPos))
1329 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1331 #if 0
1332 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1333 continue;
1335 CString sExt = entry->GetPath().GetFileExtension();
1336 sExt.MakeLower();
1337 // find the regex string which corresponds to the file extension
1338 CString rdata = mapRegex[sExt];
1339 if (rdata.IsEmpty())
1340 continue;
1342 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1343 if ((entry->textstatus != Git_wc_status_unversioned) &&
1344 (entry->textstatus != Git_wc_status_none) &&
1345 (entry->textstatus != Git_wc_status_ignored) &&
1346 (entry->textstatus != Git_wc_status_added) &&
1347 (entry->textstatus != Git_wc_status_normal))
1349 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1350 if (!basePath.IsEmpty())
1351 ScanFile(basePath.GetWinPathString(), rdata);
1353 #endif
1355 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1358 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1360 wstring sFileContent;
1361 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1362 if (hFile != INVALID_HANDLE_VALUE)
1364 DWORD size = GetFileSize(hFile, NULL);
1365 if (size > 1000000L)
1367 // no files bigger than 1 Meg
1368 CloseHandle(hFile);
1369 return;
1371 // allocate memory to hold file contents
1372 char * buffer = new char[size];
1373 DWORD readbytes;
1374 ReadFile(hFile, buffer, size, &readbytes, NULL);
1375 CloseHandle(hFile);
1376 int opts = 0;
1377 IsTextUnicode(buffer, readbytes, &opts);
1378 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1380 delete [] buffer;
1381 return;
1383 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1385 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1387 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1389 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1390 wchar_t * pWideBuf = new wchar_t[ret];
1391 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1392 if (ret2 == ret)
1393 sFileContent = wstring(pWideBuf, ret);
1394 delete [] pWideBuf;
1396 delete [] buffer;
1398 if (sFileContent.empty()|| !m_bRunThread)
1400 return;
1405 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1406 const tr1::wsregex_iterator end;
1407 wstring s = sFileContent;
1408 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1410 const tr1::wsmatch match = *it;
1411 for (size_t i=1; i<match.size(); ++i)
1413 if (match[i].second-match[i].first)
1415 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1416 m_autolist.insert(wstring(match[i]).c_str());
1421 catch (exception) {}
1424 // CSciEditContextMenuInterface
1425 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1427 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1428 m_nPopupPasteListCmd = nCmd++;
1429 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1431 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1432 if(m_History.GetCount() > 0)
1434 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1435 m_nPopupPasteLastMessage = nCmd++;
1436 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1438 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1439 m_nPopupRecentMessage = nCmd++;
1440 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1446 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1449 if (m_bBlock)
1450 return false;
1451 if (cmd == m_nPopupPasteListCmd)
1453 CString logmsg;
1454 TCHAR buf[MAX_STATUS_STRING_LENGTH];
1455 int nListItems = m_ListCtrl.GetItemCount();
1456 for (int i=0; i<nListItems; ++i)
1458 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1459 if (entry&&entry->m_Checked)
1461 CString line;
1462 CString status = entry->GetActionName();
1463 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1464 status = _T("Add");
1466 //git_wc_status_kind status = entry->status;
1467 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1468 if (m_ProjectProperties.bFileListInEnglish)
1469 langID = 1033;
1471 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1472 logmsg += line;
1475 pSciEdit->InsertText(logmsg);
1476 return true;
1479 if(cmd == m_nPopupPasteLastMessage)
1481 if(m_History.GetCount() ==0 )
1482 return false;
1484 CString logmsg;
1485 logmsg +=m_History.GetEntry(0);
1486 pSciEdit->InsertText(logmsg);
1487 return true;
1490 if(cmd == m_nPopupRecentMessage )
1492 OnBnClickedHistory();
1493 return true;
1495 return false;
1498 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1500 switch (nIDEvent)
1502 case ENDDIALOGTIMER:
1503 KillTimer(ENDDIALOGTIMER);
1504 EndDialog(0);
1505 break;
1506 case REFRESHTIMER:
1507 if (m_bThreadRunning)
1509 SetTimer(REFRESHTIMER, 200, NULL);
1510 ATLTRACE("Wait some more before refreshing\n");
1512 else
1514 KillTimer(REFRESHTIMER);
1515 ATLTRACE("Refreshing after items dropped\n");
1516 Refresh();
1518 break;
1520 __super::OnTimer(nIDEvent);
1523 void CCommitDlg::OnBnClickedHistory()
1525 m_tooltips.Pop(); // hide the tooltips
1526 if (m_pathList.GetCount() == 0)
1527 return;
1529 CHistoryDlg historyDlg;
1530 historyDlg.SetHistory(m_History);
1531 if (historyDlg.DoModal() != IDOK)
1532 return;
1534 CString sMsg = historyDlg.GetSelectedText();
1535 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1537 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1538 if (!sBugID.IsEmpty())
1540 SetDlgItemText(IDC_BUGID, sBugID);
1542 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1543 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1544 else
1545 m_cLogMessage.SetText(sMsg);
1548 UpdateOKButton();
1549 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1553 void CCommitDlg::OnBnClickedBugtraqbutton()
1555 m_tooltips.Pop(); // hide the tooltips
1556 CString sMsg = m_cLogMessage.GetText();
1558 if (m_BugTraqProvider == NULL)
1559 return;
1561 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1562 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1563 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1565 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1566 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1568 BSTR originalMessage = sMsg.AllocSysString();
1569 BSTR temp = NULL;
1570 // m_revProps.clear();
1572 // first try the IBugTraqProvider2 interface
1573 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1574 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1575 if (SUCCEEDED(hr))
1577 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1578 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1579 BSTR bugIDOut = NULL;
1580 GetDlgItemText(IDC_BUGID, m_sBugID);
1581 BSTR bugID = m_sBugID.AllocSysString();
1582 SAFEARRAY * revPropNames = NULL;
1583 SAFEARRAY * revPropValues = NULL;
1584 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1586 CString sErr;
1587 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1588 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1590 else
1592 if (bugIDOut)
1594 m_sBugID = bugIDOut;
1595 SysFreeString(bugIDOut);
1596 SetDlgItemText(IDC_BUGID, m_sBugID);
1598 SysFreeString(bugID);
1599 SysFreeString(repositoryRoot);
1600 m_cLogMessage.SetText(temp);
1601 BSTR HUGEP *pbRevNames;
1602 BSTR HUGEP *pbRevValues;
1604 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1605 if (SUCCEEDED(hr1))
1607 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1608 if (SUCCEEDED(hr2))
1610 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1612 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1614 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1617 SafeArrayUnaccessData(revPropValues);
1619 SafeArrayUnaccessData(revPropNames);
1621 if (revPropNames)
1622 SafeArrayDestroy(revPropNames);
1623 if (revPropValues)
1624 SafeArrayDestroy(revPropValues);
1627 else
1629 // if IBugTraqProvider2 failed, try IBugTraqProvider
1630 CComPtr<IBugTraqProvider> pProvider = NULL;
1631 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1632 if (FAILED(hr))
1634 CString sErr;
1635 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1636 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1637 return;
1640 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1642 CString sErr;
1643 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1644 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1646 else
1647 m_cLogMessage.SetText(temp);
1649 m_sLogMessage = m_cLogMessage.GetText();
1650 if (!m_ProjectProperties.sMessage.IsEmpty())
1652 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1653 if (!sBugID.IsEmpty())
1655 SetDlgItemText(IDC_BUGID, sBugID);
1659 m_cLogMessage.SetFocus();
1661 SysFreeString(parameters);
1662 SysFreeString(commonRoot);
1663 SafeArrayDestroy(pathList);
1664 SysFreeString(originalMessage);
1665 SysFreeString(temp);
1669 void CCommitDlg::FillPatchView()
1671 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1673 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1675 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1676 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1677 CString cmd,out;
1679 while(pos)
1681 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1682 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1683 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1685 cmd.Format(_T("git.exe diff -- \"%s\""),p->GetGitPathString());
1686 g_Git.Run(cmd,&out,CP_ACP);
1692 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1693 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1694 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1699 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM wparam, LPARAM lparam)
1701 TRACE("OnGitStatusListCtrlItemChanged %d\r\n", wparam);
1702 this->FillPatchView();
1703 return 0;
1707 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1709 UpdateOKButton();
1710 return 0;
1713 void CCommitDlg::UpdateOKButton()
1715 #if 0
1716 BOOL bValidLogSize = FALSE;
1718 if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)
1719 bValidLogSize = !m_bBlock;
1721 LONG nSelectedItems = m_ListCtrl.GetSelected();
1722 DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);
1723 #endif
1727 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1729 switch (message) {
1730 case WM_NOTIFY:
1731 if (wParam == IDC_SPLITTER)
1733 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1734 DoSize(pHdr->delta);
1736 break;
1739 return __super::DefWindowProc(message, wParam, lParam);
1742 void CCommitDlg::SetSplitterRange()
1744 if ((m_ListCtrl)&&(m_cLogMessage))
1746 CRect rcTop;
1747 m_cLogMessage.GetWindowRect(rcTop);
1748 ScreenToClient(rcTop);
1749 CRect rcMiddle;
1750 m_ListCtrl.GetWindowRect(rcMiddle);
1751 ScreenToClient(rcMiddle);
1752 if (rcMiddle.Height() && rcMiddle.Width())
1753 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1757 void CCommitDlg::DoSize(int delta)
1759 RemoveAnchor(IDC_MESSAGEGROUP);
1760 RemoveAnchor(IDC_LOGMESSAGE);
1761 RemoveAnchor(IDC_SPLITTER);
1762 RemoveAnchor(IDC_SIGNOFF);
1763 RemoveAnchor(IDC_COMMIT_AMEND);
1764 RemoveAnchor(IDC_LISTGROUP);
1765 RemoveAnchor(IDC_FILELIST);
1766 RemoveAnchor(IDC_TEXT_INFO);
1767 RemoveAnchor(IDC_VIEW_PATCH);
1769 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1770 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1771 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1772 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1773 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1774 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1775 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1776 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1778 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1779 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1780 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1781 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1782 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1783 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1784 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1785 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1786 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1787 ArrangeLayout();
1788 // adjust the minimum size of the dialog to prevent the resizing from
1789 // moving the list control too far down.
1790 CRect rcLogMsg;
1791 m_cLogMessage.GetClientRect(rcLogMsg);
1792 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1794 SetSplitterRange();
1795 m_cLogMessage.Invalidate();
1796 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1799 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1801 // first, let the resizing take place
1802 __super::OnSize(nType, cx, cy);
1804 //set range
1805 SetSplitterRange();
1810 void CCommitDlg::OnBnClickedSignOff()
1812 // TODO: Add your control notification handler code here
1813 CString str;
1814 CString username;
1815 CString email;
1816 username=g_Git.GetUserName();
1817 email=g_Git.GetUserEmail();
1818 username.Remove(_T('\n'));
1819 email.Remove(_T('\n'));
1820 str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);
1822 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);
1825 void CCommitDlg::OnStnClickedCommitlabel()
1827 // TODO: Add your control notification handler code here
1830 void CCommitDlg::OnBnClickedCommitAmend()
1832 // TODO: Add your control notification handler code here
1833 this->UpdateData();
1834 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1836 GitRev rev;
1837 BYTE_VECTOR vector;
1838 CString head(_T("HEAD"));
1839 g_Git.GetLog(vector,head,NULL,1);
1840 rev.ParserFromLog(vector);
1841 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;
1844 if(this->m_bCommitAmend)
1846 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1847 m_cLogMessage.SetText(m_AmendStr);
1849 }else
1851 this->m_AmendStr=this->m_cLogMessage.GetText();
1852 m_cLogMessage.SetText(m_NoAmendStr);
1858 void CCommitDlg::OnBnClickedWholeProject()
1860 // TODO: Add your control notification handler code here
1861 m_tooltips.Pop(); // hide the tooltips
1862 UpdateData();
1863 m_ListCtrl.Clear();
1864 if (!m_bBlock)
1866 if(m_bWholeProject)
1867 m_ListCtrl.GetStatus(NULL,true,false,true);
1868 else
1869 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1871 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());
1874 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1876 if(this->m_bWholeProject)
1877 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1878 else
1879 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1883 void CCommitDlg::OnStnClickedBugidlabel()
1885 // TODO: Add your control notification handler code here
1888 void CCommitDlg::OnFocusMessage()
1890 m_cLogMessage.SetFocus();
1893 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1895 SCNotification *pHead =(SCNotification *)pNMHDR;
1897 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1898 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1899 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1901 CString str;
1902 str.Format(_T("%d/%d"),line+1,column+1);
1903 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1905 if(*pResult)
1906 *pResult=0;
1908 void CCommitDlg::OnStnClickedViewPatch()
1910 // TODO: Add your control notification handler code here
1912 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1913 m_patchViewdlg.m_ParentCommitDlg = this;
1914 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1916 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1917 CRect rect;
1918 this->GetWindowRect(&rect);
1920 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1921 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1923 m_patchViewdlg.m_ctrlPatchView.MoveWindow(0,0,rect.Width(),rect.Height());
1924 m_patchViewdlg.ShowWindow(SW_SHOW);
1926 ShowViewPatchText(false);
1927 FillPatchView();
1929 else
1931 m_patchViewdlg.ShowWindow(SW_HIDE);
1932 m_patchViewdlg.DestroyWindow();
1933 ShowViewPatchText(true);
1935 this->m_ctrlShowPatch.Invalidate();
1938 void CCommitDlg::OnMove(int x, int y)
1940 __super::OnMove(x, y);
1942 // TODO: Add your message handler code here
1945 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
1947 __super::OnMoving(fwSide, pRect);
1949 // TODO: Add your message handler code here
1950 if (::IsWindow(m_patchViewdlg.m_hWnd))
1952 RECT patchrect;
1953 m_patchViewdlg.GetWindowRect(&patchrect);
1954 if (::IsWindow(m_hWnd))
1956 RECT thisrect;
1957 GetWindowRect(&thisrect);
1958 if (patchrect.left == thisrect.right)
1960 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
1961 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
1968 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
1970 __super::OnSizing(fwSide, pRect);
1972 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1974 CRect thisrect, patchrect;
1975 this->GetWindowRect(thisrect);
1976 this->m_patchViewdlg.GetWindowRect(patchrect);
1977 if(thisrect.right==patchrect.left)
1979 int width = patchrect.Width();
1980 patchrect.left -= (thisrect.right - pRect->right);
1981 patchrect.right-= (thisrect.right - pRect->right);
1983 if( patchrect.bottom == thisrect.bottom)
1985 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1987 if( patchrect.top == thisrect.top)
1989 patchrect.top -= thisrect.top-pRect->top;
1991 m_patchViewdlg.MoveWindow(patchrect);
1994 // TODO: Add your message handler code here
1997 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
1999 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
2000 // TODO: Add your control notification handler code here
2001 *pResult = 0;
2002 TRACE("Item Changed\r\n");