Compare commits
3 Commits
1693d8882d
...
c0fd36c8de
Author | SHA1 | Date | |
---|---|---|---|
c0fd36c8de | |||
4df98148fa | |||
93d9dc7860 |
31
Avalonia.EliteBGS/Helper.cs
Normal file
31
Avalonia.EliteBGS/Helper.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using MsBox.Avalonia;
|
||||
|
||||
namespace EliteBGS;
|
||||
|
||||
public class Helper {
|
||||
public static void MessageBox(Window owner, string caption, string text) {
|
||||
var box = MessageBoxManager
|
||||
.GetMessageBoxStandard(caption, text)
|
||||
;
|
||||
var result = box.ShowAsPopupAsync(owner);
|
||||
result.Wait();
|
||||
}
|
||||
|
||||
public static string? OpenFileDialog(Window owner) {
|
||||
OpenFileDialog dlg = new OpenFileDialog();
|
||||
|
||||
dlg.AllowMultiple = false;
|
||||
|
||||
var result = dlg.ShowAsync(owner);
|
||||
result.Wait();
|
||||
var filename = result.Result;
|
||||
|
||||
if (filename == null || filename.Length <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filename[0];
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<Window x:Class="EliteBGS.LoadEntriesWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Input;
|
||||
@ -47,8 +48,12 @@ public partial class LoadEntriesWindow : Window {
|
||||
EntriesLoaded?.Invoke(entries);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}",
|
||||
exception.ToString()));
|
||||
Helper.MessageBox(
|
||||
this, "Error",
|
||||
string.Format(
|
||||
"There was an error while parsing the JSON: {0}",
|
||||
exception.ToString())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,23 +62,14 @@ public partial class LoadEntriesWindow : Window {
|
||||
}
|
||||
|
||||
private void LoadFile_Click(object sender, RoutedEventArgs e) {
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
string? filename = Helper.OpenFileDialog(this);
|
||||
|
||||
dialog.DefaultExt = ".log";
|
||||
dialog.Filter = "Log files (*.log)|*.log|All files (*.*)|*";
|
||||
|
||||
var location = AppConfig.DefaultJournalLocation;
|
||||
if (Directory.Exists(location)) {
|
||||
dialog.InitialDirectory = location;
|
||||
}
|
||||
|
||||
bool result = dialog.ShowDialog(this) ?? false;
|
||||
if (!result) {
|
||||
if (string.IsNullOrEmpty(filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
using (FileStream stream = File.OpenRead(dialog.FileName)) {
|
||||
using (FileStream stream = File.OpenRead(filename)) {
|
||||
using (StreamReader reader = new StreamReader(stream)) {
|
||||
Lines.Text = reader.ReadToEnd();
|
||||
}
|
||||
@ -113,8 +109,11 @@ public partial class LoadEntriesWindow : Window {
|
||||
;
|
||||
Lines.Text = string.Join("\n", text).Trim();
|
||||
} catch (Exception exception) {
|
||||
MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}",
|
||||
exception.ToString()));
|
||||
Helper.MessageBox(
|
||||
"Error",
|
||||
string.Format("There was an error while parsing the JSON: {0}",
|
||||
exception.ToString())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,9 +150,6 @@ public partial class MainWindow : Window {
|
||||
DateTime today = DateTime.Today;
|
||||
DateTime tomorrow = today.AddDays(1);
|
||||
|
||||
// HOCHKULTUR
|
||||
startdate.Culture = enddate.Culture = CultureInfo.GetCultureInfo("de-AT");
|
||||
|
||||
startdate.SelectedDate = today;
|
||||
enddate.SelectedDate = tomorrow;
|
||||
}
|
||||
@ -169,7 +166,7 @@ public partial class MainWindow : Window {
|
||||
builder.Append(message);
|
||||
builder.Append("\n");
|
||||
|
||||
log.AppendText(builder.ToString());
|
||||
log.Text = log.Text + builder.ToString();
|
||||
}
|
||||
|
||||
private void Log(string message) {
|
||||
@ -364,7 +361,7 @@ public partial class MainWindow : Window {
|
||||
}
|
||||
|
||||
private void RefreshView() {
|
||||
entries.Items.Refresh();
|
||||
//entries.Items.Refresh();
|
||||
GenerateLog();
|
||||
}
|
||||
|
||||
@ -524,7 +521,7 @@ public partial class MainWindow : Window {
|
||||
startdate.SelectedDate = ResetTimeToZero(d.Value);
|
||||
}
|
||||
|
||||
d = enddate.SelectedDate;
|
||||
d = enddate.SelectedDate?.Date;
|
||||
if (d != null) {
|
||||
enddate.SelectedDate = ResetTimeToZero(d.Value);
|
||||
}
|
||||
@ -608,7 +605,7 @@ public partial class MainWindow : Window {
|
||||
Name = "Discord Server Name",
|
||||
Webhook = "..."
|
||||
});
|
||||
Webhooks.Items.Refresh();
|
||||
//Webhooks.Items.Refresh();
|
||||
RefreshPostMenu();
|
||||
}
|
||||
|
||||
@ -624,17 +621,17 @@ public partial class MainWindow : Window {
|
||||
foreach (var item in selection) {
|
||||
Config.Global.Webhooks.Remove(item);
|
||||
}
|
||||
Webhooks.Items.Refresh();
|
||||
//Webhooks.Items.Refresh();
|
||||
RefreshPostMenu();
|
||||
}
|
||||
|
||||
private void Webhooks_KeyUp(object sender, KeyEventArgs e) {
|
||||
DataGridCell cell = e.OriginalSource as DataGridCell;
|
||||
DataGridCell cell = e.Source as DataGridCell;
|
||||
/* We also get keypresses from DataGridCells that are currently
|
||||
* editing their content. Filter those out. We don't want to delete
|
||||
* the row when the user presses DEL while editing the cells content
|
||||
*/
|
||||
if (cell == null || cell.IsEditing) {
|
||||
if (cell == null) {
|
||||
return;
|
||||
}
|
||||
if (e.Key == Key.Delete) {
|
||||
|
Loading…
Reference in New Issue
Block a user