From WxWiki
Jump to: navigation, search

The wxVirtualDirTreeCtrl is a very handy component for quickly creating project browsers, repository views, smart directory selectors based upon event handlers which can be overridden to make it look even more flexible. It is based upon a wxTreeCtrl component, and designed in such a way that the native functionality of this class can still be used.

Some of the features include:

  • Smart expansion of tree nodes. Upon expansion, two levels of the directory below is scanned. This significantly increments speed and no waiting is needed for the whole directory to be read in memory. Due to this way of scanning the directory, the memory footprint will also be small, and will grow only when directories are actually visited. There is also an optional flag to load everything into memory at once if desired.
  • Every file / directory to be added consists of a base class which can be inherited to add your own functionality. You can even decide to make your root, directory and file objects all different classes (as long as they are derived from VdtcTreeItemBase).
  • Full control of which files and directories are added and which not. For every file or directory, an OnAddFile / OnAddDirectory will be called with the path of the file / dir to be added, and more optional information. If for example you only want to show directories which have certain files, all the directories that are not interesting can be denied. This also goes for files. You can even decide to deny the creation of the root, for example when the base directory doesn't point to a valid repository or doesn't contain that one file that is needed.
  • Dynamic icon and caption display of every item that is added to the tree. Upon adding the developer can decide what icon is chosen for what file. This can be done by inheriting the client data object (VdtcTreeItemBase) and overriding the methods VdtcTreeItemBase::GetIconId, VdtcTreeItemBase::GetSelectedIconId and VdtcTreeItemBase::GetCaption to modify what icon, what caption and upon selection what icon is chosen.
  • Sort functionality that can be overridden. By default, dirs are shown first, and then files by alphabetic order. If you inherit this class, the overridden OnCompareItems method can determine the order of tree items in a different way.
  • The possibility to expand a full path. If after creation you want to expand some tree nodes, simply give the path and the dynamic scanning of the directory will go on intil that path is completely scanned in memory and visible in the tree control. If the path is not (completely) valid, there will be no expansion, and an error is returned.
  • The internal tree structure is determined by the treeview which is used. This has as benefit that adding or deleting nodes can be done easily on the fly. No difficult underlying structure is present which needs to be maintained, and this makes the original wxTreeCtrl methods accessible and as transparent as they can be.

wxVirtualDirTreeCtrl can be found here; http://wastebucket.solidsteel.nl