Fixed issue #440: Don't enable 'Apply' button until the data are ok in Settings/Git...
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.cpp
blob6c75fff46cb5bba4a1d7466e86d77a64ba71d201
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 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
129 m_bShowUnversioned = m_regAddBeforeCommit;
131 m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));
133 m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);
134 m_bKeepChangeList = m_regKeepChangelists;
136 m_hAccel = LoadAccelerators(AfxGetResourceHandle(),MAKEINTRESOURCE(IDR_ACC_COMMITDLG));
138 // GitConfig config;
139 // m_bWholeProject = config.KeepLocks();
141 if(this->m_pathList.GetCount() == 0)
142 m_bWholeProject =true;
144 if(this->m_pathList.GetCount() == 1 && m_pathList[0].IsEmpty())
145 m_bWholeProject =true;
147 UpdateData(FALSE);
149 m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS | SVNSLC_COLADD |SVNSLC_COLDEL, _T("CommitDlg"));
150 m_ListCtrl.SetSelectButton(&m_SelectAll);
151 m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));
152 m_ListCtrl.SetCancelBool(&m_bCancelled);
153 m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);
154 m_ListCtrl.EnableFileDrop();
155 m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);
157 //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);
158 m_ProjectProperties.ReadPropsPathList(m_pathList);
160 m_cLogMessage.Init(m_ProjectProperties);
161 m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
162 m_cLogMessage.RegisterContextMenuHandler(this);
164 OnEnChangeLogmessage();
166 m_tooltips.Create(this);
167 m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);
168 m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);
169 // m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);
171 m_SelectAll.SetCheck(BST_INDETERMINATE);
174 CBugTraqAssociations bugtraq_associations;
175 bugtraq_associations.Load();
177 if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))
179 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
180 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
182 CComPtr<IBugTraqProvider> pProvider;
183 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());
184 if (SUCCEEDED(hr))
186 m_BugTraqProvider = pProvider;
187 BSTR temp = NULL;
188 if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))
190 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);
191 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);
192 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);
195 SysFreeString(temp);
198 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
200 else if (!m_ProjectProperties.sMessage.IsEmpty())
202 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);
203 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);
204 if (!m_ProjectProperties.sLabel.IsEmpty())
205 SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);
206 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
207 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
208 GetDlgItem(IDC_BUGID)->SetFocus();
209 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);
210 if (!sBugID.IsEmpty())
212 SetDlgItemText(IDC_BUGID, sBugID);
215 else
217 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);
218 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);
219 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);
220 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);
221 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
224 if (!m_sLogMessage.IsEmpty())
225 m_cLogMessage.SetText(m_sLogMessage);
227 GetWindowText(m_sWindowTitle);
229 AdjustControlSize(IDC_SHOWUNVERSIONED);
230 AdjustControlSize(IDC_SELECTALL);
231 AdjustControlSize(IDC_WHOLE_PROJECT);
233 GetClientRect(m_DlgOrigRect);
234 m_cLogMessage.GetClientRect(m_LogMsgOrigRect);
236 AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);
237 AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);
238 AddAnchor(IDC_BUGID, TOP_RIGHT);
239 AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);
240 AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);
241 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
242 // AddAnchor(IDC_HISTORY, TOP_LEFT);
243 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
244 AddAnchor(IDC_SIGNOFF, TOP_RIGHT);
245 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
246 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
247 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
248 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
249 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
250 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
251 AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);
252 AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);
253 AddAnchor(IDC_TEXT_INFO, TOP_RIGHT);
254 AddAnchor(IDC_WHOLE_PROJECT, BOTTOM_LEFT);
255 AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);
256 AddAnchor(IDOK, BOTTOM_RIGHT);
257 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
258 AddAnchor(IDHELP, BOTTOM_RIGHT);
259 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
261 if (hWndExplorer)
262 CenterWindow(CWnd::FromHandle(hWndExplorer));
263 EnableSaveRestore(_T("CommitDlg"));
264 DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
265 RECT rcDlg, rcLogMsg, rcFileList;
266 GetClientRect(&rcDlg);
267 m_cLogMessage.GetWindowRect(&rcLogMsg);
268 ScreenToClient(&rcLogMsg);
269 m_ListCtrl.GetWindowRect(&rcFileList);
270 ScreenToClient(&rcFileList);
271 if (yPos)
273 RECT rectSplitter;
274 m_wndSplitter.GetWindowRect(&rectSplitter);
275 ScreenToClient(&rectSplitter);
276 int delta = yPos - rectSplitter.top;
277 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))
279 m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);
280 DoSize(delta);
284 // add all directories to the watcher
285 for (int i=0; i<m_pathList.GetCount(); ++i)
287 if (m_pathList[i].IsDirectory())
288 m_pathwatcher.AddPath(m_pathList[i]);
291 m_updatedPathList = m_pathList;
293 //first start a thread to obtain the file list with the status without
294 //blocking the dialog
295 InterlockedExchange(&m_bBlock, TRUE);
296 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
297 if (m_pThread==NULL)
299 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
300 InterlockedExchange(&m_bBlock, FALSE);
302 else
304 m_pThread->m_bAutoDelete = FALSE;
305 m_pThread->ResumeThread();
307 CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
308 CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);
309 if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))
311 historyhint = TRUE;
312 // ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);
314 err = FALSE;
316 //this->UpdateData(TRUE);
317 //this->m_bCommitAmend=FALSE;
318 //this->UpdateData(FALSE);
320 this->m_ctrlShowPatch.SetURL(CString());
322 return FALSE; // return TRUE unless you set the focus to a control
323 // EXCEPTION: OCX Property Pages should return FALSE
326 void CCommitDlg::OnOK()
328 if (m_bBlock)
329 return;
330 if (m_bThreadRunning)
332 m_bCancelled = true;
333 InterlockedExchange(&m_bRunThread, FALSE);
334 WaitForSingleObject(m_pThread->m_hThread, 1000);
335 if (m_bThreadRunning)
337 // we gave the thread a chance to quit. Since the thread didn't
338 // listen to us we have to kill it.
339 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
340 InterlockedExchange(&m_bThreadRunning, FALSE);
343 this->UpdateData();
345 CString id;
346 GetDlgItemText(IDC_BUGID, id);
347 if (!m_ProjectProperties.CheckBugID(id))
349 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);
350 return;
352 m_sLogMessage = m_cLogMessage.GetText();
353 if ( m_sLogMessage.IsEmpty() )
355 // no message entered, go round again
356 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);
357 return;
359 if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))
361 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
362 return;
365 m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);
366 #if 0
367 CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);
368 if (!(DWORD)regUnversionedRecurse)
370 // Find unversioned directories which are marked for commit. The user might expect them
371 // to be added recursively since he cannot the the files. Let's ask the user if he knows
372 // what he is doing.
373 int nListItems = m_ListCtrl.GetItemCount();
374 for (int j=0; j<nListItems; j++)
376 const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
377 if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )
379 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)
380 return;
384 #endif
385 m_pathwatcher.Stop();
386 InterlockedExchange(&m_bBlock, TRUE);
387 CDWordArray arDeleted;
388 //first add all the unversioned files the user selected
389 //and check if all versioned files are selected
390 int nchecked = 0;
391 m_bRecursive = true;
392 int nListItems = m_ListCtrl.GetItemCount();
394 CTGitPathList itemsToAdd;
395 CTGitPathList itemsToRemove;
396 //std::set<CString> checkedLists;
397 //std::set<CString> uncheckedLists;
399 // now let the bugtraq plugin check the commit message
400 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
401 if (m_BugTraqProvider)
403 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
404 if (SUCCEEDED(hr))
406 BSTR temp = NULL;
407 CString common = g_Git.m_CurrentDir;
408 BSTR repositoryRoot = common.AllocSysString();
409 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
410 BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());
411 BSTR commitMessage = m_sLogMessage.AllocSysString();
412 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());
414 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
415 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
417 if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))
419 COMError ce(hr);
420 CString sErr;
421 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());
422 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseSVN"), MB_ICONERROR);
424 else
426 CString sError = temp;
427 if (!sError.IsEmpty())
429 CMessageBox::Show(m_hWnd, sError, _T("TortoiseSVN"), MB_ICONERROR);
430 return;
432 SysFreeString(temp);
437 //CString checkedfiles;
438 //CString uncheckedfiles;
440 CString cmd;
441 CString out;
443 bool bAddSuccess=true;
444 bool bCloseCommitDlg=false;
446 for (int j=0; j<nListItems; j++)
448 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);
449 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);
450 if (entry->m_Checked)
452 #if 0
453 if (entry->status == Git_wc_status_unversioned)
455 itemsToAdd.AddPath(entry->GetPath());
457 if (entry->status == Git_wc_status_conflicted)
459 bHasConflicted = true;
461 if (entry->status == Git_wc_status_missing)
463 itemsToRemove.AddPath(entry->GetPath());
465 if (entry->status == Git_wc_status_deleted)
467 arDeleted.Add(j);
469 if (entry->IsInExternal())
471 bCheckedInExternal = true;
473 #endif
474 if( entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
475 cmd.Format(_T("git.exe add -f -- \"%s\""),entry->GetGitPathString());
476 else if ( entry->m_Action & CTGitPath::LOGACTIONS_DELETED)
477 cmd.Format(_T("git.exe update-index --remove -- \"%s\""),entry->GetGitPathString());
478 else
479 cmd.Format(_T("git.exe update-index -- \"%s\""),entry->GetGitPathString());
481 if(g_Git.Run(cmd,&out,CP_ACP))
483 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
484 bAddSuccess = false ;
485 break;
488 if( entry->m_Action & CTGitPath::LOGACTIONS_REPLACED)
489 cmd.Format(_T("git.exe rm -- \"%s\""), entry->GetGitOldPathString());
491 g_Git.Run(cmd,&out,CP_ACP);
493 nchecked++;
495 //checkedLists.insert(entry->GetGitPathString());
496 // checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
498 else
500 //uncheckedLists.insert(entry->GetGitPathString());
501 if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)
502 { //To init git repository, there are not HEAD, so we can use git reset command
503 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());
504 if(g_Git.Run(cmd,&out,CP_ACP))
506 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
507 bAddSuccess = false ;
508 bCloseCommitDlg=false;
509 break;
513 else if(!( entry->m_Action & CTGitPath::LOGACTIONS_UNVER ) )
515 cmd.Format(_T("git.exe reset -- \"%s\""),entry->GetGitPathString());
516 if(g_Git.Run(cmd,&out,CP_ACP))
518 /* when reset a unstage file will report error.
519 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
520 bAddSuccess = false ;
521 bCloseCommitDlg=false;
522 break;
527 // uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");
528 #if 0
529 if ((entry->status != Git_wc_status_unversioned) &&
530 (entry->status != Git_wc_status_ignored))
532 nUnchecked++;
533 uncheckedLists.insert(entry->GetChangeList());
534 if (m_bRecursive)
536 // This algorithm is for the sake of simplicity of the complexity O(N?
537 for (int k=0; k<nListItems; k++)
539 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);
540 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath()) )
542 // Fall back to a non-recursive commit to prevent items being
543 // committed which aren't checked although its parent is checked
544 // (property change, directory deletion, ... )
545 m_bRecursive = false;
546 break;
551 #endif
554 CShellUpdater::Instance().AddPathForUpdate(*entry);
557 //if(uncheckedfiles.GetLength()>0)
559 // cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);
560 // g_Git.Run(cmd,&out);
563 m_sBugID.Trim();
564 if (!m_sBugID.IsEmpty())
566 m_sBugID.Replace(_T(", "), _T(","));
567 m_sBugID.Replace(_T(" ,"), _T(","));
568 CString sBugID = m_ProjectProperties.sMessage;
569 sBugID.Replace(_T("%BUGID%"), m_sBugID);
570 if (m_ProjectProperties.bAppend)
571 m_sLogMessage += _T("\n") + sBugID + _T("\n");
572 else
573 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
576 //if(checkedfiles.GetLength()>0)
577 if( bAddSuccess && (nchecked||m_bCommitAmend) )
579 // cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);
580 // g_Git.Run(cmd,&out);
582 bCloseCommitDlg = true;
584 CString tempfile=::GetTempFile();
586 CAppUtils::SaveCommitUnicodeFile(tempfile,m_sLogMessage);
587 //file.WriteString(m_sLogMessage);
589 CTGitPath path=g_Git.m_CurrentDir;
591 BOOL IsGitSVN = path.GetAdminDirMask() & ITEMIS_GITSVN;
593 out =_T("");
594 CString amend;
595 if(this->m_bCommitAmend)
597 amend=_T("--amend");
599 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);
601 CCommitProgressDlg progress;
602 progress.m_bBufferAll=true; // improve show speed when there are many file added.
603 progress.m_GitCmd=cmd;
604 progress.m_bShowCommand = FALSE; // don't show the commit command
605 progress.m_PreText = out; // show any output already generated in log window
607 progress.m_PostCmdList.Add( IsGitSVN? _T("&DCommit"): _T("&Push"));
609 m_PostCmd = IsGitSVN? GIT_POST_CMD_DCOMMIT:GIT_POST_CMD_PUSH;
611 DWORD userResponse = progress.DoModal();
613 if(progress.m_GitStatus)
615 bCloseCommitDlg = false;
616 this->Refresh();
618 else if(userResponse == IDC_PROGRESS_BUTTON1)
620 //User pressed 'Push' button after successful commit.
621 m_bPushAfterCommit=true;
624 CFile::Remove(tempfile);
626 if (m_BugTraqProvider && progress.m_GitStatus == 0)
628 CComPtr<IBugTraqProvider2> pProvider = NULL;
629 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);
630 if (SUCCEEDED(hr))
632 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
633 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());
635 for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)
636 SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());
638 BSTR logMessage = m_sLogMessage.AllocSysString();
640 CString hash=g_Git.GetHash(CString(_T("HEAD")));
641 LONG version = g_Git.Hash2int(hash);
643 BSTR temp = NULL;
644 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(),
645 commonRoot,
646 pathList,
647 logMessage,
648 (LONG)version,
649 &temp)))
651 CString sErr = temp;
652 if (!sErr.IsEmpty())
653 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
654 else
656 COMError ce(hr);
657 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());
658 CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
662 SysFreeString(temp);
666 }else if(bAddSuccess)
668 CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);
669 bCloseCommitDlg=false;
671 #if 0
672 if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)
674 // There are paths which got changed (touched at least).
675 // We have to find out if this affects the selection in the commit dialog
676 // If it could affect the selection, revert back to a non-recursive commit
677 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();
678 changedList.RemoveDuplicates();
679 for (int i=0; i<changedList.GetCount(); ++i)
681 if (changedList[i].IsAdminDir())
683 // something inside an admin dir was changed.
684 // if it's the entries file, then we have to fully refresh because
685 // files may have been added/removed from version control
686 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&
687 (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))
689 m_bRecursive = false;
690 break;
693 else if (!m_ListCtrl.IsPathShown(changedList[i]))
695 // a path which is not shown in the list has changed
696 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);
697 if (entry)
699 // check if the changed path would get committed by a recursive commit
700 if ((!entry->IsFromDifferentRepository()) &&
701 (!entry->IsInExternal()) &&
702 (!entry->IsNested()) &&
703 (!entry->IsChecked()))
705 m_bRecursive = false;
706 break;
714 // Now, do all the adds - make sure that the list is sorted so that parents
715 // are added before their children
716 itemsToAdd.SortByPathname();
717 Git Git;
718 if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))
720 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
721 InterlockedExchange(&m_bBlock, FALSE);
722 Refresh();
723 return;
726 // Remove any missing items
727 // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point
728 itemsToRemove.SortByPathname();
729 Git.Remove(itemsToRemove, TRUE);
731 //the next step: find all deleted files and check if they're
732 //inside a deleted folder. If that's the case, then remove those
733 //files from the list since they'll get deleted by the parent
734 //folder automatically.
735 m_ListCtrl.Block(TRUE, FALSE);
736 INT_PTR nDeleted = arDeleted.GetCount();
737 for (INT_PTR i=0; i<arDeleted.GetCount(); i++)
739 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))
741 const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();
742 if (path.IsDirectory())
744 //now find all children of this directory
745 for (int j=0; j<arDeleted.GetCount(); j++)
747 if (i!=j)
749 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));
750 if (childEntry->IsChecked())
752 if (path.IsAncestorOf(childEntry->GetPath()))
754 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);
755 nDeleted--;
763 m_ListCtrl.Block(FALSE, FALSE);
765 if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))
767 //save only the files the user has checked into the temporary file
768 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);
771 // the item count is used in the progress dialog to show the overall commit
772 // progress.
773 // deleted items only send one notification event, all others send two
774 m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();
776 if ((m_bRecursive)&&(checkedLists.size() == 1))
778 // all checked items belong to the same changelist
779 // find out if there are any unchecked items which belong to that changelist
780 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())
781 m_sChangeList = *checkedLists.begin();
783 #endif
784 UpdateData();
785 m_regAddBeforeCommit = m_bShowUnversioned;
786 if (!GetDlgItem(IDC_WHOLE_PROJECT)->IsWindowEnabled())
787 m_bWholeProject = FALSE;
788 m_regKeepChangelists = m_bKeepChangeList;
789 if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())
790 m_bKeepChangeList = FALSE;
791 InterlockedExchange(&m_bBlock, FALSE);
793 m_History.AddEntry(m_sLogMessage);
794 m_History.Save();
796 SaveSplitterPos();
798 if( bCloseCommitDlg )
799 CResizableStandAloneDialog::OnOK();
801 CShellUpdater::Instance().Flush();
804 void CCommitDlg::SaveSplitterPos()
806 if (!IsIconic())
808 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));
809 RECT rectSplitter;
810 m_wndSplitter.GetWindowRect(&rectSplitter);
811 ScreenToClient(&rectSplitter);
812 regPos = rectSplitter.top;
816 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)
818 return ((CCommitDlg*)pVoid)->StatusThread();
821 UINT CCommitDlg::StatusThread()
823 //get the status of all selected file/folders recursively
824 //and show the ones which have to be committed to the user
825 //in a list control.
826 InterlockedExchange(&m_bBlock, TRUE);
827 InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running
828 InterlockedExchange(&m_bRunThread, TRUE); // if this is set to FALSE, the thread should stop
830 g_Git.RefreshGitIndex();
832 m_bCancelled = false;
834 DialogEnableWindow(IDOK, false);
835 DialogEnableWindow(IDC_SHOWUNVERSIONED, false);
836 DialogEnableWindow(IDC_WHOLE_PROJECT, false);
837 DialogEnableWindow(IDC_SELECTALL, false);
838 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);
839 DialogEnableWindow(IDC_EXTERNALWARNING, false);
840 // read the list of recent log entries before querying the WC for status
841 // -> the user may select one and modify / update it while we are crawling the WC
843 if (m_History.GetCount()==0)
845 CString reg;
846 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);
847 reg.Replace(_T(':'),_T('_'));
848 m_History.Load(reg, _T("logmsgs"));
851 // Initialise the list control with the status of the files/folders below us
852 m_ListCtrl.Clear();
853 BOOL success;
854 if(m_bWholeProject)
855 success=m_ListCtrl.GetStatus(NULL);
856 else
857 success=m_ListCtrl.GetStatus(&m_pathList);
859 //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));
860 if(this->m_bShowUnversioned)
861 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER,true,&m_pathList);
863 m_ListCtrl.CheckIfChangelistsArePresent(false);
865 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;
866 dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;
867 if (success)
869 if (m_checkedPathList.GetCount())
870 m_ListCtrl.Show(dwShow, m_checkedPathList);
871 else
873 DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;
874 dwCheck &=~(CTGitPath::LOGACTIONS_UNVER); //don't check unversion file default.
875 m_ListCtrl.Show(dwShow, dwCheck);
876 m_bSelectFilesForCommit = true;
879 if (m_ListCtrl.HasExternalsFromDifferentRepos())
881 GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);
882 DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);
885 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());
886 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());
888 CString logmsg;
889 GetDlgItemText(IDC_LOGMESSAGE, logmsg);
890 DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);
891 if (!success)
893 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())
894 m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());
895 m_ListCtrl.Show(dwShow);
897 if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems()))
899 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
901 m_bShowUnversioned = TRUE;
902 GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);
903 DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);
904 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);
905 m_ListCtrl.Show(dwShow,dwShow&(~CTGitPath::LOGACTIONS_UNVER));
909 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
911 if(this->m_bWholeProject)
912 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString() + CString(_T("(Whole Project)")));
913 else
914 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
916 m_autolist.clear();
917 // we don't have to block the commit dialog while we fetch the
918 // auto completion list.
919 m_pathwatcher.ClearChangedPaths();
920 InterlockedExchange(&m_bBlock, FALSE);
921 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)
923 m_ListCtrl.Block(TRUE, TRUE);
924 GetAutocompletionList();
925 m_ListCtrl.Block(FALSE, FALSE);
927 if (m_bRunThread)
929 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);
930 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
931 DialogEnableWindow(IDC_SELECTALL, true);
932 if (m_ListCtrl.HasChangeLists())
933 DialogEnableWindow(IDC_KEEPLISTS, true);
934 if (m_ListCtrl.HasLocks())
935 DialogEnableWindow(IDC_WHOLE_PROJECT, true);
936 // we have the list, now signal the main thread about it
937 SendMessage(WM_AUTOLISTREADY); // only send the message if the thread wasn't told to quit!
940 InterlockedExchange(&m_bRunThread, FALSE);
941 InterlockedExchange(&m_bThreadRunning, FALSE);
942 // force the cursor to normal
943 RefreshCursor();
945 return 0;
948 void CCommitDlg::OnCancel()
950 m_bCancelled = true;
951 m_pathwatcher.Stop();
953 if (m_bBlock)
954 return;
956 if (m_bThreadRunning)
958 InterlockedExchange(&m_bRunThread, FALSE);
959 WaitForSingleObject(m_pThread->m_hThread, 1000);
960 if (m_bThreadRunning)
962 // we gave the thread a chance to quit. Since the thread didn't
963 // listen to us we have to kill it.
964 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
965 InterlockedExchange(&m_bThreadRunning, FALSE);
968 UpdateData();
969 m_sBugID.Trim();
970 m_sLogMessage = m_cLogMessage.GetText();
971 if (!m_sBugID.IsEmpty())
973 m_sBugID.Replace(_T(", "), _T(","));
974 m_sBugID.Replace(_T(" ,"), _T(","));
975 CString sBugID = m_ProjectProperties.sMessage;
976 sBugID.Replace(_T("%BUGID%"), m_sBugID);
977 if (m_ProjectProperties.bAppend)
978 m_sLogMessage += _T("\n") + sBugID + _T("\n");
979 else
980 m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;
982 if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)
983 m_History.AddEntry(m_sLogMessage);
984 m_History.Save();
985 SaveSplitterPos();
986 CResizableStandAloneDialog::OnCancel();
989 void CCommitDlg::OnBnClickedSelectall()
991 m_tooltips.Pop(); // hide the tooltips
992 UINT state = (m_SelectAll.GetState() & 0x0003);
993 if (state == BST_INDETERMINATE)
995 // It is not at all useful to manually place the checkbox into the indeterminate state...
996 // We will force this on to the unchecked state
997 state = BST_UNCHECKED;
998 m_SelectAll.SetCheck(state);
1000 m_ListCtrl.SelectAll(state == BST_CHECKED);
1003 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)
1005 if (!m_bBlock)
1006 m_tooltips.RelayEvent(pMsg);
1008 if (m_hAccel)
1010 int ret = TranslateAccelerator(m_hWnd, m_hAccel, pMsg);
1011 if (ret)
1012 return TRUE;
1015 if (pMsg->message == WM_KEYDOWN)
1017 switch (pMsg->wParam)
1019 case VK_F5:
1021 if (m_bBlock)
1022 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1023 Refresh();
1025 break;
1026 case VK_RETURN:
1028 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
1030 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
1032 PostMessage(WM_COMMAND, IDOK);
1034 return TRUE;
1036 if ( GetFocus()==GetDlgItem(IDC_BUGID) )
1038 // Pressing RETURN in the bug id control
1039 // moves the focus to the message
1040 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1041 return TRUE;
1044 break;
1048 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
1051 void CCommitDlg::Refresh()
1053 if (m_bThreadRunning)
1054 return;
1056 InterlockedExchange(&m_bBlock, TRUE);
1057 m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1058 if (m_pThread==NULL)
1060 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
1061 InterlockedExchange(&m_bBlock, FALSE);
1063 else
1065 m_pThread->m_bAutoDelete = FALSE;
1066 m_pThread->ResumeThread();
1070 void CCommitDlg::OnBnClickedHelp()
1072 OnHelp();
1075 void CCommitDlg::OnBnClickedShowunversioned()
1077 m_tooltips.Pop(); // hide the tooltips
1078 UpdateData();
1079 m_regAddBeforeCommit = m_bShowUnversioned;
1080 if (!m_bBlock)
1082 DWORD dwShow = m_ListCtrl.GetShowFlags();
1083 if (DWORD(m_regAddBeforeCommit))
1084 dwShow |= SVNSLC_SHOWUNVERSIONED;
1085 else
1086 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
1087 if(dwShow & SVNSLC_SHOWUNVERSIONED)
1089 if(m_bWholeProject)
1090 m_ListCtrl.GetStatus(NULL,false,false,true);
1091 else
1092 m_ListCtrl.GetStatus(&this->m_pathList,false,false,true);
1094 m_ListCtrl.Show(dwShow,0,true,0,true);
1098 void CCommitDlg::OnStnClickedExternalwarning()
1100 m_tooltips.Popup();
1103 void CCommitDlg::OnEnChangeLogmessage()
1105 UpdateOKButton();
1108 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)
1110 #if 0
1111 if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))
1113 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)
1115 m_bShowUnversioned = TRUE;
1116 DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;
1117 m_ListCtrl.Show(dwShow);
1118 UpdateData(FALSE);
1121 #endif
1122 return 0;
1125 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
1127 Refresh();
1128 return 0;
1131 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)
1133 #if 0
1134 BringWindowToTop();
1135 SetForegroundWindow();
1136 SetActiveWindow();
1137 // if multiple files/folders are dropped
1138 // this handler is called for every single item
1139 // separately.
1140 // To avoid creating multiple refresh threads and
1141 // causing crashes, we only add the items to the
1142 // list control and start a timer.
1143 // When the timer expires, we start the refresh thread,
1144 // but only if it isn't already running - otherwise we
1145 // restart the timer.
1146 CTGitPath path;
1147 path.SetFromWin((LPCTSTR)lParam);
1149 // just add all the items we get here.
1150 // if the item is versioned, the add will fail but nothing
1151 // more will happen.
1152 Git Git;
1153 Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);
1155 if (!m_ListCtrl.HasPath(path))
1157 if (m_pathList.AreAllPathsFiles())
1159 m_pathList.AddPath(path);
1160 m_pathList.RemoveDuplicates();
1161 m_updatedPathList.AddPath(path);
1162 m_updatedPathList.RemoveDuplicates();
1164 else
1166 // if the path list contains folders, we have to check whether
1167 // our just (maybe) added path is a child of one of those. If it is
1168 // a child of a folder already in the list, we must not add it. Otherwise
1169 // that path could show up twice in the list.
1170 bool bHasParentInList = false;
1171 for (int i=0; i<m_pathList.GetCount(); ++i)
1173 if (m_pathList[i].IsAncestorOf(path))
1175 bHasParentInList = true;
1176 break;
1179 if (!bHasParentInList)
1181 m_pathList.AddPath(path);
1182 m_pathList.RemoveDuplicates();
1183 m_updatedPathList.AddPath(path);
1184 m_updatedPathList.RemoveDuplicates();
1189 // Always start the timer, since the status of an existing item might have changed
1190 SetTimer(REFRESHTIMER, 200, NULL);
1191 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
1192 #endif
1193 return 0;
1196 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)
1198 m_cLogMessage.SetAutoCompletionList(m_autolist, '*');
1199 return 0;
1202 //////////////////////////////////////////////////////////////////////////
1203 // functions which run in the status thread
1204 //////////////////////////////////////////////////////////////////////////
1206 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)
1208 CString strLine;
1211 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);
1212 while (m_bRunThread && file.ReadString(strLine))
1214 int eqpos = strLine.Find('=');
1215 CString rgx;
1216 rgx = strLine.Mid(eqpos+1).Trim();
1218 int pos = -1;
1219 while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))
1221 mapRegex[strLine.Left(pos)] = rgx;
1222 strLine = strLine.Mid(pos+1).Trim();
1224 mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;
1226 file.Close();
1228 catch (CFileException* pE)
1230 TRACE("CFileException loading auto list regex file\n");
1231 pE->Delete();
1232 return;
1235 void CCommitDlg::GetAutocompletionList()
1237 // the auto completion list is made of strings from each selected files.
1238 // the strings used are extracted from the files with regexes found
1239 // in the file "autolist.txt".
1240 // the format of that file is:
1241 // file extensions separated with commas '=' regular expression to use
1242 // example:
1243 // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))
1244 // .cpp = (?<=[^\s]::)\b\w+\b
1246 std::map<CString, CString> mapRegex;
1247 CString sRegexFile = CPathUtils::GetAppDirectory();
1248 CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);
1249 DWORD timeoutvalue = regtimeout*1000;
1250 sRegexFile += _T("autolist.txt");
1251 if (!m_bRunThread)
1252 return;
1253 ParseRegexFile(sRegexFile, mapRegex);
1254 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));
1255 sRegexFile.ReleaseBuffer();
1256 sRegexFile += _T("\\TortoiseGit\\autolist.txt");
1257 if (PathFileExists(sRegexFile))
1259 ParseRegexFile(sRegexFile, mapRegex);
1261 DWORD starttime = GetTickCount();
1263 // now we have two arrays of strings, where the first array contains all
1264 // file extensions we can use and the second the corresponding regex strings
1265 // to apply to those files.
1267 // the next step is to go over all files shown in the commit dialog
1268 // and scan them for strings we can use
1269 int nListItems = m_ListCtrl.GetItemCount();
1271 for (int i=0; i<nListItems && m_bRunThread; ++i)
1273 // stop parsing after timeout
1274 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))
1275 return;
1277 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);
1279 if(path == NULL)
1280 continue;
1282 CString sPartPath =path->GetGitPathString();
1283 m_autolist.insert(sPartPath);
1285 // const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);
1286 // if (!entry)
1287 // continue;
1289 // add the path parts to the auto completion list too
1290 // CString sPartPath = entry->GetRelativeGitPath();
1291 // m_autolist.insert(sPartPath);
1294 int pos = 0;
1295 int lastPos = 0;
1296 while ((pos = sPartPath.Find('/', pos)) >= 0)
1298 pos++;
1299 lastPos = pos;
1300 m_autolist.insert(sPartPath.Mid(pos));
1303 // Last inserted entry is a file name.
1304 // Some users prefer to also list file name without extension.
1305 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))
1307 int dotPos = sPartPath.ReverseFind('.');
1308 if ((dotPos >= 0) && (dotPos > lastPos))
1309 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));
1311 #if 0
1312 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))
1313 continue;
1315 CString sExt = entry->GetPath().GetFileExtension();
1316 sExt.MakeLower();
1317 // find the regex string which corresponds to the file extension
1318 CString rdata = mapRegex[sExt];
1319 if (rdata.IsEmpty())
1320 continue;
1322 ScanFile(entry->GetPath().GetWinPathString(), rdata);
1323 if ((entry->textstatus != Git_wc_status_unversioned) &&
1324 (entry->textstatus != Git_wc_status_none) &&
1325 (entry->textstatus != Git_wc_status_ignored) &&
1326 (entry->textstatus != Git_wc_status_added) &&
1327 (entry->textstatus != Git_wc_status_normal))
1329 CTGitPath basePath = Git::GetPristinePath(entry->GetPath());
1330 if (!basePath.IsEmpty())
1331 ScanFile(basePath.GetWinPathString(), rdata);
1333 #endif
1335 ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);
1338 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)
1340 wstring sFileContent;
1341 HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
1342 if (hFile != INVALID_HANDLE_VALUE)
1344 DWORD size = GetFileSize(hFile, NULL);
1345 if (size > 1000000L)
1347 // no files bigger than 1 Meg
1348 CloseHandle(hFile);
1349 return;
1351 // allocate memory to hold file contents
1352 char * buffer = new char[size];
1353 DWORD readbytes;
1354 ReadFile(hFile, buffer, size, &readbytes, NULL);
1355 CloseHandle(hFile);
1356 int opts = 0;
1357 IsTextUnicode(buffer, readbytes, &opts);
1358 if (opts & IS_TEXT_UNICODE_NULL_BYTES)
1360 delete [] buffer;
1361 return;
1363 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)
1365 sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));
1367 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))
1369 int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);
1370 wchar_t * pWideBuf = new wchar_t[ret];
1371 int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);
1372 if (ret2 == ret)
1373 sFileContent = wstring(pWideBuf, ret);
1374 delete [] pWideBuf;
1376 delete [] buffer;
1378 if (sFileContent.empty()|| !m_bRunThread)
1380 return;
1385 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
1386 const tr1::wsregex_iterator end;
1387 wstring s = sFileContent;
1388 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)
1390 const tr1::wsmatch match = *it;
1391 for (size_t i=1; i<match.size(); ++i)
1393 if (match[i].second-match[i].first)
1395 ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());
1396 m_autolist.insert(wstring(match[i]).c_str());
1401 catch (exception) {}
1404 // CSciEditContextMenuInterface
1405 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)
1407 CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1408 m_nPopupPasteListCmd = nCmd++;
1409 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);
1411 //CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));
1412 if(m_History.GetCount() > 0)
1414 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_PASTELASTMESSAGE);
1415 m_nPopupPasteLastMessage = nCmd++;
1416 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteLastMessage, sMenuItemText);
1418 sMenuItemText.LoadString(IDS_COMMITDLG_POPUP_LOGHISTORY);
1419 m_nPopupRecentMessage = nCmd++;
1420 mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupRecentMessage, sMenuItemText);
1426 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)
1429 if (m_bBlock)
1430 return false;
1431 if (cmd == m_nPopupPasteListCmd)
1433 CString logmsg;
1434 TCHAR buf[MAX_STATUS_STRING_LENGTH];
1435 int nListItems = m_ListCtrl.GetItemCount();
1436 for (int i=0; i<nListItems; ++i)
1438 CTGitPath * entry = (CTGitPath*)m_ListCtrl.GetItemData(i);
1439 if (entry&&entry->m_Checked)
1441 CString line;
1442 CString status = entry->GetActionName();
1443 if(entry->m_Action & CTGitPath::LOGACTIONS_UNVER)
1444 status = _T("Add");
1446 //git_wc_status_kind status = entry->status;
1447 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());
1448 if (m_ProjectProperties.bFileListInEnglish)
1449 langID = 1033;
1451 line.Format(_T("%-10s %s\r\n"),status , (LPCTSTR)m_ListCtrl.GetItemText(i,0));
1452 logmsg += line;
1455 pSciEdit->InsertText(logmsg);
1456 return true;
1459 if(cmd == m_nPopupPasteLastMessage)
1461 if(m_History.GetCount() ==0 )
1462 return false;
1464 CString logmsg;
1465 logmsg +=m_History.GetEntry(0);
1466 pSciEdit->InsertText(logmsg);
1467 return true;
1470 if(cmd == m_nPopupRecentMessage )
1472 OnBnClickedHistory();
1473 return true;
1475 return false;
1478 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)
1480 switch (nIDEvent)
1482 case ENDDIALOGTIMER:
1483 KillTimer(ENDDIALOGTIMER);
1484 EndDialog(0);
1485 break;
1486 case REFRESHTIMER:
1487 if (m_bThreadRunning)
1489 SetTimer(REFRESHTIMER, 200, NULL);
1490 ATLTRACE("Wait some more before refreshing\n");
1492 else
1494 KillTimer(REFRESHTIMER);
1495 ATLTRACE("Refreshing after items dropped\n");
1496 Refresh();
1498 break;
1500 __super::OnTimer(nIDEvent);
1503 void CCommitDlg::OnBnClickedHistory()
1505 m_tooltips.Pop(); // hide the tooltips
1506 if (m_pathList.GetCount() == 0)
1507 return;
1509 CHistoryDlg historyDlg;
1510 historyDlg.SetHistory(m_History);
1511 if (historyDlg.DoModal() != IDOK)
1512 return;
1514 CString sMsg = historyDlg.GetSelectedText();
1515 if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))
1517 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);
1518 if (!sBugID.IsEmpty())
1520 SetDlgItemText(IDC_BUGID, sBugID);
1522 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)
1523 m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());
1524 else
1525 m_cLogMessage.SetText(sMsg);
1528 UpdateOKButton();
1529 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();
1533 void CCommitDlg::OnBnClickedBugtraqbutton()
1535 m_tooltips.Pop(); // hide the tooltips
1536 CString sMsg = m_cLogMessage.GetText();
1538 if (m_BugTraqProvider == NULL)
1539 return;
1541 BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();
1542 BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);
1543 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());
1545 for (LONG index = 0; index < m_pathList.GetCount(); ++index)
1546 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());
1548 BSTR originalMessage = sMsg.AllocSysString();
1549 BSTR temp = NULL;
1550 // m_revProps.clear();
1552 // first try the IBugTraqProvider2 interface
1553 CComPtr<IBugTraqProvider2> pProvider2 = NULL;
1554 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);
1555 if (SUCCEEDED(hr))
1557 //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();
1558 BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();
1559 BSTR bugIDOut = NULL;
1560 GetDlgItemText(IDC_BUGID, m_sBugID);
1561 BSTR bugID = m_sBugID.AllocSysString();
1562 SAFEARRAY * revPropNames = NULL;
1563 SAFEARRAY * revPropValues = NULL;
1564 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))
1566 CString sErr;
1567 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1568 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1570 else
1572 if (bugIDOut)
1574 m_sBugID = bugIDOut;
1575 SysFreeString(bugIDOut);
1576 SetDlgItemText(IDC_BUGID, m_sBugID);
1578 SysFreeString(bugID);
1579 SysFreeString(repositoryRoot);
1580 m_cLogMessage.SetText(temp);
1581 BSTR HUGEP *pbRevNames;
1582 BSTR HUGEP *pbRevValues;
1584 HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);
1585 if (SUCCEEDED(hr1))
1587 HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);
1588 if (SUCCEEDED(hr2))
1590 if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)
1592 for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)
1594 // m_revProps[pbRevNames[i]] = pbRevValues[i];
1597 SafeArrayUnaccessData(revPropValues);
1599 SafeArrayUnaccessData(revPropNames);
1601 if (revPropNames)
1602 SafeArrayDestroy(revPropNames);
1603 if (revPropValues)
1604 SafeArrayDestroy(revPropValues);
1607 else
1609 // if IBugTraqProvider2 failed, try IBugTraqProvider
1610 CComPtr<IBugTraqProvider> pProvider = NULL;
1611 hr = m_BugTraqProvider.QueryInterface(&pProvider);
1612 if (FAILED(hr))
1614 CString sErr;
1615 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1616 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1617 return;
1620 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))
1622 CString sErr;
1623 sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());
1624 CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);
1626 else
1627 m_cLogMessage.SetText(temp);
1629 m_sLogMessage = m_cLogMessage.GetText();
1630 if (!m_ProjectProperties.sMessage.IsEmpty())
1632 CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);
1633 if (!sBugID.IsEmpty())
1635 SetDlgItemText(IDC_BUGID, sBugID);
1639 m_cLogMessage.SetFocus();
1641 SysFreeString(parameters);
1642 SysFreeString(commonRoot);
1643 SafeArrayDestroy(pathList);
1644 SysFreeString(originalMessage);
1645 SysFreeString(temp);
1649 void CCommitDlg::FillPatchView()
1651 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1653 m_patchViewdlg.m_ctrlPatchView.SetText(CString());
1655 POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
1656 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, FALSE);
1657 CString cmd,out;
1659 while(pos)
1661 int nSelect = m_ListCtrl.GetNextSelectedItem(pos);
1662 CTGitPath * p=(CTGitPath*)m_ListCtrl.GetItemData(nSelect);
1663 if(p && !(p->m_Action&CTGitPath::LOGACTIONS_UNVER) )
1665 cmd.Format(_T("git.exe diff -- \"%s\""),p->GetGitPathString());
1666 g_Git.Run(cmd,&out,CP_ACP);
1672 m_patchViewdlg.m_ctrlPatchView.SetText(out);
1673 m_patchViewdlg.m_ctrlPatchView.Call(SCI_SETREADONLY, TRUE);
1674 m_patchViewdlg.m_ctrlPatchView.Call(SCI_GOTOPOS, 0);
1679 LRESULT CCommitDlg::OnGitStatusListCtrlItemChanged(WPARAM wparam, LPARAM lparam)
1681 TRACE("OnGitStatusListCtrlItemChanged %d\r\n", wparam);
1682 this->FillPatchView();
1683 return 0;
1687 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)
1689 UpdateOKButton();
1690 return 0;
1693 void CCommitDlg::UpdateOKButton()
1695 #if 0
1696 BOOL bValidLogSize = FALSE;
1698 if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)
1699 bValidLogSize = !m_bBlock;
1701 LONG nSelectedItems = m_ListCtrl.GetSelected();
1702 DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);
1703 #endif
1707 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
1709 switch (message) {
1710 case WM_NOTIFY:
1711 if (wParam == IDC_SPLITTER)
1713 SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
1714 DoSize(pHdr->delta);
1716 break;
1719 return __super::DefWindowProc(message, wParam, lParam);
1722 void CCommitDlg::SetSplitterRange()
1724 if ((m_ListCtrl)&&(m_cLogMessage))
1726 CRect rcTop;
1727 m_cLogMessage.GetWindowRect(rcTop);
1728 ScreenToClient(rcTop);
1729 CRect rcMiddle;
1730 m_ListCtrl.GetWindowRect(rcMiddle);
1731 ScreenToClient(rcMiddle);
1732 if (rcMiddle.Height() && rcMiddle.Width())
1733 m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);
1737 void CCommitDlg::DoSize(int delta)
1739 RemoveAnchor(IDC_MESSAGEGROUP);
1740 RemoveAnchor(IDC_LOGMESSAGE);
1741 RemoveAnchor(IDC_SPLITTER);
1742 RemoveAnchor(IDC_SIGNOFF);
1743 RemoveAnchor(IDC_COMMIT_AMEND);
1744 RemoveAnchor(IDC_LISTGROUP);
1745 RemoveAnchor(IDC_FILELIST);
1746 RemoveAnchor(IDC_TEXT_INFO);
1747 RemoveAnchor(IDC_VIEW_PATCH);
1749 CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);
1750 CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);
1751 CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);
1752 CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);
1753 CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);
1754 CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);
1755 CSplitterControl::ChangePos(GetDlgItem(IDC_TEXT_INFO),0,delta);
1756 CSplitterControl::ChangePos(GetDlgItem(IDC_VIEW_PATCH),0,delta);
1758 AddAnchor(IDC_VIEW_PATCH,TOP_RIGHT);
1759 AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);
1760 AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);
1761 AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);
1762 AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);
1763 AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);
1764 AddAnchor(IDC_SIGNOFF,TOP_RIGHT);
1765 AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);
1766 AddAnchor(IDC_TEXT_INFO,TOP_RIGHT);
1767 ArrangeLayout();
1768 // adjust the minimum size of the dialog to prevent the resizing from
1769 // moving the list control too far down.
1770 CRect rcLogMsg;
1771 m_cLogMessage.GetClientRect(rcLogMsg);
1772 SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));
1774 SetSplitterRange();
1775 m_cLogMessage.Invalidate();
1776 GetDlgItem(IDC_LOGMESSAGE)->Invalidate();
1779 void CCommitDlg::OnSize(UINT nType, int cx, int cy)
1781 // first, let the resizing take place
1782 __super::OnSize(nType, cx, cy);
1784 //set range
1785 SetSplitterRange();
1790 void CCommitDlg::OnBnClickedSignOff()
1792 // TODO: Add your control notification handler code here
1793 CString str;
1794 CString username;
1795 CString email;
1796 username=g_Git.GetUserName();
1797 email=g_Git.GetUserEmail();
1798 username.Remove(_T('\n'));
1799 email.Remove(_T('\n'));
1800 str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);
1802 m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);
1805 void CCommitDlg::OnStnClickedCommitlabel()
1807 // TODO: Add your control notification handler code here
1810 void CCommitDlg::OnBnClickedCommitAmend()
1812 // TODO: Add your control notification handler code here
1813 this->UpdateData();
1814 if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())
1816 GitRev rev;
1817 BYTE_VECTOR vector;
1818 CString head(_T("HEAD"));
1819 g_Git.GetLog(vector,head,NULL,1);
1820 rev.ParserFromLog(vector);
1821 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;
1824 if(this->m_bCommitAmend)
1826 this->m_NoAmendStr=this->m_cLogMessage.GetText();
1827 m_cLogMessage.SetText(m_AmendStr);
1829 }else
1831 this->m_AmendStr=this->m_cLogMessage.GetText();
1832 m_cLogMessage.SetText(m_NoAmendStr);
1838 void CCommitDlg::OnBnClickedWholeProject()
1840 // TODO: Add your control notification handler code here
1841 m_tooltips.Pop(); // hide the tooltips
1842 UpdateData();
1843 m_ListCtrl.Clear();
1844 if (!m_bBlock)
1846 if(m_bWholeProject)
1847 m_ListCtrl.GetStatus(NULL,true,false,true);
1848 else
1849 m_ListCtrl.GetStatus(&this->m_pathList,true,false,true);
1851 m_ListCtrl.Show(m_ListCtrl.GetShowFlags());
1854 CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);
1856 if(this->m_bWholeProject)
1857 SetWindowText(m_sWindowTitle + _T(" - ") + CString(_T("Whole Project")));
1858 else
1859 SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());
1863 void CCommitDlg::OnStnClickedBugidlabel()
1865 // TODO: Add your control notification handler code here
1868 void CCommitDlg::OnFocusMessage()
1870 m_cLogMessage.SetFocus();
1873 void CCommitDlg::OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult)
1875 SCNotification *pHead =(SCNotification *)pNMHDR;
1877 int pos=this->m_cLogMessage.Call(SCI_GETCURRENTPOS);
1878 int line=this->m_cLogMessage.Call(SCI_LINEFROMPOSITION,pos);
1879 int column=this->m_cLogMessage.Call(SCI_GETCOLUMN,pos);
1881 CString str;
1882 str.Format(_T("%d/%d"),line+1,column+1);
1883 this->GetDlgItem(IDC_TEXT_INFO)->SetWindowText(str);
1885 if(*pResult)
1886 *pResult=0;
1888 void CCommitDlg::OnStnClickedViewPatch()
1890 // TODO: Add your control notification handler code here
1892 m_patchViewdlg.m_pProjectProperties = &this->m_ProjectProperties;
1893 m_patchViewdlg.m_ParentCommitDlg = this;
1894 if(!IsWindow(this->m_patchViewdlg.m_hWnd))
1896 m_patchViewdlg.Create(IDD_PATCH_VIEW,this);
1897 CRect rect;
1898 this->GetWindowRect(&rect);
1900 m_patchViewdlg.SetWindowPos(NULL,rect.right,rect.top,rect.Width(),rect.Height(),
1901 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
1903 m_patchViewdlg.m_ctrlPatchView.MoveWindow(0,0,rect.Width(),rect.Height());
1904 m_patchViewdlg.ShowWindow(SW_SHOW);
1906 ShowViewPatchText(false);
1907 FillPatchView();
1909 else
1911 m_patchViewdlg.ShowWindow(SW_HIDE);
1912 m_patchViewdlg.DestroyWindow();
1913 ShowViewPatchText(true);
1915 this->m_ctrlShowPatch.Invalidate();
1918 void CCommitDlg::OnMove(int x, int y)
1920 __super::OnMove(x, y);
1922 // TODO: Add your message handler code here
1925 void CCommitDlg::OnMoving(UINT fwSide, LPRECT pRect)
1927 __super::OnMoving(fwSide, pRect);
1929 // TODO: Add your message handler code here
1930 if (::IsWindow(m_patchViewdlg.m_hWnd))
1932 RECT patchrect;
1933 m_patchViewdlg.GetWindowRect(&patchrect);
1934 if (::IsWindow(m_hWnd))
1936 RECT thisrect;
1937 GetWindowRect(&thisrect);
1938 if (patchrect.left == thisrect.right)
1940 m_patchViewdlg.SetWindowPos(NULL, patchrect.left - (thisrect.left - pRect->left), patchrect.top - (thisrect.top - pRect->top),
1941 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
1948 void CCommitDlg::OnSizing(UINT fwSide, LPRECT pRect)
1950 __super::OnSizing(fwSide, pRect);
1952 if(::IsWindow(this->m_patchViewdlg.m_hWnd))
1954 CRect thisrect, patchrect;
1955 this->GetWindowRect(thisrect);
1956 this->m_patchViewdlg.GetWindowRect(patchrect);
1957 if(thisrect.right==patchrect.left)
1959 int width = patchrect.Width();
1960 patchrect.left -= (thisrect.right - pRect->right);
1961 patchrect.right-= (thisrect.right - pRect->right);
1963 if( patchrect.bottom == thisrect.bottom)
1965 patchrect.bottom -= (thisrect.bottom - pRect->bottom);
1967 if( patchrect.top == thisrect.top)
1969 patchrect.top -= thisrect.top-pRect->top;
1971 m_patchViewdlg.MoveWindow(patchrect);
1974 // TODO: Add your message handler code here
1977 void CCommitDlg::OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult)
1979 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1980 // TODO: Add your control notification handler code here
1981 *pResult = 0;
1982 TRACE("Item Changed\r\n");