This commit is contained in:
Frank Skare
2019-04-27 01:23:58 +02:00
parent d777ca912a
commit 8c87ac0c47
22 changed files with 247 additions and 66 deletions

View File

@@ -55,13 +55,25 @@ Table of contents
### Screenshots
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/mpvnet.png)
#### Main Window
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/mpvnetContextMenu.png)
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/Main.png)
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/mpvConfEdit.png)
#### Context Menu
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/mpvInputEdit.png)
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/Menu.png)
#### Config Editor
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/ConfEditor.png)
#### Input Editor
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/InputEditor.png)
#### Command Palette
![](https://raw.githubusercontent.com/stax76/mpv.net/master/screenshots/CommandPalette.png)
### Context Menu
@@ -183,12 +195,15 @@ mpv.net bugs and requests: <https://github.com/stax76/mpv.net/issues>
the config folder should be created (portable or appdata)
- there was an issue causing keys not working after a modal window was shown
- there was a crash when no script folder existed in the conf folder
- MediaInfo, youtube-dl and libmpv were updated
- MediaInfo and youtube-dl were updated
- a new JavaScript example script was added to the wiki and the
script descriptions were improved. [Scripting Page](https://github.com/stax76/mpv.net/wiki/Scripting).
- greatly improved README.md file and github startpage
- About dialog added
- the input editor shows only a closing message if actually a change was made
- the input editor don't show menu separators any longer
- new Command Palette feature added
- the history feature had a bug causing files to be logged more than once
### 3.1 (2019-04-23)

View File

@@ -89,6 +89,15 @@ namespace mpvnet
}));
}
public static void show_command_palette(string[] args)
{
MainForm.Instance.Invoke(new Action(() => {
var w = new CommandPaletteWindow();
new WindowInteropHelper(w).Owner = MainForm.Instance.Handle;
w.ShowDialog();
}));
}
public static void show_history(string[] args)
{
var fp = mp.MpvConfFolder + "history.txt";

View File

@@ -305,13 +305,13 @@ namespace mpvnet
}
}
foreach (string i in lines)
foreach (string line in lines)
{
if (!i.Contains("#menu:")) continue;
string left = i.Substring(0, i.IndexOf("#menu:")).Trim();
if (!line.Contains("#menu:")) continue;
string left = line.Substring(0, line.IndexOf("#menu:")).Trim();
if (left.StartsWith("#")) continue;
string command = left.Substring(left.IndexOf(" ") + 1).Trim();
string menu = i.Substring(i.IndexOf("#menu:") + "#menu:".Length).Trim();
string menu = line.Substring(line.IndexOf("#menu:") + "#menu:".Length).Trim();
string input = left.Substring(0, left.IndexOf(" "));
if (input == "_") input = "";
if (menu.Contains(";")) input = menu.Substring(0, menu.IndexOf(";")).Trim();
@@ -393,6 +393,8 @@ namespace mpvnet
protected override void WndProc(ref Message m)
{
//Debug.WriteLine(m);
switch (m.Msg)
{
case 0x0201: // WM_LBUTTONDOWN

View File

@@ -163,15 +163,16 @@ namespace mpvnet
}
[Serializable]
public class InputItem : INotifyPropertyChanged
public class CommandItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string Menu { get; set; } = "";
public string Path { get; set; } = "";
public string Command { get; set; } = "";
public InputItem() { }
public CommandItem() { }
public InputItem(SerializationInfo info, StreamingContext context) { }
public CommandItem(SerializationInfo info, StreamingContext context) { }
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
@@ -188,45 +189,44 @@ namespace mpvnet
}
}
private static ObservableCollection<InputItem> _InputItems;
private static ObservableCollection<CommandItem> _Items;
public static ObservableCollection<InputItem> InputItems {
public static ObservableCollection<CommandItem> Items {
get {
if (_InputItems is null)
if (_Items is null)
{
_InputItems = new ObservableCollection<InputItem>();
_Items = new ObservableCollection<CommandItem>();
if (File.Exists(mp.InputConfPath))
{
foreach (string line in File.ReadAllLines(mp.InputConfPath))
{
string l = line.Trim();
if (l.StartsWith("#")) continue;
if (!l.Contains(" ")) continue;
InputItem item = new InputItem();
item.Input = l.Substring(0, l.IndexOf(" "));
if (item.Input == "") continue;
l = l.Substring(l.IndexOf(" ") + 1);
string val = line.Trim();
if (val.StartsWith("#")) continue;
if (!val.Contains(" ")) continue;
CommandItem item = new CommandItem();
item.Input = val.Substring(0, val.IndexOf(" ")).Replace("_", "");
val = val.Substring(val.IndexOf(" ") + 1);
if (l.Contains("#menu:"))
if (val.Contains("#menu:"))
{
item.Menu = l.Substring(l.IndexOf("#menu:") + 6).Trim();
l = l.Substring(0, l.IndexOf("#menu:"));
item.Path = val.Substring(val.IndexOf("#menu:") + 6).Trim();
val = val.Substring(0, val.IndexOf("#menu:"));
if (item.Menu.Contains(";"))
item.Menu = item.Menu.Substring(item.Menu.IndexOf(";") + 1).Trim();
if (item.Path.Contains(";"))
item.Path = item.Path.Substring(item.Path.IndexOf(";") + 1).Trim();
}
item.Command = l.Trim();
item.Command = val.Trim();
if (item.Command == "")
continue;
if (item.Command.ToLower() == "ignore")
item.Command = "";
_InputItems.Add(item);
_Items.Add(item);
}
}
}
return _InputItems;
return _Items;
}
}
}

View File

@@ -138,11 +138,12 @@
Ctrl+i script-message mpv.net show-input-editor #menu: Settings > Show Input Editor
Ctrl+f script-message mpv.net open-conf-folder #menu: Settings > Open Config Folder
h script-message mpv.net show-history #menu: Tools > Show History
l ab-loop #menu: Tools > Set/clear A-B loop points
L cycle-values loop-file "inf" "no" #menu: Tools > Toggle infinite file looping
Ctrl+h cycle-values hwdec "auto" "no" #menu: Tools > Cycle Hardware Decoding
_ script-message mpv.net execute-mpv-command #menu: Tools > Execute mpv command...
Ctrl+P script-message mpv.net show-command-palette #menu: Tools > Command Palette
h script-message mpv.net show-history #menu: Tools > Show History
l ab-loop #menu: Tools > Set/clear A-B loop points
L cycle-values loop-file "inf" "no" #menu: Tools > Toggle infinite file looping
Ctrl+h cycle-values hwdec "auto" "no" #menu: Tools > Cycle Hardware Decoding
_ script-message mpv.net execute-mpv-command #menu: Tools > Execute mpv command...
_ script-message mpv.net shell-execute https://mpv.io/manual/stable/ #menu: Help > Show mpv manual
_ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/blob/master/etc/input.conf #menu: Help > Show mpv default keys

View File

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="About mpv.net" Height="230" Width="420" FontSize="16" ShowInTaskbar="False"
WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
WindowStartupLocation="CenterOwner" ResizeMode="NoResize" PreviewKeyDown="Window_PreviewKeyDown">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock FontSize="48" HorizontalAlignment="Center" Margin="0,0,0,10">mpv.net</TextBlock>

View File

@@ -11,5 +11,10 @@ namespace mpvnet
Version.Text = $"Version {System.Windows.Forms.Application.ProductVersion}";
Foreground = WPF.WPF.ThemeBrush;
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
Close();
}
}
}

View File

@@ -0,0 +1,35 @@
<Window x:Class="mpvnet.CommandPaletteWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
mc:Ignorable="d"
Title="Command Palette" Height="295" Width="400" ResizeMode="NoResize"
WindowStartupLocation="CenterOwner" Loaded="Window_Loaded" FontSize="13">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Name="FilterTextBox" PreviewKeyDown="FilterTextBox_PreviewKeyDown" TextChanged="FilterTextBox_TextChanged"></TextBox>
<ListView Name="ListView" Grid.Row="1" MouseUp="ListView_MouseUp">
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path}"></TextBlock>
<TextBlock Grid.Column="1" Text="{Binding Input}" HorizontalAlignment="Right"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>

View File

@@ -0,0 +1,109 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
namespace mpvnet
{
public partial class CommandPaletteWindow : Window
{
ICollectionView CollectionView;
public CommandPaletteWindow()
{
InitializeComponent();
CollectionViewSource collectionViewSource = new CollectionViewSource() { Source = CommandItem.Items };
CollectionView = collectionViewSource.View;
var yourCostumFilter = new Predicate<object>(item => Filter((CommandItem)item));
CollectionView.Filter = yourCostumFilter;
ListView.ItemsSource = CollectionView;
}
bool Filter(CommandItem item)
{
if (item.Command == "") return false;
string filter = FilterTextBox.Text.ToLower();
if (filter == "") return true;
if (item.Command.ToLower().Contains(filter) ||
item.Input.ToLower().Contains(filter) ||
item.Path.ToLower().Contains(filter))
return true;
return false;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
Keyboard.Focus(FilterTextBox);
SelectFirst();
}
void SelectFirst()
{
if (ListView.Items.Count > 0)
ListView.SelectedIndex = 0;
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == 0x200 /*WM_MOUSEMOVE*/ && Mouse.LeftButton != MouseButtonState.Pressed)
handled = true;
return IntPtr.Zero;
}
private void FilterTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Up:
{
int index = ListView.SelectedIndex;
index -= 1;
if (index < 0) index = 0;
ListView.SelectedIndex = index;
ListView.ScrollIntoView(ListView.SelectedItem);
}
break;
case Key.Down:
{
int index = ListView.SelectedIndex;
index += 1;
if (index > ListView.Items.Count - 1) index = ListView.Items.Count - 1;
ListView.SelectedIndex = index;
ListView.ScrollIntoView(ListView.SelectedItem);
}
break;
case Key.Escape:
Close();
break;
case Key.Enter:
Execute();
break;
}
}
void Execute()
{
if (ListView.SelectedItem != null)
{
CommandItem item = ListView.SelectedItem as CommandItem;
Close();
mp.command_string(item.Command);
}
}
private void ListView_MouseUp(object sender, MouseButtonEventArgs e)
{
Execute();
}
private void FilterTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
CollectionView.Refresh();
SelectFirst();
}
}
}

View File

@@ -10,11 +10,11 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="4*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="6*" />
</Grid.ColumnDefinitions>
<Controls:SearchTextBoxUserControl HintText="Find a setting" x:Name="SearchControl" Width="250" Margin="0,20,0,10" Grid.ColumnSpan="2" />
<ScrollViewer x:Name="MainScrollViewer" VerticalScrollBarVisibility="Auto" Grid.Row="1" Grid.Column="1" Margin="0,0,0,10">
@@ -24,9 +24,7 @@
<ListBox x:Name="FilterListBox" ItemsSource="{Binding FilterStrings}" BorderThickness="0" SelectionChanged="ListBox_SelectionChanged" Foreground="{x:Static WPF:WPF.ThemeBrush}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" FontSize="16" />
</StackPanel>
<TextBlock Text="{Binding}" FontSize="16" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

View File

@@ -27,7 +27,7 @@
<Controls:SearchTextBoxUserControl HintText="Type ? to get help." 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="Menu" Binding="{Binding Menu}"/>
<DataGridTextColumn Header="Menu" Binding="{Binding Path}"/>
<DataGridTemplateColumn Header="Input">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>

View File

@@ -20,9 +20,9 @@ namespace mpvnet
InitialInputConfContent = GetInputConfContent();
SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged;
DataGrid.SelectionMode = DataGridSelectionMode.Single;
CollectionViewSource collectionViewSource = new CollectionViewSource() { Source = InputItem.InputItems };
CollectionViewSource collectionViewSource = new CollectionViewSource() { Source = CommandItem.Items };
CollectionView = collectionViewSource.View;
var yourCostumFilter = new Predicate<object>(item => Filter((InputItem)item));
var yourCostumFilter = new Predicate<object>(item => Filter((CommandItem)item));
CollectionView.Filter = yourCostumFilter;
DataGrid.ItemsSource = CollectionView;
}
@@ -35,8 +35,9 @@ namespace mpvnet
MessageBox.Show("Filtering works by searching in the Input, Menu and Command but it's possible to reduce the filter scope to either of Input, Menu or Command by prefixing as follows:\n\ni <input search>\ni: <input search>\n\nm <menu search>\nm: <menu search>\n\nc <command search>\nc: <command search>\n\nIf only one character is entered the search will be performed only in the input.", "Filtering", MessageBoxButton.OK, MessageBoxImage.Information);
}
bool Filter(InputItem item)
bool Filter(CommandItem item)
{
if (item.Command == "") return false;
string searchText = SearchControl.SearchTextBox.Text.ToLower();
if (searchText == "") return true;
@@ -51,11 +52,11 @@ namespace mpvnet
return item.Input.ToLower().Contains(searchText);
}
else if (searchText.StartsWith("m ") || searchText.StartsWith("m:"))
return item.Menu.ToLower().Contains(searchText.Substring(2).Trim());
return item.Path.ToLower().Contains(searchText.Substring(2).Trim());
else if (searchText.StartsWith("c ") || searchText.StartsWith("c:"))
return item.Command.ToLower().Contains(searchText.Substring(2).Trim());
else if (item.Command.ToLower().Contains(searchText) ||
item.Menu.ToLower().Contains(searchText) ||
item.Path.ToLower().Contains(searchText) ||
item.Input.ToLower().Contains(searchText))
{
return true;
@@ -65,18 +66,18 @@ namespace mpvnet
private void ButtonClick(object sender, RoutedEventArgs e)
{
InputItem item = ((Button)e.Source).DataContext as InputItem;
CommandItem item = ((Button)e.Source).DataContext as CommandItem;
if (item is null) return;
LearnWindow w = new LearnWindow();
w.Owner = this;
w.InputItem = item;
w.ShowDialog();
var items = new Dictionary<string, InputItem>();
var items = new Dictionary<string, CommandItem>();
foreach (InputItem i in InputItem.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);
foreach (CommandItem i in CommandItem.Items)
if (items.ContainsKey(i.Input) && i.Input != "")
MessageBox.Show($"Duplicate found:\n\n{i.Input}: {i.Path}\n\n{items[i.Input].Input}: {items[i.Input].Path}\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;
}
@@ -87,17 +88,18 @@ namespace mpvnet
{
string text = Properties.Resources.inputConfHeader + "\r\n";
foreach (InputItem item in InputItem.InputItems)
foreach (CommandItem item in CommandItem.Items)
{
string line = " " + item.Input.PadRight(10);
string input = item.Input == "" ? "_" : item.Input;
string line = " " + input.PadRight(10);
if (item.Command.Trim() == "")
line += " ignore";
else
line += " " + item.Command.Trim();
if (item.Menu.Trim() != "")
line = line.PadRight(40) + " #menu: " + item.Menu;
if (item.Path.Trim() != "")
line = line.PadRight(40) + " #menu: " + item.Path;
text += line + "\r\n";
}
@@ -117,7 +119,7 @@ namespace mpvnet
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)
if (MessageBox.Show($"Confirm to delete: {(grid.SelectedItem as CommandItem).Input} ({(grid.SelectedItem as CommandItem).Path})", "Confirm Delete", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
e.Handled = true;
}
}

View File

@@ -9,7 +9,7 @@ namespace mpvnet
{
public partial class LearnWindow : Window
{
public InputItem InputItem { get; set; }
public CommandItem InputItem { get; set; }
public string NewKey { get; set; } = "";
public LearnWindow()
@@ -144,7 +144,7 @@ namespace mpvnet
void SetKey(string key)
{
NewKey = key;
MenuLabel.Content = InputItem.Menu;
MenuLabel.Content = InputItem.Path;
KeyLabel.Content = key;
}

View File

@@ -231,6 +231,7 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_FILE_LOADED:
FileLoaded?.Invoke();
LoadFolder();
WriteHistory(mp.get_property_string("path"));
break;
case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
TracksChanged?.Invoke();
@@ -322,10 +323,7 @@ namespace mpvnet
VideoSizeChanged?.Invoke();
}
Task.Run(new Action(() => {
WriteHistory(mp.get_property_string("path"));
ReadMetaData();
}));
Task.Run(new Action(() => ReadMetaData()));
break;
case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE:
ChapterChange?.Invoke();

View File

@@ -145,6 +145,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Windows\CommandPaletteWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="WPF\Resources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -186,6 +190,9 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sys\TaskDialog.cs" />
<Compile Include="Windows\CommandPaletteWindow.xaml.cs">
<DependentUpon>CommandPaletteWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ConfWindow.xaml.cs">
<DependentUpon>ConfWindow.xaml</DependentUpon>
</Compile>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
screenshots/ConfEditor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 KiB

BIN
screenshots/InputEditor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 2.9 MiB

View File

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 KiB