Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Rebind overwrite dialog by adding check for modification time bias (#862
Browse files Browse the repository at this point in the history
)

Rebind overwrite dialog by adding check for modification time bias

Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
  • Loading branch information
vzhukovs authored Sep 17, 2020
1 parent bb61966 commit f2d1ca6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions che-theia-init-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions extensions/eclipse-che-theia-filesystem/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.browser_modules
lib
*.log
*-app/*
!*-app/package.json
.idea
29 changes: 29 additions & 0 deletions extensions/eclipse-che-theia-filesystem/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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<boolean> => {
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();
});
15 changes: 15 additions & 0 deletions extensions/eclipse-che-theia-filesystem/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../configs/base.tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": [
"es6",
"dom"
],
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit f2d1ca6

Please sign in to comment.