Пример #1
0
        private void DeleteNote()
        {
            if (SelectedNote == null)
            {
                return;
            }
            Modified = true;

            // Mark note as deleted
            SelectedNote.InRecyclingBin = true;

            // Remove note from filtered list
            int selectedIndex = FilteredNotes.IndexOf(SelectedNote);

            FilteredNotes.RemoveAt(selectedIndex);
            OnPropertyChanged("Notes");

            // Set new selection
            selectedIndex = Math.Min(selectedIndex, FilteredNotes.Count - 1);
            if (selectedIndex >= 0)
            {
                SelectedNote = FilteredNotes[selectedIndex];
            }
            else
            {
                SelectedNote = null;
            }
        }
        public static void PerformNoteFiltering(string Filter)
        {
            if (Filter.Trim() == null || Filter.Equals(""))
            {
                FilteredNotes.Clear();
                foreach (NoteModel note in Notes)
                {
                    FilteredNotes.Add(note);
                }
            }
            else
            {
                var lowerCaseFilter = Filter.ToLowerInvariant().Trim();

                var result = Notes.Where(d => d.NoteName.ToLowerInvariant()
                                         .Contains(lowerCaseFilter)).ToList();

                var toRemove = FilteredNotes.Except(result).ToList();

                foreach (var x in toRemove)
                {
                    FilteredNotes.Remove(x);
                }

                var resultCount = result.Count;
                for (int i = 0; i < resultCount; i++)
                {
                    var resultItem = result[i];
                    if (i + 1 > FilteredNotes.Count || !FilteredNotes[i].Equals(resultItem))
                    {
                        FilteredNotes.Insert(i, resultItem);
                    }
                }
            }
        }
        private void NewNote(NoteType noteType)
        {
            Modified = true;
            ClearFilter();

            // Create new note and update model list
            NoteModel noteModel = new NoteModel();

            noteModel.NoteType           = noteType;
            noteModel.BackgroundColorHex = _settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;

            // Update view model list
            NoteViewModel     noteViewModel = new NoteViewModel(_navigationService, Language, Icon, Theme, _webviewBaseUrl, _searchableTextConverter, _repositoryService, _feedbackService, null, _noteCryptor, _model.Safes, noteModel);
            NoteInsertionMode insertionMode = _settingsService.LoadSettingsOrDefault().DefaultNoteInsertion;

            switch (insertionMode)
            {
            case NoteInsertionMode.AtTop:
                _model.Notes.Insert(0, noteModel);
                AllNotes.Insert(0, noteViewModel);
                FilteredNotes.Insert(0, noteViewModel);
                break;

            case NoteInsertionMode.AtBottom:
                _model.Notes.Add(noteModel);
                AllNotes.Add(noteViewModel);
                FilteredNotes.Add(noteViewModel);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(insertionMode));
            }

            ShowNoteCommand.Execute(noteViewModel.Id);
        }
        private void DeleteNote(object value)
        {
            Guid          noteId       = (value is Guid) ? (Guid)value : new Guid(value.ToString());
            NoteViewModel selectedNote = AllNotes.Find(item => item.Id == noteId);

            if (selectedNote == null)
            {
                return;
            }
            Modified = true;

            // Mark note as deleted
            selectedNote.InRecyclingBin = true;

            // Remove note from filtered list
            int selectedIndex = FilteredNotes.IndexOf(selectedNote);

            FilteredNotes.RemoveAt(selectedIndex);

            Tags = Model.CollectActiveTags();
            Tags.Insert(0, EmptyTagFilter);
            OnPropertyChanged("Tags");

            // If the note was the last one containing the selected tag, the filter should be cleared
            if (!SelectedTagExistsInTags())
            {
                SelectedTag = null;
            }
            else
            {
                OnPropertyChanged("Notes");
            }

            _feedbackService.ShowToast(Language.LoadText("feedback_note_to_recycle"));
        }
        private void ShowNote(object value)
        {
            Guid          noteId = (value is Guid) ? (Guid)value : new Guid(value.ToString());
            NoteViewModel note   = FilteredNotes.FirstOrDefault(item => item.Id == noteId);

            if (note != null)
            {
                Navigation navigation = null;
                switch (note.Model.NoteType)
                {
                case NoteType.Text:
                    navigation = new Navigation(ControllerNames.Note, ControllerParameters.NoteId, noteId.ToString());
                    break;

                case NoteType.Checklist:
                    navigation = new Navigation(ControllerNames.Checklist, ControllerParameters.NoteId, noteId.ToString());
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(NoteType));
                }
                if (!string.IsNullOrEmpty(_filter))
                {
                    navigation.Variables.AddOrReplace(ControllerParameters.SearchFilter, _filter);
                }
                _navigationService.Navigate(navigation);
            }
        }
        private async static void fillList()
        {
            var folder = Windows.Storage.ApplicationData.Current.LocalFolder;
            var query  = folder.CreateFileQuery();
            var files  = await query.GetFilesAsync();

            foreach (Windows.Storage.StorageFile file in files)
            {
                //the "Files" include the .db files, added this to make sure there werent any inappropriate file taken
                if (file.FileType != ".db")
                {
                    string NoteBody = await Windows.Storage.FileIO.ReadTextAsync(file);

                    string NoteName = file.Name;
                    NoteName = NoteName.Replace(".txt", "");
                    try
                    {
                        int NoteNumber = Notes.Count + 1;
                        Notes.Add(new NoteModel(NoteNumber, NoteName, NoteBody));
                        FilteredNotes.Add(new NoteModel(NoteNumber, NoteName, NoteBody));
                    }
                    catch (Exception err)
                    {
                        string error = err.Message;
                    }
                }
            }
        }
 public static void ShowAll()
 {
     FilteredNotes.Clear();
     foreach (NoteModel note in Notes)
     {
         FilteredNotes.Add(note);
     }
 }
Пример #8
0
        private void ApplyFilter(string filter)
        {
            string     normalizedFilter = SearchableHtmlConverter.NormalizeWhitespaces(filter);
            NoteFilter noteFilter       = new NoteFilter(normalizedFilter);

            FilteredNotes.Clear();
            foreach (NoteViewModel noteViewModel in AllNotes)
            {
                if (!noteViewModel.InRecyclingBin && noteFilter.ContainsPattern(noteViewModel.SearchableContent))
                {
                    FilteredNotes.Add(noteViewModel);
                }
            }
        }
        public async static void DeleteNote()
        {
            if (_selectedNote != null)
            {
                string noteName = _selectedNote.NoteName;

                StorageFile tempFile = await storageFolder.GetFileAsync(noteName + ".txt");

                await tempFile.DeleteAsync();

                //delete that note from Notes and FilteredNotes
                // got this line from http://stackoverflow.com/questions/20403162/remove-one-item-in-observablecollection
                Notes.Remove(Notes.Where(i => i.NoteName == _selectedNote.NoteName).Single());
                FilteredNotes.Remove(FilteredNotes.Where(i => i.NoteName == _selectedNote.NoteName).Single());
            }
        }
        /// <summary>
        /// Changes <see cref="NoteViewModel.IsPinned"/> based on position.
        /// This is usually called after a drag and drop action.
        /// </summary>
        /// <remarks>Changes to true if placed in front of a
        /// pinned note. False if placed behind unpinned one.</remarks>
        internal void CheckPinStatusAtPosition(int currentIndex)
        {
            var movedNote   = FilteredNotes[currentIndex];
            var noteBehind  = FilteredNotes.ElementAtOrDefault(currentIndex + 1);
            var noteInfront = FilteredNotes.ElementAtOrDefault(currentIndex - 1);

            if (movedNote.IsPinned == false && noteBehind != null && noteBehind.IsPinned)
            {
                movedNote.IsPinned = true;
                OnPropertyChanged("Notes"); // refreshes the notes
            }
            else if (movedNote.IsPinned && noteInfront != null && noteInfront.IsPinned == false)
            {
                movedNote.IsPinned = false;
                OnPropertyChanged("Notes");
            }
        }
Пример #11
0
        private void ShowNote(Guid?noteId)
        {
            NoteViewModel note;

            if (noteId != null)
            {
                note = FilteredNotes.FirstOrDefault(item => item.Id == noteId);
            }
            else
            {
                note = SelectedNote;
            }

            if (note != null)
            {
                _navigationService.Navigate(ControllerNames.Note, ControllerParameters.NoteId, note.Id.ToString());
            }
        }
        /// <summary>
        /// Command to move a note to a new place in the list. This is usually
        /// called after a drag and drop action.
        /// </summary>
        /// <param name="oldIndex">Index of the note to move.</param>
        /// <param name="newIndex">New index to place the note in.</param>
        public void MoveNote(int oldIndex, int newIndex)
        {
            if ((oldIndex == newIndex) ||
                !IsInRange(oldIndex, 0, FilteredNotes.Count - 1) ||
                !IsInRange(newIndex, 0, FilteredNotes.Count - 1))
            {
                return;
            }
            Modified = true;

            int oldIndexInUnfilteredList = AllNotes.IndexOf(FilteredNotes[oldIndex]);
            int newIndexInUnfilteredList = AllNotes.IndexOf(FilteredNotes[newIndex]);

            ListMove(_model.Notes, oldIndexInUnfilteredList, newIndexInUnfilteredList);
            ListMove(AllNotes, oldIndexInUnfilteredList, newIndexInUnfilteredList);
            FilteredNotes.Move(oldIndex, newIndex);
            _model.RefreshOrderModifiedAt();
        }
Пример #13
0
        private void AddNote()
        {
            Modified = true;
            ClearFilter();

            // Create new note and update model list
            NoteModel noteModel = new NoteModel();

            noteModel.BackgroundColorHex = _settingsService.LoadSettingsOrDefault().DefaultNoteColorHex;
            _model.Notes.Insert(0, noteModel);

            // Update view model list
            NoteViewModel noteViewModel = new NoteViewModel(_navigationService, Language, Icon, _webviewBaseUrl, _searchableTextConverter, _repositoryService, null, noteModel);

            AllNotes.Insert(0, noteViewModel);
            FilteredNotes.Insert(0, noteViewModel);

            SelectedNote = noteViewModel;
            ShowNote(noteViewModel.Id);
        }
        private void ApplyFilter(string filter)
        {
            SettingsModel settings         = _settingsService?.LoadSettingsOrDefault();
            string        normalizedFilter = SearchableHtmlConverter.NormalizeWhitespaces(filter);
            NoteFilter    noteFilter       = new NoteFilter(normalizedFilter);

            FilteredNotes.Clear();
            foreach (NoteViewModel noteViewModel in AllNotes)
            {
                bool hideNote =
                    noteViewModel.InRecyclingBin ||
                    (settings.HideClosedSafeNotes && noteViewModel.IsLocked) ||
                    !noteFilter.ContainsPattern(noteViewModel.SearchableContent);

                if (!hideNote)
                {
                    FilteredNotes.Add(noteViewModel);
                }
            }
        }
Пример #15
0
        private void DeleteNote(Guid noteId)
        {
            NoteViewModel selectedNote = AllNotes.Find(item => item.Id == noteId);

            if (selectedNote == null)
            {
                return;
            }
            Modified = true;

            // Mark note as deleted
            selectedNote.InRecyclingBin = true;

            // Remove note from filtered list
            int selectedIndex = FilteredNotes.IndexOf(selectedNote);

            FilteredNotes.RemoveAt(selectedIndex);
            OnPropertyChanged("Notes");

            _feedbackService.ShowToast(Language.LoadText("feedback_note_to_recycle"));
        }
Пример #16
0
        private void ShowNote(Guid noteId)
        {
            NoteViewModel note = FilteredNotes.FirstOrDefault(item => item.Id == noteId);

            if (note != null)
            {
                switch (note.Model.NoteType)
                {
                case NoteType.Text:
                    _navigationService.Navigate(new Navigation(
                                                    ControllerNames.Note, ControllerParameters.NoteId, noteId.ToString()));
                    break;

                case NoteType.Checklist:
                    _navigationService.Navigate(new Navigation(
                                                    ControllerNames.Checklist, ControllerParameters.NoteId, noteId.ToString()));
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(NoteType));
                }
            }
        }
        public static async void NewNote(string noteName, string noteBody)
        {
            var folder = Windows.Storage.ApplicationData.Current.LocalFolder;
            var query  = folder.CreateFileQuery();
            var files  = await query.GetFilesAsync();

            Boolean samename = false;

            foreach (Windows.Storage.StorageFile file in files)
            {
                string fileName = file.Name;
                fileName = fileName.Replace(".txt", "");

                if (fileName.Equals(noteName))
                {
                    samename = true;
                    var OkCommand = new UICommand("Ok");
                    var dialog    = new MessageDialog("Please give your note a unique name", "Illegal Note Name");
                    dialog.Options = MessageDialogOptions.None;
                    dialog.Commands.Add(OkCommand);
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex  = 0;
                }
            }

            if (samename != true)
            {
                int Id = Convert.ToInt32(Notes.LongCount()) + 1;
                Notes.Add(new NoteModel(Id, noteName, noteBody));
                FilteredNotes.Add(new NoteModel(Id, noteName, noteBody));

                new PropertyChangedEventArgs("Notes");

                SaveNew(noteName, noteBody);
            }
        }