1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "UnicodeUtils.h"
23 #include "MessageBox.h"
26 #include "SysImageList.h"
28 //#include "GitProperties.h"
29 #include "StringUtils.h"
30 #include "PathUtils.h"
31 #include "BrowseFolder.h"
32 #include ".\filediffdlg.h"
34 #include "LoglistCommonResource.h"
35 #include "LoglistUtils.h"
36 #include "BrowseRefsDlg.h"
38 #include "RefLogDlg.h"
39 #include "GitStatusListCtrl.h"
40 #include "FormatMessageWrapper.h"
46 #define ID_CLIPBOARD_PATH 5
47 #define ID_CLIPBOARD_ALL 6
50 BOOL
CFileDiffDlg::m_bAscending
= FALSE
;
51 int CFileDiffDlg::m_nSortedColumn
= -1;
54 IMPLEMENT_DYNAMIC(CFileDiffDlg
, CResizableStandAloneDialog
)
55 CFileDiffDlg::CFileDiffDlg(CWnd
* pParent
/*=NULL*/)
56 : CResizableStandAloneDialog(CFileDiffDlg::IDD
, pParent
),
64 CFileDiffDlg::~CFileDiffDlg()
68 void CFileDiffDlg::DoDataExchange(CDataExchange
* pDX
)
70 CResizableStandAloneDialog::DoDataExchange(pDX
);
71 DDX_Control(pDX
, IDC_FILELIST
, m_cFileList
);
72 DDX_Control(pDX
, IDC_SWITCHLEFTRIGHT
, m_SwitchButton
);
73 DDX_Control(pDX
, IDC_REV1BTN
, m_cRev1Btn
);
74 DDX_Control(pDX
, IDC_REV2BTN
, m_cRev2Btn
);
75 DDX_Control(pDX
, IDC_FILTER
, m_cFilter
);
76 DDX_Control(pDX
, IDC_REV1EDIT
, m_ctrRev1Edit
);
77 DDX_Control(pDX
, IDC_REV2EDIT
, m_ctrRev2Edit
);
81 BEGIN_MESSAGE_MAP(CFileDiffDlg
, CResizableStandAloneDialog
)
82 ON_NOTIFY(NM_DBLCLK
, IDC_FILELIST
, OnNMDblclkFilelist
)
83 ON_NOTIFY(LVN_GETINFOTIP
, IDC_FILELIST
, OnLvnGetInfoTipFilelist
)
84 ON_NOTIFY(NM_CUSTOMDRAW
, IDC_FILELIST
, OnNMCustomdrawFilelist
)
87 ON_EN_SETFOCUS(IDC_SECONDURL
, &CFileDiffDlg::OnEnSetfocusSecondurl
)
88 ON_EN_SETFOCUS(IDC_FIRSTURL
, &CFileDiffDlg::OnEnSetfocusFirsturl
)
89 ON_BN_CLICKED(IDC_SWITCHLEFTRIGHT
, &CFileDiffDlg::OnBnClickedSwitchleftright
)
90 ON_NOTIFY(HDN_ITEMCLICK
, 0, &CFileDiffDlg::OnHdnItemclickFilelist
)
91 ON_BN_CLICKED(IDC_REV1BTN
, &CFileDiffDlg::OnBnClickedRev1btn
)
92 ON_BN_CLICKED(IDC_REV2BTN
, &CFileDiffDlg::OnBnClickedRev2btn
)
93 ON_MESSAGE(WM_FILTEREDIT_CANCELCLICKED
, OnClickedCancelFilter
)
94 ON_EN_CHANGE(IDC_FILTER
, &CFileDiffDlg::OnEnChangeFilter
)
96 ON_MESSAGE(ENAC_UPDATE
, &CFileDiffDlg::OnEnUpdate
)
97 ON_MESSAGE(MSG_REF_LOADED
, OnRefLoad
)
101 void CFileDiffDlg::SetDiff(CTGitPath
* path
, GitRev rev1
, GitRev rev2
)
107 m_sFilter
= path
->GetGitPathString();
113 void CFileDiffDlg::SetDiff(CTGitPath
* path
, CString
&hash1
, CString
&hash2
)
119 m_sFilter
= path
->GetGitPathString();
124 if(hash1
== GIT_REV_ZERO
)
126 m_rev1
.m_CommitHash
.Empty();
127 m_rev1
.GetSubject()=_T("Working Copy");
131 m_rev1
.GetCommit(hash1
);
136 if(hash2
== GIT_REV_ZERO
)
138 m_rev2
.m_CommitHash
.Empty();
139 m_rev2
.GetSubject()=_T("Working Copy");
143 m_rev2
.GetCommit(hash2
);
147 void CFileDiffDlg::SetDiff(CTGitPath
* path
, GitRev rev1
)
153 m_sFilter
= path
->GetGitPathString();
156 m_rev2
.m_CommitHash
.Empty();
157 m_rev2
.GetSubject() = _T("Previous Version");
159 //this->GetDlgItem()->EnableWindow(FALSE);
162 BOOL
CFileDiffDlg::OnInitDialog()
164 CResizableStandAloneDialog::OnInitDialog();
167 CString sWindowTitle
;
168 GetWindowText(sWindowTitle
);
169 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
171 this->m_ctrRev1Edit
.Init();
172 this->m_ctrRev2Edit
.Init();
174 m_tooltips
.Create(this);
175 m_tooltips
.AddTool(IDC_SWITCHLEFTRIGHT
, IDS_FILEDIFF_SWITCHLEFTRIGHT_TT
);
177 m_cFileList
.SetRedraw(false);
178 m_cFileList
.DeleteAllItems();
179 DWORD exStyle
= LVS_EX_FULLROWSELECT
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
;
180 m_cFileList
.SetExtendedStyle(exStyle
);
182 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
183 m_cFileList
.SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
185 m_SwitchButton
.SetImage((HICON
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SWITCHLEFTRIGHT
), IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
));
186 m_SwitchButton
.Invalidate();
188 m_cFilter
.SetCancelBitmaps(IDI_CANCELNORMAL
, IDI_CANCELPRESSED
);
189 m_cFilter
.SetInfoIcon(IDI_FILTEREDIT
);
190 temp
.LoadString(IDS_FILEDIFF_FILTERCUE
);
192 m_cFilter
.SetCueBanner(temp
);
193 if (!m_sFilter
.IsEmpty())
194 m_cFilter
.SetWindowText(m_sFilter
);
196 int c
= ((CHeaderCtrl
*)(m_cFileList
.GetDlgItem(0)))->GetItemCount()-1;
198 m_cFileList
.DeleteColumn(c
--);
200 temp
.LoadString(IDS_FILEDIFF_FILE
);
201 m_cFileList
.InsertColumn(0, temp
);
202 temp
.LoadString(IDS_FILEDIFF_ACTION
);
203 m_cFileList
.InsertColumn(1, temp
);
205 temp
.LoadString(IDS_FILEDIFF_STATADD
);
206 m_cFileList
.InsertColumn(2, temp
);
207 temp
.LoadString(IDS_FILEDIFF_STATDEL
);
208 m_cFileList
.InsertColumn(3, temp
);
211 int maxcol
= ((CHeaderCtrl
*)(m_cFileList
.GetDlgItem(0)))->GetItemCount()-1;
213 for (col
= mincol
; col
<= maxcol
; col
++)
215 m_cFileList
.SetColumnWidth(col
,LVSCW_AUTOSIZE_USEHEADER
);
218 m_cFileList
.SetRedraw(true);
220 AddAnchor(IDC_DIFFSTATIC1
, TOP_LEFT
, TOP_RIGHT
);
221 AddAnchor(IDC_SWITCHLEFTRIGHT
, TOP_RIGHT
);
222 AddAnchor(IDC_FIRSTURL
, TOP_LEFT
, TOP_RIGHT
);
223 AddAnchor(IDC_REV1BTN
, TOP_RIGHT
);
224 //AddAnchor(IDC_DIFFSTATIC2, TOP_LEFT, TOP_RIGHT);
225 AddAnchor(IDC_SECONDURL
, TOP_LEFT
, TOP_RIGHT
);
226 AddAnchor(IDC_REV2BTN
, TOP_RIGHT
);
227 AddAnchor(IDC_FILTER
, TOP_LEFT
, TOP_RIGHT
);
228 AddAnchor(IDC_FILELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
229 AddAnchor(IDC_REV1GROUP
,TOP_LEFT
,TOP_RIGHT
);
230 AddAnchor(IDC_REV2GROUP
,TOP_LEFT
,TOP_RIGHT
);
231 AddAnchor(IDC_REV1EDIT
,TOP_LEFT
);
232 AddAnchor(IDC_REV2EDIT
,TOP_LEFT
);
234 EnableSaveRestore(_T("FileDiffDlg"));
236 if(this->m_strRev1
.IsEmpty())
237 this->m_ctrRev1Edit
.SetWindowText(this->m_rev1
.m_CommitHash
.ToString());
240 if(m_rev1
.GetCommit(this->m_strRev1
))
241 this->m_FileListText
+=this->m_strRev1
+ _T(" is wrong");
243 this->m_ctrRev1Edit
.SetWindowText(m_strRev1
);
246 if(this->m_strRev2
.IsEmpty())
247 this->m_ctrRev2Edit
.SetWindowText(this->m_rev2
.m_CommitHash
.ToString());
250 if(m_rev2
.GetCommit(this->m_strRev2
))
251 this->m_FileListText
+=this->m_strRev2
+ _T(" is wrong");
253 this->m_ctrRev2Edit
.SetWindowText(m_strRev2
);
258 InterlockedExchange(&m_bThreadRunning
, TRUE
);
259 if (AfxBeginThread(DiffThreadEntry
, this)==NULL
)
261 InterlockedExchange(&m_bThreadRunning
, FALSE
);
262 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
265 InterlockedExchange(&m_bLoadingRef
, TRUE
);
266 if (AfxBeginThread(LoadRefThreadEntry
, this)==NULL
)
268 InterlockedExchange(&m_bLoadingRef
, FALSE
);
269 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
272 this->m_cRev1Btn
.AddEntry(_T("RefBrowse"));
273 this->m_cRev1Btn
.AddEntry(_T("Log"));
274 this->m_cRev1Btn
.AddEntry(_T("RefLog"));
276 this->m_cRev2Btn
.AddEntry(_T("RefBrowse"));
277 this->m_cRev2Btn
.AddEntry(_T("Log"));
278 this->m_cRev2Btn
.AddEntry(_T("RefLog"));
280 // Start with focus on file list
281 GetDlgItem(IDC_FILELIST
)->SetFocus();
283 if(m_rev2
.m_CommitHash
.IsEmpty())
284 m_SwitchButton
.EnableWindow(FALSE
);
286 KillTimer(IDT_INPUT
);
291 svn_error_t
* CFileDiffDlg::DiffSummarizeCallback(const CTGitPath
& path
,
292 svn_client_diff_summarize_kind_t kind
,
293 bool propchanged
, svn_node_kind_t node
)
299 fd
.propchanged
= propchanged
;
300 m_arFileList
.push_back(fd
);
305 UINT
CFileDiffDlg::DiffThreadEntry(LPVOID pVoid
)
307 return ((CFileDiffDlg
*)pVoid
)->DiffThread();
310 UINT
CFileDiffDlg::DiffThread()
313 m_cFileList
.ShowText(CString(MAKEINTRESOURCE(IDS_FILEDIFF_WAIT
)));
314 m_cFileList
.DeleteAllItems();
315 m_arFileList
.Clear();
316 EnableInputControl(false);
318 bool bSuccess
= true;
321 // bSuccess = DiffSummarizePeg(m_path1, m_peg, m_rev1, m_rev2, m_depth, m_bIgnoreancestry);
325 // bSuccess = DiffSummarize(m_path1, m_rev1, m_path2, m_rev2, m_depth, m_bIgnoreancestry);
329 // m_cFileList.ShowText(GetLastErrorMessage());
330 // InterlockedExchange(&m_bThreadRunning, FALSE);
335 if( m_rev1
.m_CommitHash
.IsEmpty() || m_rev2
.m_CommitHash
.IsEmpty())
336 g_Git
.RefreshGitIndex();
338 g_Git
.GetCommitDiffList(m_rev1
.m_CommitHash
.ToString(),m_rev2
.m_CommitHash
.ToString(),m_arFileList
);
341 m_cFilter
.GetWindowText(sFilterText
);
342 m_cFileList
.SetRedraw(false);
344 if (m_arFileList
.GetCount()>0)
346 // Highlight first entry in file list
347 m_cFileList
.SetSelectionMark(0);
348 m_cFileList
.SetItemState(0, LVIS_SELECTED
, LVIS_SELECTED
);
352 int maxcol
= ((CHeaderCtrl
*)(m_cFileList
.GetDlgItem(0)))->GetItemCount()-1;
354 for (col
= mincol
; col
<= maxcol
; col
++)
356 m_cFileList
.SetColumnWidth(col
,LVSCW_AUTOSIZE_USEHEADER
);
359 m_cFileList
.ClearText();
360 m_cFileList
.SetRedraw(true);
362 InterlockedExchange(&m_bThreadRunning
, FALSE
);
363 InvalidateRect(NULL
);
365 EnableInputControl(true);
369 int CFileDiffDlg::AddEntry(const CTGitPath
* fd
)
374 int index
= m_cFileList
.GetItemCount();
377 // if (fd->node == svn_node_dir)
378 // icon_idx = m_nIconFolder;
381 icon_idx
= SYS_IMAGE_LIST().GetPathIconIndex(fd
->GetGitPathString());
384 ret
= m_cFileList
.InsertItem(index
, fd
->GetGitPathString(), icon_idx
);
385 m_cFileList
.SetItemText(index
, 1, ((CTGitPath
*)fd
)->GetActionName());
386 m_cFileList
.SetItemText(index
, 2, ((CTGitPath
*)fd
)->m_StatAdd
);
387 m_cFileList
.SetItemText(index
, 3, ((CTGitPath
*)fd
)->m_StatDel
);
392 void CFileDiffDlg::EnableInputControl(bool b
)
394 this->m_ctrRev1Edit
.EnableWindow(b
);
395 this->m_ctrRev2Edit
.EnableWindow(b
);
396 this->m_cRev1Btn
.EnableWindow(b
);
397 this->m_cRev2Btn
.EnableWindow(b
);
398 m_cFilter
.EnableWindow(b
);
399 m_SwitchButton
.EnableWindow(b
);
402 void CFileDiffDlg::DoDiff(int selIndex
, bool blame
)
405 CTGitPath
* fd
= m_arFilteredList
[selIndex
];
406 diff
.Diff(fd
, fd
,this->m_rev1
.m_CommitHash
.ToString(), this->m_rev2
.m_CommitHash
.ToString(), blame
, FALSE
);
410 void CFileDiffDlg::OnNMDblclkFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
413 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
414 int selIndex
= pNMLV
->iItem
;
417 if (selIndex
>= (int)m_arFilteredList
.size())
420 DoDiff(selIndex
, m_bBlame
);
423 void CFileDiffDlg::OnLvnGetInfoTipFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
426 LPNMLVGETINFOTIP pGetInfoTip
= reinterpret_cast<LPNMLVGETINFOTIP
>(pNMHDR
);
427 if (pGetInfoTip
->iItem
>= (int)m_arFilteredList
.size())
430 CString path
= m_path1
.GetGitPathString() + _T("/") + m_arFilteredList
[pGetInfoTip
->iItem
]->GetGitPathString();
431 if (pGetInfoTip
->cchTextMax
> path
.GetLength())
432 _tcsncpy_s(pGetInfoTip
->pszText
, pGetInfoTip
->cchTextMax
, path
, pGetInfoTip
->cchTextMax
);
437 void CFileDiffDlg::OnNMCustomdrawFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
439 NMLVCUSTOMDRAW
* pLVCD
= reinterpret_cast<NMLVCUSTOMDRAW
*>( pNMHDR
);
440 // Take the default processing unless we set this to something else below.
441 *pResult
= CDRF_DODEFAULT
;
443 // First thing - check the draw stage. If it's the control's prepaint
444 // stage, then tell Windows we want messages for every item.
446 if ( CDDS_PREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
448 *pResult
= CDRF_NOTIFYITEMDRAW
;
450 else if ( CDDS_ITEMPREPAINT
== pLVCD
->nmcd
.dwDrawStage
)
452 // This is the prepaint stage for an item. Here's where we set the
453 // item's text color. Our return value will tell Windows to draw the
454 // item itself, but it will use the new color we set here.
456 // Tell Windows to paint the control itself.
457 *pResult
= CDRF_DODEFAULT
;
459 COLORREF crText
= GetSysColor(COLOR_WINDOWTEXT
);
461 if (m_arFilteredList
.size() > pLVCD
->nmcd
.dwItemSpec
)
463 CTGitPath
* fd
= m_arFilteredList
[pLVCD
->nmcd
.dwItemSpec
];
464 switch (fd
->m_Action
)
466 case CTGitPath::LOGACTIONS_ADDED
:
467 crText
= m_colors
.GetColor(CColors::Added
);
469 case CTGitPath::LOGACTIONS_DELETED
:
470 crText
= m_colors
.GetColor(CColors::Deleted
);
472 case CTGitPath::LOGACTIONS_MODIFIED
:
473 crText
= m_colors
.GetColor(CColors::Modified
);
475 //case svn_client_diff_summarize_kind_normal:
477 //if (fd.propchanged)
478 crText
= m_colors
.GetColor(CColors::PropertyChanged
);
482 // Store the color back in the NMLVCUSTOMDRAW struct.
483 pLVCD
->clrText
= crText
;
487 UINT
CFileDiffDlg::LoadRefThread()
489 g_Git
.GetBranchList(m_Reflist
,NULL
,CGit::BRANCH_ALL_F
);
490 g_Git
.GetTagList(m_Reflist
);
492 this->PostMessage(MSG_REF_LOADED
);
493 InterlockedExchange(&m_bLoadingRef
, FALSE
);
497 void CFileDiffDlg::OnContextMenu(CWnd
* pWnd
, CPoint point
)
499 if ((pWnd
==0)||(pWnd
!= &m_cFileList
))
501 if (m_cFileList
.GetSelectedCount() == 0)
503 // if the context menu is invoked through the keyboard, we have to use
504 // a calculated position on where to anchor the menu on
505 if ((point
.x
== -1) && (point
.y
== -1))
508 m_cFileList
.GetItemRect(m_cFileList
.GetSelectionMark(), &rect
, LVIR_LABEL
);
509 m_cFileList
.ClientToScreen(&rect
);
510 point
= rect
.CenterPoint();
513 if (popup
.CreatePopupMenu())
515 popup
.AppendMenuIcon(ID_COMPARE
, IDS_LOG_POPUP_COMPARETWO
, IDI_DIFF
);
516 popup
.AppendMenuIcon(ID_BLAME
, IDS_FILEDIFF_POPBLAME
, IDI_BLAME
);
517 popup
.AppendMenuIcon(ID_LOG
, IDS_FILEDIFF_LOG
, IDI_LOG
);
518 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
519 popup
.AppendMenuIcon(ID_EXPORT
, IDS_FILEDIFF_POPEXPORT
, IDI_EXPORT
);
520 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
521 popup
.AppendMenuIcon(ID_SAVEAS
, IDS_FILEDIFF_POPSAVELIST
, IDI_SAVEAS
);
522 popup
.AppendMenuIcon(ID_CLIPBOARD_PATH
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
523 popup
.AppendMenuIcon(ID_CLIPBOARD_ALL
, IDS_STATUSLIST_CONTEXT_COPYEXT
, IDI_COPYCLIP
);
525 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, point
.x
, point
.y
, this, 0);
526 m_bCancelled
= false;
531 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
534 int index
= m_cFileList
.GetNextSelectedItem(pos
);
535 DoDiff(index
, false);
541 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
544 int index
= m_cFileList
.GetNextSelectedItem(pos
);
545 CAppUtils::LaunchTortoiseBlame(m_arFilteredList
[index
]->GetWinPathString(), m_rev1
.m_CommitHash
.ToString());
551 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
554 int index
= m_cFileList
.GetNextSelectedItem(pos
);
556 cmd
= CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe");
557 cmd
+= _T(" /command:log");
558 cmd
+= _T(" /path:\"")+m_arFilteredList
[index
]->GetWinPathString()+_T("\" ");
559 cmd
+= _T(" /endrev:")+m_rev1
.m_CommitHash
.ToString();
560 CAppUtils::LaunchApplication(cmd
,IDS_ERR_PROC
,false);
566 if (m_cFileList
.GetSelectedCount() > 0)
571 if (!CAppUtils::FileOpenSave(pathSave
, NULL
, IDS_REPOBROWSE_SAVEAS
, IDS_COMMONFILEFILTER
, false, m_hWnd
))
575 savePath
= CTGitPath(pathSave
);
577 // now open the selected file for writing
580 CStdioFile
file(savePath
.GetWinPathString(), CFile::typeBinary
| CFile::modeReadWrite
| CFile::modeCreate
);
581 // temp.Format(IDS_FILEDIFF_CHANGEDLISTINTRO, (LPCTSTR)m_path1.GetGitPathString(), (LPCTSTR)m_rev1.ToString(), (LPCTSTR)m_path2.GetGitPathString(), (LPCTSTR)m_rev2.ToString());
582 file
.WriteString(temp
+ _T("\n"));
583 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
586 int index
= m_cFileList
.GetNextSelectedItem(pos
);
587 CTGitPath
* fd
= m_arFilteredList
[index
];
588 file
.WriteString(fd
->GetGitPathString());
589 file
.WriteString(_T("\n"));
593 catch (CFileException
* pE
)
600 case ID_CLIPBOARD_PATH
:
602 CopySelectionToClipboard();
606 case ID_CLIPBOARD_ALL
:
608 CopySelectionToClipboard(TRUE
);
613 // export all changed files to a folder
614 CBrowseFolder browseFolder
;
615 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
616 if (browseFolder
.Show(GetSafeHwnd(), m_strExportDir
) == CBrowseFolder::OK
)
618 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
621 int index
= m_cFileList
.GetNextSelectedItem(pos
);
622 CTGitPath
* fd
= m_arFilteredList
[index
];
623 // we cannot export directories or folders
624 if (fd
->m_Action
== CTGitPath::LOGACTIONS_DELETED
|| fd
->IsDirectory())
626 CAppUtils::CreateMultipleDirectory(m_strExportDir
+ _T("\\") + fd
->GetDirectory().GetWinPathString());
627 CString filename
= m_strExportDir
+ _T("\\") + fd
->GetWinPathString();
628 if(m_rev1
.m_CommitHash
.ToString() == GIT_REV_ZERO
)
630 if(!CopyFile(g_Git
.m_CurrentDir
+ _T("\\") + fd
->GetWinPath(), filename
, false))
632 MessageBox(CFormatMessageWrapper(), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
638 if(g_Git
.GetOneFile(m_rev1
.m_CommitHash
, *fd
, filename
))
641 out
.Format(_T("Fail checkout one file %s;%s"), m_rev1
.m_CommitHash
.ToString(), fd
->GetWinPath());
642 CMessageBox::Show(NULL
, out
, _T("TortoiseGit"), MB_OK
);
656 BOOL
CFileDiffDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
658 if (pWnd
!= &m_cFileList
)
659 return CResizableStandAloneDialog::OnSetCursor(pWnd
, nHitTest
, message
);
660 if (m_bThreadRunning
== 0)
662 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
664 return CResizableStandAloneDialog::OnSetCursor(pWnd
, nHitTest
, message
);
666 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_WAIT
));
671 void CFileDiffDlg::OnEnSetfocusFirsturl()
673 GetDlgItem(IDC_FIRSTURL
)->HideCaret();
676 void CFileDiffDlg::OnEnSetfocusSecondurl()
678 GetDlgItem(IDC_SECONDURL
)->HideCaret();
682 void CFileDiffDlg::OnBnClickedSwitchleftright()
685 if (m_bThreadRunning
)
689 CString sFilterString
;
690 m_cFilter
.GetWindowText(sFilterString
);
692 m_cFileList
.SetRedraw(false);
693 m_cFileList
.DeleteAllItems();
694 for (int i
=0; i
<(int)m_arFileList
.GetCount(); ++i
)
696 CTGitPath fd
= m_arFileList
[i
];
697 if (fd
.m_Action
== CTGitPath::LOGACTIONS_ADDED
)
698 fd
.m_Action
= CTGitPath::LOGACTIONS_DELETED
;
699 else if (fd
.m_Action
== CTGitPath::LOGACTIONS_DELETED
)
700 fd
.m_Action
= CTGitPath::LOGACTIONS_ADDED
;
701 std::swap(fd
.m_StatAdd
, fd
.m_StatDel
);
702 (CTGitPath
&)m_arFileList
[i
] = fd
;
704 Filter(sFilterString
);
707 m_cFileList
.SetRedraw(true);
708 CTGitPath path
= m_path1
;
716 this->m_ctrRev1Edit
.GetWindowText(str1
);
717 this->m_ctrRev2Edit
.GetWindowText(str2
);
719 this->m_ctrRev1Edit
.SetWindowText(str2
);
720 this->m_ctrRev2Edit
.SetWindowText(str1
);
723 //KillTimer(IDT_INPUT);
726 void CFileDiffDlg::SetURLLabels(int mask
)
729 // m_cRev1Btn.SetWindowText(m_rev1.m_CommitHash.ToString().Left(6));
730 // m_cRev2Btn.SetWindowText(m_rev2.m_CommitHash.ToString().Left(6));
734 SetDlgItemText(IDC_FIRSTURL
, m_rev1
.m_CommitHash
.ToString().Left(8)+_T(": ")+m_rev1
.GetSubject());
735 m_tooltips
.AddTool(IDC_FIRSTURL
,
736 CLoglistUtils::FormatDateAndTime(m_rev1
.GetAuthorDate(), DATE_SHORTDATE
, false) + _T(" ") + m_rev1
.GetAuthorName());
742 SetDlgItemText(IDC_SECONDURL
,m_rev2
.m_CommitHash
.ToString().Left(8)+_T(": ")+m_rev2
.GetSubject());
744 m_tooltips
.AddTool(IDC_SECONDURL
,
745 CLoglistUtils::FormatDateAndTime(m_rev2
.GetAuthorDate(), DATE_SHORTDATE
, false) + _T(" ") + m_rev2
.GetAuthorName());
748 this->GetDlgItem(IDC_REV2GROUP
)->SetWindowText(_T("Version 2 (Base)"));
749 this->GetDlgItem(IDC_REV1GROUP
)->SetWindowText(_T("Version 1"));
751 if( (mask
&0x3) == 0x3)
752 if(m_rev2
.GetCommitterDate() > m_rev1
.GetCommitterDate())
754 this->GetDlgItem(IDC_REV2GROUP
)->SetWindowText(_T("Version 2 (Base) (Commit Date New)"));
758 this->GetDlgItem(IDC_REV1GROUP
)->SetWindowText(_T("Version 1 (Commit Data New)"));
762 void CFileDiffDlg::ClearURLabels(int mask
)
766 SetDlgItemText(IDC_FIRSTURL
, _T(""));
767 m_tooltips
.AddTool(IDC_FIRSTURL
, _T(""));
772 SetDlgItemText(IDC_SECONDURL
, _T(""));
773 m_tooltips
.AddTool(IDC_SECONDURL
, _T(""));
776 BOOL
CFileDiffDlg::PreTranslateMessage(MSG
* pMsg
)
778 m_tooltips
.RelayEvent(pMsg
);
779 if (pMsg
->message
== WM_KEYDOWN
)
781 switch (pMsg
->wParam
)
785 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
787 // select all entries
788 for (int i
=0; i
<m_cFileList
.GetItemCount(); ++i
)
790 m_cFileList
.SetItemState(i
, LVIS_SELECTED
, LVIS_SELECTED
);
799 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
801 CopySelectionToClipboard();
808 if (GetFocus() == GetDlgItem(IDC_FILELIST
))
810 // Return pressed in file list. Show diff, as for double click
811 int selIndex
= m_cFileList
.GetSelectionMark();
812 if ((selIndex
>= 0) && (selIndex
< (int)m_arFileList
.GetCount()))
813 DoDiff(selIndex
, m_bBlame
);
820 return __super::PreTranslateMessage(pMsg
);
823 void CFileDiffDlg::OnCancel()
825 if (m_bThreadRunning
)
833 void CFileDiffDlg::OnHdnItemclickFilelist(NMHDR
*pNMHDR
, LRESULT
*pResult
)
835 LPNMHEADER phdr
= reinterpret_cast<LPNMHEADER
>(pNMHDR
);
836 if (m_bThreadRunning
)
839 if (m_nSortedColumn
== phdr
->iItem
)
840 m_bAscending
= !m_bAscending
;
843 m_nSortedColumn
= phdr
->iItem
;
847 m_cFileList
.SetRedraw(FALSE
);
848 m_cFileList
.DeleteAllItems();
849 m_cFilter
.GetWindowText(temp
);
852 CHeaderCtrl
* pHeader
= m_cFileList
.GetHeaderCtrl();
853 HDITEM HeaderItem
= {0};
854 HeaderItem
.mask
= HDI_FORMAT
;
855 for (int i
=0; i
<pHeader
->GetItemCount(); ++i
)
857 pHeader
->GetItem(i
, &HeaderItem
);
858 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
859 pHeader
->SetItem(i
, &HeaderItem
);
861 pHeader
->GetItem(m_nSortedColumn
, &HeaderItem
);
862 HeaderItem
.fmt
|= (m_bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
863 pHeader
->SetItem(m_nSortedColumn
, &HeaderItem
);
865 m_cFileList
.SetRedraw(TRUE
);
870 void CFileDiffDlg::Sort()
872 if(m_arFileList
.GetCount() < 2)
877 std::sort(m_arFileList
.m_paths
.begin(), m_arFileList
.m_paths
.end(), &CFileDiffDlg::SortCompare
);
880 bool CFileDiffDlg::SortCompare(const CTGitPath
& Data1
, const CTGitPath
& Data2
)
884 switch (m_nSortedColumn
)
886 case 0: //path column
887 result
= Data1
.GetWinPathString().Compare(Data2
.GetWinPathString());
889 case 1: //action column
890 result
= Data1
.m_Action
- Data2
.m_Action
;
893 d1
= CSorter::A2L(Data1
.m_StatAdd
);
894 d2
= CSorter::A2L(Data2
.m_StatAdd
);
898 d1
= CSorter::A2L(Data1
.m_StatDel
);;
899 d2
= CSorter::A2L(Data2
.m_StatDel
);
912 void CFileDiffDlg::OnBnClickedRev1btn()
914 ClickRevButton(&this->m_cRev1Btn
,&this->m_rev1
, &this->m_ctrRev1Edit
);
917 void CFileDiffDlg::ClickRevButton(CMenuButton
*button
, GitRev
*rev
, CACEdit
*edit
)
919 int entry
=button
->GetCurrentEntry();
920 if(entry
== 0) /* Browse Refence*/
923 CString str
= CBrowseRefsDlg::PickRef();
927 if(FillRevFromString(rev
,str
))
930 edit
->SetWindowText(str
);
934 if(entry
== 1) /*Log*/
938 if(dlg
.DoModal() == IDOK
)
940 if( dlg
.GetSelectedHash().IsEmpty() )
943 if(FillRevFromString(rev
,dlg
.GetSelectedHash()))
946 edit
->SetWindowText(dlg
.GetSelectedHash());
953 if(entry
== 2) /*RefLog*/
956 if(dlg
.DoModal() == IDOK
)
958 if(FillRevFromString(rev
,dlg
.m_SelectedHash
))
961 edit
->SetWindowText(dlg
.m_SelectedHash
);
970 InterlockedExchange(&m_bThreadRunning
, TRUE
);
971 if (AfxBeginThread(DiffThreadEntry
, this)==NULL
)
973 InterlockedExchange(&m_bThreadRunning
, FALSE
);
974 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
976 KillTimer(IDT_INPUT
);
979 void CFileDiffDlg::OnBnClickedRev2btn()
981 ClickRevButton(&this->m_cRev2Btn
,&this->m_rev2
, &this->m_ctrRev2Edit
);
984 LRESULT
CFileDiffDlg::OnClickedCancelFilter(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
986 if (m_bThreadRunning
)
988 SetTimer(IDT_FILTER
, 1000, NULL
);
992 KillTimer(IDT_FILTER
);
994 m_cFileList
.SetRedraw(FALSE
);
995 m_arFilteredList
.clear();
996 m_cFileList
.DeleteAllItems();
1000 m_cFileList
.SetRedraw(TRUE
);
1004 void CFileDiffDlg::OnEnChangeFilter()
1006 SetTimer(IDT_FILTER
, 1000, NULL
);
1009 void CFileDiffDlg::OnTimer(UINT_PTR nIDEvent
)
1011 if (m_bThreadRunning
)
1014 if( nIDEvent
== IDT_FILTER
)
1016 CString sFilterText
;
1017 KillTimer(IDT_FILTER
);
1018 m_cFilter
.GetWindowText(sFilterText
);
1020 m_cFileList
.SetRedraw(FALSE
);
1021 m_cFileList
.DeleteAllItems();
1023 Filter(sFilterText
);
1025 m_cFileList
.SetRedraw(TRUE
);
1027 __super::OnTimer(nIDEvent
);
1030 if( nIDEvent
== IDT_INPUT
)
1032 KillTimer(IDT_INPUT
);
1033 TRACE(_T("Input Timer\r\n"));
1038 this->m_ctrRev1Edit
.GetWindowText(str
);
1039 if( !gitrev
.GetCommit(str
) )
1041 this->m_rev1
=gitrev
;
1045 this->m_ctrRev2Edit
.GetWindowText(str
);
1047 if( !gitrev
.GetCommit(str
) )
1049 this->m_rev2
=gitrev
;
1053 this->SetURLLabels(mask
);
1058 InterlockedExchange(&m_bThreadRunning
, TRUE
);
1059 if (AfxBeginThread(DiffThreadEntry
, this)==NULL
)
1061 InterlockedExchange(&m_bThreadRunning
, FALSE
);
1062 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
1068 void CFileDiffDlg::Filter(CString sFilterText
)
1070 sFilterText
.MakeLower();
1072 m_arFilteredList
.clear();
1074 for (int i
=0;i
<m_arFileList
.GetCount();i
++)
1076 CString sPath
= m_arFileList
[i
].GetGitPathString();
1078 if (sPath
.Find(sFilterText
) >= 0)
1080 m_arFilteredList
.push_back((CTGitPath
*)&(m_arFileList
[i
]));
1083 for (std::vector
<CTGitPath
*>::const_iterator it
= m_arFilteredList
.begin(); it
!= m_arFilteredList
.end(); ++it
)
1089 void CFileDiffDlg::CopySelectionToClipboard(BOOL isFull
)
1091 // copy all selected paths to the clipboard
1092 POSITION pos
= m_cFileList
.GetFirstSelectedItemPosition();
1094 CString sTextForClipboard
;
1095 while ((index
= m_cFileList
.GetNextSelectedItem(pos
)) >= 0)
1097 sTextForClipboard
+= m_cFileList
.GetItemText(index
, 0);
1098 sTextForClipboard
+= _T("\t");
1102 sTextForClipboard
+= _T("\r\n");
1107 sTextForClipboard
+= m_cFileList
.GetItemText(index
, 1);
1108 sTextForClipboard
+= _T("\t");
1109 sTextForClipboard
+= m_cFileList
.GetItemText(index
, 2);
1110 sTextForClipboard
+= _T("\t");
1111 sTextForClipboard
+= m_cFileList
.GetItemText(index
, 3);
1112 sTextForClipboard
+= _T("\r\n");
1115 CStringUtils::WriteAsciiStringToClipboard(sTextForClipboard
);
1119 LRESULT
CFileDiffDlg::OnRefLoad(WPARAM wParam
, LPARAM lParam
)
1121 UNREFERENCED_PARAMETER(wParam
);
1122 UNREFERENCED_PARAMETER(lParam
);
1123 for(int i
=0;i
<m_Reflist
.size();i
++)
1125 CString str
=m_Reflist
[i
];
1127 if(str
.Find(_T("remotes/")) == 0)
1130 m_ctrRev1Edit
.AddSearchString(str
);
1131 m_ctrRev2Edit
.AddSearchString(str
);
1136 BOOL
CFileDiffDlg::DestroyWindow()
1138 return CResizableStandAloneDialog::DestroyWindow();
1141 LRESULT
CFileDiffDlg::OnEnUpdate(WPARAM
/*wParam*/, LPARAM lParam
)
1143 if(lParam
== IDC_REV1EDIT
)
1145 OnTextUpdate(&this->m_ctrRev1Edit
);
1148 if(lParam
== IDC_REV2EDIT
)
1150 OnTextUpdate(&this->m_ctrRev2Edit
);
1151 ClearURLabels(1<<1);
1156 void CFileDiffDlg::OnTextUpdate(CACEdit
* /*pEdit*/)
1158 SetTimer(IDT_INPUT
, 1000, NULL
);
1159 this->m_cFileList
.ShowText(_T("Wait For input validate version"));