Provide (experimental) clang-format file
[TortoiseGit.git] / src / TortoiseProc / BrowseRefsDlg.h
blobd04a13eb6647010ed44f0a49f0158c1c9d1b286a
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.
19 #pragma once
21 #include "StandAloneDlg.h"
22 #include "FilterEdit.h"
23 #include "ResizableColumnsListCtrl.h"
24 #include "gittype.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;
34 class CShadowTree
36 public:
37 typedef std::map<CString,CShadowTree> TShadowTreeMap;
39 CShadowTree()
40 : m_hTree(nullptr)
41 , m_pParent(nullptr)
44 CShadowTree* GetNextSub(CString& nameLeft, bool bCreateIfNotExist);
46 bool IsLeaf()const {return m_ShadowTree.empty();}
47 CString GetRefName()const
49 if (!m_pParent)
50 return m_csRefName;
51 return m_pParent->GetRefName()+"/"+m_csRefName;
54 /**
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())
68 return true;
69 if (len < name.GetLength() && name[len] == '/')
70 return true;
71 return false;
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);
84 CString m_csRefName;
85 CString m_csUpstream;
86 CString m_csRefHash;
87 CTime m_csDate;
88 CString m_csAuthor;
89 CString m_csSubject;
90 CString m_csDescription;
92 HTREEITEM m_hTree;
94 TShadowTreeMap m_ShadowTree;
95 CShadowTree* m_pParent;
97 typedef std::vector<CShadowTree*> VectorPShadowTree;
99 class CBrowseRefsDlg : public CResizableStandAloneDialog
101 DECLARE_DYNAMIC(CBrowseRefsDlg)
103 public:
104 CBrowseRefsDlg(CString cmdPath, CWnd* pParent = nullptr); // standard constructor
105 virtual ~CBrowseRefsDlg();
107 enum eCmd
109 eCmd_ViewLog = WM_APP,
110 eCmd_AddRemote,
111 eCmd_ManageRemotes,
112 eCmd_CreateBranch,
113 eCmd_CreateTag,
114 eCmd_DeleteAllTags,
115 eCmd_DeleteBranch,
116 eCmd_DeleteRemoteBranch,
117 eCmd_DeleteTag,
118 eCmd_ShowReflog,
119 eCmd_Diff,
120 eCmd_Fetch,
121 eCmd_Switch,
122 eCmd_Merge,
123 eCmd_Rename,
124 eCmd_RepoBrowser,
125 eCmd_DeleteRemoteTag,
126 eCmd_EditBranchDescription,
127 eCmd_ViewLogRange,
128 eCmd_ViewLogRangeReachableFromOnlyOne,
129 eCmd_UnifiedDiff,
130 eCmd_UpstreamDrop,
131 eCmd_UpstreamSet,
132 eCmd_DiffWC,
133 eCmd_Copy,
136 enum eCol
138 eCol_Name,
139 eCol_Upstream,
140 eCol_Date,
141 eCol_Msg,
142 eCol_LastAuthor,
143 eCol_Hash,
144 eCol_Description,
147 // Dialog Data
148 enum { IDD = IDD_BROWSE_REFS };
150 protected:
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);
179 private:
180 bool m_bHasWC;
182 CString m_cmdPath;
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;
201 int m_currSortCol;
202 bool m_currSortDesc;
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;
232 int m_pickRef_Kind;
233 CString m_pickedRef;
234 bool m_bPickOne;
235 bool m_bPickedRefSet;
237 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
238 bool m_bRelativeTimes; // Show relative times
240 public:
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);