Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


An Uncommon Solution to a Common Compact Framework Problem  : Page 3

Use these flexible UncommonDialog dialog classes to lift the restrictions built into the CommonDialog classes delivered with the .NET Compact Framework.

The FileSystemBrowser Class
The FileSystemBrowser is a key class in the hierarchy of the UncommonDialog API, providing both a user interface much like the Pocket PC's File Explorer and a developer interface with ample extensibility options (see Figure 3).
Figure 3. FileSystemBrowser Snapshot: The figure shows the FileSystemBrowser running on a PocketPC.
The class provides several protected properties (see Table 3) and methods (see Table 4) that are important for use by its subclasses.

Table 3. The FileSystemBrowser class has several protected properties.

Property Description
ComparerCollection Returns the NamedComparerCollection created by the CreateComparerCollection method.
CurrentComparer Returns the IComparer currently being used to sort the display.
CurrentDirectory Returns a DirectoryInfo instance that represents the directory currently being displayed.
FileMask Returns the file mask string used to determine the current display. By default this value is "*.*".
ListView Returns the ListView being used to display the active contents.
ListViewItemFactory Returns the IBrowserListViewItemFactory implementer created by the CreateListViewItemFactory method.
SelectedElement Returns the currently selected TaggableListViewItem.

Table 4. The table lists the FileSystemBrowser class's protected methods.
Method Description
CreateComparerCollection The factory method for creating a NamedComparerCollection.
CreateListViewItemFactory The factory method for creating an IBrowserListViewItemFactory implementer.
DisplayDirectory This method is the core of the logic that displays the contents of the current directory. Both FilterDirectory and FilterFile are called from this method.
FileSystemContentSelected This method is called whenever the user selects something in the ListView.
FilterDirectory This method returns a Boolean determining whether or not a directory should be displayed. The base implementation checks the Hidden and System file attributes against the ShowHidden and ShowSystem properties.
FilterFile Like FilterDirectory, this method determines whether or not a file should be displayed.
OnDeleteButton This method is called when the Delete toolbar button is pressed. The base implementation will delete the currently selected directory or file.
OnNewFolderButton This method is called when the New Folder toolbar button is pressed. The base implementation will create a new folder in the current directory.
OnPropertiesButton This method is called when the Properties toolbar button is pressed and will load the PropertiesDialog form which will display the various file system data bits about the selected directory or file.
ToolbarButtonClickHandler This is the raw event handler for the toolbar. If new buttons are added this method should be overridden.

If you examined the UML model shown in Figure 2, two important classes readily become apparent: FileSystemBrowserListViewItemFactory and FileSystemComparerCollection. A class that implements the IBrowserListViewItemFactory interface configures the ListView that is central to the File Explorer-like view. The IBrowserListViewItemFactory interface defines a property for retrieving an array of ColumnHeaders and a method for creating a TaggableListViewItem, which is merely a subclass of ListViewItem that has a Tag property like its standard Framework cousin. This Tag property serves to associate System.IO.FileSystemInfo instances to be associated with each entry in the ListView. The other class, FileSystemComparerCollection, a subclass of NamedComparerCollection, provides a collection of System.Collections.IComparer implementers for sorting FileSystemInfo objects by various fields such as name, date, or size exactly as you can with the File Explorer. The FileSystemBrowser class provides two virtual factory methods, CreateListViewItemFactory and CreateComparerCollection (noted in Table 4), so that subclasses can provide alternate implementers for customization. In addition to these two methods, there are a number of other virtual methods that let developers handle dialog control events such as the toolbar's button-click event.

The controls of the FileSystemBrowser are packaged neatly within two panels. The navigation and the sort dropdowns are contained within a panel named "Navigation" and the ListView within a panel named "Display." You can retrieve both panels from the NamedPanelsCollection. This contained layout makes it easy to manipulate blocks of the user interface instead of having to deal with the discrete pieces individually.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date