From 2139f2c398e55795749195fc36883d26d1f8b81b Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 30 Nov 2022 10:09:58 +0100 Subject: [PATCH 1/4] fixing readonly access with remixd --- apps/remix-ide/src/app/editor/editor.js | 10 +++++----- apps/remix-ide/src/app/files/fileManager.ts | 4 +++- libs/remix-ui/editor/src/lib/remix-ui-editor.tsx | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 4876e0618f..4183f2ec3a 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -220,7 +220,7 @@ class Editor extends Plugin { if (pathExists) { contentDep = await readFile(pathDep) if (contentDep !== '') { - this.emit('addModel', contentDep, 'typescript', pathDep, false) + this.emit('addModel', contentDep, 'typescript', pathDep, this.readOnlySessions[path]) } } else { console.log("The file ", pathDep, " can't be found.") @@ -241,7 +241,7 @@ class Editor extends Plugin { async _createSession (path, content, mode) { if (!this.activated) return - this.emit('addModel', content, mode, path, false) + this.emit('addModel', content, mode, path, this.readOnlySessions[path]) return { path, language: mode, @@ -266,7 +266,7 @@ class Editor extends Plugin { } addModel(path, content) { - this.emit('addModel', content, this._getMode(path), path, false) + this.emit('addModel', content, this._getMode(path), path, this.readOnlySessions[path]) } /** @@ -301,9 +301,9 @@ class Editor extends Plugin { - URL not prepended with the file explorer. We assume (as it is in the whole app, that this is a "browser" URL */ if (!this.sessions[path]) { + this.readOnlySessions[path] = false const session = await this._createSession(path, content, this._getMode(path)) this.sessions[path] = session - this.readOnlySessions[path] = false } else if (this.sessions[path].getValue() !== content) { this.sessions[path].setValue(content) } @@ -317,9 +317,9 @@ class Editor extends Plugin { */ async openReadOnly (path, content) { if (!this.sessions[path]) { + this.readOnlySessions[path] = true const session = await this._createSession(path, content, this._getMode(path)) this.sessions[path] = session - this.readOnlySessions[path] = true } this._switchSession(path) } diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index d6f5fd9e4b..de661ec0af 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -19,7 +19,9 @@ const profile = { icon: 'assets/img/fileManager.webp', permission: true, version: packageJson.version, - methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', 'readdir', 'dirList', 'fileList', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles', 'isGitRepo'], + methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', + 'readdir', 'dirList', 'fileList', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', + 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles', 'isGitRepo'], kind: 'file-system' } const errorMsg = { diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index b91194de2c..46428d3c83 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -671,7 +671,6 @@ export const EditorUI = (props: EditorUIProps) => { monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco)) monacoRef.current.languages.registerCompletionItemProvider('remix-solidity', new RemixCompletionProvider(props, monaco)) - loadTypes(monacoRef.current) } @@ -683,7 +682,7 @@ export const EditorUI = (props: EditorUIProps) => { language={editorModelsState[props.currentFile] ? editorModelsState[props.currentFile].language : 'text'} onMount={handleEditorDidMount} beforeMount={handleEditorWillMount} - options={{ glyphMargin: true, readOnly: (!editorRef.current || !props.currentFile) }} + options={{ glyphMargin: true, readOnly: ((!editorRef.current || !props.currentFile) && editorModelsState[props.currentFile]?.readOnly) }} defaultValue={defaultEditorValue} /> From 6ca1d64508b67c168a015d72ba018782a7be4827 Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 30 Nov 2022 11:05:27 +0100 Subject: [PATCH 2/4] added info line about readonly mode --- apps/remix-ide/src/app/tabs/settings-tab.tsx | 18 +++++++++--------- .../editor/src/lib/remix-ui-editor.tsx | 6 +++++- .../src/lib/remix-ui-locale-module.tsx | 6 ++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/settings-tab.tsx b/apps/remix-ide/src/app/tabs/settings-tab.tsx index c0d2e7d072..c92a0e423e 100644 --- a/apps/remix-ide/src/app/tabs/settings-tab.tsx +++ b/apps/remix-ide/src/app/tabs/settings-tab.tsx @@ -53,19 +53,19 @@ module.exports = class SettingsTab extends ViewPlugin { render() { return
- -
+ + } updateComponent(state: any){ return + config={state.config} + editor={state.editor} + _deps={state._deps} + useMatomoAnalytics={state.useMatomoAnalytics} + themeModule = {state._deps.themeModule} + localeModule={state._deps.localeModule} + /> } renderComponent () { diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 46428d3c83..0f0d76d29c 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -685,7 +685,11 @@ export const EditorUI = (props: EditorUIProps) => { options={{ glyphMargin: true, readOnly: ((!editorRef.current || !props.currentFile) && editorModelsState[props.currentFile]?.readOnly) }} defaultValue={defaultEditorValue} /> - + {editorModelsState[props.currentFile]?.readOnly && + + The file is opened in read-only mode. + + } ) } diff --git a/libs/remix-ui/locale-module/src/lib/remix-ui-locale-module.tsx b/libs/remix-ui/locale-module/src/lib/remix-ui-locale-module.tsx index 0e68991102..aebda165a9 100644 --- a/libs/remix-ui/locale-module/src/lib/remix-ui-locale-module.tsx +++ b/libs/remix-ui/locale-module/src/lib/remix-ui-locale-module.tsx @@ -15,9 +15,11 @@ export function RemixUiLocaleModule({ localeModule }: RemixUiLocaleModuleProps) }, [localeName, localeModule]) return ( -
+
-
+
+ +
{localeModule.getLocales() ? localeModule.getLocales().map((locale, idx) => ( From d93c26259b1e2447bbead00b31d250f1a764d94f Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 30 Nov 2022 12:05:10 +0100 Subject: [PATCH 3/4] added Readonly label to File Explorer --- apps/remix-ide/src/app/plugins/file-decorator.ts | 2 -- libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/file-decorator.ts b/apps/remix-ide/src/app/plugins/file-decorator.ts index c81c1894ff..31aaf109be 100644 --- a/apps/remix-ide/src/app/plugins/file-decorator.ts +++ b/apps/remix-ide/src/app/plugins/file-decorator.ts @@ -12,7 +12,6 @@ const profile = { events: ['fileDecoratorsChanged'], version: '0.0.1' } - export class FileDecorator extends Plugin { private _fileStates: fileDecoration[] = [] constructor() { @@ -26,7 +25,6 @@ export class FileDecorator extends Plugin { } /** - * * @param fileStates Array of file states */ async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index d76f21a1fa..a4247b9c8a 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -350,6 +350,10 @@ export function Workspace () { ) } + const formatNameForReadonly = (name: string) => { + return global.fs.readonly ? name + " (Read-only)" : name + } + const cloneModalMessage = () => { return ( <> @@ -607,7 +611,7 @@ export function Workspace () { - { selectedWorkspace ? selectedWorkspace.name : currentWorkspace === LOCALHOST ? 'localhost' : NO_WORKSPACE } + { selectedWorkspace ? selectedWorkspace.name : currentWorkspace === LOCALHOST ? formatNameForReadonly("localhost") : NO_WORKSPACE } From 10d6dceb6677d9c5f3912746a9ead74f6810f311 Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 30 Nov 2022 14:44:40 +0100 Subject: [PATCH 4/4] Read-only -> read-only --- libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index a4247b9c8a..dad84a3581 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -351,7 +351,7 @@ export function Workspace () { } const formatNameForReadonly = (name: string) => { - return global.fs.readonly ? name + " (Read-only)" : name + return global.fs.readonly ? name + " (read-only)" : name } const cloneModalMessage = () => {