17 Handler

▼ |  | Framework: Racket GUI Application Framework

1 | Framework Libraries Overview
2 | Application
3 | Autosave
4 | Canvas
5 | Color Model
6 | Color Prefs
7 | Color
8 | Comment Box
9 | Decorated Editor Snip
10 | Editor Snip
11 | Editor
12 | Exit
13 | Finder
14 | Frame
15 | Group
16 | GUI Utilities
17 | Handler
18 | Icon
19 | Keymap
20 | Menu
21 | Mode
22 | Notify-boxes
23 | Number Snip
24 | Panel
25 | Pasteboard
26 | Path Utils
27 | Preferences
28 | Preferences, Textual
29 | Racket
30 | Srcloc Snips
31 | Text
32 | Splash
33 | Test
34 | Version
35 | Backwards Compatibility
36 | Signatures
37 | Unit
| Index

On this page:

handler: handler?
handler: handler-name
handler: handler-extension
handler: handler-handler
handler: insert-format-handler
handler: find-named-format-handler
handler: find-format-handler
handler: edit-file
handler: current-create-new-window
handler: open-file
handler: install-recent-items
handler: set-recent-items-frame-superclass
handler: add-to-recent
handler: set-recent-position
handler: size-recently-opened-files
handler: update-currently-open-files

top contents ← prev up next →

### 17`` Handler🔗ℹ

> procedure (handler:handler? obj) → boolean?
> obj : any/c

This predicate determines if its input is a handler.

> procedure (handler:handler-name handler) → string?
> handler : handler:handler?

Extracts the name from a handler.

> procedure (handler:handler-extension handler)
> → (or/c (path? . -> . boolean?) (listof string?))
> handler : handler:handler?

Extracts the extension from a handler.

> procedure (handler:handler-handler handler)
> → (path? . -> . (is-a?/c frame:editor<%>))
> handler : handler:handler?

Extracts the handler’s handling function.

> > procedure
> > (handler:insert-format-handler |  | name |  |  |  |
> > |  | pred |  |  |  |
> > |  | handler) |  | → |  | void?
> name : string?
> pred : (or/c string? (listof string?) (path? . -> . boolean?))
> handler : (path? . -> . (or/c false/c (is-a?/c frame:editor<%>)))

This function inserts a format handler.

The string, name names the format handler for use with handler:find-named-format-handler. If pred is a string, it is matched with the extension of a filename by handler:find-format-handler. If pred is a list of strings, they are each matched with the extension of a filename by handler:find-format-handler. If it is a function, the filename is applied to the function and the functions result determines if this is the handler to use.

The most recently added format handler takes precedence over all other format handlers.

> procedure (handler:find-named-format-handler name)
> → (or/c #f (-> path? (is-a?/c frame:editor<%>)))
> name : string?

This function selects a format handler. See also handler:insert-format-handler.

It finds a handler based on name.

> procedure (handler:find-format-handler filename)
> → (or/c #f (-> path? (is-a?/c frame:editor<%>)))
> filename : path?

This function selects a format handler. See also handler:insert-format-handler.

It finds a handler based on filename.

> procedure (handler:edit-file filename [make-default])
> → (or/c false/c (is-a?/c frame:editor<%>))
> filename : (or/c path? false/c)
> | make-default |  | : |  | (-> (is-a?/c frame:editor<%>))
> |  |  | = |  | (λ () ((handler:current-create-new-window) filename))

This function invokes the appropriate format handler to open the file (see handler:insert-format-handler).

- If filename is a string, this function checks the result of group:get-the-frame-group to see if the filename is already open by a frame in the group.

  - If so, it returns the frame.

  - If not, this function calls handler:find-format-handler with filename.

    - If a handler is found, it is applied to filename and its result is the final result.

    - If not, make-default is used.

- If filename is #f, make-default is used.

> parameter (handler:current-create-new-window)
> → (-> (or/c false/c path?) (is-a?/c frame%))
> (handler:current-create-new-window proc) → void?
> proc : (-> (or/c false/c path?) (is-a?/c frame%))

This is a parameter that controls how the framework creates new application windows.

The default setting is this:

> (λ (filename)
> (let ([frame (make-object frame:text-info-file% filename)])
> (send frame show #t)
> frame))

> procedure (handler:open-file [dir])
> → (or/c false/c (is-a?/c frame:basic<%>))
> dir : (or/c false/c path? string?) = #f

This function queries the user for a filename and opens the file for editing. It uses handler:edit-file to open the file, once the user has chosen it.

Calls finder:get-file and handler:edit-file, passing along dir.

> procedure (handler:install-recent-items menu) → void?
> menu : (is-a?/c menu%)

This function deletes all of the items in the given menu and adds one menu item for each recently opened file. These menu items, when selected, call handler:edit-file with the filename of the recently opened file.

The menu’s size is limited to 10.

> procedure (handler:set-recent-items-frame-superclass frame) → void?
> frame : (implementation?/c frame:standard-menus<%>)

Sets the superclass for the recently opened files frame. It must be derived from frame:standard-menus.

> procedure (handler:add-to-recent filename) → void?
> filename : path?

Adds a filename to the list of recently opened files.

> > procedure
> > (handler:set-recent-position |  | filename |  |  |  |
> > |  | start |  |  |  |
> > |  | end) |  | → |  | void?
> filename : path?
> start : number?
> end : number?

Sets the selection of the recently opened file to start and end.

> procedure (handler:size-recently-opened-files num) → void?
> num : number?

Sizes the 'framework:recently-opened-files/pos preference list length to num.

> procedure (handler:update-currently-open-files) → void?

This is called when new files are opened or when files are closed or when the frontmost window changes. As long as the app is not currently exiting, it updates the preference with the key 'framework:last-opened-files to hold a list of list of paths, to record the lists of files that are currently open in tabs.
top contents ← prev up next →