Files
ThreadPilot/Views/LogViewerView.xaml.cs
T
2026-05-17 01:54:32 +02:00

126 lines
3.9 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ThreadPilot.Services;
using ThreadPilot.ViewModels;
namespace ThreadPilot.Views
{
/// <summary>
/// Interaction logic for LogViewerView.xaml.
/// </summary>
public partial class LogViewerView : System.Windows.Controls.UserControl
{
public LogViewerView()
{
this.InitializeComponent();
this.Loaded += this.OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
TaskSafety.FireAndForget(this.OnLoadedAsync(), _ =>
{
// Keep the view loaded even if background initialization fails.
});
}
private async Task OnLoadedAsync()
{
if (this.DataContext is LogViewerViewModel viewModel)
{
await viewModel.InitializeAsync();
}
}
}
/// <summary>
/// Converter to convert bytes to megabytes for display.
/// </summary>
public class BytesToMegabytesConverter : IValueConverter
{
public static readonly BytesToMegabytesConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is long bytes)
{
return bytes / (1024.0 * 1024.0);
}
return 0.0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
/// <summary>
/// Converter to invert boolean values.
/// </summary>
public class InverseBooleanConverter : IValueConverter
{
public static readonly InverseBooleanConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
}
/// <summary>
/// Converter to invert boolean values for visibility.
/// </summary>
public class InverseBooleanToVisibilityConverter : IValueConverter
{
public static readonly InverseBooleanToVisibilityConverter Instance = new();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return boolValue ? Visibility.Collapsed : Visibility.Visible;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}