Beispiel #1
0
        private void OnExecuteCommand(object sender, ExecutedRoutedEventArgs e)
        {
            EditorDocument doc;

            if (e.Parameter != null && e.Parameter is EditorDocument)
            {
                doc = e.Parameter as EditorDocument;
            }
            else
            {
                doc = Tabs != null ? (Tabs.SelectedItem as EditorDocument) : null;
            }

            if (e.Command == ApplicationCommands.New)
            {
                NewSong();
            }
            else if (e.Command == ApplicationCommands.Open)
            {
                OpenSong();
            }
            else if (e.Command == ApplicationCommands.Save)
            {
                SaveSong(doc.Song);
            }
            else if (e.Command == ApplicationCommands.SaveAs)
            {
                SaveSongAs(doc.Song);
            }
            else if (e.Command == CustomCommands.Export)
            {
                ExportSong(doc.Song);
            }
            else if (e.Command == CustomCommands.ImportFromClipboard)
            {
                try
                {
                    var song = new Song(null, new ClipboardUriResolver(), new CcliTxtSongReader());
                    Load(song);
                }
                catch
                {
                    MessageBox.Show(Resource.eMsgCouldNotImportFromClipboard);
                }
            }
            else if (e.Command == ApplicationCommands.Close)
            {
                CloseSong(doc);
            }
            else if (e.Command == CustomCommands.ViewCurrent)
            {
                SaveSong(doc.Song);
                Controller.ReloadActiveMedia();
                Controller.FocusMainWindow(true);
            }
            else if (e.Command == CustomCommands.SwitchWindow)
            {
                if (openDocuments.Count == 0)
                {
                    this.Close();
                }

                Controller.FocusMainWindow(true);
            }
            else if (e.Command == CustomCommands.SongSettings)
            {
                var win = new SongSettingsWindow(doc.Song.Formatting.Clone() as SongFormatting);
                win.Owner = this;
                if (win.ShowDialog() == true)
                {
                    if (win.Formatting.SingleFontSize && !doc.Song.CheckSingleFontSize())
                    {
                        var res = MessageBox.Show(Resource.eMsgSingleFontSize, Resource.eMsgSingleFontSizeTitle, MessageBoxButton.YesNo);
                        if (res == MessageBoxResult.No)
                        {
                            win.Formatting.SingleFontSize = false;
                        }
                    }
                    doc.Song.Formatting = win.Formatting;
                }
            }
            else if (e.Command == CustomCommands.EditChords)
            {
                var win = new EditChordsWindow(doc.Song);
                win.Owner = this;
                win.ShowDialog();
            }
            else if (e.Command == CustomCommands.AddMedia)
            {
                Controller.AddToPortfolio(doc.Song.Uri);
            }
            else if (e.Command == ApplicationCommands.Find)
            {
                Controller.ShowSongList();
            }
            else if (e.Command == CustomCommands.SearchSongSelect)
            {
                string searchString = null;
                if (e.Parameter is string)
                {
                    searchString = (string)e.Parameter;
                }
                else
                {
                    int?searchNum = e.Parameter as int?;
                    if (searchNum.HasValue)
                    {
                        searchString = searchNum.ToString();
                    }
                }

                if (!String.IsNullOrWhiteSpace(searchString))
                {
                    new Uri(String.Format(Resource.eSongSelectSearchString, searchString)).OpenInBrowser();
                }
            }
        }
        private void OnExecuteCommand(object sender, ExecutedRoutedEventArgs e)
        {
            EditorDocument doc;

            if (e.Parameter != null && e.Parameter is EditorDocument)
                doc = e.Parameter as EditorDocument;
            else
                doc = Tabs != null ? (Tabs.SelectedItem as EditorDocument) : null;

            if (e.Command == ApplicationCommands.New)
            {
                NewSong();
            }
            else if (e.Command == ApplicationCommands.Open)
            {
                OpenSong();
            }
            else if (e.Command == ApplicationCommands.Save)
            {
                SaveSong(doc.Song);
            }
            else if (e.Command == ApplicationCommands.SaveAs)
            {
                SaveSongAs(doc.Song);
            }
            else if (e.Command == CustomCommands.Export)
            {
                ExportSong(doc.Song);
            }
            else if (e.Command == CustomCommands.ImportFromClipboard)
            {
                try
                {
                    var song = new Song(null, new ClipboardUriResolver(), new CcliTxtSongReader());
                    Load(song);
                }
                catch
                {
                    MessageBox.Show(Resource.eMsgCouldNotImportFromClipboard);
                }
            }
            else if (e.Command == ApplicationCommands.Close)
            {
                CloseSong(doc);
            }
            else if (e.Command == CustomCommands.ViewCurrent)
            {
                SaveSong(doc.Song);
                Controller.ReloadActiveMedia();
                Controller.FocusMainWindow(true);
            }
            else if (e.Command == CustomCommands.SwitchWindow)
            {
                if (openDocuments.Count == 0)
                    this.Close();

                Controller.FocusMainWindow(true);
            }
            else if (e.Command == CustomCommands.SongSettings)
            {
                var win = new SongSettingsWindow(doc.Song.Formatting.Clone() as SongFormatting);
                win.Owner = this;
                if (win.ShowDialog() == true)
                {
                    if (win.Formatting.SingleFontSize && !doc.Song.CheckSingleFontSize())
                    {
                        var res = MessageBox.Show(Resource.eMsgSingleFontSize, Resource.eMsgSingleFontSizeTitle, MessageBoxButton.YesNo);
                        if (res == MessageBoxResult.No)
                        {
                            win.Formatting.SingleFontSize = false;
                        }
                    }
                    doc.Song.Formatting = win.Formatting;
                }
            }
            else if (e.Command == CustomCommands.EditChords)
            {
                var win = new EditChordsWindow(doc.Song);
                win.Owner = this;
                win.ShowDialog();
            }
            else if (e.Command == CustomCommands.AddMedia)
            {
                Controller.AddToPortfolio(doc.Song.Uri);
            }
            else if (e.Command == ApplicationCommands.Find)
            {
                Controller.ShowSongList();
            }
            else if (e.Command == CustomCommands.SearchSongSelect)
            {
                string searchString = null;
                if (e.Parameter is string)
                {
                    searchString = (string)e.Parameter;
                }
                else
                {
                    int? searchNum = e.Parameter as int?;
                    if (searchNum.HasValue)
                        searchString = searchNum.ToString();
                }

                if (!String.IsNullOrWhiteSpace(searchString))
                    new Uri(String.Format(Resource.eSongSelectSearchString, searchString)).OpenInBrowser();
            }
        }