Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
        private void buttonImport_Click(object sender, EventArgs e)
        {
            SongTemplateMapper stm = new SongTemplateMapper(_settings);

            List <String> filesToOpen = new List <string>();
            int           cnt         = 0;

            for (int x = 0; x < listViewSongs.Items.Count; x++)
            {
                var item = listViewSongs.Items[x];
                if (item.Checked)
                {
                    Song sng = ((Song)listViewSongs.Items[x].Tag);

                    // Apply formatting
                    stm.ApplyFormattingFromSettings(sng);
                    // Apply default background
                    foreach (var p in sng.Parts)
                    {
                        foreach (var s in p.Slides)
                        {
                            if (s.Background == null)
                            {
                                s.Background = stm.GetDefaultBackground();
                            }
                        }
                    }

                    // TODO: Allow selection of plugin
                    ISongFilePlugin filePlugin = SongFilePluginFactory.Create(SongFilePluginFactory.GetWriterPlugins().First().GetType());
                    string          fileName   = _settings.DataDirectory + Path.DirectorySeparatorChar
                                                 + _settings.SongDir + Path.DirectorySeparatorChar
                                                 + sng.Title + filePlugin.GetFileExtension();
                    if ((File.Exists(fileName) && (MessageBox.Show(
                                                       string.Format(StringResources.SongExistsAlready,
                                                                     ((Song)listViewSongs.Items[x].Tag).Title) + @" " + StringResources.Overwrite + @"?", StringResources.SongImporter,
                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) || !File.Exists(fileName))
                    {
                        // TODO Exception handling
                        filePlugin.Save(sng, fileName);
                        filesToOpen.Add(fileName);
                        cnt++;
                    }
                }
            }
            if (cnt > 0)
            {
                MessageBox.Show(string.Format(StringResources.SongsImported, cnt), StringResources.SongImporter,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (checkBoxUseEditor.Checked)
                {
                    foreach (var f in filesToOpen)
                    {
                        OpenInEditor.Add(f);
                    }
                }

                DialogResult = DialogResult.OK;
            }
            Close();
        }
        public void ImportDialog(IWin32Window owner)
        {
            string defaultDirectory = !string.IsNullOrEmpty(_settings.CurrentSongImporterDirectory) && Directory.Exists(_settings.CurrentSongImporterDirectory) ? _settings.CurrentSongImporterDirectory : _settings.DataDirectory;

            List <ISongFilePlugin> plugins = SongFilePluginFactory.GetImportPlugins();
            List <string>          filters = new List <string>();

            foreach (ISongFilePlugin plugin in plugins)
            {
                filters.Add(string.Format("{0} (*{1})|*{1}", plugin.GetFileTypeDescription(), plugin.GetFileExtension()));
            }

            //var plugin = new SongSelectFilePlugin();
            var dlg = new OpenFileDialog()
            {
                AddExtension     = true,
                CheckPathExists  = true,
                CheckFileExists  = true,
                Filter           = string.Join("|", filters.ToArray()),
                InitialDirectory = defaultDirectory,
                Title            = StringResources.SongImporter,
                Multiselect      = true
            };

            if (dlg.ShowDialog(owner) == DialogResult.OK)
            {
                var plugin = plugins[dlg.FilterIndex - 1];

                SongTemplateMapper stm = new SongTemplateMapper(_settings);

                // Save selected directory
                if (dlg.FileNames.Length > 0)
                {
                    _settings.CurrentSongImporterDirectory = Path.GetDirectoryName(dlg.FileNames[0]);
                }

                int i = 0;
                foreach (var selectedFileName in dlg.FileNames)
                {
                    // Load song
                    var sng = plugin.Load(selectedFileName);

                    // Apply formatting
                    stm.ApplyFormattingFromSettings(sng);
                    // Apply default background
                    foreach (var p in sng.Parts)
                    {
                        foreach (var s in p.Slides)
                        {
                            if (s.Background == null)
                            {
                                s.Background = stm.GetDefaultBackground();
                            }
                        }
                    }

                    // Initialize writer
                    ISongFilePlugin filePlugin = SongFilePluginFactory.Create(SongFilePluginFactory.GetWriterPlugins().First().GetType());

                    // Define target file name
                    string fileName = _settings.DataDirectory + Path.DirectorySeparatorChar
                                      + _settings.SongDir + Path.DirectorySeparatorChar
                                      + sng.Title + filePlugin.GetFileExtension();

                    // Check if already exists
                    if ((File.Exists(fileName) && (MessageBox.Show(
                                                       string.Format(StringResources.SongExistsAlready,
                                                                     sng.Title) + @" " + StringResources.Overwrite + @"?", StringResources.SongImporter,
                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) || !File.Exists(fileName))
                    {
                        // TODO Exception handling
                        filePlugin.Save(sng, fileName);

                        i++;

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

                MessageBox.Show(string.Format(StringResources.nSongsHaveBeenImported, i), StringResources.SongImporter, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }