278 lines
9.5 KiB
C#
278 lines
9.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using UAF.Application;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
using UAF.WPF.Themes;
|
|
|
|
namespace DataFileAnalyzer
|
|
{
|
|
/// <summary>
|
|
/// File library status to color
|
|
/// </summary>
|
|
public class StatusToColorConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (!(value is FileUpdaterStatus))
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("WhiteBrush");
|
|
FileUpdaterStatus strValue = (FileUpdaterStatus)value;
|
|
if (strValue == FileUpdaterStatus.STARTING)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("OrangeBrush");
|
|
if (strValue == FileUpdaterStatus.INITIALIZING)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("OrangeBrush");
|
|
if (strValue == FileUpdaterStatus.RUNNING)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("YellowBrush");
|
|
if (strValue == FileUpdaterStatus.READY)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("GreenBrush");
|
|
if (strValue == FileUpdaterStatus.PAUSED)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("RedBrush");
|
|
if (strValue == FileUpdaterStatus.STOPPED)
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("RedBrush");
|
|
return ThemeManager.GetGlobalThemeResource<Brush>("WhiteBrush");
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// List of DataFileError to string
|
|
/// </summary>
|
|
public class DataFileErrorListToStringConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
List<DataFileError> errorList = value as List<DataFileError>;
|
|
string result = "";
|
|
foreach (DataFileError error in errorList)
|
|
{
|
|
result += ((result.Length != 0) ? ", " : "") + error;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// DataFile to a string containing the errors and warnings of this file
|
|
/// </summary>
|
|
public class DataFileToErrorListConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
DataFile dataFile = value as DataFile;
|
|
string result = null;
|
|
if (dataFile != null && (dataFile.Warnings.Count != 0 || dataFile.Errors.Count != 0))
|
|
{
|
|
if (dataFile.Errors.Count != 0)
|
|
{
|
|
result = "";
|
|
bool needComa = false;
|
|
foreach (DataFileError error in dataFile.Errors)
|
|
{
|
|
result += (needComa ? ", " : "") + error;
|
|
needComa = true;
|
|
}
|
|
}
|
|
|
|
else if (dataFile.Warnings.Count != 0)
|
|
{
|
|
result = "";
|
|
bool needComa = false;
|
|
foreach (DataFileError error in dataFile.Warnings)
|
|
{
|
|
result += (needComa ? ", " : "") + error;
|
|
needComa = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the pause button state depending on the status
|
|
/// </summary>
|
|
public class StatusToPauseButtonTextConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
string strValue = value as string;
|
|
return (strValue == "PAUSED") ? "Resume" : "Pause";
|
|
}
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The main view of the DataFileAnalyzer
|
|
/// </summary>
|
|
public partial class DataFileAnalyzerView : UserControl
|
|
{
|
|
public DataFileAnalyzerModel Model { get { return DataContext as DataFileAnalyzerModel; } }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public DataFileAnalyzerView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save file library state
|
|
/// </summary>
|
|
private void SaveFileListClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Model.Library.Save();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pause the file library update
|
|
/// </summary>
|
|
private void PauseUpdateClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model.Library.Paused)
|
|
{
|
|
Model.Library.Resume();
|
|
}
|
|
else
|
|
{
|
|
Model.Library.Pause();
|
|
Model.RefreshFileList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Double click on a referenced file: select this file in the file list
|
|
/// </summary>
|
|
private void OnReferencedFileDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
DataFileDependency dependency = ((ListViewItem)sender).Content as DataFileDependency;
|
|
DataFile parentFile = Model.Library.GetFile(dependency.Key);
|
|
if (parentFile != null)
|
|
{
|
|
Model.FilterString = parentFile.NormalizedPath;
|
|
|
|
ScrollToFile(parentFile);
|
|
uiFileList.SelectedItem = parentFile;
|
|
uiFileList.Focus();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Double click on a referencing file: select this file in the file list
|
|
/// </summary>
|
|
private void OnReferencingFileDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
DataFileDependency dependency = ((ListViewItem)sender).Content as DataFileDependency;
|
|
DataFile childFile = Model.Library.GetFile(dependency.Key);
|
|
if (childFile != null)
|
|
{
|
|
Model.FilterString = childFile.NormalizedPath;
|
|
|
|
ScrollToFile(childFile);
|
|
uiFileList.SelectedItem = childFile;
|
|
uiFileList.Focus();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scroll to a file in the file list
|
|
/// </summary>
|
|
private void ScrollToFile(DataFile _file)
|
|
{
|
|
// This doesn't work well when virtualization is activated
|
|
//uiFileList.ScrollIntoView(_file);
|
|
|
|
VirtualizingStackPanel vsp =
|
|
(VirtualizingStackPanel)typeof(ItemsControl).InvokeMember("_itemsHost",
|
|
BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null,
|
|
uiFileList, null);
|
|
|
|
int index = Model.CurrentDataFiles.IndexOf(_file);
|
|
double scrollHeight = vsp.ScrollOwner.ScrollableHeight;
|
|
double offset = index * scrollHeight / uiFileList.Items.Count;
|
|
|
|
vsp.SetVerticalOffset(offset);
|
|
}
|
|
|
|
private void FileList_GotFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.FileView;
|
|
}
|
|
|
|
private void FileList_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.Other;
|
|
}
|
|
|
|
private void FileList_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
uiFileList.Focus();
|
|
}
|
|
|
|
private void ReferencedFileList_GotFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.ReferencedByMeView;
|
|
}
|
|
|
|
private void ReferencedFileList_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.Other;
|
|
}
|
|
|
|
private void ReferencedFileList_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
uiReferencedFileList.Focus();
|
|
}
|
|
|
|
private void ReferencingFileList_GotFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.ReferencingMeView;
|
|
}
|
|
|
|
private void ReferencingFileList_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Model != null)
|
|
Model.ActiveView = DataFileAnalyzerModel.FocusedView.Other;
|
|
}
|
|
|
|
private void ReferencingFileList_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
uiReferencingFileList.Focus();
|
|
}
|
|
}
|
|
}
|