Skip to content

Commit 28259e3

Browse files
bunsenstraatAniket-Engg
authored andcommitted
betacookbookfix
1 parent 87259be commit 28259e3

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

apps/remix-ide-e2e/src/tests/fileManager_api.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ module.exports = {
4242
})
4343
},
4444

45+
'Should execute `writeMultipleFiles` api from file manager external api #group1': function (browser: NightwatchBrowser) {
46+
browser
47+
.addFile('writeMultipleFiles.js', { content: executeWriteMultipleFiles })
48+
.executeScriptInTerminal('remix.exeCurrent()')
49+
.pause(2000)
50+
.openFile('contracts/new_contract_1.sol')
51+
.getEditorValue((content) => {
52+
browser.assert.ok(content.indexOf('pragma solidity ^0.6.0') !== -1, 'content does not contain "pragma solidity ^0.6.0"')
53+
})
54+
.openFile('new_contract_2.sol')
55+
.getEditorValue((content) => {
56+
browser.assert.ok(content.indexOf('pragma solidity ^0.8.0') !== -1, 'content does not contain "pragma solidity ^0.8.0"')
57+
})
58+
.openFile('testing.txt')
59+
.getEditorValue((content) => {
60+
browser.assert.ok(content.indexOf('test') !== -1, 'content does not contain "test"')
61+
})
62+
},
63+
4564
'Should execute `readFile` api from file manager external api #group2': function (browser: NightwatchBrowser) {
4665
browser
4766
.addFile('writeFile.js', { content: executeWriteFile })
@@ -143,6 +162,14 @@ const executeWriteFile = `
143162
run()
144163
`
145164

165+
const executeWriteMultipleFiles = `
166+
const run = async () => {
167+
await remix.call('fileManager', 'writeMultipleFiles', ['contracts/new_contract_1.sol', 'new_contract_2.sol', 'testing.txt'], ['pragma solidity ^0.6.0', 'pragma solidity ^0.8.0', 'test'], '/')
168+
}
169+
170+
run()
171+
`
172+
146173
const executeReadFile = `
147174
const run = async () => {
148175
const result = await remix.call('fileManager', 'readFile', 'new_contract.sol')
@@ -204,4 +231,4 @@ const executeRemoveOnFolder = `(async () => {
204231
} catch (e) {
205232
console.log(e.message)
206233
}
207-
})()`
234+
})()`

apps/remix-ide/src/app/files/fileManager.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,25 @@ class FileManager extends Plugin {
225225
* @param {string} folderPath base folder path
226226
* @returns {void}
227227
*/
228-
async writeMultipleFiles(filePaths, fileData, folderPath) {
228+
async writeMultipleFiles(filePaths: string[], fileData: string[], folderPath: string) {
229+
if (this.currentRequest) {
230+
const canCall = await this.askUserPermission(`writeFile`, `will write multiple files to ${folderPath}...`)
231+
const required = this.appManager.isRequired(this.currentRequest.from)
232+
if (canCall && !required) {
233+
this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, folderPath))
234+
}
235+
}
229236
try {
230-
let alert = true
231237
for (let i = 0; i < filePaths.length; i++) {
232238
const installPath = folderPath + "/" + filePaths[i]
233239

234240
let path = this.normalize(installPath)
235241
path = this.limitPluginScope(path)
236242

237-
if (await this.exists(path)) {
238-
await this._handleIsFile(path, `Cannot write file ${path}`)
239-
await this.setMultipleFileContent(path, fileData[i], folderPath, alert)
240-
} else {
241-
await this.setMultipleFileContent(path, fileData[i], folderPath, alert)
243+
if (!await this.exists(path)) {
244+
await this._setFileInternal(path, fileData[i])
242245
this.emit('fileAdded', path)
243246
}
244-
alert = false
245247
}
246248
} catch (e) {
247249
throw new Error(e)
@@ -603,18 +605,6 @@ class FileManager extends Plugin {
603605
return await this._setFileInternal(path, content)
604606
}
605607

606-
async setMultipleFileContent(path, content, folderPath, alert) {
607-
if (this.currentRequest) {
608-
const canCall = await this.askUserPermission(`writeFile`, `modifying ${folderPath} ...`)
609-
const required = this.appManager.isRequired(this.currentRequest.from)
610-
if (canCall && !required && alert) {
611-
// inform the user about modification after permission is granted and even if permission was saved before
612-
this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, folderPath))
613-
}
614-
}
615-
return await this._setFileInternal(path, content)
616-
}
617-
618608
_setFileInternal(path, content) {
619609
const provider = this.fileProviderOf(path)
620610
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` })

0 commit comments

Comments
 (0)