math-suite/Source/GraphingCalculator/Controls/LogWindow.xaml.cs

75 lines
2.1 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.Shapes;
namespace GraphingCalculator
{
/// <summary>
/// Interaction logic for LogWindow.xaml
/// </summary>
public partial class LogWindow : Window
{
public LogWindow()
{
InitializeComponent();
buttonRefresh_Click(this, new RoutedEventArgs());
}
private void buttonCopy_Click(object sender, RoutedEventArgs e)
{
if (listEntries.SelectedIndex != -1)
Clipboard.SetText(listEntries.SelectedItem.ToString());
}
private void buttonClear_Click(object sender, RoutedEventArgs e)
{
listEntries.Items.Clear();
Log.Entries.Clear();
}
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
listEntries.Items.Clear();
foreach (var i in Log.Entries)
listEntries.Items.Add(i);
}
private void buttonClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
dialog.Title = "Save log...";
dialog.Filter = "Text file|*.txt|Log file|*.log|All files|*.*";
bool? res = dialog.ShowDialog();
if (!res.HasValue && !res.Value) return;
try
{
System.IO.File.WriteAllLines(dialog.FileName, Log.Entries.ToArray());
}
catch (Exception ex)
{
Log.LogEvent("Failed to save log to file {0}: {1}", dialog.FileName, ex.Message);
MessageBox.Show("Error: " + ex.Message, "Failed to save log file!");
}
}
}
}