Ember
Loading...
Searching...
No Matches
FileExplorerTab.h
Go to the documentation of this file.
1#pragma once
2
3#include "Interfaces/ITab.h"
4#include <map>
5#include <wx/bmpbuttn.h>
6#include <wx/dir.h>
7#include <wx/filename.h>
8#include <wx/imaglist.h>
9#include <wx/scrolwin.h>
10#include <wx/splitter.h>
11#include <wx/srchctrl.h>
12#include <wx/tglbtn.h>
13#include <wx/treectrl.h>
14#include <wx/wrapsizer.h>
15#include <wx/wx.h>
16
23class FileExplorerTab : public ITab {
24 public:
29 explicit FileExplorerTab(wxWindow *parent);
30
34 virtual ~FileExplorerTab();
35
36 // Non-copyable
39
40 // ITab interface implementation
41 wxWindow *GetWidget() override;
42 wxString GetTitle() const override;
43 wxString GetTabType() const override;
44 wxBitmap GetIcon() const override;
45
46 void Initialize() override;
47 void Refresh() override;
48 void OnActivated() override;
49 void OnDeactivated() override;
50 void OnClosed() override;
51
52 bool IsValid() const override;
53 bool CanClose() const override;
54 bool CanMove() const override;
55
60 wxString GetSelectedFile() const;
61
66 void SetRootDirectory(const wxString &path);
67
68 private:
69 // Layout creation methods
70 void CreateLayout();
71 void CreateFavoritesBar(wxBoxSizer *parentSizer);
72 void CreateSplitLayout(wxBoxSizer *parentSizer);
73 void CreateBreadcrumb(wxPanel *rightPanel, wxBoxSizer *rightSizer);
74 void CreateIconGrid(wxPanel *rightPanel, wxBoxSizer *rightSizer);
75 void CreateHistoryPanel(wxPanel *rightPanel, wxBoxSizer *rightSizer);
77 void ToggleHistoryView();
78
79 // Tree methods
80 void PopulateTree();
81 void AddDirectoryToTree(const wxString &path, wxTreeItemId parentItem);
82
83 // Grid methods
84 void PopulateGrid(const wxString &path);
85 void ClearGrid();
86 void AddGridItem(const wxString &name, const wxString &fullPath, bool isDirectory);
87
88 // Icon loading (centralized for easy replacement)
89 wxBitmap LoadGridIcon(const wxString &iconType, const wxSize &size);
90 wxIcon LoadTreeIcon(const wxString &iconType);
91
92 // Event handlers - Tree
93 void OnSelectionChanged(wxTreeEvent &event);
94 void OnItemActivated(wxTreeEvent &event);
95 void OnItemExpanding(wxTreeEvent &event);
96 void OnBeginDrag(wxTreeEvent &event);
97
98 // Event handlers - Grid
99 void OnGridItemDoubleClick(wxMouseEvent &event);
100 void OnGridItemMouseDown(wxMouseEvent &event);
101 void OnGridItemMouseMove(wxMouseEvent &event);
102 void OnGridItemMouseUp(wxMouseEvent &event);
103
104 // Event handlers - View Toggle
105 void OnTreeToggle(wxCommandEvent &event);
106 void OnGridToggle(wxCommandEvent &event);
109
110 // Event handlers - Splitter sync
111 void OnSplitterSashPosChanged(wxSplitterEvent &event);
112 void OnSplitterSashPosChanging(wxSplitterEvent &event);
116 void UpdateTreeImageList();
117
118 // Event handlers - Favorites/Filter
119 void OnFavoriteFilter(wxCommandEvent &event);
120
121 // Event handlers - Search
122 void OnTreeSearchTextChanged(wxCommandEvent &event);
123 void OnTreeSearchCancel(wxCommandEvent &event);
124 void OnGridSearchTextChanged(wxCommandEvent &event);
125 void OnGridSearchCancel(wxCommandEvent &event);
126
127 // Event handlers - Breadcrumb
128 void OnBreadcrumbClick(wxCommandEvent &event);
129
130 // Event handlers - Navigation History
131 void OnBackButton(wxCommandEvent &event);
132 void OnForwardButton(wxCommandEvent &event);
133 void OnHistoryButton(wxCommandEvent &event);
134 void OnNavigationKeyDown(wxKeyEvent &event);
135
136 // Event handlers - Context Menu
137 void OnTreeContextMenu(wxTreeEvent &event);
138 void OnGridContextMenu(wxMouseEvent &event);
139 void OnGridBackgroundContextMenu(wxMouseEvent &event);
140 void OnContextMenuOpen(wxCommandEvent &event);
141 void OnContextMenuNewFolder(wxCommandEvent &event);
142 void OnContextMenuRename(wxCommandEvent &event);
143 void OnContextMenuDelete(wxCommandEvent &event);
144 void OnContextMenuCopy(wxCommandEvent &event);
145 void OnContextMenuCut(wxCommandEvent &event);
146 void OnContextMenuPaste(wxCommandEvent &event);
147 void OnContextMenuRefresh(wxCommandEvent &event);
148 void OnContextMenuProperties(wxCommandEvent &event);
149
150 // Helper methods
151 void FilterTree(const wxString &searchText);
152 void FilterGrid(const wxString &searchText);
153 void ExpandAllMatching(wxTreeItemId item, const wxString &searchText, bool &foundAny);
154 bool ItemMatchesSearch(wxTreeItemId item, const wxString &searchText) const;
155 bool DirectoryContainsMatchingFiles(const wxString &dirPath) const;
156 wxString GetExecutableDirectory() const;
157 void NavigateToPath(const wxString &path, bool recordHistory = true);
158 void UpdateBreadcrumb();
159 bool PassesFilter(const wxString &filename) const;
160 bool DirectoryContainsFilteredFiles(const wxString &path) const;
161 wxTreeItemId FindTreeItemByPath(const wxString &path, wxTreeItemId parent = wxTreeItemId());
162
163 // Navigation history helpers
165 void AddToNavigationHistory(const wxString &path);
166
167 // Context menu helpers
168 bool CreateNewFolder(const wxString &parentPath, const wxString &folderName);
169 bool RenameFolder(const wxString &oldPath, const wxString &newName);
170 bool DeleteFolder(const wxString &folderPath);
171 bool CopyFolder(const wxString &sourcePath, const wxString &destPath);
172 bool MoveFolder(const wxString &sourcePath, const wxString &destPath);
173 void ShowFolderProperties(const wxString &folderPath);
174
175 // File operations
176 bool RenameFile(const wxString &oldPath, const wxString &newName);
177 bool DeleteFile(const wxString &filePath);
178 bool CopyFile(const wxString &sourcePath, const wxString &destPath);
179 bool MoveFile(const wxString &sourcePath, const wxString &destPath);
180 void ShowFileProperties(const wxString &filePath);
181 void OpenFile(const wxString &filePath);
182
183 // Utility methods
184 wxString GetDirectorySize(const wxString &path) const;
185 int CountFilesInDirectory(const wxString &path, bool recursive = true) const;
186
187 // UI Components
188 wxPanel *m_panel;
189 wxSearchCtrl *m_treeSearchCtrl; // Search control for tree grid
190 wxSearchCtrl *m_gridSearchCtrl; // Search control for icon grid
191 wxTreeCtrl *m_treeCtrl;
192 wxSplitterWindow *m_splitter;
193 wxPanel *m_leftPanel; // Left panel containing tree (kept for view toggle)
194 wxPanel *m_rightPanel; // Right panel containing grid (kept for view toggle)
195 wxScrolledWindow *m_gridCtrl;
196 wxWrapSizer *m_gridSizer;
197 wxScrolledWindow *m_historyPanel; // Panel to display navigation history (toggles with grid)
198 wxPanel *m_breadcrumbContainerPanel; // Container for navigation, breadcrumb, and functional panels
199 wxPanel *m_navigationPanel; // Panel for search control (left side)
200 wxPanel *m_breadcrumbPanel; // Panel for breadcrumb path (center)
201 wxPanel *m_functionalPanel; // Panel for history and other functional buttons (right side)
202 wxBoxSizer *m_breadcrumbSizer;
203 wxBoxSizer *m_contentSizer; // Sizer that holds both grid and history panel
204
205 // View toggle buttons
206 wxToggleButton *m_treeToggleBtn;
207 wxToggleButton *m_gridToggleBtn;
208
209 // Favorites buttons
210 wxToggleButton *m_xmlFilterBtn;
211 wxToggleButton *m_pngFilterBtn;
212 wxToggleButton *m_jsonFilterBtn;
213
214 // Navigation history buttons (in breadcrumb area)
215 wxBitmapButton *m_gridBackButton;
216 wxBitmapButton *m_gridForwardButton;
217 wxBitmapButton *m_historyButton; // Combined history dropdown button
218
219 // State
220 wxString m_rootPath;
222 wxString m_activeFilter; // "", ".xml", ".png", ".json"
224 bool m_syncInProgress; // Flag to prevent infinite recursion during tree-grid sync
225 bool m_treeVisible; // Whether tree panel is visible
226 bool m_gridVisible; // Whether grid panel is visible
227
228 // Navigation history
229 std::vector<wxString> m_backStack; // History of previously visited directories
230 std::vector<wxString> m_forwardStack; // Directories we can navigate forward to
231 bool m_isNavigatingHistory; // Flag to prevent adding to history during back/forward navigation
232 bool m_isHistoryVisible; // Flag to track if history panel is currently visible
233
234 // Activity history
247
250 wxString path;
251 wxString details; // Additional info (e.g., old name for rename, destination for paste)
252 wxDateTime timestamp;
253 };
254
255 std::vector<ActivityEntry> m_activityHistory;
256 static const size_t MAX_ACTIVITY_ENTRIES = 100;
257
258 void LogActivity(ActivityType type, const wxString &path, const wxString &details = "");
259
260 // Icons
261 wxImageList *m_imageList;
264
265 // Grid icons (large format)
266 std::map<wxString, wxBitmap> m_gridIcons;
267
268 // Grid item tracking
269 struct GridItem {
270 wxString name;
271 wxString fullPath;
273 wxWindow *widget;
274 };
275 std::vector<GridItem> m_gridItems;
277
278 // Drag and drop state for grid items
281 wxWindow *m_dragWindow; // Currently selected grid item panel
282
283 // Context menu state
284 wxString m_contextMenuPath; // Path of item that was right-clicked
285
286 // Clipboard state for copy/cut operations
287 wxString m_clipboardPath; // Path of copied/cut folder
288 bool m_clipboardIsCut; // true = cut, false = copy
289
290 // Settings from preferences
293
294 // Tree view settings
297 int m_treeSortFilesBy; // AppPreferences::SortBy stored as int to avoid header dependency
298 int m_treeItemSize; // Tree item size in pixels (16, 20, or 24)
299
300 // Grid view settings
303 int m_gridSortFilesBy; // AppPreferences::SortBy stored as int to avoid header dependency
304 int m_gridIconSize; // Icon size in pixels (48, 80, or 128)
305
306 // Helper to reload settings from preferences
307 void LoadSettings();
308
309 // Helper to get display name (with or without extension)
310 wxString GetDisplayName(const wxString &filename, bool isDirectory, bool isTreeView) const;
311
312 // Context menu IDs
324};
virtual ~FileExplorerTab()
Destructor.
bool CreateNewFolder(const wxString &parentPath, const wxString &folderName)
wxBitmap GetIcon() const override
Returns the tab icon bitmap; defaults to null.
void OnContextMenuDelete(wxCommandEvent &event)
void OnGridBackgroundContextMenu(wxMouseEvent &event)
void OpenFile(const wxString &filePath)
wxIcon LoadTreeIcon(const wxString &iconType)
void Initialize() override
Called once when the tab is first created.
wxString m_currentGridPath
bool CanMove() const override
Returns true if the tab can be moved/reordered.
void OnContextMenuOpen(wxCommandEvent &event)
void OnForwardButton(wxCommandEvent &event)
void OnSplitterSashPosChanging(wxSplitterEvent &event)
bool CopyFile(const wxString &sourcePath, const wxString &destPath)
wxPanel * m_breadcrumbContainerPanel
void OnGridContextMenu(wxMouseEvent &event)
FileExplorerTab(wxWindow *parent)
Constructor.
void OnActivated() override
Called when the tab becomes active.
wxString m_contextMenuPath
void OnTreeContextMenu(wxTreeEvent &event)
void OnContextMenuCopy(wxCommandEvent &event)
void OnGridSearchTextChanged(wxCommandEvent &event)
void FilterGrid(const wxString &searchText)
void OnContextMenuPaste(wxCommandEvent &event)
void OnContextMenuProperties(wxCommandEvent &event)
void OnGridSearchCancel(wxCommandEvent &event)
std::vector< GridItem > m_gridItems
std::vector< wxString > m_forwardStack
void OnGridItemDoubleClick(wxMouseEvent &event)
static const size_t MAX_ACTIVITY_ENTRIES
wxString GetDisplayName(const wxString &filename, bool isDirectory, bool isTreeView) const
wxScrolledWindow * m_historyPanel
void OnContextMenuCut(wxCommandEvent &event)
wxScrolledWindow * m_gridCtrl
void ShowFileProperties(const wxString &filePath)
void OnTreeToggle(wxCommandEvent &event)
void CreateHistoryPanel(wxPanel *rightPanel, wxBoxSizer *rightSizer)
wxSplitterWindow * m_splitter
void OnHistoryButton(wxCommandEvent &event)
bool MoveFile(const wxString &sourcePath, const wxString &destPath)
void AddDirectoryToTree(const wxString &path, wxTreeItemId parentItem)
bool CopyFolder(const wxString &sourcePath, const wxString &destPath)
wxString GetTabType() const override
Returns the tab type identifier.
void OnBeginDrag(wxTreeEvent &event)
wxWindow * m_dragWindow
void OnContextMenuNewFolder(wxCommandEvent &event)
wxToggleButton * m_jsonFilterBtn
int CountFilesInDirectory(const wxString &path, bool recursive=true) const
void AddGridItem(const wxString &name, const wxString &fullPath, bool isDirectory)
FileExplorerTab & operator=(const FileExplorerTab &)=delete
void OnItemExpanding(wxTreeEvent &event)
wxBoxSizer * m_breadcrumbSizer
wxPanel * m_functionalPanel
void OnClosed() override
Called when the tab is closed.
wxWindow * m_selectedGridItem
std::map< wxString, wxBitmap > m_gridIcons
wxWrapSizer * m_gridSizer
bool RenameFolder(const wxString &oldPath, const wxString &newName)
wxWindow * GetWidget() override
Returns the wxWidgets window used as the tab content.
FileExplorerTab(const FileExplorerTab &)=delete
wxString GetTitle() const override
Returns the display title of the tab.
wxToggleButton * m_pngFilterBtn
void OnSelectionChanged(wxTreeEvent &event)
wxBitmap LoadGridIcon(const wxString &iconType, const wxSize &size)
wxTreeCtrl * m_treeCtrl
wxToggleButton * m_gridToggleBtn
void UpdateToggleButtonAppearance()
void OnTreeSearchCancel(wxCommandEvent &event)
void OnSplitterSashPosChanged(wxSplitterEvent &event)
void Refresh() override
Refreshes the tab content.
bool DirectoryContainsMatchingFiles(const wxString &dirPath) const
wxToggleButton * m_xmlFilterBtn
wxString GetSelectedFile() const
Get the current selected file path.
void OnGridToggle(wxCommandEvent &event)
void PopulateGrid(const wxString &path)
void OnBackButton(wxCommandEvent &event)
bool DeleteFolder(const wxString &folderPath)
void AddToNavigationHistory(const wxString &path)
wxTreeItemId FindTreeItemByPath(const wxString &path, wxTreeItemId parent=wxTreeItemId())
wxBitmapButton * m_historyButton
wxString GetDirectorySize(const wxString &path) const
void LogActivity(ActivityType type, const wxString &path, const wxString &details="")
wxImageList * m_imageList
bool DirectoryContainsFilteredFiles(const wxString &path) const
void CreateBreadcrumb(wxPanel *rightPanel, wxBoxSizer *rightSizer)
void OnItemActivated(wxTreeEvent &event)
bool RenameFile(const wxString &oldPath, const wxString &newName)
wxSearchCtrl * m_gridSearchCtrl
void CreateFavoritesBar(wxBoxSizer *parentSizer)
void NavigateToPath(const wxString &path, bool recordHistory=true)
bool DeleteFile(const wxString &filePath)
wxString GetExecutableDirectory() const
void SetRootDirectory(const wxString &path)
Set the root directory to display.
void ShowFolderProperties(const wxString &folderPath)
void OnNavigationKeyDown(wxKeyEvent &event)
wxPanel * m_navigationPanel
void OnContextMenuRefresh(wxCommandEvent &event)
wxPanel * m_breadcrumbPanel
std::vector< wxString > m_backStack
wxSearchCtrl * m_treeSearchCtrl
void FilterTree(const wxString &searchText)
void ExpandAllMatching(wxTreeItemId item, const wxString &searchText, bool &foundAny)
wxToggleButton * m_treeToggleBtn
void OnGridItemMouseMove(wxMouseEvent &event)
void OnGridItemMouseUp(wxMouseEvent &event)
void OnTreeSearchTextChanged(wxCommandEvent &event)
void OnBreadcrumbClick(wxCommandEvent &event)
wxBitmapButton * m_gridBackButton
void CreateSplitLayout(wxBoxSizer *parentSizer)
wxBitmapButton * m_gridForwardButton
void CreateIconGrid(wxPanel *rightPanel, wxBoxSizer *rightSizer)
bool CanClose() const override
Returns true if the tab can be closed.
wxBoxSizer * m_contentSizer
bool MoveFolder(const wxString &sourcePath, const wxString &destPath)
void OnDeactivated() override
Called when the tab becomes inactive.
void OnContextMenuRename(wxCommandEvent &event)
bool ItemMatchesSearch(wxTreeItemId item, const wxString &searchText) const
bool IsValid() const override
Returns true if the tab is in a valid state.
bool PassesFilter(const wxString &filename) const
std::vector< ActivityEntry > m_activityHistory
void OnGridItemMouseDown(wxMouseEvent &event)
void OnFavoriteFilter(wxCommandEvent &event)
Interface for tab-based UI components in the application.
Definition ITab.h:7