Skip to content

Commit

Permalink
delete/rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Jul 29, 2023
1 parent ca9db12 commit 4b5bfb8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions front/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {Observable} from './observable'
window.State = Observable({})

State.files = {}
State.selectFile = file =>
setTimeout(() => State.selectedFile = find(x => x.name == file, State.files), 300)

ws.emit('file:list')
ws.on('file:list', f => {
State.files = f
Expand Down
15 changes: 15 additions & 0 deletions front/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const onMount = (editor, monaco) => {
if (file) {
ws.emit('file:save', { value: '', file })
ws.emit('file:list', {})
State.selectFile(file)
}
},
});
Expand All @@ -46,6 +47,20 @@ const onMount = (editor, monaco) => {
},
});

editor.addAction({
id: "rename file",
label: "Rename File",
run: function (ed) {
const to = prompt('Enter new filename')
if (to) {
ws.emit('file:rename', {file: State.selectedFile.name, to})
ws.emit('file:list', {})
State.selectFile(to)
}
},
});



editor.addAction({
id: "save",
Expand Down
8 changes: 8 additions & 0 deletions rconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ for (const name of ['Sync', 'Server']) {
}


Server.on('file:delete', (ws, {file}) => {
fs.unlink(joinPath(DATADIR, file), console.log)
})

Server.on('file:rename', (ws, {file, to}) => {
fs.rename(joinPath(DATADIR, file), joinPath(DATADIR, to), console.log)
})

Server.on('file:delete', (ws, {file}) => {
fs.unlink(joinPath(DATADIR, file), console.log)
})
Expand Down

0 comments on commit 4b5bfb8

Please sign in to comment.