new FileManagerPopup(id, title, basePath, [limitToPath], [allowedExtensions], visible)
This class is used to create a popup with a file input to select a file or a directory.
It will run a promise with fs.readdir to get the list of files and directories.
The user can select a file or a directory and the popup will be closed.
Emits the following events:
"confirm" when the user confirm the file or directory selection. The file or directory path is passed as parameter like this: {path: "path/to/file", name: "file.ext"}
"cancel" when the user cancel the file or directory selection.
"exit" when the user exit
Param
Type
Default
Description
id
string
The id of the popup.
title
string
The title of the popup.
basePath
string
The main path of the popup. re case sensitive.
[limitToPath]
boolean
false
If true, the user * @param {boolean} [selectDirectory=false] - If true, the user can select a directory. Otherwise, only files are selectable. When true, to enter a directory, the user must press the space key instead of the enter key.
[allowedExtensions]
Array.<string>
[]
The allowed extensions. If not set, all extensions are allowed. The extensions a can only select files in the path. If false, the user can select files in the path and parent directories.
visible
boolean
If the popup is visible. Default is false (make it appears using show()).
Example
const popup = new FileManagerPopup("popup1", "Choose the file", "./examples").show().on("confirm", (selected) => { console.log(selected) }) // show the popup and wait for the user to confirm
This function is used to load the list of files and directories in the current path.
it return a promise with the list of files and directories. The list is an array of objects like this:
[{text: "📄 file.ext", name: "file.ext", type: "file", path: "path/to/file.ext"}, {text: "📁 dir/", name: "dir", type: "dir", path: "path/to/dir"}]
Kind: instance method of FileManagerPopupReturns: Promise.<Array.<object>> - The list of files and directories.
Param
Type
Description
path
string
The path to load the list.
fileManagerPopup.updateList(path)
This function calls the updateList function and store the result to this.options, it also refresh the list of files and directories.
This function is used to make the ConsoleManager handle the key events when the popup is showed.
Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed.
Fixes #20
Classes
EventEmitter
Constants
ConsoleManager
the instance of ConsoleManager (singleton)
FileManagerPopup ⇐
EventEmitter
Kind: global class Extends:
EventEmitter
EventEmitter
Promise.<Array.<object>>
string
|number
FileManagerPopup
FileManagerPopup
FileManagerPopup
boolean
FileManagerPopup
FileManagerPopup
FileManagerPopup
new FileManagerPopup(id, title, basePath, [limitToPath], [allowedExtensions], visible)
This class is used to create a popup with a file input to select a file or a directory. It will run a promise with fs.readdir to get the list of files and directories. The user can select a file or a directory and the popup will be closed.
Emits the following events:
string
string
string
boolean
false
Array.<string>
[]
boolean
Example
fileManagerPopup.listDir(path) ⇒
Promise.<Array.<object>>
This function is used to load the list of files and directories in the current path. it return a promise with the list of files and directories. The list is an array of objects like this: [{text: "📄 file.ext", name: "file.ext", type: "file", path: "path/to/file.ext"}, {text: "📁 dir/", name: "dir", type: "dir", path: "path/to/dir"}]
Kind: instance method of
FileManagerPopup
Returns:Promise.<Array.<object>>
- The list of files and directories.string
fileManagerPopup.updateList(path)
This function calls the updateList function and store the result to this.options, it also refresh the list of files and directories.
Kind: instance method of
FileManagerPopup
string
fileManagerPopup.keyListner(str, key)
This function is used to make the ConsoleManager handle the key events when the popup is showed. Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed.
Kind: instance method of
FileManagerPopup
string
Object
fileManagerPopup.getSelected() ⇒
string
|number
This function is used to get the selected option.
Kind: instance method of
FileManagerPopup
Returns:string
|number
- The selected value of the popup.fileManagerPopup.setSelected(selected) ⇒
FileManagerPopup
This function is used to change the selection of the popup. It also refresh the ConsoleManager.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.string
|number
fileManagerPopup.show() ⇒
FileManagerPopup
This function is used to show the popup. It also register the key events and refresh the ConsoleManager.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.fileManagerPopup.hide() ⇒
FileManagerPopup
This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.fileManagerPopup.isVisible() ⇒
boolean
This function is used to get the visibility of the popup.
Kind: instance method of
FileManagerPopup
Returns:boolean
- The visibility of the popup.fileManagerPopup.manageInput() ⇒
FileManagerPopup
This function is used to add the FileManagerPopup key listener callback to te ConsoleManager.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.fileManagerPopup.unManageInput() ⇒
FileManagerPopup
This function is used to remove the FileManagerPopup key listener callback to te ConsoleManager.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.fileManagerPopup.draw() ⇒
FileManagerPopup
This function is used to draw the FileManagerPopup to the screen in the middle.
Kind: instance method of
FileManagerPopup
Returns:FileManagerPopup
- The instance of the FileManagerPopup.CM :
ConsoleManager
the instance of ConsoleManager (singleton)
Kind: global constant