public void RefreshDiscMenuItems() { // Clear previous discs for (int i = this.openSourceButton.Items.Count - 1; i >= 0; i--) { var menuItem = this.openSourceButton.Items[i] as FrameworkElement; if (menuItem != null && menuItem.Tag != null && (string)menuItem.Tag == DiscMenuItemTag) { this.openSourceButton.Items.RemoveAt(i); } } int insertionIndex = 2; foreach (IDisposable oldCommand in this.discOpenCommands) { oldCommand.Dispose(); } this.discOpenCommands.Clear(); // Add new discs foreach (DriveInformation driveInfo in this.viewModel.DriveCollection) { var menuItem = new Fluent.MenuItem { Header = string.Format(MainRes.OpenFormat, driveInfo.DisplayText), Tag = DiscMenuItemTag }; ReactiveCommand <Unit, Unit> command = ReactiveCommand.Create( () => { this.viewModel.SetSourceFromDvd(driveInfo); }, this.viewModel.NotScanningObservable); this.discOpenCommands.Add(command); menuItem.Command = command; if (driveInfo.DiscType == DiscType.Dvd) { menuItem.Icon = "/Icons/disc.png"; } else { menuItem.Icon = "/Icons/bludisc.png"; } this.openSourceButton.Items.Insert(insertionIndex, menuItem); insertionIndex++; } }
public void RefreshDiscMenuItems() { // Clear previous discs for (int i = this.openSourceButton.Items.Count - 1; i >= 0; i--) { var menuItem = this.openSourceButton.Items[i] as FrameworkElement; if (menuItem != null && menuItem.Tag != null && (string)menuItem.Tag == DiscMenuItemTag) { this.openSourceButton.Items.RemoveAt(i); } } int insertionIndex = 2; // Add new discs foreach (DriveInformation driveInfo in this.viewModel.DriveCollection) { var menuItem = new Fluent.MenuItem { Header = string.Format(MainRes.OpenFormat, driveInfo.DisplayText), Tag = DiscMenuItemTag }; menuItem.Click += (sender, args) => { this.viewModel.SetSourceFromDvd(driveInfo); }; if (driveInfo.DiscType == DiscType.Dvd) { menuItem.Icon = "/Icons/disc.png"; } else { menuItem.Icon = "/Icons/bludisc.png"; } this.openSourceButton.Items.Insert(insertionIndex, menuItem); insertionIndex++; } }
public Main() { Ioc.Container.RegisterSingleton <Main>(() => this); this.InitializeComponent(); this.sourceRow.Height = new GridLength(Config.SourcePaneHeightStar, GridUnitType.Star); this.queueRow.Height = new GridLength(Config.QueuePaneHeightStar, GridUnitType.Star); this.Activated += (sender, args) => { DispatchUtilities.BeginInvoke(async() => { // Need to yield here for some reason, otherwise the activation is blocked. await Task.Yield(); this.toastNotificationService.Clear(); }); }; this.notifyIcon = new NotifyIcon { Visible = false }; this.notifyIcon.Click += (sender, args) => { this.RestoreWindow(); }; this.notifyIcon.DoubleClick += (sender, args) => { this.RestoreWindow(); }; StreamResourceInfo streamResourceInfo = System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/VidCoder_icon.ico")); if (streamResourceInfo != null) { Stream iconStream = streamResourceInfo.Stream; this.notifyIcon.Icon = new Icon(iconStream); } this.RefreshQueueColumns(); this.LoadCompletedColumnWidths(); #if DEBUG var debugDropDown = new DropDownButton { Header = "Debug" }; var loadScanFromJsonItem = new Fluent.MenuItem { Header = "Load scan from JSON..." }; loadScanFromJsonItem.Click += (sender, args) => { DebugJsonDialog dialog = new DebugJsonDialog("Debug Scan JSON"); dialog.ShowDialog(); if (!string.IsNullOrWhiteSpace(dialog.Json)) { try { var scanObject = JsonConvert.DeserializeObject <JsonScanObject>(dialog.Json); this.viewModel.UpdateFromNewVideoSource(new VideoSource { Titles = scanObject.TitleList, FeatureTitle = scanObject.MainFeature }); } catch (Exception exception) { MessageBox.Show(this, "Could not parse scan JSON:" + Environment.NewLine + Environment.NewLine + exception.ToString()); } } }; debugDropDown.Items.Add(loadScanFromJsonItem); var queueFromJsonItem = new Fluent.MenuItem { Header = "Queue job from JSON..." }; queueFromJsonItem.Click += (sender, args) => { if (!this.viewModel.HasVideoSource) { StaticResolver.Resolve <IMessageBoxService>().Show("Must open source before adding queue job from JSON"); return; } EncodeJobViewModel jobViewModel = this.viewModel.CreateEncodeJobVM(); DebugJsonDialog dialog = new DebugJsonDialog("Debug Encode JSON"); dialog.ShowDialog(); if (!string.IsNullOrWhiteSpace(dialog.Json)) { try { JsonEncodeObject encodeObject = JsonConvert.DeserializeObject <JsonEncodeObject>(dialog.Json); jobViewModel.DebugEncodeJsonOverride = dialog.Json; jobViewModel.Job.FinalOutputPath = encodeObject.Destination.File; jobViewModel.Job.SourcePath = encodeObject.Source.Path; this.processingService.Queue(jobViewModel); } catch (Exception exception) { MessageBox.Show(this, "Could not parse encode JSON:" + Environment.NewLine + Environment.NewLine + exception.ToString()); } } }; debugDropDown.Items.Add(queueFromJsonItem); var throwExceptionItem = new Fluent.MenuItem { Header = "Throw exception" }; throwExceptionItem.Click += (sender, args) => { throw new InvalidOperationException("Rats."); }; debugDropDown.Items.Add(throwExceptionItem); var addLogItem = new Fluent.MenuItem { Header = "Add 1 log item" }; addLogItem.Click += (sender, args) => { StaticResolver.Resolve <IAppLogger>().Log("This is a log item"); }; debugDropDown.Items.Add(addLogItem); var addTenLogItems = new Fluent.MenuItem { Header = "Add 10 log items" }; addTenLogItems.Click += (sender, args) => { for (int i = 0; i < 10; i++) { StaticResolver.Resolve <IAppLogger>().Log("This is a log item"); } }; debugDropDown.Items.Add(addTenLogItems); var addLongLogItem = new Fluent.MenuItem { Header = "Add long log item" }; addLongLogItem.Click += (sender, args) => { StaticResolver.Resolve <IAppLogger>().Log("This is a log item\r\nthat is split into multiple lines\r\nOh yes indeed"); }; debugDropDown.Items.Add(addLongLogItem); var doAnActionItem = new Fluent.MenuItem { Header = "Perform action" }; doAnActionItem.Click += (sender, args) => { var app = (App)System.Windows.Application.Current; app.ChangeTheme(new Uri("/Themes/Dark.xaml", UriKind.Relative)); }; debugDropDown.Items.Add(doAnActionItem); this.toolsRibbonGroupBox.Items.Add(debugDropDown); #endif this.DataContextChanged += this.OnDataContextChanged; TheDispatcher = this.Dispatcher; this.statusText.Opacity = 0.0; NameScope.SetNameScope(this, new NameScope()); this.RegisterName("StatusText", this.statusText); var storyboard = (Storyboard)this.FindResource("StatusTextStoryboard"); storyboard.Completed += (sender, args) => { this.statusText.Visibility = Visibility.Collapsed; }; this.presetTreeViewContainer.PresetTreeView.OnHierarchyMouseUp += (sender, args) => { this.presetButton.IsDropDownOpen = false; }; this.presetButton.DropDownOpened += (sender, args) => { var item = UIUtilities.FindDescendant <TreeViewItem>(this.presetTreeViewContainer.PresetTreeView, viewItem => { return(viewItem.Header == this.viewModel.PresetsService.SelectedPreset); }); if (item != null) { UIUtilities.BringIntoView(item); } }; this.Loaded += (e, o) => { this.RestoredWindowState = this.WindowState; }; this.statusService.MessageShown += (o, e) => { this.ShowStatusMessage(e.Value); }; this.queueView.SelectionChanged += this.QueueView_SelectionChanged; }