Ember
Loading...
Searching...
No Matches
SidePanel.h
Go to the documentation of this file.
1#pragma once
2
3#include "Components/Panel.h"
5#include "Tabs/ITab.h"
7#include <string>
8#include <vector>
9#include <wx/aui/aui.h>
10#include <wx/aui/auibook.h>
11#include <wx/aui/framemanager.h>
12#include <wx/splitter.h>
13#include <wx/wx.h>
14
15class MainFrame; // Forward declaration
16
17// Forward declarations for EmberForge namespace
18namespace EmberForge {
19enum class TabType;
20}
21
33class SidePanel : public Panel {
34 public:
35 SidePanel(wxWindow *parent, MainFrame *mainFrame = nullptr, const wxString &panelName = "Side Panel",
37 EmberForge::PanelDescriptor *parentDescriptor = nullptr);
38 virtual ~SidePanel();
39
47 void FinishSetup();
48
49 // Pure virtual methods for specialization
50 wxString GetTitle() const override = 0;
51 wxString GetPanelType() const override = 0;
52
53 // Shared tab management interface
59 int AddTab(ITabPtr tab);
60
66 ITabPtr RemoveTab(int index);
67
73 ITab *GetTab(int index) const;
74
79 size_t GetTabCount() const { return m_tabs.size(); }
80
86 bool SetActiveTab(int index);
87
92 ITab *GetActiveTab() const;
93
99
105 bool HasTabWithName(const wxString &tabName) const;
106
112 void ResetToDefaultTab(EmberForge::TabType defaultTabType);
113
119 void ResetToDefaultTabs(const std::vector<EmberForge::TabType> &defaultTabTypes);
120
125 void ClearAllTabs();
126
127 // Preferences and state management
132 virtual void ApplyPreferences();
133
138 virtual void SaveState();
139
144 virtual void RestoreState();
145
146 // Tab bar button control methods (buttons integrated into tab strip)
151 void SetTabBarButtonsEnabled(bool enabled);
152
158
162 void ToggleTabBarButtons();
163
168 void SetPanelName(const wxString &name) { m_panelName = name; }
169
175
181 m_descriptor = descriptor;
182 // Update panel name to match descriptor
183 m_panelName = descriptor.GetDisplayName();
184 }
185
186 protected:
187 // Template method pattern - base implementation with hooks for specialization
188 void CreateLayout() override;
189 virtual void CreateNotebook();
190 virtual void SetupEventHandlers();
191
192 // Hook methods for derived classes to customize behavior
193 virtual void OnPanelSpecificSetup(); // Called after basic setup
194
195 // Pure virtual methods for accessing panel-specific settings
196 // These allow the base class to implement common tab restoration logic
197 virtual bool GetRememberLastTab() const = 0;
198 virtual const std::vector<std::string> &GetLastOpenTabs() const = 0;
199 virtual std::string GetLastActiveTab() const = 0;
200 virtual std::string GetDefaultActiveTab() const = 0;
201
202 // Common helper for tab restoration and fallback logic
203 // Derived classes can call this from OnPanelSpecificSetup()
205
206 // Non-virtual helpers safe to call from constructor
207 void DoCreateLayout();
208 void DoCreateNotebook();
210
211 virtual void OnAddTabButtonClicked(wxCommandEvent &event) {} // Override for custom add tab behavior
212 virtual std::vector<EmberForge::TabType> GetSupportedTabTypes() const {
213 return {};
214 } // Override to specify supported tabs
215
216 // Shared event handlers
217 void OnTabChanged(wxAuiNotebookEvent &event);
218 void OnTabClosed(wxAuiNotebookEvent &event);
219 void OnAddTabButtonClickedInternal(wxCommandEvent &event);
220 virtual void OnMenuButtonClicked(wxCommandEvent &event);
221
222 // Menu item event handlers
223 void OnHidePanelClicked(wxCommandEvent &event);
224 void OnPanelPreferencesClicked(wxCommandEvent &event);
225
226 // Tab bar button event handlers (from CustomAuiNotebook)
227 void OnTabBarAddButtonClicked(wxCommandEvent &event);
228 void OnTabBarMenuButtonClicked(wxCommandEvent &event);
229
230 // Helper methods available to derived classes
232 void ShowTabCreationMenu();
233
234 // Protected member variables
237 std::vector<ITabPtr> m_tabs;
239 wxString m_panelName;
241 bool m_isInitializing; // Flag to prevent saving state during initialization
242 EmberForge::PanelDescriptor m_descriptor; // Panel metadata and hierarchy information
243
244 // Base event IDs - derived classes should offset from these
253
254 private:
256};
std::unique_ptr< ITab > ITabPtr
Smart pointer type for ITab instances.
Definition ITab.h:145
Custom wxAuiNotebook that integrates Add Tab and Menu buttons into the tab bar.
Descriptor that tracks panel metadata.
wxString GetDisplayName() const
Get a display name for this panel type.
Abstract interface for individual tabs that can be moved between panels.
Definition ITab.h:28
Main application window for EmberForge.
Definition MainFrame.h:65
Panel(wxWindow *parent, const wxString &name="Panel", long style=wxTAB_TRAVERSAL)
Constructor.
wxString GetPanelType() const override=0
Get a unique identifier for this panel type.
void SetTabBarButtonsEnabled(bool enabled)
Enable or disable the tab bar buttons (+ and menu)
@ ID_BASE_ADD_TAB_BUTTON
Definition SidePanel.h:249
@ ID_BASE_NOTEBOOK
Definition SidePanel.h:246
@ ID_BASE_PREFERENCES_MENU_ITEM
Definition SidePanel.h:248
@ ID_BASE_HIDE_PANEL_MENU_ITEM
Definition SidePanel.h:247
@ ID_BASE_MENU_BUTTON
Definition SidePanel.h:250
void FinishSetup()
Complete panel setup after construction.
Definition SidePanel.cpp:83
virtual void ApplyPreferences()
Apply preferences to the side panel Virtual to allow derived classes to use their specific settings.
void DoCreateNotebook()
ITabPtr RemoveTab(int index)
Remove a tab by index.
void OnTabChanged(wxAuiNotebookEvent &event)
virtual const std::vector< std::string > & GetLastOpenTabs() const =0
std::vector< ITabPtr > m_tabs
Definition SidePanel.h:237
void ClearAllTabs()
Clear all tabs from the panel Removes all tabs without creating any new ones.
void OnHidePanelClicked(wxCommandEvent &event)
bool HasTabWithName(const wxString &tabName) const
Check if this panel has a tab with the given name.
int AddTab(ITabPtr tab)
Add a tab to this panel.
wxString GetTitle() const override=0
Get the display title for this panel.
void DoCreateLayout()
Definition SidePanel.cpp:61
void ResetToDefaultTab(EmberForge::TabType defaultTabType)
Reset the panel to a single default tab Closes all tabs and creates only the specified default tab.
void RestoreAndEnsureTabs()
bool m_tabBarButtonsEnabled
Definition SidePanel.h:240
virtual void CreateNotebook()
Definition SidePanel.cpp:98
virtual void SetupEventHandlers()
ITab * GetActiveTab() const
Get the currently active tab.
virtual ~SidePanel()
Definition SidePanel.cpp:42
void OnPanelPreferencesClicked(wxCommandEvent &event)
void SetPanelName(const wxString &name)
Set the panel name (for split panels)
Definition SidePanel.h:168
virtual void OnMenuButtonClicked(wxCommandEvent &event)
virtual void OnPanelSpecificSetup()
void DoSetupEventHandlers()
void OnAddTabButtonClickedInternal(wxCommandEvent &event)
MainFrame * m_mainFrame
Definition SidePanel.h:235
SidePanel(wxWindow *parent, MainFrame *mainFrame=nullptr, const wxString &panelName="Side Panel", EmberForge::PanelType panelType=EmberForge::PanelType::LeftPanel, EmberForge::PanelDescriptor *parentDescriptor=nullptr)
void OnTabClosed(wxAuiNotebookEvent &event)
virtual std::string GetLastActiveTab() const =0
void SetPanelDescriptor(const EmberForge::PanelDescriptor &descriptor)
Update the panel descriptor (used when creating split panels)
Definition SidePanel.h:180
int m_activeTabIndex
Definition SidePanel.h:238
EmberForge::CustomAuiNotebook * GetNotebook() const
Get the notebook widget for direct access.
Definition SidePanel.h:98
void ShowTabCreationMenu()
wxString m_panelName
Definition SidePanel.h:239
const EmberForge::PanelDescriptor & GetPanelDescriptor() const
Get the panel descriptor for this panel.
Definition SidePanel.h:174
void ToggleTabBarButtons()
Toggle tab bar buttons visibility.
bool AreTabBarButtonsEnabled() const
Check if tab bar buttons are enabled.
Definition SidePanel.h:157
virtual void OnAddTabButtonClicked(wxCommandEvent &event)
Definition SidePanel.h:211
virtual void RestoreState()
Restore state from preferences Virtual to allow derived classes to use their specific settings.
void OnTabBarMenuButtonClicked(wxCommandEvent &event)
bool SetActiveTab(int index)
Set the active tab by index.
virtual bool GetRememberLastTab() const =0
void CreateAndAddTab(EmberForge::TabType tabType)
virtual void SaveState()
Save the current state (last active tab, etc.) Virtual to allow derived classes to use their specific...
EmberForge::PanelDescriptor m_descriptor
Definition SidePanel.h:242
void ResetToDefaultTabs(const std::vector< EmberForge::TabType > &defaultTabTypes)
Reset the panel to multiple default tabs Closes all tabs and creates the specified default tabs.
bool m_isInitializing
Definition SidePanel.h:241
wxDECLARE_EVENT_TABLE()
virtual std::vector< EmberForge::TabType > GetSupportedTabTypes() const
Definition SidePanel.h:212
EmberForge::CustomAuiNotebook * m_notebook
Definition SidePanel.h:236
void OnTabBarAddButtonClicked(wxCommandEvent &event)
size_t GetTabCount() const
Get the number of tabs.
Definition SidePanel.h:79
void CreateLayout() override
Create the panel's UI layout Called during initialization.
Definition SidePanel.cpp:57
virtual std::string GetDefaultActiveTab() const =0
ITab * GetTab(int index) const
Get a tab by index.
PanelType
Defines the type of panel in the UI hierarchy.
TabType
Enumeration of available tab types.
Definition TabFactory.h:17