mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
8660a2b214
commit
86311447d1
8 changed files with 59 additions and 30 deletions
|
|
@ -94,7 +94,7 @@ export class Wnd {
|
||||||
while (target && !target.isEqualNode(this.headersElement)) {
|
while (target && !target.isEqualNode(this.headersElement)) {
|
||||||
if (target.classList.contains("item__close") && target.getAttribute("data-type") === "new") {
|
if (target.classList.contains("item__close") && target.getAttribute("data-type") === "new") {
|
||||||
setPanelFocus(this.headersElement.parentElement.parentElement);
|
setPanelFocus(this.headersElement.parentElement.parentElement);
|
||||||
newFile(undefined, undefined, true);
|
newFile(undefined, undefined, undefined, true);
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") {
|
} else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") {
|
||||||
this.renderTabList(event);
|
this.renderTabList(event);
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ export class Files extends Model {
|
||||||
const pathString = target.parentElement.getAttribute("data-path");
|
const pathString = target.parentElement.getAttribute("data-path");
|
||||||
if (!window.siyuan.config.readonly) {
|
if (!window.siyuan.config.readonly) {
|
||||||
if (type === "new") {
|
if (type === "new") {
|
||||||
newFile(notebookId, pathString, true);
|
newFile(notebookId, pathString);
|
||||||
} else if (type === "more-root") {
|
} else if (type === "more-root") {
|
||||||
initNavigationMenu(target.parentElement).popup({x: event.clientX, y: event.clientY});
|
initNavigationMenu(target.parentElement).popup({x: event.clientX, y: event.clientY});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -735,7 +735,7 @@ export const newCenterEmptyTab = () => {
|
||||||
newNotebook();
|
newNotebook();
|
||||||
});
|
});
|
||||||
tab.panelElement.querySelector("#editorEmptyFile").addEventListener("click", () => {
|
tab.panelElement.querySelector("#editorEmptyFile").addEventListener("click", () => {
|
||||||
newFile(undefined, undefined, true);
|
newFile(undefined, undefined, undefined, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
paths.push(item.getAttribute("data-path"));
|
paths.push(item.getAttribute("data-path"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
newFile(notebookId, pathPosix().dirname(pathString), true, paths);
|
newFile(notebookId, pathPosix().dirname(pathString), paths);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
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);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ export class MobileFiles extends Model {
|
||||||
const notebookId = ulElement.getAttribute("data-url");
|
const notebookId = ulElement.getAttribute("data-url");
|
||||||
if (!window.siyuan.config.readonly) {
|
if (!window.siyuan.config.readonly) {
|
||||||
if (type === "new") {
|
if (type === "new") {
|
||||||
newFile(notebookId, pathString, true);
|
newFile(notebookId, pathString);
|
||||||
} else if (type === "more-root") {
|
} else if (type === "more-root") {
|
||||||
initNavigationMenu(target.parentElement).popup({x, y});
|
initNavigationMenu(target.parentElement).popup({x, y});
|
||||||
window.siyuan.menus.menu.element.style.zIndex = "310";
|
window.siyuan.menus.menu.element.style.zIndex = "310";
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ export const setEmpty = () => {
|
||||||
</div>`;
|
</div>`;
|
||||||
document.getElementById("emptyNewFile").addEventListener(getEventName(), () => {
|
document.getElementById("emptyNewFile").addEventListener(getEventName(), () => {
|
||||||
if (window.siyuan.mobile.editor) {
|
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 {
|
} else {
|
||||||
window.siyuan.notebooks.find(item => {
|
window.siyuan.notebooks.find(item => {
|
||||||
if (item.closed) {
|
if (item.closed) {
|
||||||
newFile(item.id, "/", true);
|
newFile(item.id, "/", undefined, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -597,7 +597,7 @@ export const globalShortcut = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
||||||
newFile(undefined, undefined, true);
|
newFile(undefined, undefined, undefined, true);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {getDisplayName, getOpenNotebookCount, pathPosix} from "./pathName";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {validateName} from "../editor/rename";
|
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) {
|
if (getOpenNotebookCount() === 0) {
|
||||||
showMessage(window.siyuan.languages.newFileTip);
|
showMessage(window.siyuan.languages.newFileTip);
|
||||||
return;
|
return;
|
||||||
|
|
@ -54,27 +54,56 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
|
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: notebookId}, (data) => {
|
||||||
|
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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let title = data.data.path || "Untitled"
|
||||||
|
title = title.substring(title.lastIndexOf("/") + 1);
|
||||||
|
if (!validateName(title)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const id = Lute.NewNodeID();
|
const id = Lute.NewNodeID();
|
||||||
const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");
|
const newPath = pathPosix().join(getDisplayName(currentPath, false, true), id + ".sy");
|
||||||
if (paths) {
|
if (paths.length > 0) {
|
||||||
paths[paths.indexOf(undefined)] = newPath;
|
paths[paths.indexOf(undefined)] = newPath;
|
||||||
}
|
}
|
||||||
if (!validateName(data.data.path)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fetchPost("/api/filetree/createDoc", {
|
fetchPost("/api/filetree/createDoc", {
|
||||||
notebook: notebookId,
|
notebook: notebookId,
|
||||||
path: newPath,
|
path: newPath,
|
||||||
title: data.data.name || "Untitled",
|
title,
|
||||||
md: "",
|
md: "",
|
||||||
sorts: paths
|
sorts: paths
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (open) {
|
|
||||||
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
|
||||||
}
|
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue