Ejemplo n.º 1
0
        /// <summary>
        /// Opens a new song file editor based on the given song object
        /// </summary>
        /// <param name="sng"></param>
        public void OpenNewSongObject(Song sng)
        {
            SongTemplateMapper stm = new SongTemplateMapper(_settings);

            stm.ApplyFormattingFromSettings(sng);

            CreateSongEditorChildForm(sng, null, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler for creating a new file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShowNewForm(object sender, EventArgs e)
        {
            SongTemplateMapper stm = new SongTemplateMapper(_settings);
            Song sng = stm.CreateNewSong();

            stm.ApplyFormattingFromSettings(sng);

            CreateSongEditorChildForm(sng, null, false);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }