package bogue

  1. Overview
  2. Docs

Module Bogue.FileSource

File dialog and file monitor

This module offers a quite complete file dialog layout.

  • The dialog opens either in a new window, or as a Popup on top of any existing layout. It can also be inserted anywhere just like any other layout.
  • One can choose to select only files or directories.
  • One can optionally limit the number of selected files.
  • The file system is monitored so that changes in the currently opened directory are automatically taken into account.
  • One can easily open huge directories with thousands of files.
  • The file system can be easily navigated by either clicking on the children directories, or entering manually the requested path, or clicking on parents directories in a special breadcrumb layout.
  • The whole layout is resizable by the user.
  • The dialog can be closed by pressing ESCAPE (even if ESCAPE is used for another action in the main application).

Warning: Some options are not implemented yet; these -- and more features -- will certainly be added in the future.


File dialog in a separate window
  • see Example #54

    .

Dependency graph
Sourcemodule Monitor : sig ... end

Monitoring changes in a directory.

Sourcemodule Mime : sig ... end

Mimetype information

Sourcetype t

The type for file dialogs.

Sourcetype options
Sourceval set_options : ?width:int -> ?height:int -> ?dirs_first:bool -> ?show_hidden:bool -> ?hide_backup:bool -> ?max_selected:int -> ?hide_dirs:bool -> ?only_dirs:bool -> ?select_dir:bool -> ?allow_new:bool -> ?default_name:string -> ?breadcrumb:bool -> ?system_icons:bool -> ?open_dirs_on_click:bool -> ?mimetype:Str.regexp -> ?on_select:((int * int) -> unit) -> unit -> options
  • parameter dirs_first

    partially implemented

  • parameter system_icons

    not implemented

Sourcetype entry

The entry type can be used to create filters for selecting what is actually displayed by the file dialog.

Sourceval filename : entry -> string
Sourceval lstat_opt : entry -> Unix.stats option
Sourceval stat_opt : entry -> Unix.stats option

The stat_opt and lstat_opt return the corresponding pre-computed Unix.stats results, without actually calling any system function.

Sourceval dialog : ?full_filter:(entry -> bool) -> ?options:options -> string -> t

Use this function if you need unusual combinations of options. For most common uses, see select_file (and others) below.

Sourceval get_layout : t -> Layout.t

Return the layout containing the whole file dialog except for the "select" and "cancel" buttons.

Sourceval get_selected : t -> string list

Return the (alphabetically sorted) list of selected files or directories.

Sourceval basedir : t -> string

Return the full path of the currently displayed directory.

Sourceval select_file : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?mimetype:Str.regexp -> ?name:string -> string -> (string -> unit) -> unit

select_file dirname continue will open a file dialog, initially showing the content of the directory dirname. The user can then navigate to other directories. When the user selects a file in the list and presses the "Select file" button, the dialog will close, and the continue function will be applied to the selected filename (full path).

If the dialog is closed by the user pressing the "Cancel" button or the ESCAPE key, the continue function is not used.

Note that global bindings to the ESCAPE key are temporarily disabled when the file dialog is open.

  • parameter dst

    the file selector will show up on top of the dst layout, or in a new window if dst is not provided.

  • parameter mimetype

    only show files whose mimetype string (like "image/png") matches the regular expression.

  • parameter board

    See Popup.two_buttons. Note that, if board is omitted, the window will be created at the next frame, but the file selector layout is immediately created.

  • parameter name

    default name to be chosen.

  • see Example #54

    .

Sourceval select_files : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?mimetype:Str.regexp -> ?n_files:int -> string -> (string list -> unit) -> unit

Similar to select_file except that here several files can be selected. If n_files is provided, it will be the maximum number of files that may be selected.

Sourceval select_dir : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?name:string -> string -> (string -> unit) -> unit

Similar to select_file except that here only a directory can be selected. If the user clicks on a directory name, they will be given the option to either open this directory (for further navigation), or select it (hence closing the dialog).

Sourceval select_dirs : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?n_dirs:int -> string -> (string list -> unit) -> unit

Similar to select_files except that here only directories can be selected.

Sourceval save_as : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?name:string -> string -> (string -> unit) -> unit

Similar to select_file, but here the user can enter a filename that does not already exist in the displayed directory.

Sourceval (let@) : ('a -> 'b) -> 'a -> 'b

( let@ ) f x is just f x . You can use this "syntaxic sugar" to write your code like this:

let open File in
let@ file = select_file "/tmp" in
print_endline ("Selected file : " ^ file)

instead of

File.select_file "/tmp" (fun file ->
    print_endline ("Selected file : " ^ file))