Example #1
0
        /// <summary>
        /// Event handler for opening an existing file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = _fileBoxInitialDir,
                CheckFileExists  = true,
                CheckPathExists  = true,
                Multiselect      = false,
                Title            = StringResources.OpenSong,
                Filter           = GetOpenFileBoxFilter(),
                FilterIndex      = _fileOpenBoxFilterIndex
            };

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;
                _fileBoxInitialDir      = Path.GetDirectoryName(fileName);
                _fileOpenBoxFilterIndex = openFileDialog.FilterIndex;

                ISongFilePlugin plugin  = null;
                var             plugins = GetOpenFilePlugins();
                if (_fileOpenBoxFilterIndex > 1 && _fileOpenBoxFilterIndex <= plugins.Count + 1)
                {
                    plugin = plugins[_fileOpenBoxFilterIndex - 2];
                }

                OpenSong(fileName, plugin);
            }
        }
Example #2
0
        /// <summary>
        /// Opens a new song in a song editor child window
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="plugin"></param>
        public void OpenSong(string fileName, ISongFilePlugin plugin = null)
        {
            for (int i = 0; i < MdiChildren.Count(); i++)
            {
                EditorChildMetaData md = (EditorChildMetaData)MdiChildren[i].Tag;
                if (!string.IsNullOrEmpty(md.Filename) &&
                    String.Compare(
                        Path.GetFullPath(md.Filename).TrimEnd('\\'),
                        Path.GetFullPath(fileName).TrimEnd('\\'),
                        StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    MdiChildren[i].Show();
                    MdiChildren[i].Focus();
                    return;
                }
            }

            try
            {
                if (plugin == null)
                {
                    plugin = SongFilePluginFactory.Create(fileName);
                }
                var sng = plugin.Load(fileName);

                SongTemplateMapper stm = new SongTemplateMapper(_settings);
                // Set default formattig if none exists
                if (sng.Formatting == null)
                {
                    stm.ApplyFormattingFromSettings(sng);
                }
                // Set default background if none is set
                foreach (var p in sng.Parts)
                {
                    foreach (var s in p.Slides)
                    {
                        if (s.Background == null)
                        {
                            s.Background = stm.GetDefaultBackground();
                        }
                    }
                }

                CreateSongEditorChildForm(sng, fileName, false);
            }
            catch (NotImplementedException)
            {
                MessageBox.Show(StringResources.SongFormatNotSupported, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(StringResources.SongFileHasErrors + @" (" + e.Message + @")!", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
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);
            }
        }
Example #4
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);
            }
        }