popups-file-dialog
v1.6.2
Published
popups file dialog build in c on top of lib called tinyfiledialogs and ported for node
Downloads
20
Maintainers
Readme
Popups File Dialog
This is a simple file dialog 0 dependencies for windows, linux and macos.build on library in c language called tinyfiledialogs. sence it is build in c , so this lib is super fast unlike any library build in python i saw on npm
now listen, sense node is not natively have a file dialog so i build this lib as a wrapper for the (tinyfiledialogs library build in c). i made the cli version of the tinyfiledialogs library. after that i build this lib as a wrapper for the cli version of the tinyfiledialogs library. i did think of making the tinyfiledialogs library as a node addon, but this is too much work. so i go for the easy way, and make the cli version of the tinyfiledialogs library. still have a lot of work to do i recently build the lib for windows and linux i am to lazy to download macos and build the lib for macos so if you have a macos and want to help me build the lib for macos feel free to contribute to this lib. compile and test the lib/vendors/src/cli.c for macos
demo
const fileDialog = require("popups-file-dialog");
(async () => {
const result = await fileDialog.openFile({
title: 'Open File',
startPath: './',
filterPatterns: ['*'],
filterPatternsDescription: 'all files',
allowMultipleSelects: true,
})
console.log(result);
})();
windows:
linux:
(async () => {
const result = await fileDialog.openDirectory({
title: "select folder please",
})
console.log(result);
})();
windows:
linux:
Installation
npm install popups-file-dialog
yarn add popups-file-dialog
or
git clone https://github.com/native-toolkit/popups-file-dialog.git
cd popups-file-dialog
Change log
1.6.0
- added the saveFile method
- fixed the startPath option for supporting directories with spaces in the name
- some formatting and refactoring
1.5.1
- add support for linux (finally)
- fixed some bugs (a lot of bugs)
- added the openDirectory method to select a folder
- some formatting and refactoring
Usage
const fileDialog = require("../file-dialog");
const main = async () => {
console.log(fileDialog.config.vendorPath); // check for the path of the vendor folder if the os is supported
const result = await fileDialog.openFile({
title: "Open File",
startPath: "C:\\Users\\",
filterPatterns: ["*.exe", "*.txt"],
filterPatternsDescription: "exe files,txt files",
allowMultipleSelects: true,
});
console.log(result);
const result2 = await fileDialog.messageBox({
title: "Message Box",
message: "Hello World",
dialogType: "yesNoCancel",
iconType: "info",
defaultSelected: "yes",
});
console.log(result2);
};
main();
table of content
API
fileDialog.config
super important, and big object, that contain all the config of the lib all the flags with the commands and the path of the vendor folder part of it:
config = {
vendorPath: path.join(
__dirname,
"lib",
"vendors",
"bin",
`${process.platform}${process.platform === "win32" ? ".exe" : ".app"}`
),
availableCommand: {
open: {
name: "-open-file",
flags: {
title: {
name: "--title",
defaultValue: "open",
},
startPath: {
name: "--startPath",
defaultValue: path.resolve("./"),
},
filterPatterns: {
name: "--filterPatterns",
defaultValue: "*",
},
filterPatternsDescription: {
name: "--filterPatternsDescription",
defaultValue: "",
},
allowMultipleSelects: {
name: "--allowMultipleSelects",
defaultValue: "0",
},
},
},
},
};
fileDialog.openFile(options)
open file dialog menu
example :
multiple select example:
const result = await fileDialog.openFile({
title: "Open File",
startPath: "./",
filterPatterns: ["*"],
filterPatternsDescription: "all files",
allowMultipleSelects: true
})
console.log(result);
image on windows 10:
expected result:
[
'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\.gitignore',
'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\.npmignore',
'C:\\Users\\pc\\Desktop\\workingdir\\projects\\popups-file-dialog\\file-dialog.js'
]
options
| option | type | default | description |example| | --- | --- | --- | --- |--- | | title |string| "open" | title of the dialog | "Open File" | | startPath | string | path.resolve("./") | start path of the dialog | "C:\Users\" | | filterPatterns | string[] | ["*"] | filter patterns of the dialog | ["*.exe", "*.txt"] | | filterPatternsDescription | string | "" | filter patterns description of the dialog | "exe files,txt files" | | allowMultipleSelects | boolean | false | allow multiple selects of the dialog | true |
fileDialog.saveFile(options)
save file dialog menu
example :
const result5 = await fileDialog.saveFile({
title: 'Save File',
startPath: 'C:\\Users\\pc\\Desktop\\New folder (36)\\test.txt',
filterPatterns: ['*'],
filterPatternsDescription: "all",
})
console.log(result5)
image on windows 10:
expected result:
"C:\\Users\\pc\\Desktop\\New folder (36)\\test.txt"
options
| option | type | default | description |example| | --- | --- | --- | --- |--- | | title |string| "save" | title of the dialog | "Save File" | | startPath | string | path.resolve("./default.txt") | start path and file name | "C:\Users\someFile.txt" | | filterPatterns | string[] | ["*"] | filter patterns of the dialog | ["*.exe", "*.txt"] | | filterPatternsDescription | string | "" | filter patterns description of the dialog | "exe files,txt files" |
fileDialog.openDirectory(options)
open folder dialog menu
example :
const result = await fileDialog.openDirectory({
title: "Message Box",
})
console.log(result);
image on windows 10:
expected result:
"C:\\Users\\pc\\Documents\\Adobe"
options
| option | type | default | description |example| | --- | --- | --- | --- |--- | | title |string| "open" | title of the dialog | "Open Folder" |
fileDialog.messageBox(options)
promote message box
example 1:
const result = await fileDialog.messageBox({
title: "Message Box",
message: "Hello World",
dialogType: "yesNoCancel",
iconType: "info",
defaultSelected: "yes"
})
console.log(result);
image on windows 10:
expected result:
yes -> 1
no -> 2
cancel -> 0
example 2:
const result = await fileDialog.messageBox({
title: "Message Box",
message: "Hello World",
dialogType: "okCancel",
iconType: "info",
defaultSelected: "ok"
})
console.log(result);
expected result:
ok -> 1
cancel -> 0
example 3:
const result = await fileDialog.messageBox({
title: "Message Box",
message: "Hello World",
dialogType: "yesNo",
iconType: "info",
defaultSelected: "ok"
})
console.log(result);
expected result:
yes -> 1
no -> 0
options
| option | type | default | description |example| available options | | --- | --- | --- | --- |--- | --- | | title |string| "message" | title of the dialog | "Message Box" | | | message | string | "message" | message of the dialog | "Hello World" | | | dialogType | string | "ok" | dialog type of the dialog | "okCancel" | "ok", "okCancel", "yesNo", "yesNoCancel" | | iconType | string | "info" | icon type of the dialog | "info" | "info", "warning", "error","question" | | defaultSelected | string | "ok" | default selected of the dialog | "ok" | "ok", "cancel", "yes", "no" |