mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
clone to notes now has overview of notes to clone and is available from context menu
This commit is contained in:
parent
7539e6a616
commit
b53e2a3570
@ -2,7 +2,6 @@ import noteAutocompleteService from "../services/note_autocomplete.js";
|
|||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
import cloningService from "../services/cloning.js";
|
import cloningService from "../services/cloning.js";
|
||||||
import treeUtils from "../services/tree_utils.js";
|
import treeUtils from "../services/tree_utils.js";
|
||||||
import noteDetailService from "../services/note_detail.js";
|
|
||||||
import toastService from "../services/toast.js";
|
import toastService from "../services/toast.js";
|
||||||
import treeCache from "../services/tree_cache.js";
|
import treeCache from "../services/tree_cache.js";
|
||||||
|
|
||||||
@ -10,14 +9,17 @@ const $dialog = $("#clone-to-dialog");
|
|||||||
const $form = $("#clone-to-form");
|
const $form = $("#clone-to-form");
|
||||||
const $noteAutoComplete = $("#clone-to-note-autocomplete");
|
const $noteAutoComplete = $("#clone-to-note-autocomplete");
|
||||||
const $clonePrefix = $("#clone-prefix");
|
const $clonePrefix = $("#clone-prefix");
|
||||||
|
const $noteList = $("#clone-to-note-list");
|
||||||
|
|
||||||
let clonedNoteId;
|
let clonedNoteIds;
|
||||||
|
|
||||||
export async function showDialog(noteId) {
|
export async function showDialog(noteIds) {
|
||||||
clonedNoteId = noteId || noteDetailService.getActiveTabNoteId();
|
clonedNoteIds = [];
|
||||||
|
|
||||||
if (!clonedNoteId) {
|
for (const noteId of noteIds) {
|
||||||
return;
|
if (!clonedNoteIds.includes(noteId)) {
|
||||||
|
clonedNoteIds.push(noteId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.closeActiveDialog();
|
utils.closeActiveDialog();
|
||||||
@ -28,24 +30,38 @@ export async function showDialog(noteId) {
|
|||||||
|
|
||||||
$noteAutoComplete.val('').trigger('focus');
|
$noteAutoComplete.val('').trigger('focus');
|
||||||
|
|
||||||
|
$noteList.empty();
|
||||||
|
|
||||||
|
for (const noteId of clonedNoteIds) {
|
||||||
|
const note = await treeCache.getNote(noteId);
|
||||||
|
|
||||||
|
$noteList.append($("<li>").text(note.title));
|
||||||
|
}
|
||||||
|
|
||||||
noteAutocompleteService.initNoteAutocomplete($noteAutoComplete);
|
noteAutocompleteService.initNoteAutocomplete($noteAutoComplete);
|
||||||
noteAutocompleteService.showRecentNotes($noteAutoComplete);
|
noteAutocompleteService.showRecentNotes($noteAutoComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cloneNotesTo(notePath) {
|
||||||
|
const targetNoteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||||
|
|
||||||
|
for (const cloneNoteId of clonedNoteIds) {
|
||||||
|
await cloningService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());
|
||||||
|
|
||||||
|
const clonedNote = await treeCache.getNote(cloneNoteId);
|
||||||
|
const targetNote = await treeCache.getNote(targetNoteId);
|
||||||
|
|
||||||
|
toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$form.on('submit', () => {
|
$form.on('submit', () => {
|
||||||
const notePath = $noteAutoComplete.getSelectedPath();
|
const notePath = $noteAutoComplete.getSelectedPath();
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
|
|
||||||
const targetNoteId = treeUtils.getNoteIdFromNotePath(notePath);
|
cloneNotesTo(notePath);
|
||||||
|
|
||||||
cloningService.cloneNoteTo(clonedNoteId, targetNoteId, $clonePrefix.val()).then(async () => {
|
|
||||||
const clonedNote = await treeCache.getNote(clonedNoteId);
|
|
||||||
const targetNote = await treeCache.getNote(targetNoteId);
|
|
||||||
|
|
||||||
toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error("No path to clone to.");
|
console.error("No path to clone to.");
|
||||||
|
@ -16,7 +16,6 @@ const HELP = "../dialogs/help.js";
|
|||||||
const NOTE_INFO = "../dialogs/note_info.js";
|
const NOTE_INFO = "../dialogs/note_info.js";
|
||||||
const ABOUT = "../dialogs/about.js";
|
const ABOUT = "../dialogs/about.js";
|
||||||
const LINK_MAP = "../dialogs/link_map.js";
|
const LINK_MAP = "../dialogs/link_map.js";
|
||||||
const CLONE_TO = "../dialogs/clone_to.js";
|
|
||||||
|
|
||||||
function registerEntrypoints() {
|
function registerEntrypoints() {
|
||||||
// hot keys are active also inside inputs and content editables
|
// hot keys are active also inside inputs and content editables
|
||||||
@ -185,8 +184,6 @@ function registerEntrypoints() {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
utils.bindGlobalShortcut('ctrl+e', () => import(CLONE_TO).then(d => d.showDialog()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -342,6 +342,7 @@ function getSelectedOrActiveNodes(node) {
|
|||||||
if (notes.length === 0) {
|
if (notes.length === 0) {
|
||||||
notes.push(node);
|
notes.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return notes;
|
return notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +64,8 @@ class TreeContextMenu {
|
|||||||
{ title: "----" },
|
{ title: "----" },
|
||||||
{ title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "copy",
|
{ title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "copy",
|
||||||
enabled: isNotRoot },
|
enabled: isNotRoot },
|
||||||
|
{ title: "Clone to ...", cmd: "cloneTo", uiIcon: "empty",
|
||||||
|
enabled: isNotRoot },
|
||||||
{ title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "cut",
|
{ title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "cut",
|
||||||
enabled: isNotRoot && !isHoisted && parentNotSearch },
|
enabled: isNotRoot && !isHoisted && parentNotSearch },
|
||||||
{ title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "paste",
|
{ title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "paste",
|
||||||
@ -121,6 +123,12 @@ class TreeContextMenu {
|
|||||||
else if (cmd === "copy") {
|
else if (cmd === "copy") {
|
||||||
clipboard.copy(treeService.getSelectedOrActiveNodes(this.node));
|
clipboard.copy(treeService.getSelectedOrActiveNodes(this.node));
|
||||||
}
|
}
|
||||||
|
else if (cmd === "cloneTo") {
|
||||||
|
const nodes = treeService.getSelectedOrActiveNodes(this.node);
|
||||||
|
const noteIds = nodes.map(node => node.data.noteId);
|
||||||
|
|
||||||
|
import("../dialogs/clone_to.js").then(d => d.showDialog(noteIds))
|
||||||
|
}
|
||||||
else if (cmd === "cut") {
|
else if (cmd === "cut") {
|
||||||
clipboard.cut(treeService.getSelectedOrActiveNodes(this.node));
|
clipboard.cut(treeService.getSelectedOrActiveNodes(this.node));
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div class="modal-dialog modal-lg" style="max-width: 1000px" role="document">
|
<div class="modal-dialog modal-lg" style="max-width: 1000px" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title mr-auto">Clone note to ...</h5>
|
<h5 class="modal-title mr-auto">Clone notes to ...</h5>
|
||||||
|
|
||||||
<button type="button" class="help-button" title="Help on links" data-help-page="Cloning-notes">?</button>
|
<button type="button" class="help-button" title="Help on links" data-help-page="Cloning-notes">?</button>
|
||||||
|
|
||||||
@ -12,6 +12,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<form id="clone-to-form">
|
<form id="clone-to-form">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<h5>Notes to clone</h5>
|
||||||
|
|
||||||
|
<ul id="clone-to-note-list" style="max-height: 200px; overflow: auto;"></ul>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="clone-to-note-autocomplete">Target parent note</label>
|
<label for="clone-to-note-autocomplete">Target parent note</label>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user