#442 show chapters in the command palette

This commit is contained in:
stax76
2022-06-19 05:23:10 +02:00
parent 55f4a340af
commit 500fe9abc4
7 changed files with 63 additions and 14 deletions

View File

@@ -5,10 +5,18 @@
- New options `autofit-image` and `autofit-audio`, like autofit but used for image and audio files. Default 80. - New options `autofit-image` and `autofit-audio`, like autofit but used for image and audio files. Default 80.
- New [auto-mode](https://github.com/stax76/mpv-scripts) script to use mpv and mpv.net as image viewer and audio player. - New [auto-mode](https://github.com/stax76/mpv-scripts) script to use mpv and mpv.net as image viewer and audio player.
- New support of the mpv option `snap-window`. - New support of the mpv option `snap-window`.
- New feature to show chapters in the command palette, see binding and menu definition below.
- Fix long commands causing key bindings not visible in the command palette. - Fix long commands causing key bindings not visible in the command palette.
- Fix script compatibility with mordenx and mpv-osc-tethys. - Fix script compatibility with mordenx and mpv-osc-tethys.
- Fix borderless window not resizable with mouse. - Fix borderless window not resizable with mouse.
input.conf changes:
New:
```
Ctrl+c script-message-to mpvnet show-chapters #menu: View > Show Chapters
```
# 6.0.0.0 Beta (2022-06-05) # 6.0.0.0 Beta (2022-06-05)

View File

@@ -298,6 +298,9 @@ Shows available audio devices in a message box.
Shows available audio tracks in the command palette Shows available audio tracks in the command palette
and allows to load the selected audio track. and allows to load the selected audio track.
### show-chapters
Shows chapters in the command palette.
### show-command-palette ### show-command-palette
Shows the command palette. Shows the command palette.

View File

@@ -46,6 +46,7 @@ namespace mpvnet
case "show-about": ShowDialog(typeof(AboutWindow)); break; case "show-about": ShowDialog(typeof(AboutWindow)); break;
case "show-audio-devices": Msg.ShowInfo(Core.GetPropertyOsdString("audio-device-list")); break; case "show-audio-devices": Msg.ShowInfo(Core.GetPropertyOsdString("audio-device-list")); break;
case "show-audio-tracks": ShowAudioTracks(); break; case "show-audio-tracks": ShowAudioTracks(); break;
case "show-chapters": ShowChapters(); break;
case "show-command-palette": ShowCommandPalette(); break; case "show-command-palette": ShowCommandPalette(); break;
case "show-commands": ShowCommands(); break; case "show-commands": ShowCommands(); break;
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
@@ -669,6 +670,16 @@ namespace mpvnet
CommandPalette.Instance.SelectFirst(); CommandPalette.Instance.SelectFirst();
}); });
public static void ShowChapters() => App.InvokeOnMainThread(() =>
{
var items = Core.Chapters.Select(i => new CommandPaletteItem(i.Title, i.TimeDisplay, () =>
Core.CommandV("seek", i.Time.ToString(CultureInfo.InvariantCulture), "absolute")));
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst();
});
public static void ShowMenu() => Core.RaiseShowMenu(); public static void ShowMenu() => Core.RaiseShowMenu();
public static void PlaylistAdd(int value) public static void PlaylistAdd(int value)

View File

@@ -261,6 +261,13 @@ namespace mpvnet
Action = action; Action = action;
} }
public CommandPaletteItem(string text, string secondaryText, Action action)
{
Text = text;
Action = action;
SecondaryText = secondaryText;
}
public string Text { get; set; } = ""; public string Text { get; set; } = "";
public string SecondaryText { get; set; } = ""; public string SecondaryText { get; set; } = "";
public Action Action { get; set; } public Action Action { get; set; }
@@ -283,4 +290,26 @@ namespace mpvnet
}); });
} }
} }
public class Chapter
{
public string Title { get; set; }
public double Time { get; set; }
string _TimeDisplay;
public string TimeDisplay {
get {
if (_TimeDisplay == null)
{
_TimeDisplay = TimeSpan.FromSeconds(Time).ToString();
if (_TimeDisplay.ContainsEx("."))
_TimeDisplay = _TimeDisplay.Substring(0, _TimeDisplay.LastIndexOf("."));
}
return _TimeDisplay;
}
}
}
} }

View File

@@ -74,7 +74,7 @@ namespace mpvnet
public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false);
public IntPtr Handle { get; set; } public IntPtr Handle { get; set; }
public IntPtr NamedHandle { get; set; } public IntPtr NamedHandle { get; set; }
public List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>(); public List<Chapter> Chapters { get; set; } = new List<Chapter>();
public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>(); public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>(); public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
public object MediaTracksLock { get; } = new object(); public object MediaTracksLock { get; } = new object();
@@ -1458,13 +1458,15 @@ namespace mpvnet
for (int x = 0; x < count; x++) for (int x = 0; x < count; x++)
{ {
string text = GetPropertyString($"chapter-list/{x}/title"); string title = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time"); double time = GetPropertyDouble($"chapter-list/{x}/time");
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(title) ||
text = "Chapter " + (x + 1); (title.Length == 12 && title.Contains(":") && title.Contains(".")))
Chapters.Add(new KeyValuePair<string, double>(text, time)); title = "Chapter " + (x + 1);
Chapters.Add(new Chapter() { Title = title, Time = time });
} }
} }
} }

View File

@@ -118,6 +118,7 @@ Ctrl+p script-message-to mpvnet select-profile #menu: View > Show Profile
Ctrl+P script-message-to mpvnet show-profiles #menu: View > Show Profiles Ctrl+P script-message-to mpvnet show-profiles #menu: View > Show Profiles
Ctrl+7 script-message-to mpvnet show-audio-tracks #menu: View > Show Audio Tracks Ctrl+7 script-message-to mpvnet show-audio-tracks #menu: View > Show Audio Tracks
Ctrl+8 script-message-to mpvnet show-subtitle-tracks #menu: View > Show Subtitle Tracks Ctrl+8 script-message-to mpvnet show-subtitle-tracks #menu: View > Show Subtitle Tracks
Ctrl+c script-message-to mpvnet show-chapters #menu: View > Show Chapters
b cycle border #menu: View > Toggle Border b cycle border #menu: View > Toggle Border
Ctrl+t cycle ontop #menu: View > Toggle On Top Ctrl+t cycle ontop #menu: View > Toggle On Top
t script-binding stats/display-stats-toggle #menu: View > Toggle Statistics t script-binding stats/display-stats-toggle #menu: View > Toggle Statistics

View File

@@ -301,16 +301,11 @@ namespace mpvnet
{ {
chaptersMenuItem.Items.Clear(); chaptersMenuItem.Items.Clear();
foreach (var pair in Core.Chapters) foreach (Chapter chapter in Core.Chapters)
{ {
string caption = TimeSpan.FromSeconds(pair.Value).ToString(); var chapterMenuItem = new WpfControls.MenuItem() { Header = chapter.Title };
chapterMenuItem.InputGestureText = chapter.TimeDisplay;
if (caption.ContainsEx(".")) chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", chapter.Time.ToString(CultureInfo.InvariantCulture), "absolute");
caption = caption.Substring(0, caption.LastIndexOf("."));
var chapterMenuItem = new WpfControls.MenuItem() { Header = pair.Key };
chapterMenuItem.InputGestureText = caption;
chapterMenuItem.Click += (sender, args) => Core.CommandV("seek", pair.Value.ToString(CultureInfo.InvariantCulture), "absolute");
chaptersMenuItem.Items.Add(chapterMenuItem); chaptersMenuItem.Items.Add(chapterMenuItem);
} }
} }