Ejemplo n.º 1
0
        public void BuildMenu()
        {
            string content = File.ReadAllText(Core.InputConfPath);
            var    items   = CommandItem.GetItems(content);

            if (!content.Contains("#menu:"))
            {
                var defaultItems = CommandItem.GetItems(Properties.Resources.input_conf);

                foreach (CommandItem item in items)
                {
                    foreach (CommandItem defaultItem in defaultItems)
                    {
                        if (item.Command == defaultItem.Command)
                        {
                            defaultItem.Input = item.Input;
                        }
                    }
                }

                items = defaultItems;
            }

            foreach (CommandItem item in items)
            {
                var tempItem = item;

                if (string.IsNullOrEmpty(tempItem.Path))
                {
                    continue;
                }

                var menuItem = MenuHelp.Add(ContextMenu.Items, tempItem.Path);

                if (menuItem != null)
                {
                    menuItem.Click += (sender, args) => {
                        try {
                            App.RunTask(() => {
                                MenuAutoResetEvent.WaitOne();
                                System.Windows.Application.Current.Dispatcher.Invoke(
                                    DispatcherPriority.Background, new Action(delegate { }));
                                if (!string.IsNullOrEmpty(tempItem.Command))
                                {
                                    Core.Command(tempItem.Command);
                                }
                            });
                        }
                        catch (Exception ex) {
                            Msg.ShowException(ex);
                        }
                    };

                    menuItem.InputGestureText = tempItem.Input;
                }
            }
        }
Ejemplo n.º 2
0
        void UpdateMenu()
        {
            lock (Core.MediaTracks)
            {
                var trackMenuItem = FindMenuItem("Track");

                if (trackMenuItem != null)
                {
                    trackMenuItem.Items.Clear();

                    MediaTrack[] audTracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray();
                    MediaTrack[] subTracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray();
                    MediaTrack[] vidTracks = Core.MediaTracks.Where(track => track.Type == "v").ToArray();
                    MediaTrack[] ediTracks = Core.MediaTracks.Where(track => track.Type == "e").ToArray();

                    foreach (MediaTrack track in vidTracks)
                    {
                        var mi = new WpfControls.MenuItem()
                        {
                            Header = track.Text
                        };
                        mi.Click    += (sender, args) => Core.CommandV("set", "vid", track.ID.ToString());
                        mi.IsChecked = Core.VID == track.ID.ToString();
                        trackMenuItem.Items.Add(mi);
                    }

                    if (vidTracks.Length > 0)
                    {
                        trackMenuItem.Items.Add(new WpfControls.Separator());
                    }

                    foreach (MediaTrack track in audTracks)
                    {
                        var mi = new WpfControls.MenuItem()
                        {
                            Header = track.Text
                        };
                        mi.Click    += (sender, args) => Core.CommandV("set", "aid", track.ID.ToString());
                        mi.IsChecked = Core.AID == track.ID.ToString();
                        trackMenuItem.Items.Add(mi);
                    }

                    if (subTracks.Length > 0)
                    {
                        trackMenuItem.Items.Add(new WpfControls.Separator());
                    }

                    foreach (MediaTrack track in subTracks)
                    {
                        var mi = new WpfControls.MenuItem()
                        {
                            Header = track.Text
                        };
                        mi.Click    += (sender, args) => Core.CommandV("set", "sid", track.ID.ToString());
                        mi.IsChecked = Core.SID == track.ID.ToString();
                        trackMenuItem.Items.Add(mi);
                    }

                    if (subTracks.Length > 0)
                    {
                        var mi = new WpfControls.MenuItem()
                        {
                            Header = "S: No subtitles"
                        };
                        mi.Click    += (sender, args) => Core.CommandV("set", "sid", "no");
                        mi.IsChecked = Core.SID == "no";
                        trackMenuItem.Items.Add(mi);
                    }

                    if (ediTracks.Length > 0)
                    {
                        trackMenuItem.Items.Add(new WpfControls.Separator());
                    }

                    foreach (MediaTrack track in ediTracks)
                    {
                        var mi = new WpfControls.MenuItem()
                        {
                            Header = track.Text
                        };
                        mi.Click    += (sender, args) => Core.CommandV("set", "edition", track.ID.ToString());
                        mi.IsChecked = Core.Edition == track.ID;
                        trackMenuItem.Items.Add(mi);
                    }
                }
            }

            lock (Core.Chapters)
            {
                var chaptersMenuItem = FindMenuItem("Chapters");

                if (chaptersMenuItem != null)
                {
                    chaptersMenuItem.Items.Clear();

                    foreach (var pair in Core.Chapters)
                    {
                        var chapterMenuItem = new WpfControls.MenuItem()
                        {
                            Header = pair.Key
                        };
                        chapterMenuItem.InputGestureText = TimeSpan.FromSeconds(pair.Value).ToString().Substring(0, 8);
                        chapterMenuItem.Click           += (sender, args) => Core.CommandV("seek", pair.Value.ToString(CultureInfo.InvariantCulture), "absolute");
                        chaptersMenuItem.Items.Add(chapterMenuItem);
                    }
                }
            }

            var recentMenuItem = FindMenuItem("Recent");

            if (recentMenuItem != null)
            {
                recentMenuItem.Items.Clear();

                foreach (string path in App.Settings.RecentFiles)
                {
                    var mi = MenuHelp.Add(recentMenuItem.Items, path.ShortPath(100));

                    if (mi != null)
                    {
                        mi.Click += (sender, args) =>
                                    Core.LoadFiles(new[] { path }, true, ModifierKeys.HasFlag(Keys.Control));
                    }
                }

                recentMenuItem.Items.Add(new WpfControls.Separator());
                var clearMenuItem = new WpfControls.MenuItem()
                {
                    Header = "Clear List"
                };
                clearMenuItem.Click += (sender, args) => App.Settings.RecentFiles.Clear();
                recentMenuItem.Items.Add(clearMenuItem);
            }

            var titlesMenuItem = FindMenuItem("Titles");

            if (titlesMenuItem != null)
            {
                titlesMenuItem.Items.Clear();

                lock (Core.BluRayTitles)
                {
                    List <(int Index, TimeSpan Length)> items = new List <(int, TimeSpan)>();

                    for (int i = 0; i < Core.BluRayTitles.Count; i++)
                    {
                        items.Add((i, Core.BluRayTitles[i]));
                    }

                    var titleItems = items.OrderByDescending(item => item.Length)
                                     .Take(20)
                                     .OrderBy(item => item.Index);

                    foreach (var item in titleItems)
                    {
                        if (item.Length != TimeSpan.Zero)
                        {
                            var mi = MenuHelp.Add(titlesMenuItem.Items, $"Title {item.Index + 1}");

                            if (mi != null)
                            {
                                mi.InputGestureText = item.Length.ToString();
                                mi.Click           += (sender, args) => Core.SetBluRayTitle(item.Index);
                            }
                        }
                    }
                }
            }

            var profilesMenuItem = FindMenuItem("Profile");

            if (profilesMenuItem != null)
            {
                profilesMenuItem.Items.Clear();

                foreach (string profile in ProfileNames)
                {
                    if (!profile.StartsWith("extension."))
                    {
                        var mi = MenuHelp.Add(profilesMenuItem.Items, profile);

                        if (mi != null)
                        {
                            mi.Click += (sender, args) => {
                                Core.CommandV("show-text", profile);
                                Core.CommandV("apply-profile", profile);
                            };
                        }
                    }
                }
            }
        }