mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-02 02:40:15 +01:00
This commit is contained in:
parent
df3ee3f24e
commit
67b81bfaad
15 changed files with 117 additions and 6 deletions
|
|
@ -78,6 +78,7 @@ export abstract class Constants {
|
|||
public static readonly LOCAL_EXPORTIMG = "local-exportimg";
|
||||
public static readonly LOCAL_BAZAAR = "local-bazaar";
|
||||
public static readonly LOCAL_PDFTHEME = "local-pdftheme";
|
||||
public static readonly LOCAL_LAYOUTS = "local-layouts";
|
||||
|
||||
// timeout
|
||||
public static readonly TIMEOUT_DBLCLICK = 190;
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ export const resetLayout = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const exportLayout = (reload: boolean, cb?: () => void) => {
|
||||
export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false) => {
|
||||
const useElement = document.querySelector("#barDock use");
|
||||
if (!useElement) {
|
||||
return;
|
||||
|
|
@ -158,7 +158,10 @@ export const exportLayout = (reload: boolean, cb?: () => void) => {
|
|||
right: dockToJSON(window.siyuan.layout.rightDock),
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
fetchPost("/api/system/setUILayout", {layout: layoutJSON, exit: typeof cb !== "undefined"}, () => {
|
||||
if (onlyData) {
|
||||
return layoutJSON;
|
||||
}
|
||||
fetchPost("/api/system/setUILayout", {layout: layoutJSON}, () => {
|
||||
if (reload) {
|
||||
window.location.reload();
|
||||
} else if (cb) {
|
||||
|
|
|
|||
|
|
@ -12,13 +12,15 @@ import {setStorageVal, writeText} from "../protyle/util/compatibility";
|
|||
import {openCard} from "../card/openCard";
|
||||
import {openSetting} from "../config";
|
||||
import {getAllDocks} from "../layout/getAll";
|
||||
import {getDockByType} from "../layout/util";
|
||||
import {exportLayout, getDockByType} from "../layout/util";
|
||||
import {lockScreen} from "../dialog/processSystem";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {unicode2Emoji} from "../emoji";
|
||||
import {Dock} from "../layout/dock";
|
||||
import {escapeHtml} from "../util/escape";
|
||||
import {viewCards} from "../card/viewCards";
|
||||
import {Dialog} from "../dialog";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
|
||||
const togglePinDock = (dock: Dock, icon: string) => {
|
||||
return {
|
||||
|
|
@ -101,6 +103,88 @@ export const workspaceMenu = (rect: DOMRect) => {
|
|||
}).element);
|
||||
}
|
||||
/// #endif
|
||||
const layoutSubMenu: IMenu[] = [{
|
||||
iconHTML: Constants.ZWSP,
|
||||
label: window.siyuan.languages.saveLayout,
|
||||
click() {
|
||||
const saveDialog = new Dialog({
|
||||
title: window.siyuan.languages.saveLayout,
|
||||
content: `<div class="b3-dialog__content">
|
||||
<input class="b3-text-field fn__block" placeholder="${window.siyuan.languages.memo}">
|
||||
</div>
|
||||
<div class="b3-dialog__action">
|
||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||
</div>`,
|
||||
width: "520px",
|
||||
});
|
||||
const btnsElement = saveDialog.element.querySelectorAll(".b3-button");
|
||||
saveDialog.bindInput(saveDialog.element.querySelector("input"), () => {
|
||||
btnsElement[1].dispatchEvent(new CustomEvent("click"));
|
||||
});
|
||||
btnsElement[0].addEventListener("click", () => {
|
||||
saveDialog.destroy();
|
||||
});
|
||||
btnsElement[1].addEventListener("click", () => {
|
||||
const value = saveDialog.element.querySelector("input").value;
|
||||
if (!value) {
|
||||
showMessage(window.siyuan.languages["_kernel"]["142"]);
|
||||
return;
|
||||
}
|
||||
const hadName = window.siyuan.storage[Constants.LOCAL_LAYOUTS].find((item: ISaveLayout) => {
|
||||
if (item.name === value) {
|
||||
showMessage(window.siyuan.languages.duplicate);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
if (hadName) {
|
||||
return;
|
||||
}
|
||||
window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({
|
||||
name: value,
|
||||
layout: exportLayout(false, undefined, true)
|
||||
})
|
||||
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
|
||||
saveDialog.destroy();
|
||||
});
|
||||
}
|
||||
}];
|
||||
window.siyuan.storage[Constants.LOCAL_LAYOUTS].forEach((item: ISaveLayout) => {
|
||||
layoutSubMenu.push({
|
||||
iconHTML: Constants.ZWSP,
|
||||
label: `<div class="fn__flex">
|
||||
<span class="fn__flex-1">${item.name}</span>
|
||||
<span class="fn__space"></span>
|
||||
<svg class="b3-menu__icon fn__a" style="width: 8px"><use xlink:href="#iconClose"></use></svg>
|
||||
</div>`,
|
||||
bind(menuElement) {
|
||||
menuElement.addEventListener("click", (event) => {
|
||||
if (hasClosestByClassName(event.target as HTMLElement, "fn__a")) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
window.siyuan.storage[Constants.LOCAL_LAYOUTS].find((layoutItem: ISaveLayout, index: number) => {
|
||||
if (layoutItem.name === item.name) {
|
||||
menuElement.remove();
|
||||
window.siyuan.storage[Constants.LOCAL_LAYOUTS].splice(index, 1);
|
||||
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/system/setUILayout", {layout: item.layout}, () => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.layout,
|
||||
icon: "iconLayout",
|
||||
type: "submenu",
|
||||
submenu: layoutSubMenu
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
if (!window.siyuan.config.readonly) {
|
||||
if (getOpenNotebookCount() < 2) {
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
layoutTab: 0
|
||||
};
|
||||
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark", annoColor: "var(--b3-pdf-background1)"};
|
||||
defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}}
|
||||
defaultStorage[Constants.LOCAL_BAZAAR] = {
|
||||
theme: "0",
|
||||
template: "0",
|
||||
|
|
@ -208,7 +209,7 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
|
||||
[Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
|
||||
Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA,
|
||||
Constants.LOCAL_ZOOM, Constants.LOCAL_SEARCHEKEY].forEach((key) => {
|
||||
Constants.LOCAL_ZOOM, Constants.LOCAL_SEARCHEKEY, Constants.LOCAL_LAYOUTS].forEach((key) => {
|
||||
if (typeof response.data[key] === "string") {
|
||||
try {
|
||||
window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
|
||||
|
|
|
|||
5
app/src/types/index.d.ts
vendored
5
app/src/types/index.d.ts
vendored
|
|
@ -56,6 +56,11 @@ interface Window {
|
|||
openFileByURL(URL: string): boolean
|
||||
}
|
||||
|
||||
interface ISaveLayout {
|
||||
name: string,
|
||||
layout: IObject
|
||||
}
|
||||
|
||||
interface IWorkspace {
|
||||
path: string
|
||||
closed: boolean
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue