private void btnOpen_Click(object sender, RoutedEventArgs e) { this.InvokeIfRequired(_ => { var window = new AddMediaToDocumentWindow(mainViewModel.VideoViewModel.Document.Id, mainViewModel.VideoViewModel.Document.Name, mainViewModel.VideoViewModel.Document.Media); window.Topmost = Topmost; if (window.ShowDialog() != true) { return; } playBrowsedVideo(window.Document); }); }
private void btnBrowse_Click(object sender, RoutedEventArgs e) { this.InvokeIfRequired(_ => { var videoViewModel = (DataContext as VideoViewModel); var window = new AddMediaToDocumentWindow(videoViewModel.Document.Id, videoViewModel.Document.Name, videoViewModel.Document.Media); window.Topmost = Settings.Instance.AlwaysOnTop; var result = window.ShowDialog(); if (result != true) { return; } videoViewModel.CannotOpen = false; playVideo(Settings.Instance.DocumentByDocumentGuid[videoViewModel.Document.Id]); }); }
private Document addMediaToDocumentIfNeeded(Guid id, string name, string path) { if (Settings.Instance.DocumentByDocumentGuid.ContainsKey(id)) { return(Settings.Instance.DocumentByDocumentGuid[id]); } var videoFiles = new List <string>(); try { // document is opened for the first time, try to find video file with the same name videoFiles = Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".*") .Where(f => supportedExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()) && f != path) .OrderBy(f => f).ToList(); } catch { // no video file found, e.g. the import path of the document was not set } if (videoFiles.Any()) { // if any video file found, connect it with the document var document = new Document(id, name, videoFiles.First()); Settings.Instance.DocumentByDocumentGuid[id] = document; Settings.Instance.SaveSettings(); return(document); } else { // otherwise offer to choose media var window = new AddMediaToDocumentWindow(id, name, ""); window.Topmost = Topmost; window.ShowDialog(); return(window.Document); } }