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
11
12 LeftSidePanel::LeftSidePanel(wxWindow *parent, MainFrame *mainFrame)
13 : SidePanel(parent, mainFrame, "Left Panel", EmberForge::PanelType::LeftPanel, nullptr) {
14 LOG_INFO("Panel", "Created LeftSidePanel with wxAuiToolBar");
15}
16
17LeftSidePanel::~LeftSidePanel() { LOG_INFO("Panel", "Destroying LeftSidePanel"); }
18
19// Settings accessor implementations for common tab restoration logic
24
25const std::vector<std::string> &LeftSidePanel::GetLastOpenTabs() const {
28}
29
34
39
40// Override hook methods to customize left panel behavior
42 LOG_INFO("Panel", "*** LeftSidePanel::OnPanelSpecificSetup() called ***");
44 LOG_INFO("Panel", "LeftSidePanel::OnPanelSpecificSetup() completed");
45}
46
47void LeftSidePanel::OnAddTabButtonClicked(wxCommandEvent &event) {
48 LOG_INFO("Panel", "Left panel add tab button clicked - showing tab creation menu");
50}
51
55
56void LeftSidePanel::OnAddPropertiesTab(wxCommandEvent &event) {
57 LOG_INFO("Panel", "Adding Properties tab to left panel");
59}
60
63 const auto &settings = prefs.GetLeftPanelSettings();
64
65 if (!GetNotebook()) {
66 LOG_ERROR("LeftPanel", "Cannot apply preferences - notebook is null");
67 return;
68 }
69
70 // Apply tab close button preference
71 long style = GetNotebook()->GetWindowStyle();
72 if (settings.showTabCloseButtons) {
73 style |= wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
74 } else {
75 style &= ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
76 }
77 GetNotebook()->SetWindowStyle(style);
78
79 LOG_INFO("LeftPanel",
80 wxString::Format("Applied preferences - closeButtons: %d", settings.showTabCloseButtons).ToStdString());
81}
82
84 // Don't save state during initialization - wait until RestoreState completes
85 if (m_isInitializing) {
86 return;
87 }
88
90 auto &settings = prefs.GetLeftPanelSettings();
91
92 // Always save the last active tab to lastActiveTab
93 // This way rememberLastTab can be toggled on/off without losing the value
94 if (GetNotebook()) {
95 int activeIndex = GetNotebook()->GetSelection();
96
97 if (activeIndex != wxNOT_FOUND && activeIndex < static_cast<int>(GetNotebook()->GetPageCount())) {
98 wxString tabDisplayName = GetNotebook()->GetPageText(activeIndex);
99
100 // Convert display name back to TabType string identifier
102 for (const auto &tabType : sidePanelTabs) {
103 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
104 settings.lastActiveTab = EmberForge::TabFactory::TabTypeToString(tabType);
105 LOG_INFO("LeftPanel", std::string("Saved last active tab: ") + settings.lastActiveTab);
106 break;
107 }
108 }
109 }
110
111 // Save all currently open tabs
112 settings.lastOpenTabs.clear();
113 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
114 wxString tabDisplayName = GetNotebook()->GetPageText(i);
115
116 // Convert display name back to TabType string identifier
118 for (const auto &tabType : sidePanelTabs) {
119 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
120 settings.lastOpenTabs.push_back(EmberForge::TabFactory::TabTypeToString(tabType));
121 break;
122 }
123 }
124 }
125 LOG_INFO("LeftPanel", wxString::Format("Saved %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
126 }
127}
128
131 const auto &settings = prefs.GetLeftPanelSettings();
132
133 if (!GetNotebook())
134 return;
135
136 if (settings.rememberLastTab && !settings.lastOpenTabs.empty()) {
137 // Restore all tabs that were open
138 LOG_INFO("LeftPanel", wxString::Format("Restoring %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
139
140 for (const auto &tabTypeStr : settings.lastOpenTabs) {
142 wxString tabDisplayName = EmberForge::TabFactory::GetTabDisplayName(tabType);
143
144 // Check if this tab is already open
145 bool alreadyOpen = false;
146 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
147 if (GetNotebook()->GetPageText(i) == tabDisplayName) {
148 alreadyOpen = true;
149 break;
150 }
151 }
152
153 // Create the tab if it's not already open
154 if (!alreadyOpen) {
155 CreateAndAddTab(tabType);
156 LOG_INFO("LeftPanel", wxString::Format("Restored tab: %s", tabDisplayName).ToStdString());
157 }
158 }
159
160 // Now select the last active tab
161 wxString targetTabName =
163
164 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
165 if (GetNotebook()->GetPageText(i) == targetTabName) {
166 GetNotebook()->SetSelection(i);
167 LOG_INFO("LeftPanel", wxString::Format("Selected active tab: %s", targetTabName).ToStdString());
168 break;
169 }
170 }
171 } else {
172 // Just select the default tab if it exists
173 EmberForge::TabType targetTabType = EmberForge::TabFactory::StringToTabType(settings.defaultActiveTab);
174 wxString targetTabName = EmberForge::TabFactory::GetTabDisplayName(targetTabType);
175
176 for (size_t i = 0; i < GetNotebook()->GetPageCount(); ++i) {
177 if (GetNotebook()->GetPageText(i) == targetTabName) {
178 GetNotebook()->SetSelection(i);
179 LOG_INFO("LeftPanel", wxString::Format("Selected default tab: %s", targetTabName).ToStdString());
180 break;
181 }
182 }
183 }
184
185 // Mark initialization as complete - now we can start auto-saving state
186 m_isInitializing = false;
187}
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.
wxAuiNotebook * GetNotebook() const
Returns the underlying wxAuiNotebook.
Definition SidePanel.h:35
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
bool GetRememberLastTab() const override
virtual ~LeftSidePanel()
void OnPanelSpecificSetup() override
void ApplyPreferences() override
std::vector< EmberForge::TabType > GetSupportedTabTypes() const override
std::string GetDefaultActiveTab() const override
void SaveState() override
void OnAddPropertiesTab(wxCommandEvent &event)
Main application window for EmberForge.
Definition MainFrame.h:67
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