Ember
Loading...
Searching...
No Matches
BottomPanel.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
6#include <ctime>
7#include <fstream>
8#include <wx/sizer.h>
9
11 EVT_MENU(ID_ADD_PERFORMANCE_TAB, BottomPanel::OnAddPerformanceTab)
12 EVT_MENU(ID_ADD_FILE_EXPLORER_TAB, BottomPanel::OnAddFileExplorerTab) wxEND_EVENT_TABLE()
13
14 BottomPanel::BottomPanel(wxWindow *parent, MainFrame *mainFrame)
15 : SidePanel(parent, mainFrame, "Bottom Panel", EmberForge::PanelType::BottomPanel, nullptr), m_logOutput(nullptr),
16 m_logPanel(nullptr), m_performancePanel(nullptr) {
17 SetBackgroundColour(wxColour(60, 60, 60)); // Dark gray
18}
19
21 // SidePanel destructor handles cleanup
22}
23
24// Settings accessor implementations for common tab restoration logic
29
30const std::vector<std::string> &BottomPanel::GetLastOpenTabs() const {
33}
34
39
40std::string BottomPanel::GetDefaultActiveTab() const { return "FileExplorer"; }
41
43 LOG_INFO("BottomPanel", "*** BottomPanel::OnPanelSpecificSetup() called ***");
45 LOG_INFO("BottomPanel", "OnPanelSpecificSetup() completed");
46}
47
48void BottomPanel::OnAddTabButtonClicked(wxCommandEvent &event) {
49 LOG_INFO("Panel", "Bottom panel add tab button clicked - showing tab creation menu");
51}
52
53std::vector<EmberForge::TabType> BottomPanel::GetSupportedTabTypes() const {
54 // Use TabFactory as the single source of truth for bottom panel tabs
56}
57
59
61
63
66 const auto &settings = prefs.GetBottomPanelSettings();
67
68 if (!m_notebook) {
69 LOG_ERROR("BottomPanel", "Cannot apply preferences - notebook is null");
70 return;
71 }
72
73 LOG_INFO("BottomPanel", "Applying bottom panel preferences");
74
75 // Get current notebook style
76 long style = m_notebook->GetWindowStyleFlag();
77
78 // Apply tab close buttons setting
79 if (settings.showTabCloseButtons) {
80 style |= wxAUI_NB_CLOSE_ON_ALL_TABS;
81 } else {
82 style &= ~wxAUI_NB_CLOSE_ON_ALL_TABS;
83 style &= ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB;
84 style &= ~wxAUI_NB_CLOSE_BUTTON;
85 }
86
87 // Apply the new style
88 m_notebook->SetWindowStyleFlag(style);
89
90 LOG_INFO("BottomPanel",
91 wxString::Format("Applied preferences - closeButtons: %d", settings.showTabCloseButtons).ToStdString());
92}
93
95 // Don't save state during initialization - wait until RestoreState completes
96 if (m_isInitializing) {
97 return;
98 }
99
101 auto &settings = prefs.GetBottomPanelSettings();
102
103 // Always save the last active tab to lastActiveTab
104 // This way rememberLastTab can be toggled on/off without losing the value
105 if (m_notebook) {
106 int activeIndex = m_notebook->GetSelection();
107
108 if (activeIndex != wxNOT_FOUND && activeIndex < static_cast<int>(m_notebook->GetPageCount())) {
109 wxString tabDisplayName = m_notebook->GetPageText(activeIndex);
110
111 // Convert display name back to TabType string identifier
112 auto bottomPanelTabs = EmberForge::TabFactory::GetBottomPanelTabTypes();
113 for (const auto &tabType : bottomPanelTabs) {
114 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
115 settings.lastActiveTab = EmberForge::TabFactory::TabTypeToString(tabType);
116 LOG_INFO("BottomPanel", std::string("Saved last active tab: ") + settings.lastActiveTab);
117 break;
118 }
119 }
120 }
121
122 // Save all currently open tabs
123 settings.lastOpenTabs.clear();
124 for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
125 wxString tabDisplayName = m_notebook->GetPageText(i);
126
127 // Convert display name back to TabType string identifier
128 auto bottomPanelTabs = EmberForge::TabFactory::GetBottomPanelTabTypes();
129 for (const auto &tabType : bottomPanelTabs) {
130 if (EmberForge::TabFactory::GetTabDisplayName(tabType) == tabDisplayName) {
131 settings.lastOpenTabs.push_back(EmberForge::TabFactory::TabTypeToString(tabType));
132 break;
133 }
134 }
135 }
136 LOG_INFO("BottomPanel", wxString::Format("Saved %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
137 }
138}
139
142 const auto &settings = prefs.GetBottomPanelSettings();
143
144 if (!m_notebook)
145 return;
146
147 if (settings.rememberLastTab && !settings.lastOpenTabs.empty()) {
148 // Restore all tabs that were open
149 LOG_INFO("BottomPanel",
150 wxString::Format("Restoring %zu open tabs", settings.lastOpenTabs.size()).ToStdString());
151
152 for (const auto &tabTypeStr : settings.lastOpenTabs) {
154 wxString tabDisplayName = EmberForge::TabFactory::GetTabDisplayName(tabType);
155
156 // Check if this tab is already open
157 bool alreadyOpen = false;
158 for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
159 if (m_notebook->GetPageText(i) == tabDisplayName) {
160 alreadyOpen = true;
161 break;
162 }
163 }
164
165 // Create the tab if it's not already open
166 if (!alreadyOpen) {
167 CreateAndAddTab(tabType);
168 LOG_INFO("BottomPanel", wxString::Format("Restored tab: %s", tabDisplayName).ToStdString());
169 }
170 }
171
172 // Now select the last active tab
173 wxString targetTabName =
175
176 for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
177 if (m_notebook->GetPageText(i) == targetTabName) {
178 m_notebook->SetSelection(i);
179 LOG_INFO("BottomPanel", wxString::Format("Selected active tab: %s", targetTabName).ToStdString());
180 break;
181 }
182 }
183 } else {
184 // Just select File Explorer as default if it exists
186
187 for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
188 if (m_notebook->GetPageText(i) == targetTabName) {
189 m_notebook->SetSelection(i);
190 LOG_INFO("BottomPanel", wxString::Format("Selected default tab: %s", targetTabName).ToStdString());
191 break;
192 }
193 }
194 }
195
196 // Mark initialization as complete - now we can start auto-saving state
197 m_isInitializing = false;
198}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
wxBEGIN_EVENT_TABLE(BottomPanel, SidePanel) EVT_MENU(ID_ADD_LOG_TAB
BottomPanel::OnAddLogTab EVT_MENU(ID_ADD_FILE_EXPLORER_TAB, BottomPanel::OnAddFileExplorerTab) wxEND_EVENT_TABLE() BottomPanel
#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
Bottom dockable panel for logs and output.
Definition BottomPanel.h:45
std::string GetDefaultActiveTab() const override
void RestoreState() override
void SaveState() override
void OnAddTabButtonClicked(wxCommandEvent &event) override
void OnAddPerformanceTab(wxCommandEvent &event)
void OnAddLogTab(wxCommandEvent &event)
bool GetRememberLastTab() const override
void ApplyPreferences() override
std::string GetLastActiveTab() const override
std::vector< EmberForge::TabType > GetSupportedTabTypes() const override
const std::vector< std::string > & GetLastOpenTabs() const override
void OnPanelSpecificSetup() override
void OnAddFileExplorerTab(wxCommandEvent &event)
virtual ~BottomPanel()
static AppPreferencesManager & GetInstance()
BottomPanelSettings & GetBottomPanelSettings()
static wxString GetTabDisplayName(TabType type)
Get the display name for a tab type.
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.
static std::vector< TabType > GetBottomPanelTabTypes()
Get tab types supported by the bottom panel.
wxAuiNotebook * m_notebook
Definition SidePanel.h:50
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