mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
This commit is contained in:
parent
7108855a00
commit
41dca0a498
8 changed files with 124 additions and 48 deletions
|
|
@ -11,42 +11,38 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
|
|||
import {Constants} from "../constants";
|
||||
import {validateName} from "../editor/rename";
|
||||
|
||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
||||
if (getOpenNotebookCount() === 0) {
|
||||
showMessage(window.siyuan.languages.newFileTip);
|
||||
return;
|
||||
}
|
||||
export const getNewFilePath = (useSavePath: boolean) => {
|
||||
let notebookId = ""
|
||||
let currentPath = ""
|
||||
/// #if !MOBILE
|
||||
if (!notebookId) {
|
||||
getAllModels().editor.find((item) => {
|
||||
const currentElement = item.parent.headElement;
|
||||
if (currentElement.classList.contains("item--focus")) {
|
||||
notebookId = item.editor.protyle.notebookId;
|
||||
if (useSavePath) {
|
||||
currentPath = item.editor.protyle.path;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
||||
}
|
||||
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
||||
return true;
|
||||
}
|
||||
getAllModels().editor.find((item) => {
|
||||
const currentElement = item.parent.headElement;
|
||||
if (currentElement.classList.contains("item--focus")) {
|
||||
notebookId = item.editor.protyle.notebookId;
|
||||
if (useSavePath) {
|
||||
currentPath = item.editor.protyle.path;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(item.editor.protyle.path);
|
||||
}
|
||||
});
|
||||
if (!notebookId) {
|
||||
const fileModel = getDockByType("file").data.file;
|
||||
if (fileModel instanceof Files) {
|
||||
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
||||
if (currentElement) {
|
||||
const topElement = hasTopClosestByTag(currentElement, "UL");
|
||||
if (topElement) {
|
||||
notebookId = topElement.getAttribute("data-url");
|
||||
}
|
||||
const selectPath = currentElement.getAttribute("data-path");
|
||||
if (useSavePath) {
|
||||
currentPath = selectPath;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(selectPath);
|
||||
}
|
||||
if (hasClosestByClassName(currentElement, "layout__wnd--active")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!notebookId) {
|
||||
const fileModel = getDockByType("file").data.file;
|
||||
if (fileModel instanceof Files) {
|
||||
const currentElement = fileModel.element.querySelector(".b3-list-item--focus");
|
||||
if (currentElement) {
|
||||
const topElement = hasTopClosestByTag(currentElement, "UL");
|
||||
if (topElement) {
|
||||
notebookId = topElement.getAttribute("data-url");
|
||||
}
|
||||
const selectPath = currentElement.getAttribute("data-path");
|
||||
if (useSavePath) {
|
||||
currentPath = selectPath;
|
||||
} else {
|
||||
currentPath = pathPosix().dirname(selectPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -61,6 +57,19 @@ export const newFile = (notebookId?: string, currentPath?: string, paths?: strin
|
|||
}
|
||||
});
|
||||
}
|
||||
return {notebookId, currentPath}
|
||||
}
|
||||
|
||||
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
|
||||
if (getOpenNotebookCount() === 0) {
|
||||
showMessage(window.siyuan.languages.newFileTip);
|
||||
return;
|
||||
}
|
||||
if (!notebookId) {
|
||||
const resultData = getNewFilePath(useSavePath)
|
||||
notebookId = resultData.notebookId;
|
||||
currentPath = resultData.currentPath;
|
||||
}
|
||||
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
|
||||
if (data.data.path.indexOf("/") > -1 && useSavePath) {
|
||||
if (data.data.path.startsWith("/") || currentPath === "/") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue