Ember
Loading...
Searching...
No Matches
LogTab.h
Go to the documentation of this file.
1#pragma once
2
3#include "Interfaces/ITab.h"
4#include "Utils/Logger.h"
5#include <memory>
6#include <set>
7#include <vector>
8#include <wx/listctrl.h>
9#include <wx/srchctrl.h>
10#include <wx/wx.h>
11
12namespace EmberForge {
13
14// Forward declaration
15class LogTab;
16
23class VirtualLogListCtrl : public wxListCtrl {
24 public:
25 VirtualLogListCtrl(wxWindow *parent, wxWindowID id, LogTab *logTab);
26
27 // Set the data source
28 void SetEntries(std::vector<std::shared_ptr<EmberCore::LogEntry>> *entries);
29
30 protected:
31 // Virtual list callbacks - called by wxWidgets when it needs to display a row
32 wxString OnGetItemText(long item, long column) const override;
33 wxListItemAttr *OnGetItemAttr(long item) const override;
34
35 private:
37 std::vector<std::shared_ptr<EmberCore::LogEntry>> *m_entries;
38 mutable wxListItemAttr m_itemAttr; // Reusable attribute object
39};
40
51class LogTab : public wxPanel, public ITab {
52 public:
53 LogTab(wxWindow *parent);
54 virtual ~LogTab();
55
56 // ITab interface implementation
57 wxWindow *GetWidget() override { return this; }
58 wxString GetTitle() const override { return "Log"; }
59 wxString GetTabType() const override { return "Log"; }
60 void Initialize() override;
61 void Refresh() override;
62 void OnActivated() override;
63 void OnDeactivated() override;
64 void OnClosed() override;
65
66 // Log display methods
67 void RefreshLogList();
68 void ScrollToBottom();
69
70 // Filter methods
72 void SetCategoryFilter(const wxString &category);
73 void SetSearchFilter(const wxString &searchText);
74 void ClearFilters();
75
76 // Log control methods
77 void SetConsoleLoggingEnabled(bool enabled);
78 void SetFileLoggingEnabled(bool enabled);
79
80 // Actions
81 void ClearLogs();
83 void ExportLogs();
84
85 private:
86 // Settings
87 void LoadSettings();
88
89 // UI Creation
90 void CreateLayout();
91 void CreateToolbar();
92 void CreateLogList();
93 void SetupEventHandlers();
94
95 // Event handlers
96 void OnLevelFilterChanged(wxCommandEvent &event);
97 void OnCategoryFilterChanged(wxCommandEvent &event);
98 void OnSearchTextChanged(wxCommandEvent &event);
99 void OnAutoScrollToggled(wxCommandEvent &event);
100 void OnConsoleToggled(wxCommandEvent &event);
101 void OnFileToggled(wxCommandEvent &event);
102 void OnClearClicked(wxCommandEvent &event);
103 void OnCopyClicked(wxCommandEvent &event);
104 void OnExportClicked(wxCommandEvent &event);
105 void OnListItemSelected(wxListEvent &event);
106 void OnListItemRightClick(wxListEvent &event);
107 void OnLogUpdated();
108 void OnPauseToggled(wxCommandEvent &event);
111
112 // Helper methods
113 wxColour GetLevelColor(EmberCore::LogLevel level) const;
114 wxString GetLevelString(EmberCore::LogLevel level) const;
115 void PopulateList(const std::vector<std::shared_ptr<EmberCore::LogEntry>> &entries);
117 wxString FormatTimestamp(const std::chrono::system_clock::time_point &timestamp) const;
118
119 // UI Components - Toolbar row 1
120 wxChoice *m_levelFilter;
121 wxComboBox *m_categoryFilter;
122 wxSearchCtrl *m_searchCtrl;
123 wxCheckBox *m_autoScrollCheck;
124 wxButton *m_pauseBtn;
125
126 // UI Components - Toolbar row 2
127 wxCheckBox *m_consoleCheck;
128 wxCheckBox *m_fileCheck;
129 wxButton *m_clearBtn;
130 wxButton *m_copyBtn;
131 wxButton *m_exportBtn;
132 wxStaticText *m_logCountLabel;
133
134 // UI Components - Main content
136
137 // Friend class for virtual list callbacks
138 friend class VirtualLogListCtrl;
139
140 // State
146 bool m_updatingCategories; // Guard flag to prevent recursive updates
147 std::vector<std::shared_ptr<EmberCore::LogEntry>> m_filteredEntries;
148 std::set<std::string> m_knownCategories;
149
150 // Observer management
152
153 // Control IDs
154 enum {
155 ID_LEVEL_FILTER = wxID_HIGHEST + 1,
166 };
167
169};
170
171} // namespace EmberForge
size_t ObserverId
Definition Logger.h:87
Log panel tab that displays application logs with filtering and control capabilities.
Definition LogTab.h:51
void OnFileToggled(wxCommandEvent &event)
Definition LogTab.cpp:570
void OnCategoryFilterChanged(wxCommandEvent &event)
Definition LogTab.cpp:546
wxString GetTabType() const override
Returns the tab type identifier.
Definition LogTab.h:59
void UpdateLogCountDisplay()
Definition LogTab.cpp:628
wxCheckBox * m_autoScrollCheck
Definition LogTab.h:123
wxButton * m_pauseBtn
Definition LogTab.h:124
void UpdatePauseButtonAppearance()
Definition LogTab.cpp:613
std::vector< std::shared_ptr< EmberCore::LogEntry > > m_filteredEntries
Definition LogTab.h:147
wxSearchCtrl * m_searchCtrl
Definition LogTab.h:122
wxWindow * GetWidget() override
Returns the wxWidgets window used as the tab content.
Definition LogTab.h:57
wxButton * m_copyBtn
Definition LogTab.h:130
void OnListItemSelected(wxListEvent &event)
Definition LogTab.cpp:578
void OnCopyClicked(wxCommandEvent &event)
Definition LogTab.cpp:574
bool m_updatingCategories
Definition LogTab.h:146
wxString GetLevelString(EmberCore::LogLevel level) const
Definition LogTab.cpp:387
void OnSearchTextChanged(wxCommandEvent &event)
Definition LogTab.cpp:556
void Initialize() override
Called once when the tab is first created.
Definition LogTab.cpp:112
void OnClosed() override
Called when the tab is closed.
Definition LogTab.cpp:424
friend class VirtualLogListCtrl
Definition LogTab.h:138
void OnConsoleToggled(wxCommandEvent &event)
Definition LogTab.cpp:568
wxButton * m_clearBtn
Definition LogTab.h:129
void SetConsoleLoggingEnabled(bool enabled)
Definition LogTab.cpp:462
wxChoice * m_levelFilter
Definition LogTab.h:120
void OnLevelFilterChanged(wxCommandEvent &event)
Definition LogTab.cpp:540
virtual ~LogTab()
Definition LogTab.cpp:105
VirtualLogListCtrl * m_logList
Definition LogTab.h:135
void OnClearClicked(wxCommandEvent &event)
Definition LogTab.cpp:572
wxString GetTitle() const override
Returns the display title of the tab.
Definition LogTab.h:58
void SetFileLoggingEnabled(bool enabled)
Definition LogTab.cpp:466
void RefreshLogList()
Definition LogTab.cpp:282
wxColour GetLevelColor(EmberCore::LogLevel level) const
Definition LogTab.cpp:361
void Refresh() override
Refreshes the tab content.
Definition LogTab.cpp:410
void SetCategoryFilter(const wxString &category)
Definition LogTab.cpp:439
wxString m_currentSearchFilter
Definition LogTab.h:143
void OnDeactivated() override
Called when the tab becomes inactive.
Definition LogTab.cpp:420
void ScrollToBottom()
Definition LogTab.cpp:404
LogTab(wxWindow *parent)
void SetupEventHandlers()
Definition LogTab.cpp:278
void PopulateList(const std::vector< std::shared_ptr< EmberCore::LogEntry > > &entries)
Definition LogTab.cpp:303
wxString m_currentCategoryFilter
Definition LogTab.h:142
void OnExportClicked(wxCommandEvent &event)
Definition LogTab.cpp:576
void SetSearchFilter(const wxString &searchText)
Definition LogTab.cpp:444
EmberCore::LogLevel m_currentLevelFilter
Definition LogTab.h:141
wxCheckBox * m_fileCheck
Definition LogTab.h:128
wxString FormatTimestamp(const std::chrono::system_clock::time_point &timestamp) const
Definition LogTab.cpp:345
void OnActivated() override
Called when the tab becomes active.
Definition LogTab.cpp:418
std::set< std::string > m_knownCategories
Definition LogTab.h:148
void OnListItemRightClick(wxListEvent &event)
Definition LogTab.cpp:582
wxCheckBox * m_consoleCheck
Definition LogTab.h:127
void SetLevelFilter(EmberCore::LogLevel level)
Definition LogTab.cpp:434
wxButton * m_exportBtn
Definition LogTab.h:131
void OnPauseToggled(wxCommandEvent &event)
Definition LogTab.cpp:603
wxComboBox * m_categoryFilter
Definition LogTab.h:121
void OnAutoScrollToggled(wxCommandEvent &event)
Definition LogTab.cpp:561
wxStaticText * m_logCountLabel
Definition LogTab.h:132
void UpdateCategoryChoices()
Definition LogTab.cpp:311
EmberCore::Logger::ObserverId m_observerId
Definition LogTab.h:151
void CopySelectedToClipboard()
Definition LogTab.cpp:475
std::vector< std::shared_ptr< EmberCore::LogEntry > > * m_entries
Definition LogTab.h:37
void SetEntries(std::vector< std::shared_ptr< EmberCore::LogEntry > > *entries)
Definition LogTab.cpp:33
wxListItemAttr * OnGetItemAttr(long item) const override
Definition LogTab.cpp:63
wxListItemAttr m_itemAttr
Definition LogTab.h:38
VirtualLogListCtrl(wxWindow *parent, wxWindowID id, LogTab *logTab)
Definition LogTab.cpp:18
wxString OnGetItemText(long item, long column) const override
Definition LogTab.cpp:39
Interface for tab-based UI components in the application.
Definition ITab.h:7
LogLevel
Log levels for categorizing messages.
Definition Logger.h:16