allow loading of files

This commit is contained in:
Florian Stinglmayr 2022-01-29 16:13:56 +01:00
parent a4f25a2ce3
commit 3f55e946a3
2 changed files with 34 additions and 12 deletions

View File

@ -30,8 +30,9 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="Load" Content="Load Entries" Grid.Row="0" Margin="5,5,5,5" Height="Auto" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Load_Click" />
<Button x:Name="Clear" Content="Clear" Grid.Row="0" Height="Auto" Margin="5,5,5,5" Grid.Column="3" Click="Clear_Click" />
<Button x:Name="Load" Content="Load Entries" Grid.Row="0" Margin="5,5,5,5" Height="Auto" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Load_Click" />
<Button x:Name="LoadFile" Content="Load File" Grid.Row="0" Margin="5,5,5,5" Height="Auto" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Click="LoadFile_Click" />
<Button x:Name="Clear" Content="Clear" Grid.Row="0" Height="Auto" Margin="5,5,5,5" Grid.Column="3" Click="Clear_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Grid>
</Window>

View File

@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows;
using Microsoft.Win32;
using EDJournal;
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;
using EliteBGS.Util;
namespace EliteBGS {
/// <summary>
@ -22,6 +15,8 @@ namespace EliteBGS {
public event EntriesLoadedDelegate EntriesLoaded;
Config config = new Config();
public LoadEntriesWindow() {
InitializeComponent();
}
@ -52,5 +47,31 @@ namespace EliteBGS {
private void Clear_Click(object sender, RoutedEventArgs e) {
Lines.Clear();
}
private void LoadFile_Click(object sender, RoutedEventArgs e) {
OpenFileDialog dialog = new OpenFileDialog();
dialog.DefaultExt = ".log";
dialog.Filter = "Log files (*.log)|*.log|All files (*.*)|*";
var location = config.Global.DefaultJournalLocation;
if (Directory.Exists(location)) {
dialog.InitialDirectory = location;
}
bool result = dialog.ShowDialog(this) ?? false;
if (!result) {
return;
}
try {
using (FileStream stream = File.OpenRead(dialog.FileName)) {
using (StreamReader reader = new StreamReader(stream)) {
Lines.Text = reader.ReadToEnd();
}
}
} catch (Exception) {
}
}
}
}