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,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="mpvInputEdit.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<mpvInputEdit.Properties.Settings>
<setting name="input_conf_help" serializeAs="String">
<value> # This file defines the input (keys and mouse) bindings of mpv and mpv.net
# and it also defines the context menu of mpv.net. mpv.net has a input
# editor and a conf editor as alternatives to editing this file via texteditor.
# The input and conf editors can be found in mpv.net's context menu at:
# Settings &gt; Show Config Editor
# Settings &gt; Show Input Editor
# The defaults of this file can be found at:
# https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
# the defaults of mpv can be found at:
# https://github.com/mpv-player/mpv/blob/master/etc/input.conf
# mpv.net's defaults of mpv.conf contain: 'input-default-bindings = no'
# which disables mpv's input defaults. Every line in this file begins with a
# space character to make it easier to do a text search, so if you want to know
# if 'o' has already a binding you can make a text search on ' o '.
# mpv input commands: https://github.com/stax76/mpv.net/wiki/mpv-input-commands
# mpv input keys: https://github.com/stax76/mpv.net/wiki/mpv-input-keys</value>
</setting>
</mpvInputEdit.Properties.Settings>
</userSettings>
</configuration>

View File

@@ -27,8 +27,8 @@ namespace mpvInputEdit
if (l.StartsWith("#")) continue;
if (!l.Contains(" ")) continue;
InputItem item = new InputItem();
item.Key = l.Substring(0, l.IndexOf(" "));
if (item.Key == "") continue;
item.Input = l.Substring(0, l.IndexOf(" "));
if (item.Input == "") continue;
l = l.Substring(l.IndexOf(" ") + 1);
if (l.Contains("#menu:"))

View File

@@ -277,18 +277,18 @@ namespace mpvInputEdit
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
SetKey(InputItem.Key);
SetKey(InputItem.Input);
}
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
InputItem.Key = NewKey;
InputItem.Input = NewKey;
Close();
}
private void ClearButton_Click(object sender, RoutedEventArgs e)
{
InputItem.Key = "_";
InputItem.Input = "_";
Close();
}

View File

@@ -8,18 +8,18 @@
Loaded="Window_Loaded" Closed="Window_Closed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Controls:SearchTextBoxUserControl x:Name="SearchControl" Width="300" Margin="0,0,0,10" Grid.ColumnSpan="2" />
<DataGrid Grid.Row="1" x:Name="DataGrid" AutoGenerateColumns="False" CellStyle="{StaticResource DataGrid_Font_Centering}">
<Controls:SearchTextBoxUserControl x:Name="SearchControl" Width="300" Margin="0,20,0,20" Grid.ColumnSpan="2" />
<DataGrid Grid.Row="1" x:Name="DataGrid" CommandManager.PreviewCanExecute="DataGrid_PreviewCanExecute" AutoGenerateColumns="False" CellStyle="{StaticResource DataGrid_Font_Centering}">
<DataGrid.Columns>
<DataGridTextColumn Header="Context Menu" Binding="{Binding Menu}"/>
<DataGridTemplateColumn Header="Input">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button MinHeight="20" Click="ButtonClick">
<TextBlock Text="{Binding Key}"></TextBlock>
<TextBlock Text="{Binding Input}"></TextBlock>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>

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;
}
}
}

View File

@@ -12,7 +12,7 @@ using System.Windows;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("mpv(.net) input edit")]
[assembly: AssemblyCopyright("Copyright © stax76")]
[assembly: AssemblyCopyright("Copyright © 2017 stax76")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -51,5 +51,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

View File

@@ -8,21 +8,54 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace mpvInputEdit.Properties
{
namespace mpvInputEdit.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(@" # This file defines the input (keys and mouse) bindings of mpv and mpv.net
# and it also defines the context menu of mpv.net. mpv.net has a input
# editor and a conf editor as alternatives to editing this file via texteditor.
# The input and conf editors can be found in mpv.net's context menu at:
# Settings > Show Config Editor
# Settings > Show Input Editor
# The defaults of this file can be found at:
# https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
# the defaults of mpv can be found at:
# https://github.com/mpv-player/mpv/blob/master/etc/input.conf
# mpv.net's defaults of mpv.conf contain: 'input-default-bindings = no'
# which disables mpv's input defaults. Every line in this file begins with a
# space character to make it easier to do a text search, so if you want to know
# if 'o' has already a binding you can make a text search on ' o '.
# mpv input commands: https://github.com/stax76/mpv.net/wiki/mpv-input-commands
# mpv input keys: https://github.com/stax76/mpv.net/wiki/mpv-input-keys")]
public string input_conf_help {
get {
return ((string)(this["input_conf_help"]));
}
set {
this["input_conf_help"] = value;
}
}
}
}

View File

@@ -1,7 +1,32 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="mpvInputEdit.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="input_conf_help" Type="System.String" Scope="User">
<Value Profile="(Default)"> # This file defines the input (keys and mouse) bindings of mpv and mpv.net
# and it also defines the context menu of mpv.net. mpv.net has a input
# editor and a conf editor as alternatives to editing this file via texteditor.
# The input and conf editors can be found in mpv.net's context menu at:
# Settings &gt; Show Config Editor
# Settings &gt; Show Input Editor
# The defaults of this file can be found at:
# https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
# the defaults of mpv can be found at:
# https://github.com/mpv-player/mpv/blob/master/etc/input.conf
# mpv.net's defaults of mpv.conf contain: 'input-default-bindings = no'
# which disables mpv's input defaults. Every line in this file begins with a
# space character to make it easier to do a text search, so if you want to know
# if 'o' has already a binding you can make a text search on ' o '.
# mpv input commands: https://github.com/stax76/mpv.net/wiki/mpv-input-commands
# mpv input keys: https://github.com/stax76/mpv.net/wiki/mpv-input-keys</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -21,14 +21,12 @@ namespace mpvInputEdit
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _Key = "";
private string _Input = "";
public string Key {
get {
return _Key;
}
public string Input {
get => _Input;
set {
_Key = value;
_Input = value;
NotifyPropertyChanged();
}
}