/// <summary> /// /// </summary> /// <param name="obj"></param> /// <param name="args"></param> public void MdiGotFocus(object obj, RoutedEventArgs args) { if (FocusedWindow == null) { ViewModel.CurrentChildViewModel = null; } else { PcgWindow window = FocusedWindow as PcgWindow; if (window != null) { ViewModel.SelectedMemory = window.PcgMemory; ViewModel.CurrentChildViewModel = window.ViewModel; } else { SongWindow songWindow = FocusedWindow as SongWindow; if (songWindow != null) { ViewModel.SelectedMemory = songWindow.SongMemory; } else { CombiWindow combiWindow = FocusedWindow as CombiWindow; if (combiWindow != null) { ViewModel.SelectedMemory = combiWindow.CombiViewModel.Combi.PcgRoot; ViewModel.CurrentChildViewModel = combiWindow.ViewModel; } else { SongTimbresWindow songTimbresWindow = FocusedWindow as SongTimbresWindow; if (songTimbresWindow != null) { ViewModel.SelectedMemory = songTimbresWindow.SngTimbresViewModel.Song.Memory; ViewModel.CurrentChildViewModel = songTimbresWindow.ViewModel; } else { MasterFilesWindow filesWindow = FocusedWindow as MasterFilesWindow; if (filesWindow != null) { ViewModel.SelectedMemory = null; ViewModel.CurrentChildViewModel = filesWindow.ViewModel; } else { throw new ApplicationException("Unknown focused window"); } } } } } } }
/// <summary> /// /// </summary> public MainWindow() { #if !DEBUG try { #endif var splashWindow = new SplashWindow { WindowStartupLocation = WindowStartupLocation.CenterScreen }; splashWindow.Show(); #if !DEBUG Thread.Sleep(5000); #endif // Set culture info ... check list at: http://techmantium.com/culture-codes/ try { var culture = new CultureInfo(Settings.Default.UI_Language); System.Threading.Thread.CurrentThread.CurrentUICulture = culture; System.Threading.Thread.CurrentThread.CurrentCulture = culture; } // ReSharper disable once EmptyGeneralCatchClause catch { // Continue without selecting a language. } InitializeComponent(); LoadWindowProperties(); // Set UI language. foreach (var item in menuItemUiLanguages.Items.Cast <MenuItem>().Where( item => item.Tag.ToString().Equals(CultureInfo.CurrentUICulture.Name))) { item.IsChecked = true; } // Set view model. ViewModel = new MainViewModel(); ViewModel.PropertyChanged += OnViewModelChanged; Container.Children.CollectionChanged += OnMdiContainerChanged; ViewModel.UpdateSelectedMemory = () => { ViewModel.SelectedMemory = (FocusedWindow == null) ? null : FocusedWindow.Memory; }; ViewModel.OpenFileDialog = (title, filter, filterIndex, multiSelect) => { var dlg = new OpenFileDialog { Title = title, Filter = filter, FilterIndex = filterIndex, Multiselect = multiSelect }; dynamic result = new ExpandoObject(); var showDialog = dlg.ShowDialog(); if (showDialog != null && showDialog.Value) { result.Success = true; result.Files = dlg.FileNames; result.FilterIndex = dlg.FilterIndex; } else { result.Success = false; result.Files = null; } return(result); }; ViewModel.SaveFileDialog = (title, filter, fileName) => { var dlg = new SaveFileDialog { Title = title, Filter = filter, FileName = fileName, FilterIndex = ViewModel.GetFilterIndexOfFile(System.IO.Path.GetExtension(fileName), filter) }; dynamic result = new ExpandoObject(); var showDialog = dlg.ShowDialog(); if (showDialog != null && showDialog.Value) { result.Success = true; result.Files = dlg.FileNames; } else { result.Success = false; result.Files = null; } return(result); }; ViewModel.SetCursor = WindowUtils.SetCursor; ViewModel.ShowDialog = windowType => { Window window; switch (windowType) { case MainViewModel.WindowType.Settings: window = new SettingsWindow { Owner = this }; break; case MainViewModel.WindowType.About: window = new AboutWindow(MainViewModel.Version) { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksKorgRelated: window = new ExternalLinksKorgRelatedWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksContributors: window = new ExternalLinksContributorsWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksVideoCreators: window = new ExternalLinksVideoCreatorsWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksDonators: window = new ExternalLinksDonatorsWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksTranslators: window = new ExternalLinksTranslatorsWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksThirdParties: window = new ExternalLinksThirdPartiesWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksOasysVoucherCodeSponsorsWindow: window = new ExternalLinksOasysVoucherCodeSponsorsWindow { Owner = this }; break; case MainViewModel.WindowType.ExternalLinksPersonal: window = new ExternalLinksPersonalWindow { Owner = this }; break; default: throw new ApplicationException("Illegal window type"); } window.ShowDialog(); }; ViewModel.ShowMessageBox = (text, title, messageBoxButton, messageBoxImage, messageBoxResult) => WindowUtils.ShowMessageBox( this, text, title, messageBoxButton, messageBoxImage, messageBoxResult); ViewModel.StartProcess = process => Process.Start(process); ViewModel.GotoNextWindow = () => { var nrChildren = Container.Children.Count; int index; for (index = 0; index < nrChildren; index++) { if (Equals(FocusedWindow, Container.Children[index].Content)) { break; } } if ((index < nrChildren) && (nrChildren > 0)) { Container.Children[(index + 1) % nrChildren].Focus(); } }; ViewModel.GotoPreviousWindow = () => { var nrChildren = Container.Children.Count; int index; for (index = 0; index < nrChildren; index++) { if (Equals(FocusedWindow, Container.Children[index].Content)) { break; } } if ((index < nrChildren) && (nrChildren > 0)) { Container.Children[(index - 1 + nrChildren) % nrChildren].Focus(); } }; ViewModel.CreateMdiChildWindow = (fileName, childWindowType, memory, width, height) => { UIElement uiElement; switch (childWindowType) { case MainViewModel.ChildWindowType.Pcg: uiElement = new PcgWindow(this, fileName, (PcgMemory)memory); ViewModel.OpenedPcgWindows.Items.Add(new OpenedPcgWindow { PcgMemory = (PcgMemory)memory }); break; case MainViewModel.ChildWindowType.Song: uiElement = new SongWindow(this, fileName, (SongMemory)memory, ViewModel.OpenedPcgWindows); break; case MainViewModel.ChildWindowType.MasterFiles: uiElement = new MasterFilesWindow(this); break; default: throw new ApplicationException("Illegal window type"); } var mdiChild = new MdiChild { Title = fileName, Content = uiElement, MinimizeBox = false, MaximizeBox = false, Width = width, Height = height, Margin = new Thickness(0, 0, 0, 0), }; ((IChildWindow)(mdiChild.Content)).MdiChild = mdiChild; mdiChild.GotFocus += MdiGotFocus; mdiChild.Closing += MdiClosing; Container.Children.Add(mdiChild); ViewModel.RaisePropertyChanged("ChildWindows"); return(mdiChild); }; ViewModel.CloseView = Close; DataContext = ViewModel; ViewModel.UpdateAppTitle(); splashWindow.CloseWindow(); #if !DEBUG } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(this, String.Format("{0}: \n\n{1}: {2}\n\n{3}: {4}\n\n{5}: {6}", Strings.ErrorOccurred, Strings.Message, ex.Message, Strings.InnerExceptionMessage, ex.InnerException == null ? String.Empty : ex.InnerException.Message, Strings.StackTrace, ex.StackTrace), Strings.PcgTools, MessageBoxButton.OK, MessageBoxImage.Error); } #endif }