Provide (experimental) clang-format file
[TortoiseGit.git] / src / TortoiseProc / RepositoryBrowser.h
blob394adc3b3e0a88bbf5f41d130e9640f6ba448e02
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014, 2016-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 <map>
22 #include "StandAloneDlg.h"
23 #include "GitHash.h"
24 #include "GitStatusListCtrl.h"
25 #include "GestureEnabledControl.h"
27 #define REPOBROWSER_CTRL_MIN_WIDTH 20
29 class CShadowFilesTree;
31 typedef std::map<CString, CShadowFilesTree> TShadowFilesTreeMap;
33 class CShadowFilesTree
35 public:
36 CShadowFilesTree()
37 : m_hTree(nullptr)
38 , m_pParent(nullptr)
39 , m_bFolder(false)
40 , m_bLoaded(true)
41 , m_bSubmodule(false)
42 , m_bExecutable(false)
43 , m_bSymlink(false)
44 , m_iSize(0)
47 CString m_sName;
48 CGitHash m_hash;
49 git_off_t m_iSize;
50 bool m_bFolder;
51 bool m_bLoaded;
52 bool m_bSubmodule;
53 bool m_bExecutable;
54 bool m_bSymlink;
56 HTREEITEM m_hTree;
58 TShadowFilesTreeMap m_ShadowTree;
59 CShadowFilesTree* m_pParent;
61 CString GetFullName() const
63 if (!m_pParent)
64 return m_sName;
66 CString parentPath = m_pParent->GetFullName();
67 if (parentPath.IsEmpty())
68 return m_sName;
69 else
70 return m_pParent->GetFullName() + L'/' + m_sName;
73 typedef std::vector<CShadowFilesTree *> TShadowFilesTreeList;
75 class CRepositoryBrowser : public CResizableStandAloneDialog
77 DECLARE_DYNAMIC(CRepositoryBrowser)
79 public:
80 CRepositoryBrowser(CString rev, CWnd* pParent = nullptr); // standard constructor
81 virtual ~CRepositoryBrowser();
83 // Dialog Data
84 enum { IDD = IDD_REPOSITORY_BROWSER };
86 static bool s_bSortLogical;
88 enum eCmd
90 eCmd_Open = WM_APP,
91 eCmd_OpenWith,
92 eCmd_OpenWithAlternativeEditor,
93 eCmd_ViewLog,
94 eCmd_Blame,
95 eCmd_CompareWC,
96 eCmd_Revert,
97 eCmd_SaveAs,
98 eCmd_CopyPath,
99 eCmd_CopyHash,
100 eCmd_ViewLogSubmodule,
101 eCmd_PrepareDiff,
102 eCmd_PrepareDiff_Compare,
105 enum eCol
107 eCol_Name,
108 eCol_Extension,
109 eCol_FileSize,
112 enum eOpenType
114 ALTERNATIVEEDITOR,
115 OPEN,
116 OPEN_WITH,
119 enum eSelectionType
121 ONLY_FILES,
122 ONLY_FILESSUBMODULES,
123 ONLY_FOLDERS,
124 MIXED_FOLDERS_FILES,
127 private:
128 virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
130 DECLARE_MESSAGE_MAP()
132 afx_msg void OnOK();
133 afx_msg void OnCancel();
134 afx_msg void OnDestroy();
135 virtual BOOL OnInitDialog() override;
136 afx_msg void OnSysColorChange();
138 CGestureEnabledControlTmpl<CTreeCtrl> m_RepoTree;
139 CGestureEnabledControlTmpl<CListCtrl> m_RepoList;
140 ColumnManager m_ColumnManager;
142 afx_msg void OnLvnColumnclickRepoList(NMHDR *pNMHDR, LRESULT *pResult);
143 int m_currSortCol;
144 bool m_currSortDesc;
146 CShadowFilesTree m_TreeRoot;
147 int ReadTreeRecursive(git_repository& repo, const git_tree* tree, CShadowFilesTree* treeroot, bool recursive);
148 int ReadTree(CShadowFilesTree* treeroot, const CString& root = L"", bool recursive = false);
149 int m_nIconFolder;
150 int m_nOpenIconFolder;
151 int m_nExternalOvl;
152 int m_nExecutableOvl;
153 int m_nSymlinkOvl;
155 CShadowFilesTree* GetListEntry(int index);
156 CShadowFilesTree* GetTreeEntry(HTREEITEM treeItem);
158 bool m_bHasWC;
160 void Refresh();
161 CString m_sRevision;
162 void FillListCtrlForTreeNode(HTREEITEM treeNode);
163 void FillListCtrlForShadowTree(CShadowFilesTree* pTree);
164 void UpdateInfoLabel();
165 afx_msg void OnTvnSelchangedRepoTree(NMHDR *pNMHDR, LRESULT *pResult);
166 afx_msg void OnTvnItemExpandingRepoTree(NMHDR *pNMHDR, LRESULT *pResult);
167 afx_msg void OnLvnItemchangedRepolist(NMHDR *pNMHDR, LRESULT *pResult);
169 afx_msg void OnNMDblclk_RepoList(NMHDR *pNMHDR, LRESULT *pResult);
170 afx_msg void OnContextMenu(CWnd* pWndFrom, CPoint point);
171 void OnContextMenu_RepoList(CPoint point);
172 void OnContextMenu_RepoTree(CPoint point);
173 void ShowContextMenu(CPoint point, TShadowFilesTreeList &selectedLeafs, eSelectionType selType);
175 void FileSaveAs(const CString path);
176 void OpenFile(const CString path, eOpenType mode, bool isSubmodule, CGitHash itemHash);
177 bool RevertItemToVersion(const CString &path);
179 afx_msg void OnBnClickedButtonRevision();
181 virtual BOOL PreTranslateMessage(MSG* pMsg) override;
183 CString m_sMarkForDiffFilename;
184 CGitHash m_sMarkForDiffVersion;
186 /// resizes the control so that the divider is at position 'point'
187 void HandleDividerMove(CPoint point, bool bDraw);
188 bool bDragMode;
189 void SaveDividerPosition();
190 int oldy, oldx;
191 /// draws the bar when the tree and list control are resized
192 void DrawXorBar(CDC * pDC, int x1, int y1, int width, int height);
193 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
194 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
195 afx_msg void OnCaptureChanged(CWnd *pWnd);
196 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
197 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
198 afx_msg void CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs);
199 afx_msg void OnLvnBegindragRepolist(NMHDR* pNMHDR, LRESULT* pResult);
200 afx_msg void OnTvnBegindragRepotree(NMHDR* pNMHDR, LRESULT* pResult);
201 void BeginDrag(const CWnd& window, CTGitPathList& files, const CString& root, POINT& point);
202 void RecursivelyAdd(CTGitPathList& toExport, CShadowFilesTree* pTree);