Refactor out CResizableColumnsListCtrl
[TortoiseGit.git] / src / TortoiseProc / BrowseRefsDlg.h
blob5361aad3ae068c0efef5ff8e67126c60658258cd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2016 - 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 #pragma once
21 #include "StandAloneDlg.h"
22 #include "FilterEdit.h"
23 #include "ResizableColumnsListCtrl.h"
24 #include "gittype.h"
26 const int gPickRef_Head = 1;
27 const int gPickRef_Tag = 2;
28 const int gPickRef_Remote = 4;
29 const int gPickRef_All = gPickRef_Head | gPickRef_Tag | gPickRef_Remote;
30 const int gPickRef_NoTag = gPickRef_All & ~gPickRef_Tag;
32 class CShadowTree
34 public:
35 typedef std::map<CString,CShadowTree> TShadowTreeMap;
37 CShadowTree()
38 : m_hTree(nullptr)
39 , m_pParent(nullptr)
42 CShadowTree* GetNextSub(CString& nameLeft, bool bCreateIfNotExist);
44 bool IsLeaf()const {return m_ShadowTree.empty();}
45 CString GetRefName()const
47 if (!m_pParent)
48 return m_csRefName;
49 return m_pParent->GetRefName()+"/"+m_csRefName;
52 /**
53 * from = refs/heads, refname = refs/heads/master => true
54 * from = refs/heads, refname = refs/heads => true
55 * from = refs/heads, refname = refs/headsh => false
56 * from = refs/heads/, refname = refs/heads/master => true
57 * from = refs/heads/, refname = refs/heads => false
59 bool IsFrom(const wchar_t* from)const
61 CString name = GetRefName();
62 int len = (int)wcslen(from);
63 if (from[len - 1] != '/' && wcsncmp(name, from, len) == 0)
65 if (len == name.GetLength())
66 return true;
67 if (len < name.GetLength() && name[len] == '/')
68 return true;
69 return false;
72 return wcsncmp(name, from, len) == 0;
75 CString GetRefsHeadsName() const
77 return GetRefName().Mid(11); // len = 11 refs/heads/
80 CShadowTree* FindLeaf(CString partialRefName);
82 CString m_csRefName;
83 CString m_csUpstream;
84 CString m_csRefHash;
85 CTime m_csDate;
86 CString m_csAuthor;
87 CString m_csSubject;
88 CString m_csDescription;
90 HTREEITEM m_hTree;
92 TShadowTreeMap m_ShadowTree;
93 CShadowTree* m_pParent;
95 typedef std::vector<CShadowTree*> VectorPShadowTree;
97 class CBrowseRefsDlg : public CResizableStandAloneDialog
99 DECLARE_DYNAMIC(CBrowseRefsDlg)
101 public:
102 CBrowseRefsDlg(CString cmdPath, CWnd* pParent = nullptr); // standard constructor
103 virtual ~CBrowseRefsDlg();
105 enum eCmd
107 eCmd_ViewLog = WM_APP,
108 eCmd_AddRemote,
109 eCmd_ManageRemotes,
110 eCmd_CreateBranch,
111 eCmd_CreateTag,
112 eCmd_DeleteAllTags,
113 eCmd_DeleteBranch,
114 eCmd_DeleteRemoteBranch,
115 eCmd_DeleteTag,
116 eCmd_ShowReflog,
117 eCmd_Diff,
118 eCmd_Fetch,
119 eCmd_Switch,
120 eCmd_Merge,
121 eCmd_Rename,
122 eCmd_RepoBrowser,
123 eCmd_DeleteRemoteTag,
124 eCmd_EditBranchDescription,
125 eCmd_ViewLogRange,
126 eCmd_ViewLogRangeReachableFromOnlyOne,
127 eCmd_UnifiedDiff,
128 eCmd_UpstreamDrop,
129 eCmd_UpstreamSet,
132 enum eCol
134 eCol_Name,
135 eCol_Upstream,
136 eCol_Date,
137 eCol_Msg,
138 eCol_LastAuthor,
139 eCol_Hash,
140 eCol_Description,
143 // Dialog Data
144 enum { IDD = IDD_DIALOG_BROWSE_REFS };
146 protected:
147 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
149 DECLARE_MESSAGE_MAP()
151 afx_msg void OnBnClickedOk();
152 virtual BOOL OnInitDialog();
154 CString GetSelectedRef(bool onlyIfLeaf, bool pickFirstSelIfMultiSel = false);
156 void Refresh(CString selectRef = CString());
158 CShadowTree& GetTreeNode(CString refName, CShadowTree* pTreePos = nullptr, bool bCreateIfNotExist = false);
160 void FillListCtrlForTreeNode(HTREEITEM treeNode);
162 void FillListCtrlForShadowTree(CShadowTree* pTree, CString refNamePrefix, bool isFirstLevel);
164 bool SelectRef(CString refName, bool bExactMatch);
166 bool ConfirmDeleteRef(VectorPShadowTree& leafs);
167 bool DoDeleteRefs(VectorPShadowTree& leafs);
168 bool DoDeleteRef(CString completeRefName);
170 CString GetFullRefName(CString partialRefName);
172 private:
173 bool m_bHasWC;
175 CString m_cmdPath;
177 STRING_VECTOR remotes;
179 CShadowTree m_TreeRoot;
180 CShadowTree* m_pListCtrlRoot;
181 CTreeCtrl m_RefTreeCtrl;
182 CResizableColumnsListCtrl<CListCtrl> m_ListRefLeafs;
184 CFilterEdit m_ctrlFilter;
185 afx_msg void OnEnChangeEditFilter();
186 afx_msg void OnTimer(UINT_PTR nIDEvent);
187 DWORD m_SelectedFilters;
188 void SetFilterCueText();
189 afx_msg LRESULT OnClickedInfoIcon(WPARAM wParam, LPARAM lParam);
190 afx_msg LRESULT OnClickedCancelFilter(WPARAM wParam, LPARAM lParam);
191 bool IsMatchFilter(const CShadowTree* pTree, const CString &ref, const CString &filter, bool positive);
193 int m_currSortCol;
194 bool m_currSortDesc;
195 CRegDWORD m_regCurrSortCol;
196 CRegDWORD m_regCurrSortDesc;
197 afx_msg void OnTvnSelchangedTreeRef(NMHDR *pNMHDR, LRESULT *pResult);
199 afx_msg void OnContextMenu(CWnd* pWndFrom, CPoint point);
201 void GetSelectedLeaves(VectorPShadowTree& selectedLeafs);
202 void OnContextMenu_ListRefLeafs(CPoint point);
203 void OnContextMenu_RefTreeCtrl(CPoint point);
204 static CString GetTwoSelectedRefs(VectorPShadowTree& selectedLeafs, const CString &lastSelected, const CString &separator);
206 bool AreAllFrom(VectorPShadowTree& leafs, const wchar_t* from);
207 void ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPShadowTree& selectedLeafs);
208 virtual BOOL PreTranslateMessage(MSG* pMsg);
209 afx_msg void OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
210 afx_msg void OnDestroy();
211 afx_msg void OnNMDblclkListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
212 afx_msg void OnItemChangedListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
213 afx_msg void OnLvnEndlabeleditListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
214 afx_msg void OnLvnBeginlabeleditListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
215 afx_msg void OnBnClickedCurrentbranch();
216 afx_msg void OnBnClickedIncludeNestedRefs();
217 BOOL m_bIncludeNestedRefs;
218 CRegDWORD m_regIncludeNestedRefs;
219 void UpdateInfoLabel();
221 CString m_sLastSelected;
222 CString m_initialRef;
223 int m_pickRef_Kind;
224 CString m_pickedRef;
225 bool m_bPickOne;
226 bool m_bPickedRefSet;
228 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
229 bool m_bRelativeTimes; // Show relative times
231 public:
232 static CString PickRef(bool returnAsHash = false, CString initialRef = CString(), int pickRef_Kind = gPickRef_All, bool pickMultipleRefsOrRange = false);
233 static bool PickRefForCombo(CComboBoxEx* pComboBox, int pickRef_Kind = gPickRef_All);