chore(desktop): include manifest and code-behind

This commit is contained in:
Anna 2020-11-23 13:18:19 -05:00
parent 13a60994a8
commit 8a0128c7d1
2 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using XIVChatCommon.Message;
namespace XIVChat_Desktop {
public partial class ManageNotification {
#region Commands
public static readonly RoutedUICommand AddEmpty = new RoutedUICommand(
"AddEmpty",
"AddEmpty",
typeof(ManageNotification)
);
private void AddEmpty_Execute(object sender, ExecutedRoutedEventArgs e) {
if (!(e.Parameter is ObservableCollection<StringWrapper> list)) {
return;
}
list.Add(new StringWrapper(string.Empty));
}
private void AddEmpty_CanExecute(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = true;
}
#endregion
public App App => (App)Application.Current;
public Notification Notification { get; }
private bool NewNotification { get; }
public ObservableCollection<StringWrapper> Regexes { get; }
public ObservableCollection<StringWrapper> Substrings { get; }
public ManageNotification(Window owner, Notification? notification) {
this.Owner = owner;
this.NewNotification = notification == null;
this.Notification = notification ?? new Notification("");
this.Regexes = new ObservableCollection<StringWrapper>(this.Notification.Regexes.Select(regex => new StringWrapper(regex)));
this.Substrings = new ObservableCollection<StringWrapper>(this.Notification.Substrings.Select(sub => new StringWrapper(sub)));
this.InitializeComponent();
this.DataContext = this;
this.SetUpChannels();
}
private void SetUpChannels() {
var buttonsPanel = new WrapPanel {
Margin = new Thickness(0, 0, 0, 4),
};
var selectButton = new Button {
Content = "Select all",
};
selectButton.Click += (sender, e) => SetAllChecked(true);
var deselectButton = new Button {
Content = "Deselect all",
Margin = new Thickness(4, 0, 0, 0),
};
deselectButton.Click += (sender, e) => SetAllChecked(false);
void SetAllChecked(bool isChecked) {
foreach (var child in this.Channels.Children) {
if (!(child is CheckBox)) {
continue;
}
var check = (CheckBox)child;
check.IsChecked = isChecked;
}
}
buttonsPanel.Children.Add(selectButton);
buttonsPanel.Children.Add(deselectButton);
this.Channels.Children.Add(buttonsPanel);
this.Channels.Children.Add(new Separator());
foreach (var type in (ChatType[])Enum.GetValues(typeof(ChatType))) {
var check = new CheckBox {
Content = type.Name(),
IsChecked = this.Notification.Channels.Contains(type),
};
check.Checked += (sender, e) => {
this.Notification.Channels.Add(type);
};
check.Unchecked += (sender, e) => {
this.Notification.Channels.Remove(type);
};
this.Channels.Children.Add(check);
}
}
private void ManageNotification_OnClosed(object? sender, EventArgs e) {
this.Notification.Regexes = this.Regexes
.Select(wrapper => wrapper.Value)
.Where(regex => regex.Length > 0 && regex.IsValidRegex())
.ToList();
this.Notification.Substrings = this.Substrings
.Select(wrapper => wrapper.Value)
.Where(substring => substring.Length > 0)
.ToList();
if (this.NewNotification) {
this.App.Config.Notifications.Add(this.Notification);
}
this.App.Config.Save();
}
}
}

View File

@ -11,6 +11,7 @@
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<ApplicationIcon>Resources\logo.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
@ -49,11 +50,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.0.8" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="6.1.1" />
<PackageReference Include="ModernWpfUI" Version="0.9.2" />
<PackageReference Include="ModernWpfUI.MahApps" Version="0.9.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Sodium.Core" Version="1.2.3" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
</ItemGroup>
<ItemGroup>