//----------------------------------- onOpenFileMenu() { const options = { title: "Open Markdown File", defaultPath: process.env.HOME, filters: [ { name: "Markdown files", extensions: ["md", "markdown"] } ], properties: [ "openFile" ] } if (this.menu.browserWindow) { Dialog.showOpenDialog(this.menu.browserWindow, options, onOpenFileCB) } else { Dialog.showOpenDialog(options, onOpenFileCB) } //----------------------------------- function onOpenFileCB(fileNames) { if (!fileNames) return fileNames.forEach(function(fileName) { main.openFile(fileName) }) } }
ipcMain.on('open-file-dialog', function (event) { dialog.showOpenDialog({ properties: ['openFile'] }, function (files) { if (files) event.sender.send('file-open', files) }) })
WindowsManager.prototype.getFileOrFolderPaths = function (isFolder, clb) { var storageKey = isFolder ? WindowsManager.workingDirFolderPickerStorageKey : WindowsManager.workingDirFilePickerStorageKey; var workingDir = storage.getItem(storageKey); var focussedWindow = this.getFocusedWindow(); var pickerProperties; if (env.isMac) { pickerProperties = ['multiSelections', 'openDirectory', 'openFile', 'createDirectory']; } else { pickerProperties = ['multiSelections', isFolder ? 'openDirectory' : 'openFile', 'createDirectory']; } Dialog.showOpenDialog(focussedWindow && focussedWindow.win, { defaultPath: workingDir, properties: pickerProperties }, function (paths) { if (paths && paths.length > 0) { // Remember path in storage for next time var selectedPath = paths[0]; storage.setItem(storageKey, isFolder ? path.dirname(selectedPath) : selectedPath); // Return clb(paths); } else { clb(void (0)); } }); };
openFile(options) { var dialogOptions = { title: 'OpenFileDialog', properties: [ 'openFile', 'openDirectory', 'multiSelections' ] }; var _this = this; Dialog.showOpenDialog(dialogOptions, function(files){ fs.readFile(files[0], 'utf8', function (err,data) { if (err) { return console.log(err); } else { options.bufferdoc = { path: files[0], content: data }; // Open new window with options.mddoc _this.openWithOptions(options); // Clear buffer doc so new windows don't load with previously opened doc options.bufferdoc = null; } }); }); }
ipc.on('connect', function(e, config) { if(config.type == 'upload') { var options = { title: 'Select a file to upload', properties: [ 'openFile' ] }; config.file_upload = dialog.showOpenDialog(options); if(! config.file_upload) { main.webContents.send('reset', false); return main.webContents.send('status', 'Nothing selected to upload.'); } config.file_upload = config.file_upload.toString(); } terminal.show(); terminal.focus(); if(config.grayscale) terminal.webContents.send('grayscale'); main.setSize(300, 380); main.webContents.send('working', 'Connecting'); ssh_connect(config); });
showDirectoryPickerDialog : function (browserWindow, title, defaultPath, callback) { debug('Within showDirectoryPickerDialog - title: %s, path: %s', title, defaultPath); dialog.showOpenDialog(browserWindow, { title : title, defaultPath : defaultPath, properties : ['openDirectory', 'createDirectory'] }, callback); }
server.addMethod("Dialog-show-open-dialog", function(param, callback) { param = param || {}; var handle = param.handle || -1; var win = handleStore[handle]; var options = param.options || {}; var result = { "selected": Dialog.showOpenDialog(win, options) }; callback(0, result); });
function showOpenDialog() { // Open a dialog so the user can select a Git repository dialog.showOpenDialog(mainWindow, {title: 'Open a repository', properties: ['openDirectory']}, function(folders) { if (typeof(folders) != 'undefined') { loadRepository(folders[0]); } }); }
{ label: "Open", accelerator: "CmdOrCtrl+O", click: function() { dialog.showOpenDialog(mainWindow,{ filters: [ { name: 'Javascript', extensions: ['js'] } ], title:"Open a file", properties:["multiSelections","openFile"] },openFile); } },
function Open() { var opts = {properties: ['openFile']} dialog.showOpenDialog(win, opts, function(paths) { if (!paths) return; var path = paths[0]; var text = fs.readFileSync(path, {encoding: 'utf8'}); win.webContents.send('file:open', path, text); }); }
ipc.on('openFileDialog', function(event, arg) { dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] }, function(filePath) { console.log("filePath = " + filePath); event.sender.send('asynchronous-reply', filePath); }); event.returnValue = "OK"; });
function selectDirectory() { var dialogOptions = { properties: ['openDirectory'] }; dialog.showOpenDialog(mainWindow, dialogOptions, function(filenames) { if (filenames === undefined) return; var path = filenames[0]; mapDirectory(path); }); }
/** open record directory */ function openRecord () { var result = dialog.showOpenDialog({defaultPath:[FILEMACHINE_RECORD_ROOTPATH], properties: ['openDirectory']}); console.log("open in finder がわからん。開くだけなので、なんかアウトプットしないとな。アウトプット先を指定とか。うーーんつらい。制約ができない result:" + result); // /Users/runnershigh/Library/Caches/FileMachine/0 // 実ファイルのパスをひろってくる必要があるのか〜〜。面倒くささがある。 // WebContents.insertCSS(css) mainWindow.webContents.send('ping', '/Users/runnershigh/Desktop/sample/1.jpg'); }
click: function() { var result = Dialog.showOpenDialog({ title: 'Choose Applications Location', properties: ['openDirectory'] }); if(result && result[0]) { mainWindow.webContents.send('appsLocation', result[0]); } }
var dialogBox = function() { dialog.showOpenDialog({ properties: ['openFile']}, function(res) { if (res) { if (res[0].match(/\.md$|\.markdown$/i)) currentFile = res[0]; mainMenu.currentFile = res[0]; mainWindow.webContents.send('open-file', currentFile); } }); };
ipc.on('selectOpenProject', function(event, arg) { console.log('selectOpenProject: ', arg); var paths = dialog.showOpenDialog(mainWindow, { title:"Open Project", filters: [{ name: 'Project files', extensions: ['ngeprj'] }, { name: 'All Files', extensions: ['*'] }], defaultPath: ".", properties: ['openFile'] }); event.returnValue = paths?paths[0]:null; // Protect from 'undefined' causing Electron error });
return new Promise(function (resolve) { dialog.showOpenDialog({title: '打开文件', properties: ['openFile']}, function (data) { if (data && data.length) { if (file && file !== data[0]) { mdfile.emit('close', file); } mdfile.emit('open', data[0]); resolve(data[0]); } }); });
function importServers() { info("importServers") var dialog = require('dialog'); dialog.showOpenDialog({ properties: ['openFile'] }, function(files) { if (!files) return; const file = files[0]; info("selected file: " + file); configManager.importServers(files[0]); autoshadow.run(); }); }
function loadProject() { var files = dialog.showOpenDialog({ properties: ['openFile'], title: 'Open Invoker config file' }); if (Array.isArray(files)) { invoker.start(files[0], function(error, stdout, stderr) { if (!error) { console.log('invoker started'); } else { console.log(error); } }); } }
openFile: function (cb) { dialog.init() dialogLib.showOpenDialog({ properties: ['openFile', 'multiSelections'], filters: [{ name: 'Images', extensions: ['jpg', 'png', 'jpeg'] }] }, function (files) { if (files) { dialog.path = files[0].substr(0, files[0].lastIndexOf('/')) } cb(files || []) }) },
function openFile() { var options = { properties: ["openFile", "multiSelections"], filters: [ { name: "Log Files", extensions: ['log'] } ] } function callback(paths) { paths.forEach(function(path) { var stream = fs.createReadStream(path); var logfile = new LogFile(stream); logfile.on("error", function() { console.log("boom!"); console.log(arguments); }); mainWindow.webContents.send("open-file", path, logfile); }); } dialog.showOpenDialog(options, callback) }
importFile() { dialog.showOpenDialog({ title: 'Select file to import', properties: ['openFile'], filters: [{ name: 'Markdown', extensions: ['md', 'markdown'] }], }, filePath => { if (filePath) { fs.readFile(filePath[0], 'utf8', (err, data) => { if (err) { return console.log(err); }else{ this.mainWindow.sendData('fileContent', data); } }); } }); }
click: function() { var fileArray = dialog.showOpenDialog({ properties: ['openFile'], filters: [{ name: 'Markdown', extensions: ['md'] }], }); // Since we do not have multiple selections enabled, only take first // item in first index if (fileArray != undefined && fileArray.length !== 0) { filename = fileArray[0]; filenameArr = filename.split('.'); // Extension is really not needed, but I'll leave it here for now. extension = filenameArr[1]; } else { // error('danger', "There was a problem."); // Opening was probably aborted console.log("Well, there seems to be a problem with the file array"); return; } console.log(filename); if (filename == undefined) { error('danger', "<strong>Uh-Oh!</strong> The file could not be opened."); // dialog.showErrorBox("Uh-Oh!", "The file could not be opened. -1"); } else { try { var data = fs.readFile(filename, 'utf8', function(err, data) { if (err) { error('danger', "<strong>Uh-Oh!</strong> The file could not be opened."); throw err; } if (mainWindow.send('fileContent', data)) { mainWindow.send('extension', extension); } mainWindow.setTitle(filename + " | Proton"); }); } catch (err) { // dialog.showErrorBox("Uh-Oh!", "The file could not be opened. -2"); error('danger', "<strong>Uh-Oh!</strong> The file could not be opened."); console.log(err); } } }
ipc.on('synchronous-message', function(event, arg) { var title = arg.title, action = arg.action, filters = arg.filters; switch (action) { case 'openFile': console.log('Open file'); try { event.returnValue = dialog.showOpenDialog(mainWindow, { title: title, properties: [ 'openFile', ], filters: filters, }); } catch (err) { console.error(err); event.returnValue = null; } break; case 'saveFile': console.log('Save file'); try { event.returnValue = dialog.showSaveDialog(mainWindow, { title: title, filters: filters, }); } catch (err) { console.error(err); event.returnValue = null; } break; } })
ipc.on('setup-browse-path', () => { dialog.showOpenDialog(welcomeWindow, { title: 'Select a directory', defaultPath: path, properties: [ 'openDirectory', 'createDirectory' ] }, (res) => { if (!res) return userPath = res[0] if (!userPath.match(/.ipfs\/?$/)) { userPath = join(userPath, '.ipfs') } ipc.send('setup-config-path', userPath) }) })
click: function () { dialog.showOpenDialog({ title: 'Open File or Files', defaultPath: process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], properties: ['openFile', 'multiSelections', 'createDirectory'], filters: [ { name: 'All', extensions: ['md', 'markdown', 'MD', 'txt', 'TXT' ]}, { name: 'Markdown', extensions: ['md', 'markdown', 'MD' ]}, { name: 'Plaintext', extensions: ['txt', 'TXT' ]} ] }, function(filenames) { if (filenames) { for (var i = 0, length = filenames.length; i < length; i++) { var filename = filenames[i]; var data = fs.readFileSync(filename); var stats = fs.statSync(filename); mainWindow.webContents.send('editor-text',{ filename: filename, contents: data.toString(), timestamp: stats.mtime }); } } }); }
click: function () { var win = getWindow(); dialog.showOpenDialog(win, { defaultPath: jsbinStoragePath, properties: ['openDirectory'] }, function (filenames) { var filepath = filenames && filenames[0], isValid = filepath && filepath.indexOf(jsbinStoragePath) === 0; // Dialog cancelled if (!filepath) { return; } win.webContents.send('command', { command: 'file:open', name: path.basename(filepath), path: filepath, isValid: isValid }); }); }
MainMenu.prototype.openFileClick = function() { var mainMenu = this; dialog.showOpenDialog({ properties: ['openFile']}, function(res) { enableSave(); }); };
ipc.on('open-file-dialog', function (event) { var files = dialog.showOpenDialog(mainWindow, { properties: [ 'openFile', 'openDirectory' ]}) if (files) { event.sender.send('selected-directory', files) } })
ipc.on('application:open-sync-resource', (event, options) => { event.returnValue = dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), options) || []; });