Don't import ogdf namespace
[TortoiseGit.git] / src / TortoiseProc / BrowseRefsDlg.h
blob80028974dc8df2fa69a0a7a96472007909e00f56
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2018 - 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((int)wcslen(L"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,
134 eCmd_Select,
137 enum eCol
139 eCol_Name,
140 eCol_Upstream,
141 eCol_Date,
142 eCol_Msg,
143 eCol_LastAuthor,
144 eCol_Hash,
145 eCol_Description,
148 // Dialog Data
149 enum { IDD = IDD_BROWSE_REFS };
151 protected:
152 virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
154 DECLARE_MESSAGE_MAP()
156 afx_msg void OnBnClickedOk();
157 virtual BOOL OnInitDialog() override;
159 CString GetSelectedRef(bool onlyIfLeaf, bool pickFirstSelIfMultiSel = false);
161 void Refresh(CString selectRef = CString());
163 CShadowTree& GetTreeNode(CString refName, CShadowTree* pTreePos = nullptr, bool bCreateIfNotExist = false);
165 void FillListCtrlForTreeNode(HTREEITEM treeNode);
167 void FillListCtrlForShadowTree(CShadowTree* pTree, CString refNamePrefix, bool isFirstLevel);
169 bool SelectRef(CString refName, bool bExactMatch);
171 bool ConfirmDeleteRef(VectorPShadowTree& leafs);
172 bool DoDeleteRefs(VectorPShadowTree& leafs);
173 bool DoDeleteRef(CString completeRefName);
175 CString GetFullRefName(CString partialRefName);
177 CShadowTree* GetListEntry(int index);
178 CShadowTree* GetTreeEntry(HTREEITEM treeItem);
180 private:
181 bool m_bHasWC;
183 CString m_cmdPath;
185 STRING_VECTOR remotes;
187 CShadowTree m_TreeRoot;
188 CShadowTree* m_pListCtrlRoot;
189 CGestureEnabledControlTmpl<CTreeCtrl> m_RefTreeCtrl;
190 CGestureEnabledControlTmpl<CResizableColumnsListCtrl<CListCtrl>> m_ListRefLeafs;
192 CFilterEdit m_ctrlFilter;
193 afx_msg void OnEnChangeEditFilter();
194 afx_msg void OnTimer(UINT_PTR nIDEvent);
195 DWORD m_SelectedFilters;
196 void SetFilterCueText();
197 afx_msg LRESULT OnClickedInfoIcon(WPARAM wParam, LPARAM lParam);
198 afx_msg LRESULT OnClickedCancelFilter(WPARAM wParam, LPARAM lParam);
199 bool IsMatchFilter(const CShadowTree* pTree, const CString &ref, const CString &filter, bool positive);
200 CComboBox m_cBranchFilter;
202 int m_currSortCol;
203 bool m_currSortDesc;
204 CRegDWORD m_regCurrSortCol;
205 CRegDWORD m_regCurrSortDesc;
206 afx_msg void OnTvnSelchangedTreeRef(NMHDR *pNMHDR, LRESULT *pResult);
208 afx_msg void OnContextMenu(CWnd* pWndFrom, CPoint point);
210 void GetSelectedLeaves(VectorPShadowTree& selectedLeafs);
211 void OnContextMenu_ListRefLeafs(CPoint point);
212 void OnContextMenu_RefTreeCtrl(CPoint point);
213 static CString GetTwoSelectedRefs(VectorPShadowTree& selectedLeafs, const CString &lastSelected, const CString &separator);
215 bool AreAllFrom(VectorPShadowTree& leafs, const wchar_t* from);
216 void ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPShadowTree& selectedLeafs);
217 virtual BOOL PreTranslateMessage(MSG* pMsg) override;
218 afx_msg void OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
219 afx_msg void OnDestroy();
220 afx_msg void OnNMDblclkListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
221 afx_msg void OnItemChangedListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
222 afx_msg void OnLvnEndlabeleditListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
223 afx_msg void OnLvnBeginlabeleditListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult);
224 afx_msg void OnBnClickedCurrentbranch();
225 afx_msg void OnBnClickedIncludeNestedRefs();
226 afx_msg void OnCbnSelchangeBrowseRefsBranchfilter();
227 BOOL m_bIncludeNestedRefs;
228 CRegDWORD m_regIncludeNestedRefs;
229 void UpdateInfoLabel();
231 CString m_sLastSelected;
232 CString m_initialRef;
233 int m_pickRef_Kind;
234 CString m_pickedRef;
235 bool m_bWantPick;
236 bool m_bPickOne;
237 bool m_bPickedRefSet;
239 DWORD m_DateFormat; // DATE_SHORTDATE or DATE_LONGDATE
240 bool m_bRelativeTimes; // Show relative times
242 public:
243 static CString PickRef(bool returnAsHash = false, CString initialRef = CString(), int pickRef_Kind = gPickRef_All, bool pickMultipleRefsOrRange = false);
244 static bool PickRefForCombo(CHistoryCombo& refComboBox, int pickRef_Kind = gPickRef_All, int useShortName = gPickRef_Head);