1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - TortoiseGit
4 // Copyright (C) 2012 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2012 - TortoiseSVN
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 // RepositoryBrowser.cpp : implementation file
25 #include "TortoiseProc.h"
26 #include "RepositoryBrowser.h"
30 #include "UnicodeUtils.h"
31 #include "SysImageList.h"
35 #include "PathUtils.h"
36 #include "StringUtils.h"
39 void SetSortArrowA(CListCtrl
* control
, int nColumn
, bool bAscending
)
45 CHeaderCtrl
* pHeader
= control
->GetHeaderCtrl();
46 HDITEM HeaderItem
= {0};
47 HeaderItem
.mask
= HDI_FORMAT
;
48 for (int i
= 0; i
< pHeader
->GetItemCount(); ++i
)
50 pHeader
->GetItem(i
, &HeaderItem
);
51 HeaderItem
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
52 pHeader
->SetItem(i
, &HeaderItem
);
56 pHeader
->GetItem(nColumn
, &HeaderItem
);
57 HeaderItem
.fmt
|= (bAscending
? HDF_SORTUP
: HDF_SORTDOWN
);
58 pHeader
->SetItem(nColumn
, &HeaderItem
);
62 class CRepoListCompareFunc
65 CRepoListCompareFunc(CListCtrl
* pList
, int col
, bool desc
)
71 static int CALLBACK
StaticCompare(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
73 return ((CRepoListCompareFunc
*) lParamSort
)->Compare(lParam1
, lParam2
);
76 int Compare(LPARAM lParam1
, LPARAM lParam2
)
78 CShadowFilesTree
* pLeft
= (CShadowFilesTree
*)m_pList
->GetItemData(lParam1
);
79 CShadowFilesTree
* pRight
= (CShadowFilesTree
*)m_pList
->GetItemData(lParam2
);
84 case CRepositoryBrowser::eCol_Name
:
85 result
= SortStrCmp(pLeft
->m_sName
, pRight
->m_sName
);
88 case CRepositoryBrowser::eCol_Extension
:
89 result
= m_pList
->GetItemText(static_cast<int>(lParam1
), 1).CompareNoCase(m_pList
->GetItemText(static_cast<int>(lParam2
), 1));
90 if (result
== 0) // if extensions are the same, use the filename to sort
91 result
= SortStrCmp(pRight
->m_sName
, pRight
->m_sName
);
94 case CRepositoryBrowser::eCol_FileSize
:
95 if (pLeft
->m_iSize
> pRight
->m_iSize
)
97 else if (pLeft
->m_iSize
< pRight
->m_iSize
)
100 result
= SortStrCmp(pLeft
->m_sName
, pRight
->m_sName
);
106 if (pLeft
->m_bFolder
!= pRight
->m_bFolder
)
108 if (pRight
->m_bFolder
)
116 int SortStrCmp(CString
&left
, CString
&right
)
118 if (CRepositoryBrowser::s_bSortLogical
)
119 return StrCmpLogicalW(left
, right
);
120 return StrCmpI(left
, right
);
128 // CRepositoryBrowser dialog
130 bool CRepositoryBrowser::s_bSortLogical
= true;
132 IMPLEMENT_DYNAMIC(CRepositoryBrowser
, CResizableStandAloneDialog
)
134 CRepositoryBrowser::CRepositoryBrowser(CString rev
, CWnd
* pParent
/*=NULL*/)
135 : CResizableStandAloneDialog(CRepositoryBrowser::IDD
, pParent
)
137 , m_currSortDesc(false)
143 CRepositoryBrowser::~CRepositoryBrowser()
147 void CRepositoryBrowser::DoDataExchange(CDataExchange
* pDX
)
149 CDialog::DoDataExchange(pDX
);
150 DDX_Control(pDX
, IDC_REPOTREE
, m_RepoTree
);
151 DDX_Control(pDX
, IDC_REPOLIST
, m_RepoList
);
155 BEGIN_MESSAGE_MAP(CRepositoryBrowser
, CResizableStandAloneDialog
)
156 ON_NOTIFY(TVN_SELCHANGED
, IDC_REPOTREE
, &CRepositoryBrowser::OnTvnSelchangedRepoTree
)
158 ON_NOTIFY(LVN_COLUMNCLICK
, IDC_REPOLIST
, &CRepositoryBrowser::OnLvnColumnclickRepoList
)
159 ON_NOTIFY(NM_DBLCLK
, IDC_REPOLIST
, &CRepositoryBrowser::OnNMDblclk_RepoList
)
160 ON_BN_CLICKED(IDC_BUTTON_REVISION
, &CRepositoryBrowser::OnBnClickedButtonRevision
)
168 // CRepositoryBrowser message handlers
170 BOOL
CRepositoryBrowser::OnInitDialog()
172 CResizableStandAloneDialog::OnInitDialog();
173 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
175 AddAnchor(IDC_STATIC_REPOURL
, TOP_LEFT
);
176 AddAnchor(IDC_REPOBROWSER_URL
, TOP_LEFT
, TOP_RIGHT
);
177 AddAnchor(IDC_STATIC_REF
, TOP_RIGHT
);
178 AddAnchor(IDC_BUTTON_REVISION
, TOP_RIGHT
);
179 AddAnchor(IDC_REPOTREE
, TOP_LEFT
, BOTTOM_LEFT
);
180 AddAnchor(IDC_REPOLIST
, TOP_LEFT
, BOTTOM_RIGHT
);
181 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
182 AddAnchor(IDOK
, BOTTOM_RIGHT
);
183 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
185 CRepositoryBrowser::s_bSortLogical
= !CRegDWORD(L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_CURRENT_USER
);
186 if (CRepositoryBrowser::s_bSortLogical
)
187 CRepositoryBrowser::s_bSortLogical
= !CRegDWORD(L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_LOCAL_MACHINE
);
190 temp
.LoadString(IDS_STATUSLIST_COLFILENAME
);
191 m_RepoList
.InsertColumn(eCol_Name
, temp
, 0, 150);
192 temp
.LoadString(IDS_STATUSLIST_COLEXT
);
193 m_RepoList
.InsertColumn(eCol_Extension
, temp
, 0, 100);
194 temp
.LoadString(IDS_LOG_SIZE
);
195 m_RepoList
.InsertColumn(eCol_FileSize
, temp
, 0, 100);
197 // set up the list control
198 // set the extended style of the list control
199 // the style LVS_EX_FULLROWSELECT interferes with the background watermark image but it's more important to be able to select in the whole row.
200 CRegDWORD
regFullRowSelect(_T("Software\\TortoiseGit\\FullRowSelect"), TRUE
);
201 DWORD exStyle
= LVS_EX_HEADERDRAGDROP
| LVS_EX_DOUBLEBUFFER
| LVS_EX_INFOTIP
| LVS_EX_SUBITEMIMAGES
;
202 if (DWORD(regFullRowSelect
))
203 exStyle
|= LVS_EX_FULLROWSELECT
;
204 m_RepoList
.SetExtendedStyle(exStyle
);
205 m_RepoList
.SetImageList(&SYS_IMAGE_LIST(), LVSIL_SMALL
);
206 CAppUtils::SetListCtrlBackgroundImage(m_RepoList
.GetSafeHwnd(), IDI_REPOBROWSER_BKG
);
208 m_RepoTree
.SetImageList(&SYS_IMAGE_LIST(), TVSIL_NORMAL
);
209 if (SysInfo::Instance().IsVistaOrLater())
211 DWORD exStyle
= TVS_EX_FADEINOUTEXPANDOS
| TVS_EX_AUTOHSCROLL
| TVS_EX_DOUBLEBUFFER
;
212 m_RepoTree
.SetExtendedStyle(exStyle
, exStyle
);
215 SetWindowTheme(m_RepoTree
.GetSafeHwnd(), L
"Explorer", NULL
);
216 SetWindowTheme(m_RepoList
.GetSafeHwnd(), L
"Explorer", NULL
);
218 m_nIconFolder
= SYS_IMAGE_LIST().GetDirIconIndex();
219 m_nOpenIconFolder
= SYS_IMAGE_LIST().GetDirOpenIconIndex();
221 EnableSaveRestore(L
"Reposbrowser");
223 DWORD xPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RepobrowserDivider"), 0);
227 GetDlgItem(IDC_REPOTREE
)->GetClientRect(&rc
);
228 xPos
= rc
.right
- rc
.left
;
231 HandleDividerMove(CPoint(xPos
+ 20, 10), false);
233 CString sWindowTitle
;
234 GetWindowText(sWindowTitle
);
235 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
237 m_bHasWC
= !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
);
241 m_RepoList
.SetFocus();
246 void CRepositoryBrowser::OnOK()
248 SaveDividerPosition();
249 CResizableStandAloneDialog::OnOK();
252 void CRepositoryBrowser::OnCancel()
254 SaveDividerPosition();
255 CResizableStandAloneDialog::OnCancel();
258 void CRepositoryBrowser::OnNMDblclk_RepoList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
260 UNREFERENCED_PARAMETER(pNMHDR
);
263 LPNMITEMACTIVATE pNmItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
264 if (pNmItemActivate
->iItem
< 0)
267 CShadowFilesTree
* pItem
= (CShadowFilesTree
*)m_RepoList
.GetItemData(pNmItemActivate
->iItem
);
271 if (!pItem
->m_bFolder
)
273 OpenFile(pItem
->GetFullName(), OPEN
);
278 FillListCtrlForShadowTree(pItem
);
279 m_RepoTree
.SelectItem(pItem
->m_hTree
);
283 void CRepositoryBrowser::Refresh()
285 m_RepoTree
.DeleteAllItems();
286 m_RepoList
.DeleteAllItems();
287 m_TreeRoot
.m_ShadowTree
.clear();
288 m_TreeRoot
.m_sName
= "";
289 m_TreeRoot
.m_bFolder
= true;
291 TVINSERTSTRUCT tvinsert
= {0};
292 tvinsert
.hParent
= TVI_ROOT
;
293 tvinsert
.hInsertAfter
= TVI_ROOT
;
294 tvinsert
.itemex
.mask
= TVIF_DI_SETITEM
| TVIF_PARAM
| TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_STATE
;
295 tvinsert
.itemex
.pszText
= L
"/";
296 tvinsert
.itemex
.lParam
= (LPARAM
)&m_TreeRoot
;
297 tvinsert
.itemex
.iImage
= m_nIconFolder
;
298 tvinsert
.itemex
.iSelectedImage
= m_nOpenIconFolder
;
299 m_TreeRoot
.m_hTree
= m_RepoTree
.InsertItem(&tvinsert
);
301 ReadTree(&m_TreeRoot
);
302 m_RepoTree
.Expand(m_TreeRoot
.m_hTree
, TVE_EXPAND
);
303 FillListCtrlForShadowTree(&m_TreeRoot
);
304 m_RepoTree
.SelectItem(m_TreeRoot
.m_hTree
);
307 int CRepositoryBrowser::ReadTreeRecursive(git_repository
&repo
, git_tree
* tree
, CShadowFilesTree
* treeroot
)
309 size_t count
= git_tree_entrycount(tree
);
311 for (int i
= 0; i
< count
; i
++)
313 const git_tree_entry
*entry
= git_tree_entry_byindex(tree
, i
);
316 int mode
= git_tree_entry_attributes(entry
);
318 CString base
= CUnicodeUtils::GetUnicode(git_tree_entry_name(entry
), CP_UTF8
);
320 git_object
*object
= NULL
;
321 git_tree_entry_2object(&object
, &repo
, entry
);
325 CShadowFilesTree
* pNextTree
= &treeroot
->m_ShadowTree
[base
];
326 pNextTree
->m_sName
= base
;
327 pNextTree
->m_pParent
= treeroot
;
331 pNextTree
->m_bFolder
= true;
333 TVINSERTSTRUCT tvinsert
= {0};
334 tvinsert
.hParent
= treeroot
->m_hTree
;
335 tvinsert
.hInsertAfter
= TVI_SORT
;
336 tvinsert
.itemex
.mask
= TVIF_DI_SETITEM
| TVIF_PARAM
| TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_STATE
;
337 tvinsert
.itemex
.pszText
= base
.GetBuffer(base
.GetLength());
338 tvinsert
.itemex
.lParam
= (LPARAM
)pNextTree
;
339 tvinsert
.itemex
.iImage
= m_nIconFolder
;
340 tvinsert
.itemex
.iSelectedImage
= m_nOpenIconFolder
;
341 pNextTree
->m_hTree
= m_RepoTree
.InsertItem(&tvinsert
);
342 base
.ReleaseBuffer();
344 ReadTreeRecursive(repo
, (git_tree
*)object
, pNextTree
);
348 const git_oid
* oid
= git_object_id(object
);
351 git_blob_lookup(&blob
, &repo
, oid
);
355 pNextTree
->m_iSize
= git_blob_rawsize(blob
);
359 git_object_free(object
);
365 int CRepositoryBrowser::ReadTree(CShadowFilesTree
* treeroot
)
367 CStringA gitdir
= CUnicodeUtils::GetMulti(g_Git
.m_CurrentDir
, CP_UTF8
);
368 git_repository
*repository
= NULL
;
369 git_commit
*commit
= NULL
;
370 git_tree
* tree
= NULL
;
374 ret
= git_repository_open(&repository
, gitdir
.GetBuffer());
378 CGitHash hash
= g_Git
.GetHash(m_sRevision
);
379 ret
= git_commit_lookup(&commit
, repository
, (git_oid
*) hash
.m_hash
);
383 ret
= git_commit_tree(&tree
, commit
);
387 ret
= ReadTreeRecursive(*repository
, tree
, treeroot
);
391 this->GetDlgItem(IDC_BUTTON_REVISION
)->SetWindowText(m_sRevision
);
398 git_commit_free(commit
);
401 git_repository_free(repository
);
406 void CRepositoryBrowser::OnTvnSelchangedRepoTree(NMHDR
*pNMHDR
, LRESULT
*pResult
)
408 LPNMTREEVIEW pNMTreeView
= reinterpret_cast<LPNMTREEVIEW
>(pNMHDR
);
411 FillListCtrlForTreeNode(pNMTreeView
->itemNew
.hItem
);
414 void CRepositoryBrowser::FillListCtrlForTreeNode(HTREEITEM treeNode
)
416 m_RepoList
.DeleteAllItems();
418 CShadowFilesTree
* pTree
= (CShadowFilesTree
*)(m_RepoTree
.GetItemData(treeNode
));
425 CString url
= _T("/") + pTree
->GetFullName();
426 GetDlgItem(IDC_REPOBROWSER_URL
)->SetWindowText(url
);
428 FillListCtrlForShadowTree(pTree
);
431 void CRepositoryBrowser::FillListCtrlForShadowTree(CShadowFilesTree
* pTree
)
433 for (TShadowFilesTreeMap::iterator itShadowTree
= pTree
->m_ShadowTree
.begin(); itShadowTree
!= pTree
->m_ShadowTree
.end(); ++itShadowTree
)
435 int icon
= m_nIconFolder
;
436 if (!(*itShadowTree
).second
.m_bFolder
)
437 icon
= SYS_IMAGE_LIST().GetFileIconIndex((*itShadowTree
).second
.m_sName
);
439 int indexItem
= m_RepoList
.InsertItem(m_RepoList
.GetItemCount(), (*itShadowTree
).second
.m_sName
, icon
);
441 m_RepoList
.SetItemData(indexItem
, (DWORD_PTR
)&(*itShadowTree
).second
);
442 if (!(*itShadowTree
).second
.m_bFolder
)
446 temp
= CPathUtils::GetFileExtFromPath((*itShadowTree
).second
.m_sName
);
447 m_RepoList
.SetItemText(indexItem
, eCol_Extension
, temp
);
449 StrFormatByteSize((*itShadowTree
).second
.m_iSize
, temp
.GetBuffer(20), 20);
450 temp
.ReleaseBuffer();
451 m_RepoList
.SetItemText(indexItem
, eCol_FileSize
, temp
);
455 CRepoListCompareFunc
compareFunc(&m_RepoList
, m_currSortCol
, m_currSortDesc
);
456 m_RepoList
.SortItemsEx(&CRepoListCompareFunc::StaticCompare
, (DWORD_PTR
)&compareFunc
);
458 SetSortArrowA(&m_RepoList
, m_currSortCol
, !m_currSortDesc
);
461 void CRepositoryBrowser::OnContextMenu(CWnd
* pWndFrom
, CPoint point
)
463 if (pWndFrom
== &m_RepoList
)
464 OnContextMenu_RepoList(point
);
465 else if (pWndFrom
== &m_RepoTree
)
466 OnContextMenu_RepoTree(point
);
469 void CRepositoryBrowser::OnContextMenu_RepoTree(CPoint point
)
471 CPoint clientPoint
= point
;
472 m_RepoTree
.ScreenToClient(&clientPoint
);
474 HTREEITEM hTreeItem
= m_RepoTree
.HitTest(clientPoint
);
475 if (hTreeItem
== NULL
)
478 TShadowFilesTreeList selectedLeafs
;
479 selectedLeafs
.push_back((CShadowFilesTree
*)m_RepoTree
.GetItemData(hTreeItem
));
481 ShowContextMenu(point
, selectedLeafs
, ONLY_FOLDERS
);
484 void CRepositoryBrowser::OnContextMenu_RepoList(CPoint point
)
486 TShadowFilesTreeList selectedLeafs
;
487 selectedLeafs
.reserve(m_RepoList
.GetSelectedCount());
489 bool folderSelected
= false;
490 bool filesSelected
= false;
492 POSITION pos
= m_RepoList
.GetFirstSelectedItemPosition();
495 CShadowFilesTree
* item
= (CShadowFilesTree
*)m_RepoList
.GetItemData(m_RepoList
.GetNextSelectedItem(pos
));
497 folderSelected
= true;
499 filesSelected
= true;
500 selectedLeafs
.push_back(item
);
503 eSelectionType selType
= ONLY_FILES
;
504 if (folderSelected
&& filesSelected
)
506 else if (folderSelected
)
507 selType
= ONLY_FOLDERS
;
509 ShowContextMenu(point
, selectedLeafs
, selType
);
512 void CRepositoryBrowser::ShowContextMenu(CPoint point
, TShadowFilesTreeList
&selectedLeafs
, eSelectionType selType
)
515 popupMenu
.CreatePopupMenu();
517 bool bAddSeparator
= false;
519 if (selectedLeafs
.size() == 1)
521 popupMenu
.AppendMenuIcon(eCmd_Open
, IDS_REPOBROWSE_OPEN
, IDI_OPEN
);
522 popupMenu
.SetDefaultItem(eCmd_Open
, FALSE
);
523 if (selType
== ONLY_FILES
)
525 popupMenu
.AppendMenuIcon(eCmd_OpenWith
, IDS_LOG_POPUP_OPENWITH
, IDI_OPEN
);
526 popupMenu
.AppendMenuIcon(eCmd_OpenWithAlternativeEditor
, IDS_LOG_POPUP_VIEWREV
);
529 popupMenu
.AppendMenu(MF_SEPARATOR
);
531 if (m_bHasWC
&& selType
== ONLY_FILES
)
533 popupMenu
.AppendMenuIcon(eCmd_CompareWC
, IDS_LOG_POPUP_COMPARE
, IDI_DIFF
);
534 bAddSeparator
= true;
538 popupMenu
.AppendMenu(MF_SEPARATOR
);
539 bAddSeparator
= false;
542 temp
.LoadString(IDS_MENULOG
);
543 popupMenu
.AppendMenuIcon(eCmd_ViewLog
, temp
, IDI_LOG
);
545 if (selType
== ONLY_FILES
)
547 popupMenu
.AppendMenu(MF_SEPARATOR
);
548 temp
.LoadString(IDS_LOG_POPUP_SAVE
);
549 popupMenu
.AppendMenuIcon(eCmd_SaveAs
, temp
, IDI_SAVEAS
);
552 bAddSeparator
= true;
555 if (selType
== ONLY_FILES
&& m_bHasWC
)
557 popupMenu
.AppendMenuIcon(eCmd_Revert
, IDS_LOG_POPUP_REVERTTOREV
, IDI_REVERT
);
558 bAddSeparator
= true;
562 popupMenu
.AppendMenu(MF_SEPARATOR
);
563 bAddSeparator
= false;
565 popupMenu
.AppendMenuIcon(eCmd_CopyPath
, IDS_STATUSLIST_CONTEXT_COPY
, IDI_COPYCLIP
);
567 eCmd cmd
= (eCmd
)popupMenu
.TrackPopupMenuEx(TPM_LEFTALIGN
|TPM_RETURNCMD
, point
.x
, point
.y
, this, 0);
573 sCmd
.Format(_T("/command:log /path:\"%s\\%s\""), g_Git
.m_CurrentDir
, selectedLeafs
.at(0)->GetFullName());
574 CAppUtils::RunTortoiseProc(sCmd
);
578 if (selectedLeafs
.at(0)->m_bFolder
)
580 FillListCtrlForTreeNode(selectedLeafs
.at(0)->m_hTree
);
581 m_RepoTree
.SelectItem(selectedLeafs
.at(0)->m_hTree
);
584 OpenFile(selectedLeafs
.at(0)->GetFullName(), OPEN
);
587 OpenFile(selectedLeafs
.at(0)->GetFullName(), OPEN_WITH
);
589 case eCmd_OpenWithAlternativeEditor
:
590 OpenFile(selectedLeafs
.at(0)->GetFullName(), ALTERNATIVEEDITOR
);
594 CTGitPath
file(selectedLeafs
.at(0)->GetFullName());
595 CGitDiff::Diff(&file
, &file
, GIT_REV_ZERO
, m_sRevision
);
601 for (TShadowFilesTreeList::iterator itShadowTree
= selectedLeafs
.begin(); itShadowTree
!= selectedLeafs
.end(); ++itShadowTree
)
603 if (RevertItemToVersion((*itShadowTree
)->GetFullName()))
609 msg
.Format(IDS_STATUSLIST_FILESREVERTED
, count
, m_sRevision
);
610 MessageBox(msg
, _T("TortoiseGit"), MB_OK
);
614 FileSaveAs(selectedLeafs
.at(0)->GetFullName());
619 for (TShadowFilesTreeList::iterator itShadowTree
= selectedLeafs
.begin(); itShadowTree
!= selectedLeafs
.end(); ++itShadowTree
)
621 sClipboard
+= (*itShadowTree
)->m_sName
+ _T("\r\n");
623 CStringUtils::WriteAsciiStringToClipboard(sClipboard
);
629 BOOL
CRepositoryBrowser::PreTranslateMessage(MSG
* pMsg
)
631 if (pMsg
->message
== WM_KEYDOWN
)
633 switch (pMsg
->wParam
)
643 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
646 void CRepositoryBrowser::OnLvnColumnclickRepoList(NMHDR
*pNMHDR
, LRESULT
*pResult
)
648 LPNMLISTVIEW pNMLV
= reinterpret_cast<LPNMLISTVIEW
>(pNMHDR
);
652 if (m_currSortCol
== pNMLV
->iSubItem
)
653 m_currSortDesc
= !m_currSortDesc
;
656 m_currSortCol
= pNMLV
->iSubItem
;
657 m_currSortDesc
= false;
660 CRepoListCompareFunc
compareFunc(&m_RepoList
, m_currSortCol
, m_currSortDesc
);
661 m_RepoList
.SortItemsEx(&CRepoListCompareFunc::StaticCompare
, (DWORD_PTR
)&compareFunc
);
663 SetSortArrowA(&m_RepoList
, m_currSortCol
, !m_currSortDesc
);
666 void CRepositoryBrowser::OnBnClickedButtonRevision()
668 // use the git log to allow selection of a version
670 // tell the dialog to use mode for selecting revisions
672 // only one revision must be selected however
673 dlg
.SingleSelection(true);
674 if (dlg
.DoModal() == IDOK
)
676 // get selected hash if any
677 m_sRevision
= dlg
.GetSelectedHash();
682 void CRepositoryBrowser::SaveDividerPosition()
685 GetDlgItem(IDC_REPOTREE
)->GetClientRect(&rc
);
686 CRegDWORD xPos
= CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RepobrowserDivider"));
687 xPos
= rc
.right
- rc
.left
;
690 void CRepositoryBrowser::HandleDividerMove(CPoint point
, bool bDraw
)
692 RECT rect
, tree
, list
, treelist
, treelistclient
;
694 // create an union of the tree and list control rectangle
695 GetDlgItem(IDC_REPOLIST
)->GetWindowRect(&list
);
696 GetDlgItem(IDC_REPOTREE
)->GetWindowRect(&tree
);
697 UnionRect(&treelist
, &tree
, &list
);
698 treelistclient
= treelist
;
699 ScreenToClient(&treelistclient
);
701 ClientToScreen(&point
);
702 GetClientRect(&rect
);
703 ClientToScreen(&rect
);
705 CPoint point2
= point
;
706 if (point2
.x
< treelist
.left
+ REPOBROWSER_CTRL_MIN_WIDTH
)
707 point2
.x
= treelist
.left
+ REPOBROWSER_CTRL_MIN_WIDTH
;
708 if (point2
.x
> treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
)
709 point2
.x
= treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
;
711 point
.x
-= rect
.left
;
712 point
.y
-= treelist
.top
;
714 OffsetRect(&treelist
, -treelist
.left
, -treelist
.top
);
716 if (point
.x
< treelist
.left
+REPOBROWSER_CTRL_MIN_WIDTH
)
717 point
.x
= treelist
.left
+REPOBROWSER_CTRL_MIN_WIDTH
;
718 if (point
.x
> treelist
.right
-REPOBROWSER_CTRL_MIN_WIDTH
)
719 point
.x
= treelist
.right
-REPOBROWSER_CTRL_MIN_WIDTH
;
724 DrawXorBar(pDC
, oldx
+ 2, treelistclient
.top
, 4, treelistclient
.bottom
- treelistclient
.top
- 2);
731 //position the child controls
732 GetDlgItem(IDC_REPOTREE
)->GetWindowRect(&treelist
);
733 treelist
.right
= point2
.x
- 2;
734 ScreenToClient(&treelist
);
735 RemoveAnchor(IDC_REPOTREE
);
736 GetDlgItem(IDC_REPOTREE
)->MoveWindow(&treelist
);
737 GetDlgItem(IDC_REPOLIST
)->GetWindowRect(&treelist
);
738 treelist
.left
= point2
.x
+ 2;
739 ScreenToClient(&treelist
);
740 RemoveAnchor(IDC_REPOLIST
);
741 GetDlgItem(IDC_REPOLIST
)->MoveWindow(&treelist
);
743 AddAnchor(IDC_REPOTREE
, TOP_LEFT
, BOTTOM_LEFT
);
744 AddAnchor(IDC_REPOLIST
, TOP_LEFT
, BOTTOM_RIGHT
);
747 void CRepositoryBrowser::OnMouseMove(UINT nFlags
, CPoint point
)
749 if (bDragMode
== FALSE
)
752 RECT rect
, tree
, list
, treelist
, treelistclient
;
753 // create an union of the tree and list control rectangle
754 GetDlgItem(IDC_REPOLIST
)->GetWindowRect(&list
);
755 GetDlgItem(IDC_REPOTREE
)->GetWindowRect(&tree
);
756 UnionRect(&treelist
, &tree
, &list
);
757 treelistclient
= treelist
;
758 ScreenToClient(&treelistclient
);
760 //convert the mouse coordinates relative to the top-left of
762 ClientToScreen(&point
);
763 GetClientRect(&rect
);
764 ClientToScreen(&rect
);
765 point
.x
-= rect
.left
;
766 point
.y
-= treelist
.top
;
768 //same for the window coordinates - make them relative to 0,0
769 OffsetRect(&treelist
, -treelist
.left
, -treelist
.top
);
771 if (point
.x
< treelist
.left
+ REPOBROWSER_CTRL_MIN_WIDTH
)
772 point
.x
= treelist
.left
+ REPOBROWSER_CTRL_MIN_WIDTH
;
773 if (point
.x
> treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
)
774 point
.x
= treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
;
776 if ((nFlags
& MK_LBUTTON
) && (point
.x
!= oldx
))
782 DrawXorBar(pDC
, oldx
+ 2, treelistclient
.top
, 4, treelistclient
.bottom
- treelistclient
.top
- 2);
783 DrawXorBar(pDC
, point
.x
+ 2, treelistclient
.top
, 4, treelistclient
.bottom
- treelistclient
.top
- 2);
792 CStandAloneDialogTmpl
<CResizableDialog
>::OnMouseMove(nFlags
, point
);
795 void CRepositoryBrowser::OnLButtonDown(UINT nFlags
, CPoint point
)
797 RECT rect
, tree
, list
, treelist
, treelistclient
;
799 // create an union of the tree and list control rectangle
800 GetDlgItem(IDC_REPOLIST
)->GetWindowRect(&list
);
801 GetDlgItem(IDC_REPOTREE
)->GetWindowRect(&tree
);
802 UnionRect(&treelist
, &tree
, &list
);
803 treelistclient
= treelist
;
804 ScreenToClient(&treelistclient
);
806 //convert the mouse coordinates relative to the top-left of
808 ClientToScreen(&point
);
809 GetClientRect(&rect
);
810 ClientToScreen(&rect
);
811 point
.x
-= rect
.left
;
812 point
.y
-= treelist
.top
;
814 //same for the window coordinates - make them relative to 0,0
815 OffsetRect(&treelist
, -treelist
.left
, -treelist
.top
);
817 if (point
.x
< treelist
.left
+ REPOBROWSER_CTRL_MIN_WIDTH
)
818 return CStandAloneDialogTmpl
< CResizableDialog
>::OnLButtonDown(nFlags
, point
);
819 if (point
.x
> treelist
.right
- 3)
820 return CStandAloneDialogTmpl
< CResizableDialog
>::OnLButtonDown(nFlags
, point
);
821 if (point
.x
> treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
)
822 point
.x
= treelist
.right
- REPOBROWSER_CTRL_MIN_WIDTH
;
824 if ((point
.y
< treelist
.top
+ 3) || (point
.y
> treelist
.bottom
- 3))
825 return CStandAloneDialogTmpl
<CResizableDialog
>::OnLButtonDown(nFlags
, point
);
832 DrawXorBar(pDC
, point
.x
+ 2, treelistclient
.top
, 4, treelistclient
.bottom
- treelistclient
.top
- 2);
838 CStandAloneDialogTmpl
<CResizableDialog
>::OnLButtonDown(nFlags
, point
);
841 void CRepositoryBrowser::OnLButtonUp(UINT nFlags
, CPoint point
)
843 if (bDragMode
== FALSE
)
846 HandleDividerMove(point
, true);
851 CStandAloneDialogTmpl
<CResizableDialog
>::OnLButtonUp(nFlags
, point
);
854 void CRepositoryBrowser::OnCaptureChanged(CWnd
*pWnd
)
858 __super::OnCaptureChanged(pWnd
);
861 void CRepositoryBrowser::DrawXorBar(CDC
* pDC
, int x1
, int y1
, int width
, int height
)
863 static WORD _dotPatternBmp
[8] =
865 0x0055, 0x00aa, 0x0055, 0x00aa,
866 0x0055, 0x00aa, 0x0055, 0x00aa
870 HBRUSH hbr
, hbrushOld
;
872 hbm
= CreateBitmap(8, 8, 1, 1, _dotPatternBmp
);
873 hbr
= CreatePatternBrush(hbm
);
875 pDC
->SetBrushOrg(x1
, y1
);
876 hbrushOld
= (HBRUSH
)pDC
->SelectObject(hbr
);
878 PatBlt(pDC
->GetSafeHdc(), x1
, y1
, width
, height
, PATINVERT
);
880 pDC
->SelectObject(hbrushOld
);
886 BOOL
CRepositoryBrowser::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
892 GetClientRect(&rect
);
895 if (PtInRect(&rect
, pt
))
898 // are we right of the tree control?
899 GetDlgItem(IDC_REPOTREE
)->GetWindowRect(&rect
);
900 if ((pt
.x
> rect
.right
) && (pt
.y
>= rect
.top
+ 3) && (pt
.y
<= rect
.bottom
- 3))
902 // but left of the list control?
903 GetDlgItem(IDC_REPOLIST
)->GetWindowRect(&rect
);
904 if (pt
.x
< rect
.left
)
906 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_SIZEWE
));
913 return CStandAloneDialogTmpl
<CResizableDialog
>::OnSetCursor(pWnd
, nHitTest
, message
);
916 void CRepositoryBrowser::FileSaveAs(const CString path
)
918 CTGitPath
gitPath(path
);
921 filename
.Format(_T("%s-%s%s"), gitPath
.GetBaseFilename(), m_sRevision
.Left(g_Git
.GetShortHASHLength()), gitPath
.GetFileExtension());
922 CFileDialog
dlg(FALSE
, NULL
, filename
, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
, NULL
);
925 if (dlg
.DoModal() == IDOK
)
927 filename
= dlg
.GetPathName();
928 if (g_Git
.GetOneFile(m_sRevision
, gitPath
, filename
))
930 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, gitPath
.GetGitPathString(), m_sRevision
, filename
);
931 MessageBox(out
, _T("TortoiseGit"), MB_OK
);
937 void CRepositoryBrowser::OpenFile(const CString path
, eOpenType mode
)
939 CTGitPath
gitPath(path
);
943 GetTempPath(temppath
);
944 file
.Format(_T("%s%s_%s%s"), temppath
, gitPath
.GetBaseFilename(), m_sRevision
.Left(g_Git
.GetShortHASHLength()), gitPath
.GetFileExtension());
947 if(g_Git
.GetOneFile(m_sRevision
, gitPath
, file
))
949 out
.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED
, gitPath
.GetGitPathString(), m_sRevision
, file
);
950 MessageBox(out
, _T("TortoiseGit"), MB_OK
);
954 if (mode
== ALTERNATIVEEDITOR
)
956 CAppUtils::LaunchAlternativeEditor(file
);
959 else if (mode
== OPEN
)
961 int ret
= HINSTANCE_ERROR
;
962 ret
= (int)ShellExecute(this->m_hWnd
, NULL
, file
, NULL
, NULL
, SW_SHOW
);
964 if (ret
> HINSTANCE_ERROR
)
968 CString cmd
= _T("RUNDLL32 Shell32,OpenAs_RunDLL ") + file
;
969 CAppUtils::LaunchApplication(cmd
, NULL
, false);
971 bool CRepositoryBrowser::RevertItemToVersion(const CString
&path
)
974 cmd
.Format(_T("git.exe checkout %s -- \"%s\""), m_sRevision
, path
);
975 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
977 if (MessageBox(out
, _T("TortoiseGit"), MB_ICONEXCLAMATION
| MB_OKCANCEL
) == IDCANCEL
)