mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 07:48:49 +01:00
This commit is contained in:
parent
eb2b45b175
commit
fa1e63302f
1 changed files with 74 additions and 68 deletions
|
|
@ -638,75 +638,81 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
|
|||
};
|
||||
|
||||
export const genImportMenu = (notebookId: string, pathString: string) => {
|
||||
if (!window.siyuan.config.readonly) {
|
||||
/// #if !BROWSER
|
||||
const importstdmd = (label: string, isDoc?: boolean) => {
|
||||
return {
|
||||
icon: isDoc ? "iconMarkdown" : "iconFolder",
|
||||
label,
|
||||
click: async () => {
|
||||
let filters: FileFilter[] = [];
|
||||
if (isDoc) {
|
||||
filters = [{name: "Markdown", extensions: ["md", "markdown"]}];
|
||||
}
|
||||
const localPath = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
|
||||
cmd: "showOpenDialog",
|
||||
defaultPath: window.siyuan.config.system.homeDir,
|
||||
filters,
|
||||
properties: [isDoc ? "openFile" : "openDirectory"],
|
||||
});
|
||||
if (localPath.filePaths.length === 0) {
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/import/importStdMd", {
|
||||
notebook: notebookId,
|
||||
localPath: localPath.filePaths[0],
|
||||
toPath: pathString,
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
/// #endif
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconDownload",
|
||||
label: window.siyuan.languages.import,
|
||||
submenu: [{
|
||||
icon: "iconSiYuan",
|
||||
label: 'SiYuan .sy.zip<input class="b3-form__upload" type="file" accept="application/zip">',
|
||||
bind: (element) => {
|
||||
element.querySelector(".b3-form__upload").addEventListener("change", (event: InputEvent & {
|
||||
target: HTMLInputElement
|
||||
}) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", event.target.files[0]);
|
||||
formData.append("notebook", notebookId);
|
||||
formData.append("toPath", pathString);
|
||||
fetchPost("/api/import/importSY", formData, () => {
|
||||
let files;
|
||||
/// #if MOBILE
|
||||
files = window.siyuan.mobile.files;
|
||||
/// #else
|
||||
files = (getDockByType("file").data["file"] as Files);
|
||||
/// #endif
|
||||
const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
|
||||
const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
|
||||
if (toggleElement) {
|
||||
toggleElement.classList.remove("b3-list-item__arrow--open");
|
||||
liElement.nextElementSibling?.remove();
|
||||
}
|
||||
files.getLeaf(liElement, notebookId);
|
||||
window.siyuan.menus.menu.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
/// #if !BROWSER
|
||||
importstdmd("Markdown " + window.siyuan.languages.doc, true),
|
||||
importstdmd("Markdown " + window.siyuan.languages.folder)
|
||||
/// #endif
|
||||
],
|
||||
}).element);
|
||||
if (window.siyuan.config.readonly) {
|
||||
return;
|
||||
}
|
||||
const reloadDocTree = () => {
|
||||
let files;
|
||||
/// #if MOBILE
|
||||
files = window.siyuan.mobile.files;
|
||||
/// #else
|
||||
files = (getDockByType("file").data["file"] as Files);
|
||||
/// #endif
|
||||
const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
|
||||
const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
|
||||
if (toggleElement) {
|
||||
toggleElement.classList.remove("b3-list-item__arrow--open");
|
||||
liElement.nextElementSibling?.remove();
|
||||
}
|
||||
files.getLeaf(liElement, notebookId);
|
||||
window.siyuan.menus.menu.remove();
|
||||
}
|
||||
/// #if !BROWSER
|
||||
const importstdmd = (label: string, isDoc?: boolean) => {
|
||||
return {
|
||||
icon: isDoc ? "iconMarkdown" : "iconFolder",
|
||||
label,
|
||||
click: async () => {
|
||||
let filters: FileFilter[] = [];
|
||||
if (isDoc) {
|
||||
filters = [{name: "Markdown", extensions: ["md", "markdown"]}];
|
||||
}
|
||||
const localPath = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
|
||||
cmd: "showOpenDialog",
|
||||
defaultPath: window.siyuan.config.system.homeDir,
|
||||
filters,
|
||||
properties: [isDoc ? "openFile" : "openDirectory"],
|
||||
});
|
||||
if (localPath.filePaths.length === 0) {
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/import/importStdMd", {
|
||||
notebook: notebookId,
|
||||
localPath: localPath.filePaths[0],
|
||||
toPath: pathString,
|
||||
}, () => {
|
||||
reloadDocTree();
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
/// #endif
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconDownload",
|
||||
label: window.siyuan.languages.import,
|
||||
submenu: [{
|
||||
icon: "iconSiYuan",
|
||||
label: 'SiYuan .sy.zip<input class="b3-form__upload" type="file" accept="application/zip">',
|
||||
bind: (element) => {
|
||||
element.querySelector(".b3-form__upload").addEventListener("change", (event: InputEvent & {
|
||||
target: HTMLInputElement
|
||||
}) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", event.target.files[0]);
|
||||
formData.append("notebook", notebookId);
|
||||
formData.append("toPath", pathString);
|
||||
fetchPost("/api/import/importSY", formData, () => {
|
||||
reloadDocTree();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
/// #if !BROWSER
|
||||
importstdmd("Markdown " + window.siyuan.languages.doc, true),
|
||||
importstdmd("Markdown " + window.siyuan.languages.folder)
|
||||
/// #endif
|
||||
],
|
||||
}).element);
|
||||
};
|
||||
|
||||
export const sortMenu = (type: "notebooks" | "notebook", sortMode: number, clickEvent: (sort: number) => void) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue