Ember
Loading...
Searching...
No Matches
RightSidePanel.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
5#include "Utils/Logger.h"
6
7// Event table for right panel specific events
9 EVT_MENU(ID_ADD_SCENE_HIERARCHY_TAB, RightSidePanel::OnAddSceneHierarchyTab)
10 EVT_MENU(ID_ADD_PROPERTIES_TAB, RightSidePanel::OnAddPropertiesTab) wxEND_EVENT_TABLE()
11
12 RightSidePanel::RightSidePanel(wxWindow *parent, MainFrame *mainFrame)
13 : SidePanel(parent, mainFrame, "Right Panel", EmberForge::PanelType::RightPanel, nullptr) {
14 LOG_INFO("Panel", "Created RightSidePanel with wxAuiToolBar");
15}
16
17RightSidePanel::~RightSidePanel() { LOG_INFO("Panel", "Destroying RightSidePanel"); }
18
19// Settings accessor implementations for common tab restoration logic
24
25const std::vector<std::string> &RightSidePanel::GetLastOpenTabs() const {
28}
29
34
39
40// Override hook methods to customize right panel behavior
42 LOG_INFO("Panel", "*** RightSidePanel::OnPanelSpecificSetup() called ***");
44 LOG_INFO("Panel", "RightSidePanel::OnPanelSpecificSetup() completed");
45}
46
50
51void RightSidePanel::OnAddTabButtonClicked(wxCommandEvent &event) {
52 LOG_INFO("Panel", "Right panel add tab button clicked - showing custom menu");
54}
55
56// Right panel specific event handlers for tab creation menu items
57void RightSidePanel::OnAddSceneHierarchyTab(wxCommandEvent &event) {
58 LOG_INFO("Panel", "Adding Scene Hierarchy tab to right panel");
60}
61
62void RightSidePanel::OnAddPropertiesTab(wxCommandEvent &event) {
63 LOG_INFO("Panel", "Adding Properties tab to right panel");
65}
66
69 const auto &settings = prefs.GetRightPanelSettings();
70
71 if (!GetNotebook()) {
72 LOG_ERROR("RightPanel", "Cannot apply preferences - notebook is null");
73 return;
74 }
75
76 // Apply tab close button preference
77 long style = GetNotebook()->GetWindowStyle();
78 if (settings.showTabCloseButtons) {
79 style |= wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
80 } else {
81 style &= ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
82 }
83 GetNotebook()->SetWindowStyle(style);
84
85 LOG_INFO("RightPanel",
86 wxString::Format("Applied preferences - closeButtons: %d", settings.showTabCloseButtons).ToStdString());
87}
88
90 // Don't save state during initialization - wait until RestoreState completes
91 if (m_isInitializing) {
92 return;
93 }
94
96 auto &settings = prefs.GetRightPanelSettings();
97
98 // Always save the last active tab to lastActiveTab
99 // This way rememberLastTab can be toggled on/off without losing the value
100 if (GetNotebook()) {
101 int activeIndex = GetNotebook()->GetSelection();
102
103 if (activeIndex != wxNOT_FOUND && activeIndex < static_cast<int>(GetNotebook()->GetPageCount())) {
104 wxString tabDisplayName = GetNotebook()->GetPageText(activeIndex);
105
106 // Convert display name back to TabType string identifier
108 for (const auto &tabType : sidePanelTabs) {
109 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
110 settings.lastActiveTab = EmberForge::TabFactory::TabTypeToString(tabType);
111 LOG_INFO("RightPanel", std::string("Saved last active tab: ") + settings.lastActiveTab);
112 break;
113 }
114 }
115 }
116
117 // Save all currently open tabs
118 settings.lastOpenTabs.clear();
119 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
120 wxString tabDisplayName = GetNotebook()->GetPageText(i);
121
122 // Convert display name back to TabType string identifier
124 for (const auto &tabType : sidePanelTabs) {
125 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
126 settings.lastOpenTabs.push_back(EmberForge::TabFactory::TabTypeToString(tabType));
127 break;
128 }
129 }
130 }
131 LOG_INFO("RightPanel", wxString::Format("Saved %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
132 }
133}
134
137 const auto &settings = prefs.GetRightPanelSettings();
138
139 if (!GetNotebook())
140 return;
141
142 if (settings.rememberLastTab && !settings.lastOpenTabs.empty()) {
143 // Restore all tabs that were open
144 LOG_INFO("RightPanel", wxString::Format("Restoring %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
145
146 for (const auto &tabTypeStr : settings.lastOpenTabs) {
148 wxString tabDisplayName = EmberForge::TabFactory::GetTabDisplayName(tabType);
149
150 // Check if this tab is already open
151 bool alreadyOpen = false;
152 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
153 if (GetNotebook()->GetPageText(i) == tabDisplayName) {
154 alreadyOpen = true;
155 break;
156 }
157 }
158
159 // Create the tab if it's not already open
160 if (!alreadyOpen) {
161 CreateAndAddTab(tabType);
162 LOG_INFO("RightPanel", wxString::Format("Restored tab: %s", tabDisplayName).ToStdString());
163 }
164 }
165
166 // Now select the last active tab
167 wxString targetTabName =
169
170 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
171 if (GetNotebook()->GetPageText(i) == targetTabName) {
172 GetNotebook()->SetSelection(i);
173 LOG_INFO("RightPanel", wxString::Format("Selected active tab: %s", targetTabName).ToStdString());
174 break;
175 }
176 }
177 } else {
178 // Just select the default tab if it exists
179 EmberForge::TabType targetTabType = EmberForge::TabFactory::StringToTabType(settings.defaultActiveTab);
180 wxString targetTabName = EmberForge::TabFactory::GetTabDisplayName(targetTabType);
181
182 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
183 if (GetNotebook()->GetPageText(i) == targetTabName) {
184 GetNotebook()->SetSelection(i);
185 LOG_INFO("RightPanel", wxString::Format("Selected default tab: %s", targetTabName).ToStdString());
186 break;
187 }
188 }
189 }
190
191 // Mark initialization as complete - now we can start auto-saving state
192 m_isInitializing = false;
193}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
#define LOG_ERROR(category, message)
Definition Logger.h:116
#define LOG_INFO(category, message)
Definition Logger.h:114
MainFrame::OnExit EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(ID_NewProject
wxBEGIN_EVENT_TABLE(RightSidePanel, SidePanel) EVT_MENU(ID_ADD_PROPERTIES_TAB
static AppPreferencesManager & GetInstance()
RightPanelSettings & GetRightPanelSettings()
static wxString GetTabDisplayName(TabType type)
Get the display name for a tab type.
static std::vector< TabType > GetSidePanelTabTypes()
Get tab types supported by the side panels.
static std::string TabTypeToString(TabType type)
Convert tab type to string identifier (for preferences storage)
static TabType StringToTabType(const std::string &str)
Convert string identifier to tab type.
Main application window for EmberForge.
Definition MainFrame.h:65
Right sidebar panel specialized for right-side functionality.
std::vector< EmberForge::TabType > GetSupportedTabTypes() const override
void OnAddTabButtonClicked(wxCommandEvent &event) override
void RestoreState() override
Restore state from preferences Virtual to allow derived classes to use their specific settings.
void SaveState() override
Save the current state (last active tab, etc.) Virtual to allow derived classes to use their specific...
const std::vector< std::string > & GetLastOpenTabs() const override
std::string GetDefaultActiveTab() const override
void OnAddSceneHierarchyTab(wxCommandEvent &event)
void ApplyPreferences() override
Apply preferences to the side panel Virtual to allow derived classes to use their specific settings.
void OnPanelSpecificSetup() override
void OnAddPropertiesTab(wxCommandEvent &event)
std::string GetLastActiveTab() const override
bool GetRememberLastTab() const override
virtual ~RightSidePanel()
Base class for sidebar panels with shared tab management backend.
Definition SidePanel.h:33
void RestoreAndEnsureTabs()
EmberForge::CustomAuiNotebook * GetNotebook() const
Get the notebook widget for direct access.
Definition SidePanel.h:98
void ShowTabCreationMenu()
void CreateAndAddTab(EmberForge::TabType tabType)
bool m_isInitializing
Definition SidePanel.h:241
TabType
Enumeration of available tab types.
Definition TabFactory.h:17
std::vector< EmberCore::String > lastOpenTabs