import { IDirectoryItem , IItemClipboard } from "models" ; import { DirectoryTextFinder } from "objects" ; import { IDirectoryListProps } from "props/panels" ; import { IDirectoryListState } from "states/panels" ; import { ClipboardAction , MappedColumnSizes } from "types" ; /** Provides a model that handles non-view DirectoryList functionality. */ class DirectoryListModel { /** An internally compatible clipboard object for copying files. */ private _itemClipboard : IItemClipboard ; /** A stack of cached selected indices. */ private selectedIndexCache : number [ ] ; /** Finds directory items using simple text matching. */ private _textFinder : DirectoryTextFinder ; /**
     * Instantiates a new DirectoryListModel.
     */ public constructor ( ) { this . _itemClipboard = { } ; this . selectedIndexCache = [ ] ; this . _textFinder = new DirectoryTextFinder ( ) ; } /** Gets the current clipboard action, if any. */ public get clipboardAction ( ) : ClipboardAction | undefined { return this . _itemClipboard . clipboardAction ; } /** Gets the current clipboard item, if any. */ public get clipboardItems ( ) : IDirectoryItem [ ] | undefined { return this . _itemClipboard . directoryItems ; } /** Gets the directory text finder. */ public get textFinder ( ) : DirectoryTextFinder { return this . _textFinder ; } /** Sets the item clipboard with the given value. */ public set itemClipboard ( value ) { this . _itemClipboard = value ; } param prevState param nextState returns public stateChanged ( prevState , nextState ) { return prevState . creatingNewItem !== nextState . creatingNewItem || prevState . itemDeleted !== nextState . itemDeleted || prevState . renamingItem !== nextState . renamingItem || prevState . selectedIndex !== nextState . selectedIndex || prevState . showHiddenItems !== nextState . showHiddenItems || prevState . isGotoOpen !== nextState . isGotoOpen || prevState . isFocused !== nextState . isFocused ; } param prevProps param nextProps returns public propsChanged ( prevProps , nextProps ) { return prevProps . isSelectedPane !== nextProps . isSelectedPane || prevProps . path !== nextProps . path || DirectoryListModel . columnSizeChanged ( prevProps . columnSizes , nextProps . columnSizes ) ; } param prevItems param nextItems returns public chosenItemsChanged ( prevItems , nextItems ) { return prevItems . length !== nextItems . length ; } param prevItems param nextItems returns public directoryItemsChanged ( prevItems , nextItems ) { if ( prevItems . length !== nextItems . length ) { return true ; } for ( let i = 0 ; i < prevItems . length ; i ++ ) { if ( prevItems [ i ] . name !== nextItems [ i ] . name ) { return true ; } } return false ; } param value public cacheSelectedIndex ( value ) { this . selectedIndexCache . push ( value ) ; } /** Pops the top selected index off the cache and returns it, if any. */ public popSelectedIndex ( ) { return this . selectedIndexCache . pop ( ) ; } /** Clears the selected index cache. */ public clearSelectedIndexCache ( ) { this . selectedIndexCache = [ ] ; } param previousColumnSizes param nextColumnSizes returns private static columnSizeChanged ( previousColumnSizes , nextColumnSizes ) { const keys = Object . keys ( previousColumnSizes ) as Array < keyof MappedColumnSizes > ; return keys . some ( columnType => previousColumnSizes [ columnType ] !== nextColumnSizes [ columnType ] ) ; } } export default DirectoryListModel ;