#442 show chapters in the command palette
This commit is contained in:
@@ -46,6 +46,7 @@ namespace mpvnet
|
||||
case "show-about": ShowDialog(typeof(AboutWindow)); break;
|
||||
case "show-audio-devices": Msg.ShowInfo(Core.GetPropertyOsdString("audio-device-list")); break;
|
||||
case "show-audio-tracks": ShowAudioTracks(); break;
|
||||
case "show-chapters": ShowChapters(); break;
|
||||
case "show-command-palette": ShowCommandPalette(); break;
|
||||
case "show-commands": ShowCommands(); break;
|
||||
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
|
||||
@@ -669,6 +670,16 @@ namespace mpvnet
|
||||
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 PlaylistAdd(int value)
|
||||
|
||||
@@ -261,6 +261,13 @@ namespace mpvnet
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public CommandPaletteItem(string text, string secondaryText, Action action)
|
||||
{
|
||||
Text = text;
|
||||
Action = action;
|
||||
SecondaryText = secondaryText;
|
||||
}
|
||||
|
||||
public string Text { get; set; } = "";
|
||||
public string SecondaryText { 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace mpvnet
|
||||
public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false);
|
||||
public IntPtr Handle { 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<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
|
||||
public object MediaTracksLock { get; } = new object();
|
||||
@@ -1458,13 +1458,15 @@ namespace mpvnet
|
||||
|
||||
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");
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
text = "Chapter " + (x + 1);
|
||||
if (string.IsNullOrEmpty(title) ||
|
||||
(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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user