Download vty-ui User`s Manual

Transcript
CHAPTER 4. GUIDED TOUR OF BUILT-IN VTY-UI WIDGETS
4.7.2
49
Annotations
For each type of file on the filesystem, the browser displays the kind of file in addition
to some information about it. For example, for regular files, the size is displayed. For
symbolic links, the link target is displayed.
It may be important to add your own such enhancements to the browser. For example,
you may want to apply an attribute to files with a specific extension to make them easy to
see in the browser. In addition you may wish to generate a description about the file in the
status bar. To accomplish this, the DirBrowser provides annotations.
An annotation is made up of three components:
• A predicate to determine whether the annotation should apply to a given file,
• A function to generate a description of the file such as its size or application-specific
metadata, and
• An attribute to apply to files of this type in the browser listing.
Annotations are stored in the BrowserSkin itself since they are used to influence the
browser’s appearance. To add annotations to a skin, use withAnnotations. The following example adds an annotation for “emacs backup files,” which end in ’˜’:
let mySkin = defaultBrowserSkin ‘withAnnotations‘ myAnnotations
myAnnotations = [ ( \path _ -> "˜" ‘isSuffixOf‘ path
, \_ _ -> return "emacs backup file"
, green ‘on‘ blue
)
]
For the full specification of the annotation’s type, please see the API documentation.
4.7.3
Error Reporting
When a user selects a file in the browser, your application may determine that the file
does not meet certain requirements. At this point it may be useful to report an error to
the user without leaving the browser interface. The DirBrowser provides a function to
do just this called reportBrowserError. The function displays an error message in the
browser’s error message area.