示例#1
0
        public MainWindow()
        {
            Model = new MainModel();
            View = new MainView();

#if !MONO
            MusicPlayer = new WindowsMediaPlayerModel();
#else
            MusicPlayer = new DefaultMusicPlayerModel();
#endif

            View.ResetView(Model.Files, Model.SelectedFiles);
            View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());

            // Handle files

            View.ChangeFolderRequest += (sender, args) =>
            {
                MusicPlayer.Stop();
                Model.ChangeFolder(args.FolderPath);
                Model.ChangeAllFilesSelection(true);
                Model.ChangeFilter(MusicFileFilter.None);
                View.RefreshGrid(Model.DisplayedFiles, Model.SelectedFiles);
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());
                View.CompleteFolderChange();
            };

            View.SaveAllRequest += (sender, args) =>
            {
                Model.SaveConfiguration();
                Model.SaveAll();
                View.CompleteSaveAll();
            };

            View.ChangeFilterRequest += (sender, args) =>
            {
                Model.ChangeFilter(args.Filter);
                View.RefreshGrid(Model.DisplayedFiles, Model.SelectedFiles);
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());
            };

            // Edit files

            View.SelectedFilesChanged += (sender, args) =>
            {
                string path = Path.Combine(Model.WorkingDirectory, args.Filename);
                Model.ChangeFileSelection(path, args.IsSelected);
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());
            };

            View.AlbumNameChanged += (sender, args) =>
            {
                string path = Path.Combine(Model.WorkingDirectory, args.Filename);
                Model.ChangeFileAlbumName(path, args.AlbumName);
                View.HighlightAlbumChange(args.Filename);
                View.SetAsEdited();
            };

            View.IndividualWizardRequest += (sender, args) =>
            {
                MusicPlayer.Stop();

                var editor = new MusicFileCollectionEditor(Model.MusicFileCollectionEditor[Model[args.Filename].Path]);

                var coverSeriesWizardDialog = new CoverSeriesWizardDialog(editor, Model.GalleryManager);
                coverSeriesWizardDialog.View.ShowDialog();

                View.RefreshGrid(Model.DisplayedFiles, Model.SelectedFiles);
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());

                View.SetAsEdited();
            };

            // Dialogs

            View.ShowGalleryManagerRequest += (sender, args) =>
            {
                var galleryManagerUi = new GalleryManagerDialog(Model.GalleryManager);
                galleryManagerUi.View.ShowDialog();
            };

            View.ShowCoverSeriesWizardRequest += (sender, args) =>
            {
                MusicPlayer.Stop();

                var coverSeriesWizardDialog = new CoverSeriesWizardDialog(Model.MusicFileCollectionEditor, Model.GalleryManager);
                coverSeriesWizardDialog.View.ShowDialog();

                View.RefreshGrid(Model.DisplayedFiles, Model.SelectedFiles);
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());

                View.SetAsEdited();
            };

            // Music player

            View.PlayMusicRequest += (sender, args) =>
            {
                string path = Path.Combine(Model.WorkingDirectory, args.Filename);
                MusicPlayer.Play(path);
                View.CompleteMusicPlay(args.Filename);
            };

            View.StopMusicRequest += (sender, args) =>
            {
                View.DisableStopButton();
                MusicPlayer.Stop();
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());
            };

            MusicPlayer.MusicEnded += (sender, args) =>
            {
                View.DisableStopButton();
                View.ShowCountsInStatusStrip(Model.Files.Count(), Model.SelectedFiles.Count(), Model.DisplayedFiles.Count());
            };

            // Closing

            View.CloseRequest += (sender, args) =>
            {
                Model.SaveConfiguration();

                if (args.SaveRequested)
                    Model.SaveAll();
            };
        }
        public CoverSeriesWizardDialog(MusicFileCollectionEditor musicFileEditors, GalleryManager galleryManager)
        {
            Model = new CoverSeriesWizard(musicFileEditors, galleryManager);
            View = new CoverSeriesWizardView();

#if !MONO
            MusicPlayer = new WindowsMediaPlayerModel();
#else
            MusicPlayer = new DefaultMusicPlayerModel();
#endif

            // Initialization

            Model.Initialize += (sender, args) =>
            {
                if (MusicPlayer.IsPlaying)
                    MusicPlayer.Play(Model.FilePath);
                View.Initialize(Model.FilePath, Model.SelectedCover, Model.EditedAlbum, Model.FileIndex, Model.FilesCount);
            };

            // Edition

            View.ApplyRequest += (sender, args) =>
            {
                Model.Apply();
            };

            View.EditAlbumRequest += (sender, args) =>
            {
                Model.EditAlbum(args.AlbumName);
            };

            View.ResetAlbumRequest += (sender, args) =>
            {
                View.ChangeAlbumName(Model.EditedAlbum);
            };

            View.CoverSelectionRequest += (sender, args) =>
            {
                switch (args.Action)
                {
                    case CoverSeriesWizardView.CoverSelectionAction.Remove:
                        Model.RemoveCoverSelected();
                        break;
                    case CoverSeriesWizardView.CoverSelectionAction.Reset:
                        Model.ResetCoverSelected();
                        break;
                    case CoverSeriesWizardView.CoverSelectionAction.Change:
                        Model.ChangeCoverSelected(args.SelectionIndex);
                        break;
                }

                View.ChangeCover(Model.SelectedCover);
            };

            // Search state

            Model.SearchProgress += (sender, args) =>
            {
                View.SearchProgress(args.Status);
            };

            Model.SearchCancel += (sender, args) =>
            {
                View.SearchCancel();
            };

            Model.SearchError += (sender, args) =>
            {
                View.SearchError(args.ErrorMessage);
            };

            Model.SearchSuccess += (sender, args) =>
            {
                View.SearchSuccess();
            };

            Model.SearchEnd += (sender, args) =>
            {
                View.SearchEnd(Model.State);
            };

            // Music player

            View.ToggleSongRequest += (sender, args) =>
            {
                MusicPlayer.Toggle(Model.FilePath);
                View.UpdatePlayMusicButton(MusicPlayer.IsPlaying);
            };

            MusicPlayer.MusicEnded += (sender, args) =>
            {
                View.UpdatePlayMusicButton(MusicPlayer.IsPlaying);
            };

            // Close form

            Model.ProcessEnd += (sender, args) =>
            {
                View.Close();
            };

            View.Closing += (sender, args) =>
            {
                Model.Close();
                MusicPlayer.Stop();
            };

            Model.ResetSearch();
        }