Exemplo n.º 1
0
        /// <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
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mainWindow"></param>
        /// <param name="pcgFileName"></param>
        /// <param name="pcgMemory"></param>
        public PcgWindow(MainWindow mainWindow, string pcgFileName, IPcgMemory pcgMemory)
        {
            InitializeComponent();

            _mainWindow = mainWindow;
            ViewModel   = new PcgViewModel(mainWindow.ViewModel.PcgClipBoard)
            {
                ShowDialog = (type, items) =>
                {
                    Window window = null;

                    switch (type)
                    {
                    // Programs
                    case ViewModels.PcgViewModel.DialogType.EditSingleProgram:
                        window = new WindowEditSingleProgram(items.First() as IProgram)
                        {
                            Owner = _mainWindow
                        };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultiplePrograms:
                        //window = new WindowEditMultiplePrograms(items as List<IProgram>) { Owner = _mainWindow };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditSingleProgramBank:
                        //window = new WindowEditSingleProgramBank(items.First() as IProgramBank) { Owner = _mainWindow };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultipleProgramBanks:
                        //window = new WindowEditMultipleProgramBanks(items as List<IProgramBank>) { Owner = _mainWindow };
                        break;

                    // Combis
                    case ViewModels.PcgViewModel.DialogType.EditSingleCombi:
                        window = new WindowEditSingleCombi(items.First() as ICombi)
                        {
                            Owner = _mainWindow
                        };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultipleCombis:
                        //window = new WindowEditMultipleCombis(items as List<ICombi>) { Owner = _mainWindow };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditSingleCombiBank:
                        //window = new WindowEditSingleCombiBank(items.First() as ICombiBank) { Owner = _mainWindow };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultipleCombiBanks:
                        //window = new WindowEditMultipleCombiBanks(items as List<ICombiBank>) { Owner = _mainWindow };
                        break;


                    // Set list slots
                    case ViewModels.PcgViewModel.DialogType.EditSingleSetListSlot:
                        window = new WindowEditSingleSetListSlot(items.First() as ISetListSlot)
                        {
                            Owner = _mainWindow
                        };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultipleSetListSlots:
                        //window = new WindowEditMultipleSetListSlot(items as List<ISetListSlot>)
                        //{
                        //    Owner = _mainWindow
                        //};
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditSingleSetList:
                        window = new WindowEditSingleSetList(items.First() as ISetList)
                        {
                            Owner = _mainWindow
                        };
                        break;

                    case ViewModels.PcgViewModel.DialogType.EditMultipleSetLists:
                        //window = new WindowEditMultipleSetLists(items as List<ISetLists>) { Owner = _mainWindow };
                        break;

                    default:
                        throw new ApplicationException("Illegal window type");
                    }

                    window?.ShowDialog();
                },


                ShowPasteWindow = () =>
                {
                    var window = new SettingsWindow {
                        Owner = _mainWindow
                    };
                    window.ShowDialog();
                },


                ShowMessageBox = (text, title, messageBoxButton, messageBoxImage, messageBoxResult) =>
                                 WindowUtils.ShowMessageBox(_mainWindow, text, title, messageBoxButton,
                                                            messageBoxImage, messageBoxResult),


                SetCursor = WindowUtils.SetCursor,


                ShowListGenerator = () =>
                {
                    var window = new ListGeneratorWindow((PcgMemory)ViewModel.SelectedMemory)
                    {
                        Owner = _mainWindow
                    };
                    try
                    {
                        window.ShowDialog();
                    }
                    catch (InvalidOperationException)
                    {
                        // Do nothing
                    }
                },


                ShowProgramReferencesChanger = () =>
                {
                    var window = new ProgramReferenceChangerWindow((PcgMemory)ViewModel.SelectedMemory)
                    {
                        Owner = _mainWindow
                    };

                    try
                    {
                        window.ShowDialog();
                    }
                    catch (InvalidOperationException)
                    {
                        // Do nothing
                    }
                },

                ShowTimbresWindow = (combi, width, height) =>
                {
                    // Check if already exists. If so, show the already opened window.
                    foreach (var child in from child in _mainWindow.Container.Children
                             where (child.Content is CombiWindow)
                             let combiWindowIteration = child.Content as CombiWindow
                                                        where combiWindowIteration.CombiViewModel.Combi == combi
                                                        select child)
                    {
                        child.Focus();
                        return;
                    }

                    // Create combi window if not already present.
                    var mdiChild = new MdiChild
                    {
                        Title       = GenerateCombiWindowTitle(combi),
                        Content     = new CombiWindow(PcgViewModel, combi),
                        MinimizeBox = false,
                        MaximizeBox = false,
                        Width       = width,
                        Height      = height,
                        Margin      = new Thickness(0, 0, 0, 0)
                    };

                    ((CombiWindow)(mdiChild.Content)).MdiChild = mdiChild;
                    _mainWindow.Container.Children.Add(mdiChild);
                    mdiChild.GotFocus += _mainWindow.MdiGotFocus;
                    mdiChild.Closing  += _mainWindow.MdiClosing;
                },


                EditParameterWindow = patches =>
                {
                    var window = new WindowEditParameter(patches);
                    window.ShowDialog();
                },

                UpdateTimbresWindows = () =>
                {
                    // Update every timbre window.
                    foreach (var child in from child in _mainWindow.Container.Children
                             where (child.Content is CombiWindow)
                             select child)
                    {
                        var viewModel = ((CombiWindow)(child.Content)).CombiViewModel;
                        viewModel.UpdateUiContent();
                        child.Title = GenerateCombiWindowTitle(viewModel.Combi);
                    }

                    /*
                     *      // If it is a master file being changed, also update all other windows.
                     *      var masterFile = MasterFiles.Instances.FindMasterPcg(PcgMemory.ModelType);
                     *      if (masterFile != null)
                     *      {
                     *
                     *          _mainWindow.ViewModel.UpdatePcgWindowsOfModelType(PcgMemory.ModelType);
                     *      }
                     */
                },


                MoveSelectedPatchesUp = MoveSelectedPatchesUp,


                MoveSelectedPatchesDown = MoveSelectedPatchesDown,


                GetSelectedPatchListViewIndex = () => listViewPatches.SelectedIndex,


                SetPcgFileAsMasterFile = SetPcgFileAsMasterFile,


                CloseWindow = CloseWindow
            };

            DataContext = ViewModel;
            ViewModel.PropertyChanged  += OnViewPropertyChanged;
            listViewBanks.ItemsSource   = PcgViewModel.Banks;
            listViewPatches.ItemsSource = PcgViewModel.Patches;

            _pcgMemory          = pcgMemory;
            _pcgMemory.FileName = pcgFileName;

            if (_pcgMemory.CombiBanks == null)
            {
                ButtonTimbres.Visibility = Visibility.Collapsed;
            }

            if (_pcgMemory.SetLists == null)
            {
                ButtonAssign.Visibility = Visibility.Collapsed;
            }

            //ToolTipService.ShowOnDisabled = "True"
            //         ToolTipService.IsEnabled = "{Binding Path=ToolTipEnabled, Converter={StaticResource InverseBooleanConverter}}"
            //        ToolTipService.ToolTip = "{Binding Path=ToolTip, Mode=OneTime}"
        }