mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
feat(views/table): delete row from context menu (closes #6288)
This commit is contained in:
parent
201e8911c5
commit
458d66cb21
@ -95,7 +95,15 @@ async function moveToParentNote(branchIdsToMove: string[], newParentBranchId: st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteNotes(branchIdsToDelete: string[], forceDeleteAllClones = false) {
|
/**
|
||||||
|
* Shows the delete confirmation screen
|
||||||
|
*
|
||||||
|
* @param branchIdsToDelete the list of branch IDs to delete.
|
||||||
|
* @param forceDeleteAllClones whether to check by default the "Delete also all clones" checkbox.
|
||||||
|
* @param moveToParent whether to automatically go to the parent note path after a succesful delete. Usually makes sense if deleting the active note(s).
|
||||||
|
* @returns promise that returns false if the operation was cancelled or there was nothing to delete, true if the operation succeeded.
|
||||||
|
*/
|
||||||
|
async function deleteNotes(branchIdsToDelete: string[], forceDeleteAllClones = false, moveToParent = true) {
|
||||||
branchIdsToDelete = filterRootNote(branchIdsToDelete);
|
branchIdsToDelete = filterRootNote(branchIdsToDelete);
|
||||||
|
|
||||||
if (branchIdsToDelete.length === 0) {
|
if (branchIdsToDelete.length === 0) {
|
||||||
@ -110,10 +118,12 @@ async function deleteNotes(branchIdsToDelete: string[], forceDeleteAllClones = f
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (moveToParent) {
|
||||||
await activateParentNotePath();
|
try {
|
||||||
} catch (e) {
|
await activateParentNotePath();
|
||||||
console.error(e);
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const taskId = utils.randomString(10);
|
const taskId = utils.randomString(10);
|
||||||
|
@ -1949,5 +1949,8 @@
|
|||||||
"book_properties_config": {
|
"book_properties_config": {
|
||||||
"hide-weekends": "Hide weekends",
|
"hide-weekends": "Hide weekends",
|
||||||
"display-week-numbers": "Display week numbers"
|
"display-week-numbers": "Display week numbers"
|
||||||
|
},
|
||||||
|
"table_context_menu": {
|
||||||
|
"delete_row": "Delete row"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import { RowComponent, Tabulator } from "tabulator-tables";
|
||||||
|
import contextMenu from "../../../menus/context_menu.js";
|
||||||
|
import { TableData } from "./rows.js";
|
||||||
|
import branches from "../../../services/branches.js";
|
||||||
|
import { t } from "../../../services/i18n.js";
|
||||||
|
|
||||||
|
export function setupContextMenu(tabulator: Tabulator) {
|
||||||
|
tabulator.on("rowContext", showRowContextMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showRowContextMenu(_e: UIEvent, row: RowComponent) {
|
||||||
|
const e = _e as MouseEvent;
|
||||||
|
const rowData = row.getData() as TableData;
|
||||||
|
contextMenu.show({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
title: t("table_context_menu.delete_row"),
|
||||||
|
uiIcon: "bx bx-trash",
|
||||||
|
handler: () => branches.deleteNotes([ rowData.branchId ], false, false)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
selectMenuItemHandler: () => {},
|
||||||
|
x: e.pageX,
|
||||||
|
y: e.pageY
|
||||||
|
});
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
@ -13,6 +13,7 @@ import { canReorderRows, configureReorderingRows } from "./dragging.js";
|
|||||||
import buildFooter from "./footer.js";
|
import buildFooter from "./footer.js";
|
||||||
import getPromotedAttributeInformation, { buildRowDefinitions } from "./rows.js";
|
import getPromotedAttributeInformation, { buildRowDefinitions } from "./rows.js";
|
||||||
import { buildColumnDefinitions } from "./columns.js";
|
import { buildColumnDefinitions } from "./columns.js";
|
||||||
|
import { setupContextMenu } from "./context_menu.js";
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="table-view">
|
<div class="table-view">
|
||||||
@ -144,6 +145,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
persistenceReaderFunc: (_id, type: string) => this.persistentData?.[type],
|
persistenceReaderFunc: (_id, type: string) => this.persistentData?.[type],
|
||||||
});
|
});
|
||||||
configureReorderingRows(this.api);
|
configureReorderingRows(this.api);
|
||||||
|
setupContextMenu(this.api);
|
||||||
this.setupEditing();
|
this.setupEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user