// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Interaction logic for LogView.xaml
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using HandBrakeWPF.ViewModels;
///
/// Interaction logic for LogView.xaml
///
public partial class LogView : Window
{
///
/// Initializes a new instance of the class.
///
public LogView()
{
this.InitializeComponent();
this.DataContextChanged += this.LogView_DataContextChanged;
}
///
/// The log view_ data context changed.
///
///
/// The sender.
///
///
/// The e.
///
private void LogView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
LogViewModel vm = e.NewValue as LogViewModel;
if (vm != null)
{
this.logText.AppendText(vm.ActivityLog);
vm.LogMessageReceived += this.Vm_LogMessageReceived;
}
}
///
/// The vm_ log message received.
///
///
/// The sender.
///
///
/// The e.
///
private void Vm_LogMessageReceived(object sender, HandBrake.ApplicationServices.Services.Logging.EventArgs.LogEventArgs e)
{
try
{
if (e == null)
{
Caliburn.Micro.Execute.OnUIThread(
() =>
{
LogViewModel vm = this.DataContext as LogViewModel;
if (vm != null)
{
this.logText.Clear();
this.logText.AppendText(vm.ActivityLog);
}
else
{
Debug.WriteLine("Failed to Reset Log correctly.");
}
});
}
else
{
// This works better than Data Binding because of the scroll.
this.logText.AppendText(Environment.NewLine + e.Log.Content);
if (this.AutoScroll.IsChecked)
{
this.logText.ScrollToEnd();
}
}
}
catch (Exception exc)
{
Debug.WriteLine(exc);
}
}
///
/// Hide the Toolbar Endplate.
///
///
/// The sender.
///
///
/// The e.
///
private void ToolBarLoaded(object sender, RoutedEventArgs e)
{
ToolBar toolBar = sender as ToolBar;
if (toolBar != null)
{
var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
if (overflowGrid != null)
{
overflowGrid.Visibility = Visibility.Collapsed;
}
}
}
}
}