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