diff --git a/che-theia-init-sources.yml b/che-theia-init-sources.yml index 5c84ea507..dcaa9458d 100644 --- a/che-theia-init-sources.yml +++ b/che-theia-init-sources.yml @@ -17,6 +17,7 @@ sources: - extensions/eclipse-che-theia-file-sync-tracker - extensions/eclipse-che-theia-cli-endpoint - extensions/eclipse-che-theia-workspace + - extensions/eclipse-che-theia-filesystem plugins: - plugins/containers-plugin - plugins/workspace-plugin diff --git a/extensions/eclipse-che-theia-filesystem/.gitignore b/extensions/eclipse-che-theia-filesystem/.gitignore new file mode 100644 index 000000000..ea3d8e091 --- /dev/null +++ b/extensions/eclipse-che-theia-filesystem/.gitignore @@ -0,0 +1,7 @@ +node_modules +.browser_modules +lib +*.log +*-app/* +!*-app/package.json +.idea diff --git a/extensions/eclipse-che-theia-filesystem/package.json b/extensions/eclipse-che-theia-filesystem/package.json new file mode 100644 index 000000000..d27e7ee8d --- /dev/null +++ b/extensions/eclipse-che-theia-filesystem/package.json @@ -0,0 +1,29 @@ +{ + "name": "@eclipse-che/theia-filesystem-extension", + "keywords": [ + "theia-extension" + ], + "version": "0.0.1", + "files": [ + "lib", + "src" + ], + "dependencies": { + "@theia/filesystem": "next" + }, + "scripts": { + "prepare": "yarn clean && yarn build", + "clean": "rimraf lib", + "format": "tsfmt -r --useTsfmt ../../configs/tsfmt.json", + "lint": "eslint --cache=true --no-error-on-unmatched-pattern=true \"{src,test}/**/*.{ts,tsx}\"", + "compile": "tsc", + "build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\"", + "watch": "tsc -w" + }, + "license": "EPL-2.0", + "theiaExtensions": [ + { + "frontend": "lib/browser/che-filesystem-module" + } + ] +} diff --git a/extensions/eclipse-che-theia-filesystem/src/browser/che-filesystem-module.ts b/extensions/eclipse-che-theia-filesystem/src/browser/che-filesystem-module.ts new file mode 100644 index 000000000..7d5f1f9a8 --- /dev/null +++ b/extensions/eclipse-che-theia-filesystem/src/browser/che-filesystem-module.ts @@ -0,0 +1,30 @@ +/********************************************************************* + * Copyright (c) 2020 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +import { ContainerModule } from 'inversify'; +import { LabelProvider, ConfirmDialog } from '@theia/core/lib/browser'; +import { FileShouldOverwrite, FileStat } from '@theia/filesystem/lib/common/filesystem'; +import URI from '@theia/core/lib/common/uri'; + +export default new ContainerModule((bind, unbind, isBound, rebind) => { + rebind(FileShouldOverwrite).toDynamicValue(context => async (file: FileStat, stat: FileStat): Promise => { + if (Math.abs(file.lastModification - stat.lastModification) <= 1) { + return true; + } + + const labelProvider = context.container.get(LabelProvider); + const dialog = new ConfirmDialog({ + title: `The file '${labelProvider.getName(new URI(file.uri))}' has been changed on the file system.`, + msg: `Do you want to overwrite the changes made to '${labelProvider.getLongName(new URI(file.uri))}' on the file system?`, + ok: 'Yes', + cancel: 'No' + }); + return !!await dialog.open(); + }).inSingletonScope(); +}); diff --git a/extensions/eclipse-che-theia-filesystem/tsconfig.json b/extensions/eclipse-che-theia-filesystem/tsconfig.json new file mode 100644 index 000000000..4e68c8fc4 --- /dev/null +++ b/extensions/eclipse-che-theia-filesystem/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../configs/base.tsconfig.json", + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "lib": [ + "es6", + "dom" + ], + "rootDir": "src", + "outDir": "lib" + }, + "include": [ + "src" + ] +} diff --git a/yarn.lock b/yarn.lock index cc291e435..02527438f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2252,7 +2252,7 @@ fuzzy "^0.1.3" vscode-ripgrep "^1.2.4" -"@theia/filesystem@1.4.0-next.89694867": +"@theia/filesystem@1.4.0-next.89694867", "@theia/filesystem@next": version "1.4.0-next.89694867" resolved "https://registry.yarnpkg.com/@theia/filesystem/-/filesystem-1.4.0-next.89694867.tgz#5c21e9515f82667f99f78e7c906c05ad0e22daae" integrity sha512-DW8e+k66zQlODh1y1/wv7qUpe6ZfgdmPtDVsfEtQnxgSgKrYHkKRchxFSwjwSYbGtCjobO/f2LRMHqsBo2tYrA==