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