mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
🎨 Supports specifying the notebook to save new docs https://github.com/siyuan-note/siyuan/issues/10671
This commit is contained in:
parent
78216e7909
commit
b102219a13
2 changed files with 27 additions and 5 deletions
|
|
@ -20,14 +20,14 @@ declare interface INotebookConf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const genNotebookOption = (id: string) => {
|
export const genNotebookOption = (id: string, notebookId?: string) => {
|
||||||
let html = `<option value="">${window.siyuan.languages.currentNotebook}</option>`;
|
let html = `<option value="">${window.siyuan.languages.currentNotebook}</option>`;
|
||||||
const helpIds: string[] = [];
|
const helpIds: string[] = [];
|
||||||
Object.keys(Constants.HELP_PATH).forEach((key: "zh_CN") => {
|
Object.keys(Constants.HELP_PATH).forEach((key: "zh_CN") => {
|
||||||
helpIds.push(Constants.HELP_PATH[key]);
|
helpIds.push(Constants.HELP_PATH[key]);
|
||||||
});
|
});
|
||||||
window.siyuan.notebooks.forEach((item) => {
|
window.siyuan.notebooks.forEach((item) => {
|
||||||
if (helpIds.includes(item.id)) {
|
if (helpIds.includes(item.id) || item.id === notebookId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
html += `<option value="${item.id}" ${id === item.id ? "selected" : ""}>${item.name}</option>`;
|
html += `<option value="${item.id}" ${id === item.id ? "selected" : ""}>${item.name}</option>`;
|
||||||
|
|
@ -45,7 +45,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
|
||||||
<div class="b3-label__text">${window.siyuan.languages.fileTree13}</div>
|
<div class="b3-label__text">${window.siyuan.languages.fileTree13}</div>
|
||||||
<span class="fn__hr"></span>
|
<span class="fn__hr"></span>
|
||||||
<div class="fn__flex">
|
<div class="fn__flex">
|
||||||
<select style="min-width: 200px" class="b3-select" id="docCreateSaveBox">${genNotebookOption(data.conf.docCreateSaveBox)}</select>
|
<select style="min-width: 200px" class="b3-select" id="docCreateSaveBox">${genNotebookOption(data.conf.docCreateSaveBox, data.box)}</select>
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
<input class="b3-text-field fn__flex-1" id="docCreateSavePath" value="">
|
<input class="b3-text-field fn__flex-1" id="docCreateSavePath" value="">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -55,7 +55,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
|
||||||
<div class="b3-label__text">${window.siyuan.languages.fileTree6}</div>
|
<div class="b3-label__text">${window.siyuan.languages.fileTree6}</div>
|
||||||
<span class="fn__hr"></span>
|
<span class="fn__hr"></span>
|
||||||
<div class="fn__flex">
|
<div class="fn__flex">
|
||||||
<select style="min-width: 200px" class="b3-select" id="refCreateSaveBox">${genNotebookOption(data.conf.refCreateSaveBox)}</select>
|
<select style="min-width: 200px" class="b3-select" id="refCreateSaveBox">${genNotebookOption(data.conf.refCreateSaveBox, data.box)}</select>
|
||||||
<div class="fn__space"></div>
|
<div class="fn__space"></div>
|
||||||
<input class="b3-text-field fn__flex-1" id="refCreateSavePath" value="">
|
<input class="b3-text-field fn__flex-1" id="refCreateSavePath" value="">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,9 @@ export const newFile = (optios: {
|
||||||
optios.currentPath = resultData.currentPath;
|
optios.currentPath = resultData.currentPath;
|
||||||
}
|
}
|
||||||
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: optios.notebookId}, (data) => {
|
fetchPost("/api/filetree/getDocCreateSavePath", {notebook: optios.notebookId}, (data) => {
|
||||||
|
if (!optios.useSavePath) {
|
||||||
|
data.data.box = optios.notebookId;
|
||||||
|
}
|
||||||
if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) {
|
if ((data.data.path.indexOf("/") > -1 && optios.useSavePath) || optios.name) {
|
||||||
if (data.data.path.startsWith("/") || optios.currentPath === "/") {
|
if (data.data.path.startsWith("/") || optios.currentPath === "/") {
|
||||||
fetchPost("/api/filetree/createDocWithMd", {
|
fetchPost("/api/filetree/createDocWithMd", {
|
||||||
|
|
@ -138,8 +141,27 @@ export const newFile = (optios: {
|
||||||
if (!validateName(title)) {
|
if (!validateName(title)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (optios.notebookId !== data.data.box) {
|
||||||
|
fetchPost("/api/filetree/createDocWithMd", {
|
||||||
|
notebook: data.data.box,
|
||||||
|
path: pathPosix().join(data.data.path || "/", optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
|
||||||
|
markdown: ""
|
||||||
|
}, response => {
|
||||||
|
/// #if !MOBILE
|
||||||
|
openFileById({
|
||||||
|
app: optios.app,
|
||||||
|
id: response.data,
|
||||||
|
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
|
||||||
|
});
|
||||||
|
/// #else
|
||||||
|
openMobileFileById(optios.app, response.data, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
|
/// #endif
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const id = Lute.NewNodeID();
|
const id = Lute.NewNodeID();
|
||||||
const newPath = optios.notebookId === data.data.box ? (pathPosix().join(getDisplayName(optios.currentPath, false, true), id + ".sy")) : (data.data.path || "/");
|
const newPath = (pathPosix().join(getDisplayName(optios.currentPath, false, true), id + ".sy"));
|
||||||
if (optios.paths) {
|
if (optios.paths) {
|
||||||
optios.paths[optios.paths.indexOf(undefined)] = newPath;
|
optios.paths[optios.paths.indexOf(undefined)] = newPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue