Files
video-v1/vav2/platforms/windows/applications/vav2player/Vav2Player/LogMessagePage.xaml.h

78 lines
3.2 KiB
C++

#pragma once
#include "LogMessagePage.g.h"
#include "src/Logger/LogManager.h"
#include "src/Logger/ILogManager.h"
#include <winrt/Windows.UI.Xaml.Data.h>
#include <vector>
#include <string>
#include <memory>
#include <mutex>
namespace winrt::Vav2Player::implementation
{
// Use LogManager's LogLevel and LogMessage types to eliminate duplication
using LogLevel = ::Vav2Player::LogLevel;
using LogMessage = ::Vav2Player::LogMessage;
// UI wrapper for log messages with visual styling information
struct LogMessageUI
{
std::wstring text;
LogLevel level;
bool isError() const { return level == LogLevel::Error; }
bool isWarning() const { return level == LogLevel::Warning; }
bool isInfo() const { return level == LogLevel::Info || level == LogLevel::Debug; }
};
struct LogMessagePage : LogMessagePageT<LogMessagePage>
{
LogMessagePage();
~LogMessagePage();
// Event handlers
void CopyLogButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& e);
void ClearLogButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& e);
void AutoScrollCheckBox_CheckedChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& e);
void LogLevelFilterComboBox_SelectionChanged(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& e);
void LogBorder_Loaded(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& e);
// Observer pattern - LogMessagePage subscribes to LogManager updates
void InitializeLogObserver();
void OnLogAdded(const ::Vav2Player::LogMessage& message);
// Static instance for global access (temporary - will be replaced by dependency injection)
static std::shared_ptr<LogMessagePage> GetInstance();
static void SetInstance(std::shared_ptr<LogMessagePage> instance);
private:
void UpdateLogDisplay();
void ScrollToBottom();
bool ShouldShowMessage(LogLevel level) const;
std::wstring GetLogLevelString(LogLevel level) const;
std::wstring FormatLogMessageForUI(const ::Vav2Player::LogMessage& message) const;
void SetLogItemBackground(uint32_t index, LogLevel level);
// UI state
LogLevel m_currentFilter = LogLevel::Debug; // Show all by default
bool m_autoScroll = true;
// Observer pattern - callback registration with LogManager
bool m_observerInitialized = false;
// Static instance for global access
static std::weak_ptr<LogMessagePage> s_instance;
static std::mutex s_instanceMutex;
// Observable collection for UI binding - populated from LogManager via Observer pattern
Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> m_logCollection;
std::mutex m_uiUpdateMutex;
};
}
namespace winrt::Vav2Player::factory_implementation
{
struct LogMessagePage : LogMessagePageT<LogMessagePage, implementation::LogMessagePage>
{
};
}