本文整理汇总了TypeScript中electron.dialog.showOpenDialog方法的典型用法代码示例。如果您正苦于以下问题:TypeScript dialog.showOpenDialog方法的具体用法?TypeScript dialog.showOpenDialog怎么用?TypeScript dialog.showOpenDialog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.dialog
的用法示例。
在下文中一共展示了dialog.showOpenDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
click: (item: Electron.MenuItem, focusedWindow: Electron.BrowserWindow) => {
const options: Electron.OpenDialogOptions = { properties: ["openDirectory"] };
dialog.showOpenDialog(options, (dirnames) => {
if (dirnames) {
focusedWindow.webContents.send("openDir", dirnames[0]);
}
});
}
示例2: function
ipcMain.on("open-output-directory-dialog", (event: Electron.IpcMessageEvent) => {
dialog.showOpenDialog({
properties: ["openDirectory"]
}, function (dirs:string[]) {
if (dirs) {
event.sender.send("selected-output-directory", dirs[0]);
}
});
}
示例3: resolve
const promise = new ItchPromise<string>((resolve, reject) => {
const callback = (response: string[]) => {
if (!response) {
return resolve();
}
return resolve(response[0]);
};
dialog.showOpenDialog(nativeWindow, dialogOpts, callback);
});
示例4:
ipcMain.on('open-project', (event) => {
dialog.showOpenDialog({
title: 'Open Project',
properties: ['openDirectory', 'createDirectory']
}, folders => {
if (folders && folders.length > 0) {
event.sender.send('open-project', folders);
}
});
});
示例5: showOpenDialog
export function showOpenDialog() {
dialog.showOpenDialog({
title: 'Open Fiddle',
properties: ['openDirectory']
}, (filePaths) => {
if (!filePaths || filePaths.length < 1) {
return;
}
ipcMainManager.send(IpcEvents.FS_OPEN_FIDDLE, [ filePaths[0] ]);
});
}
示例6: openScheduleFileDialog
function openScheduleFileDialog() {
if (window) {
dialog.showOpenDialog(mainWindow, {
filters: [{ name: 'Schedules', extensions: ['json']}],
properties: ['openFile'],
}, (filenames: string[]) => {
if (filenames && filenames[0]) {
openScheduleFromFile(filenames[0]);
}
});
}
}
示例7: function
open: function () {
var options = {
title: 'Message from callback',
type: 'info',
buttons: ['OK', 'Cancel'],
message: 'Callback passs',
detail: "ssss"
};
const {dialog} = require('electron');
dialog.showOpenDialog(BrowserWindow,options);
}
示例8: onChooseFolder
function onChooseFolder(event: Electron.IpcMainEvent, secretKey: string, ipcId: string, origin: string) {
if (secretKeys.get(event.sender) !== secretKey) return;
electron.dialog.showOpenDialog({ properties: [ "openDirectory" ] }, (directory: string[]) => {
if (directory == null) { event.sender.send("choose-folder-callback", ipcId, null); return; }
const normalizedPath = path.normalize(directory[0]);
getAuthorizationsForOrigin(origin).folders.push(normalizedPath);
event.sender.send("choose-folder-callback", ipcId, normalizedPath);
});
}
示例9:
ipcMain.on('open-file', (event) => {
dialog.showOpenDialog(mainWindow, {
title: "Open Image",
filters: [
{ name: 'Images', extensions: ['png', 'jpg', 'gif', 'pdd'] },
],
properties: ["multiSelections", "openFile"]
}, files => {
if (files && files.length > 0) {
event.sender.send('opened-files', files);
}
});
});
示例10: onChooseExportFolder
function onChooseExportFolder(event: Electron.IPCMainEvent) {
electron.dialog.showOpenDialog({ properties: ["openDirectory"] }, (directory: string[]) => {
if (directory == null) return;
const outputFolder = directory[0];
let isFolderEmpty = false;
try { isFolderEmpty = fs.readdirSync(outputFolder).length === 0; }
catch (e) { event.sender.send("export-folder-failed", `Error while checking if folder was empty: ${e.message}`); return; }
if (!isFolderEmpty) { event.sender.send("export-folder-failed", "Output folder must be empty."); return; }
event.sender.send("export-folder-success", outputFolder);
});
}
示例11: onChooseFolder
function onChooseFolder(event: Electron.IpcMainEvent) {
electron.dialog.showOpenDialog({ properties: [ "openDirectory" ] }, (directory: string[]) => {
if (directory == null) { event.sender.send("choose-folder-callback", null, null); return; }
const outputFolder = directory[0];
let isFolderEmpty = false;
try { isFolderEmpty = fs.readdirSync(outputFolder).length === 0; }
catch (e) { event.sender.send("choose-folder-callback", `Error while checking if folder is empty: ${e.message}`, null); return; }
if (!isFolderEmpty) { event.sender.send("choose-folder-callback", "Folder must be empty.", null); return; }
event.sender.send("choose-folder-callback", null, outputFolder);
});
}
示例12: onChooseFile
function onChooseFile(event: Electron.IpcMainEvent, secretKey: string, ipcId: string, origin: string, access: "readWrite"|"execute") {
if (secretKeys.get(event.sender) !== secretKey) return;
electron.dialog.showOpenDialog({ properties: [ "openFile" ] }, (file: string[]) => {
if (file == null) { event.sender.send("choose-file-callback", ipcId, null); return; }
const normalizedPath = path.normalize(file[0]);
const auths = getAuthorizationsForOrigin(origin);
if (access === "execute") auths.exeFiles.push(normalizedPath);
else auths.rwFiles.push(normalizedPath);
event.sender.send("choose-file-callback", ipcId, normalizedPath);
});
}
示例13:
export const openVideoDialog = (webContents: Electron.WebContents) => {
const paths = dialog.showOpenDialog({
filters: videoFilters,
properties: ['openFile'],
});
if (!Array.isArray(paths) || paths.length === 0) {
return;
}
if (paths.length > 1) {
console.log('only support one file');
}
webContents.send('open-video', paths[0]);
};
示例14: download
ipcMain.on('download-file-message', (event, args) => {
console.log(args) // prints "ping"
event.sender.send('download-file-reply', 'pong');
var folderPaths = dialog.showOpenDialog({ properties: ['openDirectory'] });
console.log(folderPaths);
if (folderPaths.length > 0) {
download(BrowserWindow.getFocusedWindow(), args.url, {
directory: folderPaths[0],
filename: args.fileName
})
.then(dl => console.log(dl.getSavePath()))
.catch(console.error);
}
})
示例15: switch
ipcMain.on('action', (event: any, args: [AppState, AppAction]) => {
const action = args[1];
switch (action.type) {
case FolderActionType.BrowseForFolder:
dialog.showOpenDialog(mainWindow!, { properties: ['openDirectory', 'createDirectory'] }, paths => {
event.sender.send('action', setFolderPath(paths[0]));
});
break;
case FolderFormActionType.SetFolderPath:
case FolderFormActionType.SetRemotePath:
case FolderActionType.AddFolder:
case FolderActionType.DeleteFolder:
case FolderActionType.UpdateFolderStatus:
saveStore(args[0]);
break;
}
});