private void ExportNote()
        {
            if (SelectedNote == null)
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            if (SelectedNote.HasTagCaseInsensitive(AppSettings.TAG_MARKDOWN))
            {
                sfd.Filter   = "Markdown files (*.md)|*.md";
                sfd.FileName = SelectedNote.Title + ".md";
            }
            else
            {
                sfd.Filter   = "Text files (*.txt)|*.txt";
                sfd.FileName = SelectedNote.Title + ".txt";
            }

            if (sfd.ShowDialog() == true)
            {
                try
                {
                    File.WriteAllText(sfd.FileName, SelectedNote.Text, Encoding.UTF8);
                }
                catch (Exception e)
                {
                    App.Logger.Error("Main", "Could not write to file", e);
                    ExceptionDialog.Show(Owner, "Could not write to file", e, string.Empty);
                }
            }
        }
Beispiel #2
0
        private void ExportNote()
        {
            if (SelectedNote == null)
            {
                return;
            }

            var selection = AllSelectedNotes.ToList();

            if (selection.Count > 1)
            {
                var dialog = new VistaFolderBrowserDialog();
                if (!(dialog.ShowDialog() ?? false))
                {
                    return;
                }

                try
                {
                    var directory = dialog.SelectedPath;
                    foreach (var note in selection)
                    {
                        var filenameRaw = ANFilenameHelper.StripStringForFilename(note.Title);
                        var filename    = filenameRaw;
                        var ext         = SelectedNote.HasTagCaseInsensitive(AppSettings.TAG_MARKDOWN) ? ".md" : ".txt";

                        int i = 1;
                        while (File.Exists(Path.Combine(directory, filename + ext)))
                        {
                            i++;
                            filename = $"{filenameRaw} ({i})";
                        }

                        File.WriteAllText(Path.Combine(directory, filename + ext), note.Text, Encoding.UTF8);
                    }
                }
                catch (Exception e)
                {
                    App.Logger.Error("Main", "Could not write to file", e);
                    ExceptionDialog.Show(Owner, "Could not write to file", e, string.Empty);
                }
            }
            else
            {
                var sfd = new SaveFileDialog();

                if (SelectedNote.HasTagCaseInsensitive(AppSettings.TAG_MARKDOWN))
                {
                    sfd.Filter   = "Markdown files (*.md)|*.md";
                    sfd.FileName = SelectedNote.Title + ".md";
                }
                else
                {
                    sfd.Filter   = "Text files (*.txt)|*.txt";
                    sfd.FileName = SelectedNote.Title + ".txt";
                }

                if (sfd.ShowDialog() != true)
                {
                    return;
                }
                try
                {
                    File.WriteAllText(sfd.FileName, SelectedNote.Text, Encoding.UTF8);
                }
                catch (Exception e)
                {
                    App.Logger.Error("Main", "Could not write to file", e);
                    ExceptionDialog.Show(Owner, "Could not write to file", e, string.Empty);
                }
            }
        }