1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2017 - 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.
21 #include "StandAloneDlg.h"
22 #include "FilterEdit.h"
23 #include "ResizableColumnsListCtrl.h"
25 #include "HistoryCombo.h"
26 #include "GestureEnabledControl.h"
28 const int gPickRef_Head
= 1;
29 const int gPickRef_Tag
= 2;
30 const int gPickRef_Remote
= 4;
31 const int gPickRef_All
= gPickRef_Head
| gPickRef_Tag
| gPickRef_Remote
;
32 const int gPickRef_NoTag
= gPickRef_All
& ~gPickRef_Tag
;
37 typedef std::map
<CString
,CShadowTree
> TShadowTreeMap
;
44 CShadowTree
* GetNextSub(CString
& nameLeft
, bool bCreateIfNotExist
);
46 bool IsLeaf()const {return m_ShadowTree
.empty();}
47 CString
GetRefName()const
51 return m_pParent
->GetRefName()+"/"+m_csRefName
;
55 * from = refs/heads, refname = refs/heads/master => true
56 * from = refs/heads, refname = refs/heads => true
57 * from = refs/heads, refname = refs/headsh => false
58 * from = refs/heads/, refname = refs/heads/master => true
59 * from = refs/heads/, refname = refs/heads => false
61 bool IsFrom(const wchar_t* from
)const
63 CString name
= GetRefName();
64 int len
= (int)wcslen(from
);
65 if (from
[len
- 1] != '/' && wcsncmp(name
, from
, len
) == 0)
67 if (len
== name
.GetLength())
69 if (len
< name
.GetLength() && name
[len
] == '/')
74 return wcsncmp(name
, from
, len
) == 0;
77 CString
GetRefsHeadsName() const
79 return GetRefName().Mid(11); // len = 11 refs/heads/
82 CShadowTree
* FindLeaf(CString partialRefName
);
90 CString m_csDescription
;
94 TShadowTreeMap m_ShadowTree
;
95 CShadowTree
* m_pParent
;
97 typedef std::vector
<CShadowTree
*> VectorPShadowTree
;
99 class CBrowseRefsDlg
: public CResizableStandAloneDialog
101 DECLARE_DYNAMIC(CBrowseRefsDlg
)
104 CBrowseRefsDlg(CString cmdPath
, CWnd
* pParent
= nullptr); // standard constructor
105 virtual ~CBrowseRefsDlg();
109 eCmd_ViewLog
= WM_APP
,
116 eCmd_DeleteRemoteBranch
,
125 eCmd_DeleteRemoteTag
,
126 eCmd_EditBranchDescription
,
128 eCmd_ViewLogRangeReachableFromOnlyOne
,
148 enum { IDD
= IDD_BROWSE_REFS
};
151 virtual void DoDataExchange(CDataExchange
* pDX
) override
; // DDX/DDV support
153 DECLARE_MESSAGE_MAP()
155 afx_msg
void OnBnClickedOk();
156 virtual BOOL
OnInitDialog() override
;
158 CString
GetSelectedRef(bool onlyIfLeaf
, bool pickFirstSelIfMultiSel
= false);
160 void Refresh(CString selectRef
= CString());
162 CShadowTree
& GetTreeNode(CString refName
, CShadowTree
* pTreePos
= nullptr, bool bCreateIfNotExist
= false);
164 void FillListCtrlForTreeNode(HTREEITEM treeNode
);
166 void FillListCtrlForShadowTree(CShadowTree
* pTree
, CString refNamePrefix
, bool isFirstLevel
);
168 bool SelectRef(CString refName
, bool bExactMatch
);
170 bool ConfirmDeleteRef(VectorPShadowTree
& leafs
);
171 bool DoDeleteRefs(VectorPShadowTree
& leafs
);
172 bool DoDeleteRef(CString completeRefName
);
174 CString
GetFullRefName(CString partialRefName
);
176 CShadowTree
* GetListEntry(int index
);
177 CShadowTree
* GetTreeEntry(HTREEITEM treeItem
);
184 STRING_VECTOR remotes
;
186 CShadowTree m_TreeRoot
;
187 CShadowTree
* m_pListCtrlRoot
;
188 CGestureEnabledControlTmpl
<CTreeCtrl
> m_RefTreeCtrl
;
189 CGestureEnabledControlTmpl
<CResizableColumnsListCtrl
<CListCtrl
>> m_ListRefLeafs
;
191 CFilterEdit m_ctrlFilter
;
192 afx_msg
void OnEnChangeEditFilter();
193 afx_msg
void OnTimer(UINT_PTR nIDEvent
);
194 DWORD m_SelectedFilters
;
195 void SetFilterCueText();
196 afx_msg LRESULT
OnClickedInfoIcon(WPARAM wParam
, LPARAM lParam
);
197 afx_msg LRESULT
OnClickedCancelFilter(WPARAM wParam
, LPARAM lParam
);
198 bool IsMatchFilter(const CShadowTree
* pTree
, const CString
&ref
, const CString
&filter
, bool positive
);
199 CComboBox m_cBranchFilter
;
203 CRegDWORD m_regCurrSortCol
;
204 CRegDWORD m_regCurrSortDesc
;
205 afx_msg
void OnTvnSelchangedTreeRef(NMHDR
*pNMHDR
, LRESULT
*pResult
);
207 afx_msg
void OnContextMenu(CWnd
* pWndFrom
, CPoint point
);
209 void GetSelectedLeaves(VectorPShadowTree
& selectedLeafs
);
210 void OnContextMenu_ListRefLeafs(CPoint point
);
211 void OnContextMenu_RefTreeCtrl(CPoint point
);
212 static CString
GetTwoSelectedRefs(VectorPShadowTree
& selectedLeafs
, const CString
&lastSelected
, const CString
&separator
);
214 bool AreAllFrom(VectorPShadowTree
& leafs
, const wchar_t* from
);
215 void ShowContextMenu(CPoint point
, HTREEITEM hTreePos
, VectorPShadowTree
& selectedLeafs
);
216 virtual BOOL
PreTranslateMessage(MSG
* pMsg
) override
;
217 afx_msg
void OnLvnColumnclickListRefLeafs(NMHDR
*pNMHDR
, LRESULT
*pResult
);
218 afx_msg
void OnDestroy();
219 afx_msg
void OnNMDblclkListRefLeafs(NMHDR
*pNMHDR
, LRESULT
*pResult
);
220 afx_msg
void OnItemChangedListRefLeafs(NMHDR
*pNMHDR
, LRESULT
*pResult
);
221 afx_msg
void OnLvnEndlabeleditListRefLeafs(NMHDR
*pNMHDR
, LRESULT
*pResult
);
222 afx_msg
void OnLvnBeginlabeleditListRefLeafs(NMHDR
*pNMHDR
, LRESULT
*pResult
);
223 afx_msg
void OnBnClickedCurrentbranch();
224 afx_msg
void OnBnClickedIncludeNestedRefs();
225 afx_msg
void OnCbnSelchangeBrowseRefsBranchfilter();
226 BOOL m_bIncludeNestedRefs
;
227 CRegDWORD m_regIncludeNestedRefs
;
228 void UpdateInfoLabel();
230 CString m_sLastSelected
;
231 CString m_initialRef
;
235 bool m_bPickedRefSet
;
237 DWORD m_DateFormat
; // DATE_SHORTDATE or DATE_LONGDATE
238 bool m_bRelativeTimes
; // Show relative times
241 static CString
PickRef(bool returnAsHash
= false, CString initialRef
= CString(), int pickRef_Kind
= gPickRef_All
, bool pickMultipleRefsOrRange
= false);
242 static bool PickRefForCombo(CHistoryCombo
& refComboBox
, int pickRef_Kind
= gPickRef_All
, int useShortName
= gPickRef_Head
);