Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Dec 23, 2023
1 parent 3e4ea03 commit 764f00e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 96 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Expand Up @@ -4,6 +4,11 @@
- Support of the mpv option `title-bar`.
- Command line parser fix using list options with `-add` suffix.
- Fix video being rendered with black line at the bottom.
- The conf file reader/writer detects if the user prefers space before and after the equal sign.
- The portable download includes like the installer debug symbols.
- Setup questions on startup removed.
- Pressing shift while drag and drop (and clipboard import) appends
instead of replaces files in the playlist. mpv supports this as well.

# v7.0.0.4 Beta (2023-12-19)

Expand Down
6 changes: 4 additions & 2 deletions src/MpvNet.Windows/GuiCommand.cs
Expand Up @@ -153,10 +153,12 @@ public static void ShowCommands()

public void OpenFromClipboard(IList<string> args)
{
bool append = Control.ModifierKeys == Keys.Shift;

if (System.Windows.Forms.Clipboard.ContainsFileDropList())
{
string[] files = System.Windows.Forms.Clipboard.GetFileDropList().Cast<string>().ToArray();
Player.LoadFiles(files, false, false);
Player.LoadFiles(files, false, append);
}
else
{
Expand All @@ -173,7 +175,7 @@ public void OpenFromClipboard(IList<string> args)
return;
}

Player.LoadFiles(files.ToArray(), false, false);
Player.LoadFiles(files.ToArray(), false, append);
}
}

Expand Down
55 changes: 0 additions & 55 deletions src/MpvNet.Windows/Help/WinMpvHelp.cs

This file was deleted.

78 changes: 49 additions & 29 deletions src/MpvNet.Windows/WPF/ConfWindow.xaml.cs
Expand Up @@ -20,13 +20,16 @@ namespace MpvNet.Windows.WPF;

public partial class ConfWindow : Window, INotifyPropertyChanged
{
List<Setting> Settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd());
List<ConfItem> ConfItems = new List<ConfItem>();
string InitialContent;
string ThemeConf = GetThemeConf();
List<Setting> _settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd());
List<ConfItem> _confItems = new List<ConfItem>();
string _initialContent;
string _themeConf = GetThemeConf();
string? _searchText;
List<NodeViewModel>? _nodes;
bool _shown;
int _useSpace;
int _useNoSpace;

public event PropertyChangedEventHandler? PropertyChanged;

public ConfWindow()
Expand All @@ -37,7 +40,7 @@ public ConfWindow()
LoadConf(App.ConfPath);
LoadLibplaceboConf();
LoadSettings();
InitialContent = GetCompareString();
_initialContent = GetCompareString();

if (string.IsNullOrEmpty(App.Settings.ConfigEditorSearch))
SearchText = "General:";
Expand Down Expand Up @@ -74,7 +77,7 @@ public List<NodeViewModel> Nodes
{
var rootNode = new TreeNode();

foreach (Setting setting in Settings)
foreach (Setting setting in _settings)
AddNode(rootNode.Children, setting.Directory!);

_nodes = new NodeViewModel(rootNode).Children;
Expand Down Expand Up @@ -127,14 +130,14 @@ public List<NodeViewModel> Nodes

void LoadSettings()
{
foreach (Setting setting in Settings)
foreach (Setting setting in _settings)
{
setting.StartValue = setting.Value;

if (!FilterStrings.Contains(setting.Directory!))
FilterStrings.Add(setting.Directory!);

foreach (ConfItem item in ConfItems)
foreach (ConfItem item in _confItems)
{
if (setting.Name == item.Name &&
setting.File == item.File &&
Expand Down Expand Up @@ -164,7 +167,7 @@ void LoadSettings()

static string GetThemeConf() => Theme.DarkMode + App.DarkTheme + App.LightTheme;

string GetCompareString() => string.Join("", Settings.Select(item => item.Name + item.Value).ToArray());
string GetCompareString() => string.Join("", _settings.Select(item => item.Name + item.Value).ToArray());

void LoadConf(string file)
{
Expand All @@ -176,9 +179,12 @@ void LoadConf(string file)

bool isSectionItem = false;

foreach (string currentLine in File.ReadAllLines(file))
foreach (string it in File.ReadAllLines(file))
{
string line = currentLine.Trim();
string line = it.Trim();

if (line.StartsWith("-"))
line = line.TrimStart('-');

if (line == "")
comment += "\r\n";
Expand All @@ -187,7 +193,7 @@ void LoadConf(string file)
else if (line.StartsWith("[") && line.Contains(']'))
{
if (!isSectionItem && comment != "" && comment != "\r\n")
ConfItems.Add(new ConfItem() {
_confItems.Add(new ConfItem() {
Comment = comment, File = Path.GetFileNameWithoutExtension(file)});

section = line.Substring(0, line.IndexOf("]") + 1);
Expand All @@ -197,7 +203,20 @@ void LoadConf(string file)
else if (line.Contains('=') || Regex.Match(line, "^[\\w-]+$").Success)
{
if (!line.Contains('='))
line += "=yes";
{
if (line.StartsWith("no-"))
{
line = line.Substring(3);
line += "=no";
}
else
line += "=yes";
}

if (line.Contains(" =") || line.Contains("= "))
_useSpace += 1;
else
_useNoSpace += 1;

ConfItem item = new();
item.File = Path.GetFileNameWithoutExtension(file);
Expand All @@ -207,7 +226,7 @@ void LoadConf(string file)
item.Section = section;
section = "";

if (line.Contains('#') && !line.Contains("'") && !line.Contains("\""))
if (line.Contains('#') && !line.Contains('\'') && !line.Contains('"'))
{
item.LineComment = line.Substring(line.IndexOf("#")).Trim();
line = line.Substring(0, line.IndexOf("#")).Trim();
Expand All @@ -231,7 +250,7 @@ void LoadConf(string file)

item.Name = left;
item.Value = right;
ConfItems.Add(item);
_confItems.Add(item);
}
}
}
Expand All @@ -240,7 +259,7 @@ string GetKeyValueContent(string filename)
{
List<string> pairs = new();

foreach (Setting setting in Settings)
foreach (Setting setting in _settings)
{
if (filename != setting.File)
continue;
Expand All @@ -254,7 +273,7 @@ string GetKeyValueContent(string filename)

void LoadLibplaceboConf()
{
foreach (ConfItem item in ConfItems.ToArray())
foreach (ConfItem item in _confItems.ToArray())
if (item.Name == "libplacebo-opts")
LoadKeyValueList(item.Value, "libplacebo");
}
Expand All @@ -276,7 +295,7 @@ void LoadKeyValueList(string options, string file)
item.Name = left;
item.Value = right;
item.File = file;
ConfItems.Add(item);
_confItems.Add(item);
}
}

Expand All @@ -301,8 +320,9 @@ string GetContent(string filename)
{
StringBuilder sb = new StringBuilder();
List<string> namesWritten = new List<string>();
string equalString = _useSpace > _useNoSpace ? " = " : "=";

foreach (ConfItem item in ConfItems)
foreach (ConfItem item in _confItems)
{
if (filename != item.File || item.Section != "" || item.IsSectionItem)
continue;
Expand All @@ -314,7 +334,7 @@ string GetContent(string filename)
{
if (item.Name != "")
{
sb.Append(item.Name + " = " + EscapeValue(item.Value));
sb.Append(item.Name + equalString + EscapeValue(item.Value));

if (item.LineComment != "")
sb.Append(" " + item.LineComment);
Expand All @@ -325,7 +345,7 @@ string GetContent(string filename)
}
else if ((item.SettingBase.Value ?? "") != item.SettingBase.Default)
{
sb.Append(item.Name + " = " + EscapeValue(item.SettingBase.Value!));
sb.Append(item.Name + equalString + EscapeValue(item.SettingBase.Value!));

if (item.LineComment != "")
sb.Append(" " + item.LineComment);
Expand All @@ -335,16 +355,16 @@ string GetContent(string filename)
}
}

foreach (Setting setting in Settings)
foreach (Setting setting in _settings)
{
if (filename != setting.File || namesWritten.Contains(setting.Name!))
continue;

if ((setting.Value ?? "") != setting.Default)
sb.AppendLine(setting.Name + " = " + EscapeValue(setting.Value!));
sb.AppendLine(setting.Name + equalString + EscapeValue(setting.Value!));
}

foreach (ConfItem item in ConfItems)
foreach (ConfItem item in _confItems)
{
if (filename != item.File || (item.Section == "" && !item.IsSectionItem))
continue;
Expand All @@ -360,7 +380,7 @@ string GetContent(string filename)
if (item.Comment != "")
sb.Append(item.Comment);

sb.Append(item.Name + " = " + EscapeValue(item.Value));
sb.Append(item.Name + equalString + EscapeValue(item.Value));

if (item.LineComment != "")
sb.Append(" " + item.LineComment);
Expand Down Expand Up @@ -415,10 +435,10 @@ protected override void OnClosed(EventArgs e)
base.OnClosed(e);
App.Settings.ConfigEditorSearch = SearchText;

if (InitialContent == GetCompareString())
if (_initialContent == GetCompareString())
return;

foreach (Setting setting in Settings)
foreach (Setting setting in _settings)
{
if (setting.Name == "libplacebo-opts")
{
Expand All @@ -430,7 +450,7 @@ protected override void OnClosed(EventArgs e)
File.WriteAllText(Player.ConfPath, GetContent("mpv"));
File.WriteAllText(App.ConfPath, GetContent("mpvnet"));

foreach (Setting it in Settings)
foreach (Setting it in _settings)
{
if (it.Value != it.StartValue)
{
Expand All @@ -447,7 +467,7 @@ protected override void OnClosed(EventArgs e)
Theme.Init();
Theme.UpdateWpfColors();

if (ThemeConf != GetThemeConf())
if (_themeConf != GetThemeConf())
MessageBox.Show("Changed theme settings require mpv.net being restarted.", "Info");
}

Expand Down
14 changes: 5 additions & 9 deletions src/MpvNet.Windows/WinForms/MainForm.cs
Expand Up @@ -1352,14 +1352,8 @@ protected override void OnShown(EventArgs e)
InitAndBuildContextMenu();
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
GlobalHotkey.RegisterGlobalHotkeys(Handle);
WasShown = true;
StrongReferenceMessenger.Default.Send(new MainWindowIsLoadedMessage());

TaskHelp.Run(() => {
System.Windows.Application.Current.Dispatcher.BeginInvoke(() => {
WinMpvHelp.Setup();
}, DispatcherPriority.Background);
});
WasShown = true;
}

void ContextMenu_Closed(object sender, System.Windows.RoutedEventArgs e) => MenuAutoResetEvent.Set();
Expand Down Expand Up @@ -1448,10 +1442,12 @@ protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop(e);

bool append = ModifierKeys == Keys.Shift;

if (e.Data!.GetDataPresent(DataFormats.FileDrop))
Player.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as string[], true, false);
Player.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as string[], true, append);
else if (e.Data.GetDataPresent(DataFormats.Text))
Player.LoadFiles(new[] { e.Data.GetData(DataFormats.Text)!.ToString()! }, true, false);
Player.LoadFiles(new[] { e.Data.GetData(DataFormats.Text)!.ToString()! }, true, append);
}

protected override void OnKeyDown(KeyEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/MpvNet/Player.cs
Expand Up @@ -452,7 +452,7 @@ public void ProcessCommandLineFiles()

files.Add(arg);

LoadFiles(files.ToArray(), !App.Queue, false || App.Queue);
LoadFiles(files.ToArray(), !App.Queue, App.Queue);

if (App.CommandLine.Contains("--shuffle"))
{
Expand Down

0 comments on commit 764f00e

Please sign in to comment.