Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / RepositoryBrowser.h
blob7f4be7ae8c27501ef7ce588ab2d6c5d70646c13d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014, 2016-2017, 2020-2023 - 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 using TShadowFilesTreeMap = std::map<CString, CShadowFilesTree>;
33 class CShadowFilesTree
35 public:
36 CShadowFilesTree() = default;
38 CString m_sName;
39 CGitHash m_hash;
40 git_off_t m_iSize = 0;
41 bool m_bFolder = false;
42 bool m_bLoaded = true;
43 bool m_bSubmodule = false;
44 bool m_bExecutable = false;
45 bool m_bSymlink = false;
47 HTREEITEM m_hTree = nullptr;
49 TShadowFilesTreeMap m_ShadowTree;
50 CShadowFilesTree* m_pParent = nullptr;
52 CString GetFullName() const
54 if (!m_pParent)
55 return m_sName;
57 CString parentPath = m_pParent->GetFullName();
58 if (parentPath.IsEmpty())
59 return m_sName;
60 else
61 return m_pParent->GetFullName() + L'/' + m_sName;
64 using TShadowFilesTreeList = std::vector<CShadowFilesTree*>;
66 class CRepositoryBrowser : public CResizableStandAloneDialog
68 DECLARE_DYNAMIC(CRepositoryBrowser)
70 public:
71 CRepositoryBrowser(CString rev, CWnd* pParent = nullptr); // standard constructor
72 virtual ~CRepositoryBrowser();
74 // Dialog Data
75 enum { IDD = IDD_REPOSITORY_BROWSER };
77 static bool s_bSortLogical;
79 enum eCmd
81 eCmd_Open = WM_APP,
82 eCmd_OpenWith,
83 eCmd_OpenWithAlternativeEditor,
84 eCmd_ViewLog,
85 eCmd_Blame,
86 eCmd_CompareWC,
87 eCmd_Revert,
88 eCmd_SaveAs,
89 eCmd_CopyPath,
90 eCmd_CopyHash,
91 eCmd_ViewLogSubmodule,
92 eCmd_PrepareDiff,
93 eCmd_PrepareDiff_Compare,
96 enum eCol
98 eCol_Name,
99 eCol_Extension,
100 eCol_FileSize,
103 enum eOpenType
105 ALTERNATIVEEDITOR,
106 OPEN,
107 OPEN_WITH,
110 enum eSelectionType
112 ONLY_FILES,
113 ONLY_FILESSUBMODULES,
114 ONLY_FOLDERS,
115 MIXED_FOLDERS_FILES,
118 private:
119 void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
121 DECLARE_MESSAGE_MAP()
123 afx_msg void OnOK() override;
124 afx_msg void OnCancel() override;
125 afx_msg void OnDestroy();
126 BOOL OnInitDialog() override;
128 CGestureEnabledControlTmpl<CTreeCtrl> m_RepoTree;
129 CGestureEnabledControlTmpl<CListCtrl> m_RepoList;
130 ColumnManager m_ColumnManager;
132 afx_msg void OnLvnColumnclickRepoList(NMHDR *pNMHDR, LRESULT *pResult);
133 int m_currSortCol = 0;
134 bool m_currSortDesc = false;
136 CShadowFilesTree m_TreeRoot;
137 int ReadTreeRecursive(git_repository& repo, const git_tree* tree, CShadowFilesTree* treeroot, bool recursive);
138 int ReadTree(CShadowFilesTree* treeroot, const CString& root = L"", bool recursive = false);
139 int m_nIconFolder = 0;
140 int m_nOpenIconFolder = 0;
141 int m_nExternalOvl = 0;
142 int m_nExecutableOvl = 0;
143 int m_nSymlinkOvl = 0;
145 CShadowFilesTree* GetListEntry(int index);
146 CShadowFilesTree* GetTreeEntry(HTREEITEM treeItem);
148 bool m_bHasWC = true;
150 void Refresh();
151 CString m_sRevision;
152 void FillListCtrlForTreeNode(HTREEITEM treeNode);
153 void FillListCtrlForShadowTree(CShadowFilesTree* pTree);
154 void UpdateInfoLabel();
155 afx_msg void OnTvnSelchangedRepoTree(NMHDR *pNMHDR, LRESULT *pResult);
156 afx_msg void OnTvnItemExpandingRepoTree(NMHDR *pNMHDR, LRESULT *pResult);
157 afx_msg void OnLvnItemchangedRepolist(NMHDR *pNMHDR, LRESULT *pResult);
159 afx_msg void OnNMDblclk_RepoList(NMHDR *pNMHDR, LRESULT *pResult);
160 afx_msg void OnContextMenu(CWnd* pWndFrom, CPoint point);
161 void OnContextMenu_RepoList(CPoint point);
162 void OnContextMenu_RepoTree(CPoint point);
163 void ShowContextMenu(CPoint point, TShadowFilesTreeList &selectedLeafs, eSelectionType selType);
165 void FileSaveAs(const CString path);
166 void OpenFile(const CString path, eOpenType mode, bool isSubmodule, const CGitHash& itemHash);
167 bool RevertItemToVersion(const CString &path);
169 afx_msg void OnBnClickedButtonRevision();
171 BOOL PreTranslateMessage(MSG* pMsg) override;
173 void UpdateDiffWithFileFromReg();
174 CString m_sMarkForDiffFilename;
175 CGitHash m_sMarkForDiffVersion;
177 /// resizes the control so that the divider is at position 'point'
178 void HandleDividerMove(CPoint point, bool bDraw);
179 bool bDragMode = false;
180 void SaveDividerPosition();
181 int m_oldSliderXPos = 0;
182 /// draws the bar when the tree and list control are resized
183 void DrawXorBar(CDC * pDC, int x1, int y1, int width, int height);
184 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
185 afx_msg void OnMouseMove(UINT nFlags, CPoint point);
186 afx_msg void OnCaptureChanged(CWnd *pWnd);
187 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
188 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
189 afx_msg void CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs);
190 afx_msg void OnLvnBegindragRepolist(NMHDR* pNMHDR, LRESULT* pResult);
191 afx_msg void OnTvnBegindragRepotree(NMHDR* pNMHDR, LRESULT* pResult);
192 void BeginDrag(const CWnd& window, CTGitPathList& files, const CString& root, POINT& point);
193 void RecursivelyAdd(CTGitPathList& toExport, CShadowFilesTree* pTree);