Ejemplo n.º 1
0
        private void CreateNotebook(object arg)
        {
            MainWindowInstance.ShowInputAsync("Add notebook", "Name:").ContinueWith(delegate(Task <string> task)
            {
                string newName = task.Result;
                if (string.IsNullOrEmpty(newName))
                {
                    return;
                }

                Notebook nb = new Notebook
                {
                    Name    = newName,
                    Created = DateTime.Now
                };
                nb.Save();

                var newNotebook = ViewModelLocator.Instance.GetNotebookViewModel(nb);

                List <NotebookViewModel> temp = new List <NotebookViewModel>();
                temp.AddRange(Notebooks.ToArray());
                temp.Add(newNotebook);
                temp.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));

                Notebooks.Clear();
                temp.ForEach(Notebooks.Add);

                SelectedNotebook            = newNotebook;
                SelectedNotebook.IsSelected = true;
            });
        }
Ejemplo n.º 2
0
        private void CreateNotebook(object arg)
        {
            MainWindowInstance.ShowInputAsync("Add notebook", "Name:").ContinueWith(delegate(Task <string> task)
            {
                string newName = task.Result;
                if (string.IsNullOrEmpty(newName))
                {
                    return;
                }

                Notebook nb = new Notebook
                {
                    Name      = newName,
                    Created   = DateTime.Now,
                    SortIndex = 0
                };
                nb.Save();
                var item = new NotebookMenuItem(nb);

                List <NotebookMenuItem> temp = new List <NotebookMenuItem>();
                temp.AddRange(MenuContext.Notebooks.ToArray());
                temp.Add(item);
                temp.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));

                MenuContext.Notebooks.Clear();
                temp.ForEach(MenuContext.Notebooks.Add);

                MenuContext.SelectedNotebook            = item;
                MenuContext.SelectedNotebook.IsSelected = true;
            });
        }
Ejemplo n.º 3
0
        private void CreateNewNote(bool secure)
        {
            var settings = DialogHelpers.GetDefaultDialogSettings();

            MainWindowInstance.ShowInputAsync("New note", "Name of the new note:", settings).ContinueWith(delegate(Task <string> task)
            {
                string name = task.Result;
                if (!string.IsNullOrWhiteSpace(name))
                {
                    CreateNewNote(name, secure);
                }
            });
        }
Ejemplo n.º 4
0
        private void RenameNote()
        {
            // TODO: i18n
            string name     = Note.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 (!string.IsNullOrWhiteSpace(newName))
                {
                    Note.Name = newName;
                    //NoteMenuContext.SelectedNote.Note.Save();
                }
            });
        }
Ejemplo n.º 5
0
        private SecureString SystemNeedsEncryptionPassword()
        {
            //string password = "******";

            Task <SecureString> pass = MainWindowInstance.ShowInputAsync("Password required", "Password:"******"Password required.");
            });

            if (pass?.Result == null)
            {
                throw new Exception("Password required.");
            }

            return(pass.Result);
        }
Ejemplo n.º 6
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);
                            });
                        }
                    }
                });
            }
        }
Ejemplo n.º 7
0
        private void RenameItem(object arg)
        {
            if (SelectedMenuItem is TagViewModel)
            {
                return;
            }

            string name     = SelectedMenuItem.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 (!string.IsNullOrWhiteSpace(newName))
                {
                    if (SelectedMenuItem is NotebookViewModel)
                    {
                        SelectedNotebook.Notebook.Name = newName;
                        SelectedNotebook.Notebook.Save();
                    }
                }
            });
        }