Ember
Loading...
Searching...
No Matches
RightSidePanel.cpp
Go to the documentation of this file.
1#include "Panels/RightSidePanel.h"
2#include "App/MainFrame.h"
5#include "Utils/Logger.h"
6
7// Event table for right panel specific events
10
11 RightSidePanel::RightSidePanel(wxWindow *parent, MainFrame *mainFrame)
12 : SidePanel(parent, mainFrame, "Right Panel", EmberForge::PanelType::RightPanel, nullptr) {
13 LOG_INFO("Panel", "Created RightSidePanel with wxAuiToolBar");
14}
15
16RightSidePanel::~RightSidePanel() { LOG_INFO("Panel", "Destroying RightSidePanel"); }
17
18// Settings accessor implementations for common tab restoration logic
23
24const std::vector<std::string> &RightSidePanel::GetLastOpenTabs() const {
27}
28
33
38
39// Override hook methods to customize right panel behavior
41 LOG_INFO("Panel", "*** RightSidePanel::OnPanelSpecificSetup() called ***");
43 LOG_INFO("Panel", "RightSidePanel::OnPanelSpecificSetup() completed");
44}
45
49
50void RightSidePanel::OnAddTabButtonClicked(wxCommandEvent &event) {
51 LOG_INFO("Panel", "Right panel add tab button clicked - showing custom menu");
53}
54
55void RightSidePanel::OnAddPropertiesTab(wxCommandEvent &event) {
56 LOG_INFO("Panel", "Adding Properties tab to right panel");
58}
59
62 const auto &settings = prefs.GetRightPanelSettings();
63
64 if (!GetNotebook()) {
65 LOG_ERROR("RightPanel", "Cannot apply preferences - notebook is null");
66 return;
67 }
68
69 // Apply tab close button preference
70 long style = GetNotebook()->GetWindowStyle();
71 if (settings.showTabCloseButtons) {
72 style |= wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
73 } else {
74 style &= ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
75 }
76 GetNotebook()->SetWindowStyle(style);
77
78 LOG_INFO("RightPanel",
79 wxString::Format("Applied preferences - closeButtons: %d", settings.showTabCloseButtons).ToStdString());
80}
81
83 // Don't save state during initialization - wait until RestoreState completes
84 if (m_isInitializing) {
85 return;
86 }
87
89 auto &settings = prefs.GetRightPanelSettings();
90
91 // Always save the last active tab to lastActiveTab
92 // This way rememberLastTab can be toggled on/off without losing the value
93 if (GetNotebook()) {
94 int activeIndex = GetNotebook()->GetSelection();
95
96 if (activeIndex != wxNOT_FOUND && activeIndex < static_cast<int>(GetNotebook()->GetPageCount())) {
97 wxString tabDisplayName = GetNotebook()->GetPageText(activeIndex);
98
99 // Convert display name back to TabType string identifier
101 for (const auto &tabType : sidePanelTabs) {
102 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
103 settings.lastActiveTab = EmberForge::TabFactory::TabTypeToString(tabType);
104 LOG_INFO("RightPanel", std::string("Saved last active tab: ") + settings.lastActiveTab);
105 break;
106 }
107 }
108 }
109
110 // Save all currently open tabs
111 settings.lastOpenTabs.clear();
112 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
113 wxString tabDisplayName = GetNotebook()->GetPageText(i);
114
115 // Convert display name back to TabType string identifier
117 for (const auto &tabType : sidePanelTabs) {
118 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
119 settings.lastOpenTabs.push_back(EmberForge::TabFactory::TabTypeToString(tabType));
120 break;
121 }
122 }
123 }
124 LOG_INFO("RightPanel", wxString::Format("Saved %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
125 }
126}
127
130 const auto &settings = prefs.GetRightPanelSettings();
131
132 if (!GetNotebook())
133 return;
134
135 if (settings.rememberLastTab && !settings.lastOpenTabs.empty()) {
136 // Restore all tabs that were open
137 LOG_INFO("RightPanel", wxString::Format("Restoring %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
138
139 for (const auto &tabTypeStr : settings.lastOpenTabs) {
141 wxString tabDisplayName = EmberForge::TabFactory::GetTabDisplayName(tabType);
142
143 // Check if this tab is already open
144 bool alreadyOpen = false;
145 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
146 if (GetNotebook()->GetPageText(i) == tabDisplayName) {
147 alreadyOpen = true;
148 break;
149 }
150 }
151
152 // Create the tab if it's not already open
153 if (!alreadyOpen) {
154 CreateAndAddTab(tabType);
155 LOG_INFO("RightPanel", wxString::Format("Restored tab: %s", tabDisplayName).ToStdString());
156 }
157 }
158
159 // Now select the last active tab
160 wxString targetTabName =
162
163 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
164 if (GetNotebook()->GetPageText(i) == targetTabName) {
165 GetNotebook()->SetSelection(i);
166 LOG_INFO("RightPanel", wxString::Format("Selected active tab: %s", targetTabName).ToStdString());
167 break;
168 }
169 }
170 } else {
171 // Just select the default tab if it exists
172 EmberForge::TabType targetTabType = EmberForge::TabFactory::StringToTabType(settings.defaultActiveTab);
173 wxString targetTabName = EmberForge::TabFactory::GetTabDisplayName(targetTabType);
174
175 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
176 if (GetNotebook()->GetPageText(i) == targetTabName) {
177 GetNotebook()->SetSelection(i);
178 LOG_INFO("RightPanel", wxString::Format("Selected default tab: %s", targetTabName).ToStdString());
179 break;
180 }
181 }
182 }
183
184 // Mark initialization as complete - now we can start auto-saving state
185 m_isInitializing = false;
186}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
wxBEGIN_EVENT_TABLE(RightSidePanel, SidePanel) EVT_MENU(ID_ADD_PROPERTIES_TAB
#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
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.
wxAuiNotebook * GetNotebook() const
Returns the underlying wxAuiNotebook.
Definition SidePanel.h:35
Main application window for EmberForge.
Definition MainFrame.h:67
Right sidebar panel specialized for right-side functionality.
std::vector< EmberForge::TabType > GetSupportedTabTypes() const override
void OnAddTabButtonClicked(wxCommandEvent &event) override
void RestoreState() override
void SaveState() override
const std::vector< std::string > & GetLastOpenTabs() const override
std::string GetDefaultActiveTab() const override
void ApplyPreferences() override
void OnPanelSpecificSetup() override
void OnAddPropertiesTab(wxCommandEvent &event)
std::string GetLastActiveTab() const override
bool GetRememberLastTab() const override
virtual ~RightSidePanel()
void RestoreAndEnsureTabs()
void ShowTabCreationMenu()
void CreateAndAddTab(EmberForge::TabType tabType)
bool m_isInitializing
TabType
Enumeration of available tab types.
Definition TabFactory.h:17
std::vector< EmberCore::String > lastOpenTabs