aspen-tree-model
Version:
State container for aspen trees
56 lines (55 loc) • 2.17 kB
TypeScript
import { Directory, FileEntry, Root } from 'aspen-core';
import { IDisposable } from 'notificar';
import { ISerializableState } from './types';
export declare enum Operation {
SetExpanded = 1,
SetCollapsed = 2,
SetActive = 3
}
export declare class TreeStateManager {
private root;
private events;
private expandedDirectories;
private _scrollOffset;
private stashing;
private stashKeyframes;
private stashLockingItems;
constructor(root: Root);
get scrollOffset(): number;
saveScrollOffset(scrollOffset: number): void;
onDidLoadState(callback: () => void): IDisposable;
onChangeScrollOffset(callback: (newOffset: number) => void): IDisposable;
onDidChangeDirExpansionState(callback: (relDirPath: string, nowExpanded: boolean, visibleAtSurface: boolean) => void): IDisposable;
onDidChangeRelativePath(callback: (prevPath: string, newPath: string) => void): IDisposable;
/**
* Starts recording directory expands and collapses
*
* `reverseStash` can then be used to undo all those actions.
*
* Internally used by `FileTree#peekABoo`
*
* Stashing can be used for peeking file(s) temporarily, where you don't want a mess of expanded folders for user to deal with.
*
* `beginStashing` => then expand the folder(s) you need to get to the file you want => `endStahsing` => once you're done => `reverseStash` to clean up the mess
*/
beginStashing(): void;
/**
* Ends the recording session of directory expands and collapses
*
* See documentation for `beginStashing` for details
*/
endStashing(): void;
/**
* Reverses all the recorded directory expands and collapses
*
* See documentation for `beginStashing` for details
*/
reverseStash(): Promise<void>;
loadTreeState(state: ISerializableState): Promise<void>;
/**
* This will ensure directory expansions aren't altered atleast for directories leading to file to be excluded when `reverseStash` is called
*/
excludeFromStash(file: FileEntry | Directory): void;
private handleExpansionChange;
private handleDidChangePath;
}