Пример #1
0
        private void CreateNewSecureNote()
        {
            if (!Hub.Instance.EncryptionManager.SecureNotesEnabled)
            {
                MainWindowInstance.ShowMessageAsync("Secure notes", "To create secure notes you need to activate this function in settings.");
                return;
            }

            CreateNewNote(true);
        }
Пример #2
0
        private void DeleteCurrentNoteBook()
        {
            if (MenuContext.SelectedNotebook != null)
            {
                var notes = Hub.Instance.Storage.GetNotes(MenuContext.SelectedNotebook.Notebook);
                if (!notes.Any())
                {
                    var settings = DialogHelpers.GetDefaultDialogSettings();

                    if (MenuContext.Notebooks.Count == 1)
                    {
                        MainWindowInstance.ShowMessageAsync("Delete", "You can't delete the last notebook, rename it if the name is wrong.", MessageDialogStyle.Affirmative, settings);
                        return;
                    }

                    MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete the notebook {MenuContext.SelectedNotebook.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task)
                    {
                        if (task.Result == MessageDialogResult.Affirmative)
                        {
                            InvokeOnCurrentDispatcher(() =>
                            {
                                int index = MenuContext.Notebooks.IndexOf(MenuContext.SelectedNotebook);
                                if (index >= MenuContext.Notebooks.Count - 1)
                                {
                                    index--;
                                }

                                MenuContext.SelectedNotebook.Notebook.Delete();

                                if (MenuContext.Notebooks.Contains(MenuContext.SelectedNotebook))
                                {
                                    MenuContext.Notebooks.Remove(MenuContext.SelectedNotebook);
                                }

                                if (NotebookMenuItems.Contains(MenuContext.SelectedNotebook))
                                {
                                    NotebookMenuItems.Remove(MenuContext.SelectedNotebook);
                                }

                                MenuContext.SelectedNotebook = MenuContext.Notebooks[index];
                            });
                        }
                    });
                }
                else
                {
                    MainWindowInstance.ShowMessageAsync("Delete", "You can't delete a notebook that contains notes.");
                }
            }
        }
Пример #3
0
        private void DeleteLibrary()
        {
            var settings = DialogHelpers.GetDefaultDialogSettings();

            var message = $"Do you want to delete the library '{Library.Name}'?\nAll files will be left untouched, it's just the connection that is removed.";
            MainWindowInstance.ShowMessageAsync("Delete library", message, MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task<MessageDialogResult> task)
            {
                if (task.Result == MessageDialogResult.Affirmative)
                    InvokeOnCurrentDispatcher(() =>
                    {
                        Hub.Instance.AppSettings.Librarys.Remove(Library);
                        Library.Delete();
                    });
            });
        }
Пример #4
0
 private void CopyNote()
 {
     if (Note.Encrypted)
     {
         var settings = DialogHelpers.GetDefaultDialogSettings();
         MainWindowInstance.ShowMessageAsync(Properties.Resources.Note_Copy_SecureTitle, Properties.Resources.Note_Copy_SecureText, MessageDialogStyle.AffirmativeAndNegative, settings).
         ContinueWith(delegate(Task <MessageDialogResult> task)
         {
             if (task.Result == MessageDialogResult.Affirmative)
             {
                 DoCopyNote(Note);
             }
         });
     }
     else
     {
         DoCopyNote(Note);
     }
 }
Пример #5
0
        private void EmptyTrash(object arg)
        {
            var settings = DialogHelpers.GetDefaultDialogSettings();

            MainWindowInstance.ShowMessageAsync("Empty trash", "Do you want to delete all notes in the trashcan?\nThis operation can not be undone.", MessageDialogStyle.AffirmativeAndNegative, settings).
            ContinueWith(delegate(Task <MessageDialogResult> task)
            {
                if (task.Result == MessageDialogResult.Affirmative)
                {
                    // TODO: Send empty trash message instead
                    foreach (NoteViewModel n in ViewModelLocator.Instance.NoteMenu.DataSource)
                    {
                        Guid noteId = n.Note.ID;
                        ViewModelLocator.Instance.Unregister(noteId.ToString());
                        n.Note.Delete();
                    }

                    ViewModelLocator.Instance.NoteMenu.SelectedNote = null;
                    ViewModelLocator.Instance.NoteMenu.DataSource.Clear();
                }
            });
        }
Пример #6
0
        private void DeleteNote(DeleteNote message)
        {
            // TODO: i18n
            if (SelectedNote == null || SelectedNote != message.Note)
            {
                return;
            }

            Note note = SelectedNote.Note;

            if (note.InTrashCan)
            {
                return;
            }

            if (note.Protected)
            {
                MessengerInstance.Send(new QuickMessage("You cant delete this note, it's protected from that."));

                return;
            }

            var settings = DialogHelpers.GetDefaultDialogSettings();

            MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete {note.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task)
            {
                if (task.Result == MessageDialogResult.Affirmative)
                {
                    InvokeOnCurrentDispatcher(() =>
                    {
                        note.InTrashCan = true;

                        DataSource.Remove(SelectedNote);
                        SelectedNote = DataSource.FirstOrDefault();
                        Hub.Instance.Settings.RefreshTags();
                    });
                }
            });
        }
Пример #7
0
        private void RenameFile(object obj)
        {
            NoteFile nf = SelectedNoteFile;

            if (nf != null)
            {
                string name     = nf.Name;
                var    settings = DialogHelpers.GetDefaultDialogSettings();
                settings.DefaultText = name;
                MainWindowInstance.ShowInputAsync("Rename", "Enter new name:", settings).ContinueWith(delegate(Task <string> task)
                {
                    string newName = task.Result;
                    if (task.IsCanceled)
                    {
                        return;
                    }

                    if (!string.IsNullOrWhiteSpace(newName))
                    {
                        var existingNoteFile = Note.Files.FirstOrDefault(enf => enf.Name.Equals(newName));
                        if (existingNoteFile == null)
                        {
                            nf.Name            = newName;
                            Note.DecryptedText = Note.DecryptedText.Replace($"[!{name}]", $"[!{newName}]");
                            IsDirty            = true;
                        }
                        else
                        {
                            InvokeOnCurrentDispatcher(() =>
                            {
                                MainWindowInstance.ShowMessageAsync("Error", "You already have a file in this note called " + newName);
                                RenameFile(obj);
                            });
                        }
                    }
                });
            }
        }
Пример #8
0
        private void DeleteCurrentNote()
        {
            if (SelectedMenuItem == _trashLibraryMenuItem)
            {
                return;
            }

            if (NoteMenuContext.SelectedNote.Note.Protected)
            {
                ShowQuickMessage("You cant delete this note, it's protected from that.");
                return;
            }

            var settings = DialogHelpers.GetDefaultDialogSettings();

            MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete {NoteMenuContext.SelectedNote.Note.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task)
            {
                if (task.Result == MessageDialogResult.Affirmative)
                {
                    InvokeOnCurrentDispatcher(() =>
                    {
                        Guid noteId = NoteMenuContext.SelectedNote.Note.ID;
                        if (NoteViewModels.ContainsKey(noteId))
                        {
                            //NoteMenuContext.SelectedNote.Note.Delete();
                            NoteMenuContext.SelectedNote.Note.InTrashCan = true;
                            //NoteMenuContext.SelectedNote.Note.Save();

                            var nvm = NoteViewModels[noteId];
                            NoteViewModels.Remove(noteId);
                            NoteMenuContext.DataSource.Remove(nvm);
                            NoteMenuContext.SelectedNote = NoteMenuContext.DataSource.FirstOrDefault();
                            Hub.Instance.Settings.RefreshTags();
                        }
                    });
                }
            });
        }
Пример #9
0
        private void EmptyTrash(object arg)
        {
            var settings = DialogHelpers.GetDefaultDialogSettings();

            MainWindowInstance.ShowMessageAsync("Empty trash", "Do you want to delete all notes in the trashcan?\nThis operation can not be undone.", MessageDialogStyle.AffirmativeAndNegative, settings).
            ContinueWith(delegate(Task <MessageDialogResult> task)
            {
                if (task.Result == MessageDialogResult.Affirmative)
                {
                    foreach (NoteViewModel n in NoteMenuContext.DataSource)
                    {
                        Guid noteId = n.Note.ID;
                        if (NoteViewModels.ContainsKey(noteId))
                        {
                            n.Note.Delete();
                            NoteViewModels.Remove(noteId);
                        }
                    }
                    NoteMenuContext.SelectedNote = null;
                    NoteMenuContext.DataSource.Clear();
                }
            });
        }