예제 #1
0
        /// <summary>
        /// Saves a song
        /// </summary>
        /// <param name="sng">Song to be saved</param>
        /// <param name="fileName">Target file name</param>
        private void SaveSong(Song sng, String fileName)
        {
            // Load plugin based on the song filename
            ISongFilePlugin plugin = SongFilePluginFactory.Create(fileName);

            // Save song using plugin
            plugin.Save(sng, fileName);

            // Set status
            SetStatus(String.Format(StringResources.SongSavedAs, fileName));

            // Inform others by firing a SongSaved event
            if (SongSaved != null)
            {
                SongSavedEventArgs p = new SongSavedEventArgs(sng, fileName);
                SongSaved(this, p);
            }
        }
예제 #2
0
        /// <summary>
        /// Saves a song by asking for a file name
        /// </summary>
        /// <param name="sng">Song to be saved</param>
        /// <param name="fileName">Existing filename, can be null</param>
        /// <returns>The choosen name, if the song has been saved, or null if the action has been cancelled</returns>
        private string SaveSongAskForName(Song sng, String fileName)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                InitialDirectory = fileName != null
                    ? Path.GetDirectoryName(fileName)
                    : _fileBoxInitialDir,
                CheckPathExists = true,
                FileName        = sng.Title,
                Filter          = GetSaveFileBoxFilter(),
                FilterIndex     = _fileSaveBoxFilterIndex,
                AddExtension    = true,
                Title           = StringResources.SaveSongAs
            };

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                // Load plugin based on selected filter index
                ISongFilePlugin plugin = CreateByTypeIndex(saveFileDialog.FilterIndex - 1);

                // Save song using plugin
                plugin.Save(sng, saveFileDialog.FileName);

                // Store selected filter index
                _fileSaveBoxFilterIndex = saveFileDialog.FilterIndex;

                // Set status
                SetStatus(string.Format(StringResources.SongSavedAs, saveFileDialog.FileName));

                // Inform others by firing a SongSaved event
                if (SongSaved != null)
                {
                    SongSavedEventArgs p = new SongSavedEventArgs(sng, saveFileDialog.FileName);
                    SongSaved(this, p);
                }

                // Return file name
                return(saveFileDialog.FileName);
            }
            return(null);
        }