mirror of
https://github.com/heyman/heynote.git
synced 2024-11-24 17:03:19 +01:00
Implement functionality for deleting notes
This commit is contained in:
parent
c010df083c
commit
b1746c58cb
@ -96,6 +96,14 @@ export class FileLibrary {
|
||||
await this.jetpack.moveAsync(fullOldPath, fullNewPath)
|
||||
}
|
||||
|
||||
async delete(path) {
|
||||
if (path === SCRATCH_FILE_NAME) {
|
||||
throw new Error("Can't delete scratch file")
|
||||
}
|
||||
const fullPath = join(this.basePath, path)
|
||||
await this.jetpack.removeAsync(fullPath)
|
||||
}
|
||||
|
||||
async getList() {
|
||||
//console.log("Listing notes")
|
||||
const notes = {}
|
||||
@ -262,6 +270,10 @@ export function setupFileLibraryEventHandlers(win) {
|
||||
return await library.move(path, newPath)
|
||||
});
|
||||
|
||||
ipcMain.handle('buffer:delete', async (event, path) => {
|
||||
return await library.delete(path)
|
||||
});
|
||||
|
||||
ipcMain.handle("library:selectLocation", async () => {
|
||||
let result = await dialog.showOpenDialog({
|
||||
title: "Select directory to store buffer",
|
||||
|
@ -77,6 +77,10 @@ contextBridge.exposeInMainWorld("heynote", {
|
||||
return await ipcRenderer.invoke("buffer:save", path, content)
|
||||
},
|
||||
|
||||
async delete(path) {
|
||||
return await ipcRenderer.invoke("buffer:delete", path)
|
||||
},
|
||||
|
||||
async move(path, newPath) {
|
||||
return await ipcRenderer.invoke("buffer:move", path, newPath)
|
||||
},
|
||||
|
@ -22,14 +22,7 @@
|
||||
await this.updateNotes()
|
||||
this.$refs.container.focus()
|
||||
this.$refs.input.focus()
|
||||
this.items = Object.entries(this.notes).map(([path, metadata]) => {
|
||||
return {
|
||||
"path": path,
|
||||
"name": metadata?.name || path,
|
||||
"folder": path.split("/").slice(0, -1).join("/"),
|
||||
"scratch": path === SCRATCH_FILE_NAME,
|
||||
}
|
||||
})
|
||||
this.buildItems()
|
||||
if (this.items.length > 1) {
|
||||
this.selected = 1
|
||||
}
|
||||
@ -89,8 +82,21 @@
|
||||
...mapActions(useNotesStore, [
|
||||
"updateNotes",
|
||||
"editNote",
|
||||
"deleteNote",
|
||||
]),
|
||||
|
||||
buildItems() {
|
||||
//console.log("buildItems", Object.entries(this.notes))
|
||||
this.items = Object.entries(this.notes).map(([path, metadata]) => {
|
||||
return {
|
||||
"path": path,
|
||||
"name": metadata?.name || path,
|
||||
"folder": path.split("/").slice(0, -1).join("/"),
|
||||
"scratch": path === SCRATCH_FILE_NAME,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onKeydown(event) {
|
||||
if (this.filteredItems.length === 0) {
|
||||
return
|
||||
@ -185,9 +191,13 @@
|
||||
this.deleteConfirm = false
|
||||
},
|
||||
|
||||
deleteConfirmNote(path) {
|
||||
async deleteConfirmNote(path) {
|
||||
if (this.deleteConfirm) {
|
||||
console.log("delete file:", path)
|
||||
await this.deleteNote(path)
|
||||
this.hideActionButtons()
|
||||
this.buildItems()
|
||||
this.selected = Math.min(this.selected, this.items.length - 1)
|
||||
} else {
|
||||
this.deleteConfirm = true
|
||||
this.actionButton = 2
|
||||
|
@ -325,8 +325,10 @@ export const deleteBlock = (editor) => ({state, dispatch}) => {
|
||||
const block = getActiveNoteBlock(state)
|
||||
const blocks = state.facet(blockState)
|
||||
let replace = ""
|
||||
let newSelection = block.delimiter.from
|
||||
if (blocks.length == 1) {
|
||||
replace = getBlockDelimiter(editor.defaultBlockToken, editor.defaultBlockAutoDetect)
|
||||
newSelection = replace.length
|
||||
}
|
||||
dispatch(state.update({
|
||||
changes: {
|
||||
@ -334,7 +336,7 @@ export const deleteBlock = (editor) => ({state, dispatch}) => {
|
||||
to: block.range.to,
|
||||
insert: replace,
|
||||
},
|
||||
selection: EditorSelection.cursor(block.delimiter.from),
|
||||
selection: EditorSelection.cursor(newSelection),
|
||||
annotations: [heynoteEvent.of(DELETE_BLOCK)],
|
||||
}))
|
||||
}
|
||||
|
@ -109,11 +109,11 @@ export const useNotesStore = defineStore("notes", {
|
||||
if (this.currentEditor.path !== path) {
|
||||
throw new Error(`Can't update note (${path}) since it's not the active one (${this.currentEditor.path})`)
|
||||
}
|
||||
console.log("currentEditor", this.currentEditor)
|
||||
//console.log("currentEditor", this.currentEditor)
|
||||
toRaw(this.currentEditor).setName(name)
|
||||
await (toRaw(this.currentEditor)).save()
|
||||
if (newPath && path !== newPath) {
|
||||
console.log("moving note", path, newPath)
|
||||
//console.log("moving note", path, newPath)
|
||||
editorCacheStore.freeEditor(path)
|
||||
await window.heynote.buffer.move(path, newPath)
|
||||
this.openNote(newPath)
|
||||
@ -121,6 +121,20 @@ export const useNotesStore = defineStore("notes", {
|
||||
}
|
||||
},
|
||||
|
||||
async deleteNote(path) {
|
||||
if (path === SCRATCH_FILE_NAME) {
|
||||
throw new Error("Can't delete scratch file")
|
||||
}
|
||||
const editorCacheStore = useEditorCacheStore()
|
||||
if (this.currentEditor.path === path) {
|
||||
this.currentEditor = null
|
||||
this.currentNotePath = SCRATCH_FILE_NAME
|
||||
}
|
||||
editorCacheStore.freeEditor(path)
|
||||
await window.heynote.buffer.delete(path)
|
||||
await this.updateNotes()
|
||||
},
|
||||
|
||||
async reloadLibrary() {
|
||||
const editorCacheStore = useEditorCacheStore()
|
||||
await this.updateNotes()
|
||||
|
Loading…
Reference in New Issue
Block a user