import addon from "../utils/addon"; import { QWidget } from "./QWidget"; import { NativeElement } from "../core/Component"; import { AcceptMode, DialogLabel, FileMode, Option, ViewMode, } from "../QtEnums"; import { QDialog, QDialogSignals } from "./QDialog"; import { wrapperCache } from "../core/WrapperCache"; import { checkIfNativeElement } from "../utils/helpers"; /** > Create and control file dialogs. * **This class is a JS wrapper around Qt's [QFileDialog class](https://doc.qt.io/qt-5/qfiledialog.html)** A `QFileDialog` class provides a dialog that allow users to select files or directories. ### Example ```javascript import { QFileDialog } from "@vixen-js/core"; const fileDialog = new QFileDialog(); fileDialog.setFileMode(FileMode.AnyFile); fileDialog.setNameFilter('Images (*.png *.xpm *.jpg)'); fileDialog.exec(); const selectedFiles = fileDialog.selectedFiles(); console.log(selectedFiles); ``` */ export class QFileDialog extends QDialog { constructor(); constructor( parent: QWidget, caption?: string, directory?: string, filter?: string ); constructor( arg?: QWidget, caption = "Select File", directory = "", filter = "" ) { let native: NativeElement; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (arg != null) { native = new addon.QFileDialog(arg.native, caption, directory, filter); } else { native = new addon.QFileDialog(); } super(native); } supportedSchemes(): string[] { return this.native?.supportedSchemes(); } setSupportedSchemes(schemes: string[]): void { this.native?.setSupportedSchemes(schemes); } setNameFilter(filter: string): void { this.native?.setNameFilter(filter); } selectedFiles(): string[] { return this.native?.selectedFiles(); } labelText(label: DialogLabel): string { return this.native?.labelText(label); } setLabelText(label: DialogLabel, text: string): void { this.native?.setLabelText(label, text); } setOption(option: Option, on = true): void { this.native?.setOption(option, on); } acceptMode(): AcceptMode { return this.property("acceptMode").toInt(); } defaultSuffix(): string { return this.property("defaultSuffix").toString(); } fileMode(): FileMode { return this.property("fileMode").toInt(); } options(): Option { return this.property("options").toInt(); } viewMode(): ViewMode { return this.property("viewMode").toInt(); } setAcceptMode(acceptMode: AcceptMode): void { this.setProperty("acceptMode", acceptMode); } setDefaultSuffix(defaultSuffix: string): void { this.setProperty("defaultSuffix", defaultSuffix); } setFileMode(fileMode: FileMode): void { this.setProperty("fileMode", fileMode); } setOptions(options: Option): void { this.setProperty("options", options); } } wrapperCache.registerWrapper("QFileDialogWrap", QFileDialog); export interface QFileDialogSignals extends QDialogSignals { onCurrentChange: (path: string) => void; onCurrentUrlChange: (url: string) => void; onDirectoryEnter: (directory: string) => void; onDirectoryUrlEnter: (url: string) => void; onFileSelect: (file: string) => void; onFilesSelect: (selected: string[]) => void; onFilterSelect: (filter: string) => void; onUrlSelect: (url: string) => void; onUrlsSelect: (urls: string[]) => void; }