예제 #1
0
        private void AddTagToNote(string t)
        {
            if (SelectedNote == null)
            {
                return;
            }
            if (Settings.IsReadOnlyMode)
            {
                return;
            }

            if (!Repository.SupportsTags)
            {
                MessageBox.Show(Owner, "Tags are not supported by your note provider", "Unsupported operation!", MessageBoxButton.OK);
                return;
            }

            if (SelectedNote == null)
            {
                return;
            }

            var selection = AllSelectedNotes.ToList();

            if (selection.Count > 1)
            {
                if (MessageBox.Show(Owner, $"Do you really want to add the tag [{t}] to {selection.Count} notes?", $"Add tag?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                {
                    return;
                }

                foreach (var note in selection)
                {
                    if (note.IsLocked)
                    {
                        continue;
                    }
                    if (!note.Tags.Contains(t))
                    {
                        note.Tags.Add(t);
                    }
                }
            }
            else
            {
                if (SelectedNote.IsLocked)
                {
                    return;
                }
                if (!SelectedNote.Tags.Contains(t))
                {
                    SelectedNote.Tags.Add(t);
                }
            }
        }
예제 #2
0
        private void DeleteNote()
        {
            try
            {
                if (SelectedNote == null)
                {
                    return;
                }
                if (Settings.IsReadOnlyMode)
                {
                    return;
                }

                var selection = AllSelectedNotes.ToList();
                if (selection.Count > 1)
                {
                    if (MessageBox.Show(Owner, $"Do you really want to delete {selection.Count} notes?", "Delete multiple notes?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                    {
                        return;
                    }

                    foreach (var note in selection)
                    {
                        Repository.DeleteNote(note, true);
                    }

                    SelectedNote = Repository.Notes.FirstOrDefault();
                }
                else
                {
                    if (MessageBox.Show(Owner, "Do you really want to delete this note?", "Delete note?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                    {
                        return;
                    }

                    Repository.DeleteNote(SelectedNote, true);

                    SelectedNote = Repository.Notes.FirstOrDefault();
                }
            }
            catch (Exception e)
            {
                App.Logger.Error("Main", "Could not delete note(s)", e);
                ExceptionDialog.Show(Owner, "Could not delete note(s)", e, string.Empty);
            }
        }
예제 #3
0
        private void LockUnlockNote()
        {
            if (Settings.IsReadOnlyMode)
            {
                return;
            }

            if (!Repository.SupportsLocking)
            {
                MessageBox.Show(Owner, "Locking notes is not supported by your note provider", "Unsupported operation!", MessageBoxButton.OK);
                return;
            }

            if (SelectedNote == null)
            {
                return;
            }

            var selection = AllSelectedNotes.ToList();

            if (selection.Count > 1)
            {
                var newlock = !selection[0].IsLocked;

                if (MessageBox.Show(Owner, $"Do you really want to {(newlock ? "lock" : "unlock")} {selection.Count} notes?", $"{(newlock ? "Lock" : "Unlock")} multiple note?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                {
                    return;
                }

                foreach (var note in selection)
                {
                    note.IsLocked = newlock;
                }
            }
            else
            {
                SelectedNote.IsLocked = !SelectedNote.IsLocked;
            }
        }
예제 #4
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);
                }
            }
        }
예제 #5
0
        private void DuplicateNote()
        {
            if (SelectedNote == null)
            {
                return;
            }
            if (Settings.IsReadOnlyMode)
            {
                return;
            }

            if (Owner.Visibility == Visibility.Hidden)
            {
                ShowMainWindow();
            }

            var selection = AllSelectedNotes.ToList();

            if (selection.Count > 1)
            {
                if (MessageBox.Show(Owner, $"Do you really want to duplicate {selection.Count} notes?", "Duplicate multiple notes?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                {
                    return;
                }

                var lastNote = SelectedNote;
                foreach (var note in selection)
                {
                    var title = note.Title;
                    var path  = note.Path;
                    var text  = note.Text;
                    var tags  = note.Tags.ToList();

                    var ntitle = title + " (copy)";
                    var i      = 2;
                    while (Repository.Notes.Any(n => n.Title.ToLower() == ntitle.ToLower()))
                    {
                        ntitle = title + " (copy-" + (i++) + ")";
                    }
                    title = ntitle;

                    lastNote = Repository.CreateNewNote(path);

                    lastNote.Title = title;
                    lastNote.Text  = text;
                    lastNote.Tags.SynchronizeCollection(tags);
                }

                SelectedNote = lastNote;
            }
            else
            {
                var title = SelectedNote.Title;
                var path  = SelectedNote.Path;
                var text  = SelectedNote.Text;
                var tags  = SelectedNote.Tags.ToList();

                var ntitle = title + " (copy)";
                var i      = 2;
                while (Repository.Notes.Any(n => n.Title.ToLower() == ntitle.ToLower()))
                {
                    ntitle = title + " (copy-" + (i++) + ")";
                }
                title = ntitle;

                SelectedNote = Repository.CreateNewNote(path);

                SelectedNote.Title = title;
                SelectedNote.Text  = text;
                SelectedNote.Tags.SynchronizeCollection(tags);
            }
        }