mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
🎨 https://github.com/siyuan-note/siyuan/issues/1359 选中多个文档后菜单或快捷键的移动
This commit is contained in:
parent
e3a6bb2251
commit
f250b00de6
5 changed files with 41 additions and 24 deletions
|
|
@ -793,13 +793,13 @@ export const renameMenu = (options: {
|
||||||
}).element;
|
}).element;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const movePathToMenu = (notebookId: string, path: string) => {
|
export const movePathToMenu = (paths: string[]) => {
|
||||||
return new MenuItem({
|
return new MenuItem({
|
||||||
label: window.siyuan.languages.move,
|
label: window.siyuan.languages.move,
|
||||||
icon: "iconMove",
|
icon: "iconMove",
|
||||||
accelerator: window.siyuan.config.keymap.general.move.custom,
|
accelerator: window.siyuan.config.keymap.general.move.custom,
|
||||||
click() {
|
click() {
|
||||||
movePathTo(notebookId, path);
|
movePathTo(paths);
|
||||||
}
|
}
|
||||||
}).element;
|
}).element;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {dialog as remoteDialog} from "@electron/remote";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {MenuItem} from "./Menu";
|
import {MenuItem} from "./Menu";
|
||||||
import {getDisplayName, getNotebookName, pathPosix} from "../util/pathName";
|
import {getDisplayName, getNotebookName, getTopPaths, pathPosix} from "../util/pathName";
|
||||||
import {hideMessage, showMessage} from "../dialog/message";
|
import {hideMessage, showMessage} from "../dialog/message";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {onGetnotebookconf} from "./onGetnotebookconf";
|
import {onGetnotebookconf} from "./onGetnotebookconf";
|
||||||
|
|
@ -208,7 +208,9 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(movePathToMenu(notebookId, pathString));
|
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
||||||
|
Array.from(fileElement.querySelectorAll(".b3-list-item--focus"))
|
||||||
|
)));
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
icon: "iconTrashcan",
|
icon: "iconTrashcan",
|
||||||
label: window.siyuan.languages.delete,
|
label: window.siyuan.languages.delete,
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ export class Title {
|
||||||
submenu: copySubMenu(protyle.block.rootID)
|
submenu: copySubMenu(protyle.block.rootID)
|
||||||
}).element);
|
}).element);
|
||||||
if (!protyle.disabled) {
|
if (!protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(movePathToMenu(protyle.notebookId, protyle.path));
|
window.siyuan.menus.menu.append(movePathToMenu([protyle.path]));
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
icon: "iconTrashcan",
|
icon: "iconTrashcan",
|
||||||
label: window.siyuan.languages.delete,
|
label: window.siyuan.languages.delete,
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ import {hideElements} from "../protyle/ui/hideElements";
|
||||||
import {fetchPost} from "./fetch";
|
import {fetchPost} from "./fetch";
|
||||||
import {goBack, goForward} from "./backForward";
|
import {goBack, goForward} from "./backForward";
|
||||||
import {onGet} from "../protyle/util/onGet";
|
import {onGet} from "../protyle/util/onGet";
|
||||||
import {getDisplayName, getNotebookName, movePathTo} from "./pathName";
|
import {getDisplayName, getNotebookName, getTopPaths, movePathTo} from "./pathName";
|
||||||
import {confirmDialog} from "../dialog/confirmDialog";
|
|
||||||
import {openFileById} from "../editor/util";
|
import {openFileById} from "../editor/util";
|
||||||
import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll";
|
import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll";
|
||||||
import {openGlobalSearch} from "../search/util";
|
import {openGlobalSearch} from "../search/util";
|
||||||
|
|
@ -35,7 +34,7 @@ import {showMessage} from "../dialog/message";
|
||||||
import {openHistory} from "./history";
|
import {openHistory} from "./history";
|
||||||
import {Dialog} from "../dialog";
|
import {Dialog} from "../dialog";
|
||||||
import {unicode2Emoji} from "../emoji";
|
import {unicode2Emoji} from "../emoji";
|
||||||
import {deleteFile, deleteFiles} from "../editor/deleteFile";
|
import {deleteFiles} from "../editor/deleteFile";
|
||||||
import {escapeHtml} from "./escape";
|
import {escapeHtml} from "./escape";
|
||||||
import {syncGuide} from "../sync/syncGuide";
|
import {syncGuide} from "../sync/syncGuide";
|
||||||
import {showPopover} from "../block/popover";
|
import {showPopover} from "../block/popover";
|
||||||
|
|
@ -797,7 +796,7 @@ const editKeydown = (event: KeyboardEvent) => {
|
||||||
if (nodeElement && range && protyle.element.contains(range.startContainer)) {
|
if (nodeElement && range && protyle.element.contains(range.startContainer)) {
|
||||||
protyle.toolbar.showFile(protyle, [nodeElement], range);
|
protyle.toolbar.showFile(protyle, [nodeElement], range);
|
||||||
} else {
|
} else {
|
||||||
movePathTo(protyle.notebookId, protyle.path);
|
movePathTo([protyle.path]);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -911,7 +910,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
|
||||||
}
|
}
|
||||||
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
|
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
movePathTo(notebookId, pathString, false);
|
movePathTo(getTopPaths(liElements), false);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -59,17 +59,34 @@ export const pathPosix = () => {
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveToPath = (notebookId: string, path: string, toNotebookId: string, toFolderPath: string, dialog: Dialog) => {
|
export const getTopPaths = (liElements:Element[]) => {
|
||||||
fetchPost("/api/filetree/moveDoc", {
|
const fromPaths:string[] = []
|
||||||
fromNotebook: notebookId,
|
liElements.forEach((item: HTMLElement) => {
|
||||||
toNotebook: toNotebookId,
|
if (item.getAttribute("data-type") !== "navigation-root") {
|
||||||
fromPath: path,
|
const dataPath = item.getAttribute("data-path")
|
||||||
toPath: toFolderPath,
|
const isChild = fromPaths.find(item => {
|
||||||
|
if (dataPath.startsWith(item.replace(".sy", ""))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!isChild) {
|
||||||
|
fromPaths.push(dataPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return fromPaths
|
||||||
|
}
|
||||||
|
|
||||||
|
const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string, dialog: Dialog) => {
|
||||||
|
fetchPost("/api/filetree/moveDocs", {
|
||||||
|
toNotebook,
|
||||||
|
fromPaths,
|
||||||
|
toPath,
|
||||||
});
|
});
|
||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const movePathTo = async (notebookId: string, path: string, focus = true) => {
|
export const movePathTo = async (paths: string[], focus = true) => {
|
||||||
const exitDialog = window.siyuan.dialogs.find((item) => {
|
const exitDialog = window.siyuan.dialogs.find((item) => {
|
||||||
if (item.element.querySelector("#foldList")) {
|
if (item.element.querySelector("#foldList")) {
|
||||||
item.destroy();
|
item.destroy();
|
||||||
|
|
@ -79,16 +96,15 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
|
||||||
if (exitDialog) {
|
if (exitDialog) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
|
const response = await fetchSyncPost("/api/filetree/getHPathsByPaths", {
|
||||||
notebook: notebookId,
|
paths
|
||||||
path
|
|
||||||
});
|
});
|
||||||
let range: Range;
|
let range: Range;
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
range = getSelection().getRangeAt(0);
|
range = getSelection().getRangeAt(0);
|
||||||
}
|
}
|
||||||
const dialog = new Dialog({
|
const dialog = new Dialog({
|
||||||
title: `${window.siyuan.languages.move} <span class="ft__smaller ft__on-surface">${escapeHtml(pathPosix().join(getNotebookName(notebookId), response.data))}</span>`,
|
title: `${window.siyuan.languages.move} <span class="ft__smaller ft__on-surface">${escapeHtml(response.data.join(", "))}</span>`,
|
||||||
content: `<div class="b3-form__icon b3-form__space">
|
content: `<div class="b3-form__icon b3-form__space">
|
||||||
<svg class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
|
<svg class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
|
||||||
<input class="b3-text-field fn__block b3-form__icon-input" value="" placeholder="${window.siyuan.languages.search}">
|
<input class="b3-text-field fn__block b3-form__icon-input" value="" placeholder="${window.siyuan.languages.search}">
|
||||||
|
|
@ -115,7 +131,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
|
||||||
}, (data) => {
|
}, (data) => {
|
||||||
let fileHTML = "";
|
let fileHTML = "";
|
||||||
data.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
|
data.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
|
||||||
if (item.path === pathPosix().dirname(path) + "/" || item.path === path) {
|
if (paths.includes(item.path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fileHTML += `<li class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
|
fileHTML += `<li class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
|
||||||
|
|
@ -167,7 +183,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === "Enter") {
|
} else if (event.key === "Enter") {
|
||||||
moveToPath(notebookId, path, currentList.getAttribute("data-box"), currentList.getAttribute("data-path"), dialog);
|
moveToPath(paths, currentList.getAttribute("data-box"), currentList.getAttribute("data-path"), dialog);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -175,7 +191,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
|
||||||
const target = event.target as HTMLElement;
|
const target = event.target as HTMLElement;
|
||||||
const liElement = hasClosestByClassName(target, "b3-list-item");
|
const liElement = hasClosestByClassName(target, "b3-list-item");
|
||||||
if (liElement) {
|
if (liElement) {
|
||||||
moveToPath(notebookId, path, liElement.getAttribute("data-box"), liElement.getAttribute("data-path"), dialog);
|
moveToPath(paths, liElement.getAttribute("data-box"), liElement.getAttribute("data-path"), dialog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue