package bogue

  1. Overview
  2. Docs

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
module Monitor : sig ... end

Monitoring changes in a directory.

type t

The type for file dialogs.

type options
val 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

type entry

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

val filename : entry -> string
val lstat_opt : entry -> Unix.stats option
val 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.

val 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.

val get_layout : t -> Layout.t
val get_selected : t -> string list

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

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

Open a file selector 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

    .

val 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 can be selected.

val 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.

val 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.

val save_as : ?dst:Layout.t -> ?board:Main.board -> ?w:int -> ?h:int -> ?name:string -> string -> (string -> unit) -> unit
val 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))
OCaml

Innovation. Community. Security.