Vanessa 2023-02-03 22:29:34 +08:00
parent 8660a2b214
commit 86311447d1
8 changed files with 59 additions and 30 deletions

View file

@ -94,7 +94,7 @@ export class Wnd {
while (target && !target.isEqualNode(this.headersElement)) {
if (target.classList.contains("item__close") && target.getAttribute("data-type") === "new") {
setPanelFocus(this.headersElement.parentElement.parentElement);
newFile(undefined, undefined, true);
newFile(undefined, undefined, undefined, true);
break;
} else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") {
this.renderTabList(event);

View file

@ -231,7 +231,7 @@ export class Files extends Model {
const pathString = target.parentElement.getAttribute("data-path");
if (!window.siyuan.config.readonly) {
if (type === "new") {
newFile(notebookId, pathString, true);
newFile(notebookId, pathString);
} else if (type === "more-root") {
initNavigationMenu(target.parentElement).popup({x: event.clientX, y: event.clientY});
}

View file

@ -735,7 +735,7 @@ export const newCenterEmptyTab = () => {
newNotebook();
});
tab.panelElement.querySelector("#editorEmptyFile").addEventListener("click", () => {
newFile(undefined, undefined, true);
newFile(undefined, undefined, undefined, true);
});
}
}

View file

@ -206,7 +206,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
paths.push(item.getAttribute("data-path"));
}
});
newFile(notebookId, pathPosix().dirname(pathString), true, paths);
newFile(notebookId, pathPosix().dirname(pathString), paths);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@ -222,7 +222,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
}
}
});
newFile(notebookId, pathPosix().dirname(pathString), true, paths);
newFile(notebookId, pathPosix().dirname(pathString), paths);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);

View file

@ -174,7 +174,7 @@ export class MobileFiles extends Model {
const notebookId = ulElement.getAttribute("data-url");
if (!window.siyuan.config.readonly) {
if (type === "new") {
newFile(notebookId, pathString, true);
newFile(notebookId, pathString);
} else if (type === "more-root") {
initNavigationMenu(target.parentElement).popup({x, y});
window.siyuan.menus.menu.element.style.zIndex = "310";

View file

@ -21,11 +21,11 @@ export const setEmpty = () => {
</div>`;
document.getElementById("emptyNewFile").addEventListener(getEventName(), () => {
if (window.siyuan.mobile.editor) {
newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, true);
newFile(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path, undefined, true);
} else {
window.siyuan.notebooks.find(item => {
if (item.closed) {
newFile(item.id, "/", true);
newFile(item.id, "/", undefined, true);
}
});
}

View file

@ -597,7 +597,7 @@ export const globalShortcut = () => {
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
newFile(undefined, undefined, true);
newFile(undefined, undefined, undefined, true);
event.preventDefault();
return;
}

View file

@ -11,7 +11,7 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
import {Constants} from "../constants";
import {validateName} from "../editor/rename";
export const newFile = (notebookId?: string, currentPath?: string, open?: boolean, paths?: string[]) => {
export const newFile = (notebookId?: string, currentPath?: string, paths?: string[], useSavePath = false) => {
if (getOpenNotebookCount() === 0) {
showMessage(window.siyuan.languages.newFileTip);
return;
@ -54,27 +54,56 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
});
}
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
const id = Lute.NewNodeID();
const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");
if (paths) {
paths[paths.indexOf(undefined)] = newPath;
}
if (!validateName(data.data.path)) {
return;
}
fetchPost("/api/filetree/createDoc", {
notebook: notebookId,
path: newPath,
title: data.data.name || "Untitled",
md: "",
sorts: paths
}, () => {
/// #if !MOBILE
if (open) {
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
if (data.data.path.indexOf("/") > -1 && useSavePath) {
if (data.data.path.startsWith("/")) {
fetchPost("/api/filetree/createDocWithMd", {
notebook: notebookId,
path: data.data.path,
markdown: ""
}, response => {
/// #if !MOBILE
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
/// #endif
});
} else {
fetchPost("/api/filetree/getHPathByPath", {
notebook: notebookId,
path: currentPath
}, (responseHPath) => {
fetchPost("/api/filetree/createDocWithMd", {
notebook: notebookId,
path: pathPosix().join(responseHPath.data, data.data.path),
markdown: ""
}, response => {
/// #if !MOBILE
openFileById({id: response.data, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
/// #endif
});
});
}
/// #endif
});
} else {
let title = data.data.path || "Untitled"
title = title.substring(title.lastIndexOf("/") + 1);
if (!validateName(title)) {
return;
}
const id = Lute.NewNodeID();
const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");
if (paths.length > 0) {
paths[paths.indexOf(undefined)] = newPath;
}
fetchPost("/api/filetree/createDoc", {
notebook: notebookId,
path: newPath,
title,
md: "",
sorts: paths
}, () => {
/// #if !MOBILE
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
/// #endif
});
}
});
};