This commit is contained in:
Frank Skare
2019-04-05 15:49:01 +02:00
parent 1caa814c95
commit b16bcd0295
14 changed files with 286 additions and 93 deletions

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
@@ -35,13 +35,11 @@ namespace mpvInputEdit
bool Filter(InputItem item)
{
string searchText = SearchControl.SearchTextBox.Text.ToLowerInvariant();
if (searchText == "")
return true;
if (searchText == "") return true;
if (item.Command.ToLower().Contains(searchText) ||
item.Menu.ToLower().Contains(searchText) ||
item.Key.ToLower().Contains(searchText))
item.Input.ToLower().Contains(searchText))
{
return true;
}
@@ -56,44 +54,33 @@ namespace mpvInputEdit
w.Owner = this;
w.InputItem = item;
w.ShowDialog();
var items = new Dictionary<string, InputItem>();
foreach (InputItem i in App.InputItems)
if (items.ContainsKey(i.Input) && i.Input != "_")
MessageBox.Show($"Duplicate found:\n\n{i.Input}: {i.Menu}\n\n{items[i.Input].Input}: {items[i.Input].Menu}\n\nPlease note that you can chain multiple commands in the same line by using a semicolon as separator.", "Duplicate Found", MessageBoxButton.OK, MessageBoxImage.Warning);
else
items[i.Input] = i;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Keyboard.Focus(SearchControl.SearchTextBox);
}
private void Grid_PreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
DataGrid grid = (DataGrid)sender;
if (e.Command == DataGrid.DeleteCommand)
{
if (MessageBox.Show($"Would you like to delete the selected item?\n\n{(grid.SelectedItem as InputItem).Menu}",
"Confirm Delete", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
{
e.Handled = true;
}
}
}
private void Window_Loaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox);
private void Window_Closed(object sender, EventArgs e)
{
if (MessageBox.Show("Would you like to save changes?", "Confirm Save", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
return;
var backupDir = Path.GetDirectoryName(App.InputConfPath) + "\\backup\\";
if (!Directory.Exists(backupDir))
Directory.CreateDirectory(backupDir);
File.Copy(App.InputConfPath, backupDir + "input conf " + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".conf");
if (File.Exists(App.InputConfPath))
File.Copy(App.InputConfPath, backupDir + "input conf " + DateTime.Now.ToString("yyyy-MM-dd HH-mm") + ".conf");
string text = "";
string text = "\r\n" + Properties.Settings.Default.input_conf_help + "\r\n\r\n";
foreach (InputItem item in App.InputItems)
{
string line = " " + item.Key.PadRight(14);
string line = " " + item.Input.PadRight(10);
if (item.Command.Trim() == "")
line += " ignore";
@@ -108,11 +95,17 @@ namespace mpvInputEdit
File.WriteAllText(App.InputConfPath, text);
foreach (Process process in Process.GetProcesses())
if (process.ProcessName == "mpvnet")
MessageBox.Show("Restart mpv.net in order to apply changed input bindings.", Title, MessageBoxButton.OK, MessageBoxImage.Information);
else if (process.ProcessName == "mpv")
MessageBox.Show("Restart mpv in order to apply changed input bindings.", Title, MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show("Changes will be available on next mpv(.net) startup.",
Title, MessageBoxButton.OK, MessageBoxImage.Information);
}
private void DataGrid_PreviewCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
DataGrid grid = (DataGrid)sender;
if (e.Command == DataGrid.DeleteCommand)
if (MessageBox.Show($"Confirm to delete: {(grid.SelectedItem as InputItem).Input} ({(grid.SelectedItem as InputItem).Menu})", "Confirm Delete", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
e.Handled = true;
}
}
}