public NotesViewHierarchical() { App.Logger.Trace("NotesViewHierarchical", ".ctr()"); _hierarchyCache = HierarchyConfigCache.LoadFromFile(AppSettings.PATH_HIERARCHYCACHE); SetCurrentValue(SelectedNotesListProperty, new ObservableCollection <INote>()); _displayItems = new HierarchicalWrapper_Folder("ROOT", this, DirectoryPath.Root(), true, false); InitializeComponent(); RootGrid.DataContext = this; }
private void ResyncDisplayItems(IList <INote> notes) { App.Logger.Trace("NotesViewHierarchical", "ResyncDisplayItems", string.Join("\n", notes.Select(n => $"{n.UniqueName} {n.Title}"))); _isNotesInitialized = false; HierarchicalWrapper_Folder root = new HierarchicalWrapper_Folder("ROOT", this, DirectoryPath.Root(), true, false); if (Settings?.FolderViewShowRootNode == true) { var root2 = root.GetOrCreateRootFolder(); foreach (var note in notes) { var parent = root2; foreach (var pathcomp in note.Path.Enumerate()) { parent = parent.GetOrCreateFolder(pathcomp, out _); } parent.Add(note); } } else { foreach (var note in notes) { var parent = root; foreach (var pathcomp in note.Path.Enumerate()) { parent = parent.GetOrCreateFolder(pathcomp, out _); } parent.Add(note); } } DisplayItems.CopyPermanentsTo(root); _hierarchyCache.Get(Settings.ActiveAccount.ID).ApplyTo(Settings, root); root.Sort(); root.FinalizeCollection(Settings?.DeepFolderView ?? false); // Also refreshes/synchronizes SelectedFolder.AllSubNotes DisplayItems.Sync(root, new HierarchicalWrapper_Folder[0]); _isNotesInitialized = true; }
public void MoveFolder(DirectoryPath folder, int delta) { App.Logger.TraceExt("NotesViewHierarchical", "MoveFolder", Tuple.Create("folder", folder.Formatted), Tuple.Create("delta", delta.ToString())); if (folder.IsRoot()) { return; } var curr = DisplayItems; if (Settings?.FolderViewShowRootNode == true) { curr = DisplayItems.GetRootFolder(); } if (curr == null) { App.Logger.Warn("NotesViewHierarchical", "MoveFolder encountered missing (root) path"); return; } HierarchicalWrapper_Folder currParent = null; foreach (var comp in folder.Enumerate()) { currParent = curr; curr = curr.GetFolder(comp); if (curr == null) { App.Logger.Warn("NotesViewHierarchical", "MoveFolder encountered missing path", $"folder := '{folder.Formatted}'\ncomp := '{comp}'"); return; } } if (curr == null || currParent == null) { App.Logger.Warn("NotesViewHierarchical", "MoveFolder encountered missing parent"); return; } var counter = 1; foreach (var f in currParent.SubFolder) { f.CustomOrder = counter * 100; counter++; } curr.CustomOrder += delta * 100 + Math.Sign(delta) * 50; currParent.Sort(false); counter = 1; foreach (var f in currParent.SubFolder) { f.CustomOrder = counter * 100; counter++; } if (_isNotesInitialized) { _hierarchyCache.UpdateAndRequestSave(RepositoryAccountID, DisplayItems, SelectedFolderPath, SelectedNote?.UniqueName); } }