Ember
Loading...
Searching...
No Matches
TabFactory.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
5#include "Tabs/LogTab.h"
6#include "Tabs/PropertiesTab.h"
7#include "Utils/Logger.h"
9
10namespace EmberForge {
11
12std::unique_ptr<ITab> TabFactory::CreateTab(TabType type, wxWindow *parent, MainFrame *mainFrame) {
13 if (!parent) {
14 LOG_ERROR("TabFactory", "Cannot create tab: parent window is null");
15 return nullptr;
16 }
17
18 try {
19 switch (type) {
21 LOG_INFO("TabFactory", "Creating Properties tab");
22 auto tab = std::make_unique<PropertiesTab>(parent, mainFrame);
23
24 // If we have a main frame, update its reference and set the selected node
25 if (mainFrame) {
26 mainFrame->UpdatePropertiesTabReference(tab.get());
27 }
28
29 return tab;
30 }
31
32 case TabType::Log: {
33 LOG_INFO("TabFactory", "Creating Log tab");
34 return std::make_unique<LogTab>(parent);
35 }
36
38 LOG_INFO("TabFactory", "Creating Performance tab");
39 return std::make_unique<EmberForge::PerformancePanel>(parent);
40 }
41
43 LOG_INFO("TabFactory", "Creating File Explorer tab");
44 return std::make_unique<FileExplorerTab>(parent);
45 }
46
47 case TabType::Navigator: {
48 LOG_INFO("TabFactory", "Creating Navigator tab");
49 auto tab = std::make_unique<ForgeNavigatorTab>(parent, mainFrame);
50
51 if (mainFrame) {
52 mainFrame->UpdateNavigatorTabReference(tab.get());
53 }
54
55 return tab;
56 }
57
58 default:
59 LOG_ERROR("TabFactory", "Unknown tab type requested: " + std::to_string(static_cast<int>(type)));
60 return nullptr;
61 }
62 } catch (const std::exception &e) {
63 LOG_ERROR("TabFactory", "Exception while creating tab: " + std::string(e.what()));
64 return nullptr;
65 } catch (...) {
66 LOG_ERROR("TabFactory", "Unknown exception while creating tab");
67 return nullptr;
68 }
69}
70
72 switch (type) {
74 return "Properties";
75 case TabType::Log:
76 return "Log";
78 return "Performance";
80 return "File Explorer";
82 return "Navigator";
83 default:
84 return "Unknown Tab";
85 }
86}
87
89 switch (type) {
91 return "View and edit object properties";
92 case TabType::Log:
93 return "View application logs and debug information";
95 return "Monitor application performance metrics";
97 return "Browse and manage project files";
99 return "Browse trees, navigate node hierarchy, and search across the project";
100 default:
101 return "Unknown tab type";
102 }
103}
104
106 switch (type) {
108 return false; // Only one properties panel per panel makes sense
109 case TabType::Log:
110 return false; // Only one log panel per panel makes sense
112 return false; // Only one performance panel per panel makes sense
114 return false; // Only one file explorer per panel makes sense
116 return false;
117 default:
118 return false;
119 }
120}
121
123 // Configure the maximum number of instances allowed across ALL panels.
124 // Return 0 = unlimited instances
125 // Return 1 = single global instance (default for most tabs)
126 // Return 2+ = allow that many instances across panels
127 switch (type) {
128 case TabType::Log:
129 return 1; // Only one log output
131 return 1; // Only one performance monitor
133 return 1; // Only one file explorer
135 return 1; // Change to 2 to allow in two panels
137 return 1;
138 default:
139 return 1;
140 }
141}
142
144 // Configure which tabs are allowed in which panel types.
145 // This provides fine-grained control over tab placement.
146 switch (tabType) {
148 // Properties: only in side panels (left/right)
149 return panelType == PanelType::LeftPanel || panelType == PanelType::RightPanel;
150
151 case TabType::Log:
152 // Log: only in bottom panel
153 return panelType == PanelType::BottomPanel;
154
156 // Performance: only in bottom panel
157 return panelType == PanelType::BottomPanel;
158
160 // File Explorer: only in bottom panel
161 return panelType == PanelType::BottomPanel;
162
164 return panelType == PanelType::LeftPanel || panelType == PanelType::RightPanel;
165
166 default:
167 return true;
168 }
169}
170
174
178
180
182 switch (type) {
184 return "Properties";
185 case TabType::Log:
186 return "Log";
188 return "Performance";
190 return "FileExplorer";
192 return "Navigator";
193 default:
194 return "FileExplorer";
195 }
196}
197
198TabType TabFactory::StringToTabType(const std::string &str) {
199 // Migrate deprecated tab types
200 if (str == "SceneHierarchy" || str == "TreeSelector")
201 return TabType::Navigator;
202 if (str == "Tool") // Legacy name for Properties tab
203 return TabType::Properties;
204 if (str == "Properties")
205 return TabType::Properties;
206 if (str == "Log")
207 return TabType::Log;
208 if (str == "Performance")
210 if (str == "FileExplorer")
212 if (str == "Navigator")
213 return TabType::Navigator;
215}
216
217} // namespace EmberForge
#define LOG_ERROR(category, message)
Definition Logger.h:116
#define LOG_INFO(category, message)
Definition Logger.h:114
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 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 int GetMaxGlobalInstances(TabType type)
Get the maximum number of instances allowed globally across all panels.
static std::vector< TabType > GetAvailableTabTypes()
Get all available tab types.
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.
static std::vector< TabType > GetBottomPanelTabTypes()
Get tab types supported by the bottom panel.
Main application window for EmberForge.
Definition MainFrame.h:67
void UpdatePropertiesTabReference(PropertiesTab *propertiesTab)
void UpdateNavigatorTabReference(ForgeNavigatorTab *navigatorTab)
PanelType
Defines the type of panel in the UI hierarchy.
TabType
Enumeration of available tab types.
Definition TabFactory.h:17