14#include <wx/artprov.h>
15#include <wx/bmpbuttn.h>
16#include <wx/filename.h>
21#include <wxSVG/imagsvg.h>
33 :
Panel(parent, panelName), m_mainFrame(mainFrame), m_notebook(
nullptr), m_activeTabIndex(-1),
34 m_panelName(panelName), m_tabBarButtonsEnabled(true), m_isInitializing(true),
35 m_descriptor(panelType, parentDescriptor ? parentDescriptor->GetHierarchyLevel() + 1 : 0, parentDescriptor) {
36 LOG_INFO(
"Panel", std::string(
"Creating side panel: ") + m_panelName.ToStdString() +
37 " (Type: " + m_descriptor.GetDisplayName().ToStdString() +
38 ", Level: " + std::to_string(m_descriptor.GetHierarchyLevel()) +
")");
63 wxBoxSizer *mainSizer =
new wxBoxSizer(wxVERTICAL);
72 mainSizer->Add(
m_notebook, 1, wxEXPAND | wxALL, 2);
80 LOG_INFO(
"Panel", std::string(
"Layout created for side panel: ") +
m_panelName.ToStdString());
86 LOG_INFO(
"Panel", std::string(
"Calling OnPanelSpecificSetup() for ") +
m_panelName.ToStdString() +
87 " (type: " + std::string(
typeid(*this).name()) +
")");
89 LOG_INFO(
"Panel", std::string(
"OnPanelSpecificSetup() completed for ") +
m_panelName.ToStdString());
93 LOG_INFO(
"Panel", std::string(
"Notebook has ") + std::to_string(
m_notebook->GetPageCount()) +
94 " pages after OnPanelSpecificSetup()");
104 long style = wxAUI_NB_DEFAULT_STYLE;
105 style &= ~wxAUI_NB_TAB_MOVE;
106 style &= ~wxAUI_NB_TAB_EXTERNAL_MOVE;
107 style &= ~wxAUI_NB_TAB_SPLIT;
117 " with integrated tab bar buttons");
132 LOG_INFO(
"Panel", std::string(
"Base OnPanelSpecificSetup() called for %s") +
m_panelName.ToStdString());
136 LOG_INFO(
"Panel", std::string(
"*** RestoreAndEnsureTabs() called for ") +
m_panelName.ToStdString() +
" ***");
141 if (!lastOpenTabs.empty()) {
142 LOG_INFO(
"Panel", wxString::Format(
"Restoring %zu saved tabs", lastOpenTabs.size()).ToStdString());
143 for (
const auto &tabTypeStr : lastOpenTabs) {
153 LOG_INFO(
"Panel",
"No tabs exist, trying to create a default tab");
156 for (
const auto &tabType : supportedTypes) {
161 if (countAfter > countBefore) {
162 LOG_INFO(
"Panel", wxString::Format(
"Created fallback tab: %s",
170 LOG_ERROR(
"Panel", std::string(
"Failed to create any default tab for ") +
m_panelName.ToStdString() +
171 " - all supported types at max instances");
186 for (
size_t i = 0; i <
GetNotebook()->GetPageCount(); ++i) {
187 if (
GetNotebook()->GetPageText(i) == targetTabName) {
188 targetIndex =
static_cast<int>(i);
194 LOG_INFO(
"Panel", wxString::Format(
"Set active tab to '%s' (index %d) [rememberLastTab=%s], total tabs: %d",
200 LOG_INFO(
"Panel", std::string(
"RestoreAndEnsureTabs() completed for ") +
m_panelName.ToStdString());
211 wxWindow *tabWindow = tab->GetWidget();
212 wxString tabTitle = tab->GetTitle();
215 bool success =
m_notebook->AddPage(tabWindow, tabTitle,
true);
216 int index = success ?
static_cast<int>(
m_notebook->GetPageCount()) - 1 : -1;
222 m_tabs.push_back(std::move(tab));
224 LOG_INFO(
"Panel", std::string(
"Added tab '") + tabTitle.ToStdString() +
"' to " +
m_panelName.ToStdString() +
225 " at index " + std::to_string(index));
234 if (prefManager.GetPreferences().SaveToFile(configPath)) {
235 LOG_INFO(
"Panel",
"Saved tab state to disk after tab addition");
237 LOG_ERROR(
"Panel",
"Failed to save tab state to disk after tab addition");
241 std::string(
"Failed to add tab '") + tabTitle.ToStdString() +
"' to " +
m_panelName.ToStdString());
249 std::string(
"Invalid tab index ") + std::to_string(index) +
" for " +
m_panelName.ToStdString());
263 removedTab->OnClosed();
274 std::string(
"Removed tab at index ") + std::to_string(index) +
" from " +
m_panelName.ToStdString());
278 LOG_ERROR(
"Panel", std::string(
"Failed to remove tab at index ") + std::to_string(index) +
" from " +
284 if (index < 0 || index >=
static_cast<int>(
m_tabs.size())) {
287 return m_tabs[index].get();
299 std::string(
"Set active tab to index ") + std::to_string(index) +
" in " +
m_panelName.ToStdString());
317 " to default tab: " + defaultTabName.ToStdString());
321 wxWindow *defaultTabWindow =
nullptr;
322 for (
size_t i = 0; i <
m_notebook->GetPageCount(); ++i) {
323 if (
m_notebook->GetPageText(i) == defaultTabName) {
331 for (
int i =
static_cast<int>(
m_notebook->GetPageCount()) - 1; i >= 0; --i) {
332 if (
m_notebook->GetPage(i) != defaultTabWindow) {
338 if (defaultTabWindow ==
nullptr) {
349 " complete, tab count: " + std::to_string(
m_notebook->GetPageCount()));
358 std::to_string(defaultTabTypes.size()) +
" default tabs");
366 for (
const auto &tabType : defaultTabTypes) {
377 " complete, tab count: " + std::to_string(
m_notebook->GetPageCount()));
396 int newSelection =
event.GetSelection();
397 if (newSelection != wxNOT_FOUND) {
399 LOG_TRACE(
"Panel", std::string(
"Tab changed to index ") + std::to_string(newSelection) +
" in " +
410 if (prefManager.GetPreferences().SaveToFile(configPath)) {
411 LOG_TRACE(
"Panel",
"Saved active tab state to disk after tab change");
413 LOG_ERROR(
"Panel",
"Failed to save active tab state to disk after tab change");
421 int closedIndex =
event.GetSelection();
422 LOG_INFO(
"Panel", std::string(
"Tab at index ") + std::to_string(closedIndex) +
" closed");
426 if (closedIndex >= 0 && closedIndex <
static_cast<int>(
m_tabs.size())) {
428 if (
m_tabs[closedIndex]) {
429 m_tabs[closedIndex]->OnClosed();
432 m_tabs[closedIndex].release();
436 CallAfter([
this, closedIndex]() {
437 if (closedIndex >= 0 && closedIndex <
static_cast<int>(
m_tabs.size())) {
454 if (prefManager.GetPreferences().SaveToFile(configPath)) {
455 LOG_INFO(
"Panel",
"Saved tab state to disk after tab removal");
457 LOG_ERROR(
"Panel",
"Failed to save tab state to disk after tab removal");
465 LOG_INFO(
"Panel", std::string(
"Add tab button clicked in %s") +
m_panelName.ToStdString());
471 if (event.GetSkipped()) {
477 LOG_INFO(
"Panel", std::string(
"Tab bar add button clicked in %s") +
m_panelName.ToStdString());
480 wxCommandEvent addEvent;
485 LOG_INFO(
"Panel", std::string(
"Tab bar menu button clicked in %s") +
m_panelName.ToStdString());
488 wxCommandEvent menuEvent;
496 wxMenu *mainMenu =
new wxMenu();
502 mainMenu->AppendSeparator();
518 LOG_ERROR(
"Panel",
"Cannot hide panel - no MainFrame reference");
523 wxAuiManager *auiManager =
m_mainFrame->GetAuiManager();
525 LOG_ERROR(
"Panel",
"Cannot hide panel - no AUI manager");
532 wxAuiPaneInfo &pane = auiManager->GetPane(paneName);
535 auiManager->Update();
548 LOG_ERROR(
"Panel",
"Cannot open preferences - no MainFrame reference");
559 int result = dialog.ShowModal();
560 if (result == wxID_OK) {
569 for (
const auto &tab :
m_tabs) {
570 if (tab && tab->GetTitle() == tabName) {
580 std::string(
"Cannot create tab - missing notebook or mainframe in %s") +
m_panelName.ToStdString());
590 std::string(
"Tab '") + tabName.ToStdString() +
"' is not allowed in " +
m_panelName.ToStdString());
597 std::string(
"Tab '") + tabName.ToStdString() +
"' already exists in " +
m_panelName.ToStdString());
603 if (maxInstances > 0) {
604 int currentCount =
m_mainFrame->CountTabGlobally(tabName);
605 if (currentCount >= maxInstances) {
606 LOG_WARNING(
"Panel", std::string(
"Tab '") + tabName.ToStdString() +
"' has reached max instances (" +
607 std::to_string(maxInstances) +
")");
617 std::string(
"Created and added tab '") + tabName.ToStdString() +
"' to " +
m_panelName.ToStdString());
620 std::string(
"Failed to create tab '") + tabName.ToStdString() +
"' for " +
m_panelName.ToStdString());
626 if (supportedTypes.empty()) {
636 for (
size_t i = 0; i < supportedTypes.size(); ++i) {
648 wxMenuItem *item = menu.Append(menuId, displayName, tooltip);
652 bool existsInThisPanel =
657 int currentCount =
m_mainFrame->CountTabGlobally(displayName);
658 bool atMaxInstances = (maxInstances > 0) && (currentCount >= maxInstances);
660 if (existsInThisPanel || atMaxInstances) {
662 if (atMaxInstances && !existsInThisPanel) {
663 if (maxInstances == 1) {
664 item->SetItemLabel(displayName +
" (open in another panel)");
666 item->SetItemLabel(displayName +
" (max " + std::to_string(maxInstances) +
" reached)");
675 wxEVT_COMMAND_MENU_SELECTED, [
this, tabType](wxCommandEvent &) {
CreateAndAddTab(tabType); }, menuId);
678 if (validItems == 0) {
679 wxMenuItem *item = menu.Append(wxID_ANY,
"(No tabs available for this panel)");
686 LOG_TRACE(
"Panel", std::string(
"Showed tab creation menu for ") +
m_panelName.ToStdString() +
" with " +
687 std::to_string(validItems) +
" options");
700 LOG_INFO(
"Panel", std::string(
"Tab bar buttons ") + (enabled ?
"enabled" :
"disabled") +
" for " +
714 LOG_INFO(
"SidePanel", std::string(
"Base ApplyPreferences called for ") +
m_panelName.ToStdString() +
715 " - derived class should override this");
721 LOG_INFO(
"SidePanel", std::string(
"Base SaveState called for ") +
m_panelName.ToStdString() +
722 " - derived class should override this");
728 LOG_INFO(
"SidePanel", std::string(
"Base RestoreState called for ") +
m_panelName.ToStdString() +
729 " - derived class should override this");
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
std::unique_ptr< ITab > ITabPtr
Smart pointer type for ITab instances.
#define LOG_ERROR(category, message)
#define LOG_TRACE(category, message)
#define LOG_WARNING(category, message)
#define LOG_INFO(category, message)
MainFrame::OnExit EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(ID_NewProject
Centralized resource path management for EmberForge.
wxBEGIN_EVENT_TABLE(SidePanel, Panel) EVT_AUINOTEBOOK_PAGE_CHANGED(SidePanel
static AppPreferencesManager & GetInstance()
static EmberCore::String GetDefaultConfigPath()
Custom wxAuiNotebook that integrates Add Tab and Menu buttons into the tab bar.
static wxString GetTabDisplayName(TabType type)
Get the display name for a tab type.
static wxString GetTabTooltip(TabType type)
Get the tooltip text for a tab type.
static std::unique_ptr< ITab > CreateTab(TabType type, wxWindow *parent, MainFrame *mainFrame=nullptr)
Create a tab of the specified type.
static int GetMaxGlobalInstances(TabType type)
Get the maximum number of instances allowed globally across all panels.
static bool IsTabAllowedInPanel(TabType tabType, EmberForge::PanelType panelType)
Check if a tab type is allowed in a specific panel type.
static bool AllowMultipleInstances(TabType type)
Check if a tab type can be created multiple times within a single panel.
static TabType StringToTabType(const std::string &str)
Convert string identifier to tab type.
Abstract interface for individual tabs that can be moved between panels.
Main application window for EmberForge.
Base implementation of IPanel interface.
Preferences dialog for configuring EmberForge application settings.
bool SelectSection(const wxString §ionName)
Select a section in the preferences tree by name.
Base class for sidebar panels with shared tab management backend.
void SetTabBarButtonsEnabled(bool enabled)
Enable or disable the tab bar buttons (+ and menu)
@ ID_BASE_PREFERENCES_MENU_ITEM
@ ID_BASE_HIDE_PANEL_MENU_ITEM
void FinishSetup()
Complete panel setup after construction.
virtual void ApplyPreferences()
Apply preferences to the side panel Virtual to allow derived classes to use their specific settings.
ITabPtr RemoveTab(int index)
Remove a tab by index.
void OnTabChanged(wxAuiNotebookEvent &event)
virtual const std::vector< std::string > & GetLastOpenTabs() const =0
std::vector< ITabPtr > m_tabs
void ClearAllTabs()
Clear all tabs from the panel Removes all tabs without creating any new ones.
void OnHidePanelClicked(wxCommandEvent &event)
bool HasTabWithName(const wxString &tabName) const
Check if this panel has a tab with the given name.
int AddTab(ITabPtr tab)
Add a tab to this panel.
void ResetToDefaultTab(EmberForge::TabType defaultTabType)
Reset the panel to a single default tab Closes all tabs and creates only the specified default tab.
void RestoreAndEnsureTabs()
bool m_tabBarButtonsEnabled
virtual void CreateNotebook()
virtual void SetupEventHandlers()
ITab * GetActiveTab() const
Get the currently active tab.
void OnPanelPreferencesClicked(wxCommandEvent &event)
virtual void OnMenuButtonClicked(wxCommandEvent &event)
virtual void OnPanelSpecificSetup()
void DoSetupEventHandlers()
void OnAddTabButtonClickedInternal(wxCommandEvent &event)
void OnTabClosed(wxAuiNotebookEvent &event)
virtual std::string GetLastActiveTab() const =0
EmberForge::CustomAuiNotebook * GetNotebook() const
Get the notebook widget for direct access.
void ShowTabCreationMenu()
void ToggleTabBarButtons()
Toggle tab bar buttons visibility.
virtual void OnAddTabButtonClicked(wxCommandEvent &event)
virtual void RestoreState()
Restore state from preferences Virtual to allow derived classes to use their specific settings.
void OnTabBarMenuButtonClicked(wxCommandEvent &event)
bool SetActiveTab(int index)
Set the active tab by index.
virtual bool GetRememberLastTab() const =0
void CreateAndAddTab(EmberForge::TabType tabType)
virtual void SaveState()
Save the current state (last active tab, etc.) Virtual to allow derived classes to use their specific...
EmberForge::PanelDescriptor m_descriptor
void ResetToDefaultTabs(const std::vector< EmberForge::TabType > &defaultTabTypes)
Reset the panel to multiple default tabs Closes all tabs and creates the specified default tabs.
virtual std::vector< EmberForge::TabType > GetSupportedTabTypes() const
EmberForge::CustomAuiNotebook * m_notebook
void OnTabBarAddButtonClicked(wxCommandEvent &event)
void CreateLayout() override
Create the panel's UI layout Called during initialization.
virtual std::string GetDefaultActiveTab() const =0
ITab * GetTab(int index) const
Get a tab by index.
PanelType
Defines the type of panel in the UI hierarchy.
TabType
Enumeration of available tab types.