Skip to content

Commit

Permalink
Prevent accidental deletions on renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
juanlao7 committed Jan 23, 2021
1 parent 5f42067 commit feb15f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client/apps/remolacha.Files/src/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export class ContextMenu extends React.Component<ContextMenuProps, ContextMenuSt

private onNewFileMenuItemClick() {
this.props.onClose();
this.props.files.createNewFile();
this.props.files.openNewFileDialog();
}

private onNewDirectoryMenuItemClick() {
this.props.onClose();
this.props.files.createNewDirectory();
this.props.files.openNewDirectoryDialog();
}

private onOpenFileMenuItemClick() {
Expand Down
25 changes: 13 additions & 12 deletions client/apps/remolacha.Files/src/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ export class Files extends React.Component<FilesProps, FilesState> {
this.setState({selected: selected});
}

openDeleteDialog() {
this.setState({deleteNames: [...this.state.selected.keys()]});
openNewFileDialog() {
this.setState({newElementName: 'file'});
}

openRenameDialog() {
this.setState({renameName: this.state.selected.keys().next().value});
openNewDirectoryDialog() {
this.setState({newElementName: 'directory'});
}

createNewFile() {
this.setState({newElementName: 'file'});
openDeleteDialog() {
this.setState({deleteNames: [...this.state.selected.keys()]});
}

createNewDirectory() {
this.setState({newElementName: 'directory'});
openRenameDialog() {
this.setState({renameName: this.state.selected.keys().next().value});
}

private onLocationInputChange(e : React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) {
Expand Down Expand Up @@ -259,11 +259,12 @@ export class Files extends React.Component<FilesProps, FilesState> {
});
}

private async onRenameDialogCloseImpl(newName : string) {
private async onRenameDialogCloseImpl(newName : string, overwrite : boolean) {
try {
await this.props.appInstance.callBackend('move', {
from: this.resolvePath(this.state.renameName),
to: this.resolvePath(newName)
to: this.resolvePath(newName),
overwrite: overwrite
});

this.setState({
Expand All @@ -288,7 +289,7 @@ export class Files extends React.Component<FilesProps, FilesState> {
this.setState({dialogLoading: true});

if (this.getElementByName(newName) == null) {
this.onRenameDialogCloseImpl(newName);
this.onRenameDialogCloseImpl(newName, false);
return;
}

Expand All @@ -299,7 +300,7 @@ export class Files extends React.Component<FilesProps, FilesState> {
this.setState({overwriteName: null});

if (overwrite) {
this.onRenameDialogCloseImpl(newName);
this.onRenameDialogCloseImpl(newName, true);
}
else {
this.setState({dialogLoading: false});
Expand Down
2 changes: 1 addition & 1 deletion server/src/apps/remolacha.Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const app : App = {
throw new Error('Unexpected params.');
}

await fs.move(params.from, params.to, {overwrite: true});
await fs.move(params.from, params.to, {overwrite: (params.overwrite === true)});
connection.close();
},

Expand Down

0 comments on commit feb15f5

Please sign in to comment.