This commit is contained in:
parent
4673795801
commit
910558e18f
2 changed files with 148 additions and 141 deletions
146
app/src/boot/globalEvent/command/global.ts
Normal file
146
app/src/boot/globalEvent/command/global.ts
Normal file
|
@ -0,0 +1,146 @@
|
|||
import {newDailyNote} from "../../../util/mount";
|
||||
import {openHistory} from "../../../history/history";
|
||||
import {Editor} from "../../../editor";
|
||||
/// #if MOBILE
|
||||
import {openDock} from "../../../mobile/dock/util";
|
||||
import {popMenu} from "../../../mobile/menu";
|
||||
/// #else
|
||||
import {closeTabByType, getActiveTab, getDockByType} from "../../../layout/tabUtil";
|
||||
import {openSetting} from "../../../config";
|
||||
import {Tab} from "../../../layout/Tab";
|
||||
/// #endif
|
||||
import {App} from "../../../index";
|
||||
import {editor} from "../../../config/editor";
|
||||
|
||||
export const globalCommand = (command: string, app: App) => {
|
||||
/// #if MOBILE
|
||||
switch (command) {
|
||||
case "fileTree":
|
||||
openDock("file");
|
||||
return true;
|
||||
case "outline":
|
||||
case "bookmark":
|
||||
case "tag":
|
||||
case "inbox":
|
||||
openDock(command);
|
||||
return true;
|
||||
case "backlinks":
|
||||
openDock("backlink");
|
||||
return true;
|
||||
case "config":
|
||||
popMenu();
|
||||
return true;
|
||||
}
|
||||
/// #else
|
||||
switch (command) {
|
||||
case "fileTree":
|
||||
getDockByType("file").toggleModel("file");
|
||||
return true;
|
||||
case "outline":
|
||||
getDockByType("outline").toggleModel("outline");
|
||||
return true;
|
||||
case "bookmark":
|
||||
case "tag":
|
||||
case "inbox":
|
||||
getDockByType(command).toggleModel(command);
|
||||
return true;
|
||||
case "backlinks":
|
||||
getDockByType("backlink").toggleModel("backlink");
|
||||
return true;
|
||||
case "graphView":
|
||||
getDockByType("graph").toggleModel("graph");
|
||||
return true;
|
||||
case "globalGraph":
|
||||
getDockByType("globalGraph").toggleModel("globalGraph");
|
||||
return true;
|
||||
case "config":
|
||||
openSetting(app);
|
||||
return true;
|
||||
}
|
||||
if (command === "closeUnmodified") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
const unmodifiedTabs: Tab[] = [];
|
||||
tab.parent.children.forEach((item: Tab) => {
|
||||
const editor = item.model as Editor;
|
||||
if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
|
||||
unmodifiedTabs.push(item);
|
||||
}
|
||||
});
|
||||
if (unmodifiedTabs.length > 0) {
|
||||
closeTabByType(tab, "other", unmodifiedTabs);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeTab") {
|
||||
const activeTabElement = document.querySelector(".layout__tab--active");
|
||||
if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
|
||||
let type = "";
|
||||
Array.from(activeTabElement.classList).find(item => {
|
||||
if (item.startsWith("sy__")) {
|
||||
type = item.replace("sy__", "");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (type) {
|
||||
getDockByType(type)?.toggleModel(type, false, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeOthers" || command === "closeAll") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
closeTabByType(tab, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeLeft" || command === "closeRight") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
const leftTabs: Tab[] = [];
|
||||
const rightTabs: Tab[] = [];
|
||||
let midIndex = -1;
|
||||
tab.parent.children.forEach((item: Tab, index: number) => {
|
||||
if (item.id === tab.id) {
|
||||
midIndex = index;
|
||||
}
|
||||
if (midIndex === -1) {
|
||||
leftTabs.push(item);
|
||||
} else if (index > midIndex) {
|
||||
rightTabs.push(item);
|
||||
}
|
||||
});
|
||||
if (command === "closeLeft") {
|
||||
if (leftTabs.length > 0) {
|
||||
closeTabByType(tab, "other", leftTabs);
|
||||
}
|
||||
} else {
|
||||
if (rightTabs.length > 0) {
|
||||
closeTabByType(tab, "other", rightTabs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// #endif
|
||||
switch (command) {
|
||||
case "dailyNote":
|
||||
newDailyNote(app);
|
||||
return true;
|
||||
case "dataHistory":
|
||||
openHistory(app);
|
||||
return true;
|
||||
case "editReadonly":
|
||||
editor.setReadonly(!window.siyuan.config.editor.readOnly);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
|
@ -7,23 +7,17 @@ import {Constants} from "../../../constants";
|
|||
import {Editor} from "../../../editor";
|
||||
/// #if MOBILE
|
||||
import {getCurrentEditor} from "../../../mobile/editor";
|
||||
import {openDock} from "../../../mobile/dock/util";
|
||||
import {popMenu} from "../../../mobile/menu";
|
||||
/// #else
|
||||
import {closeTabByType, getActiveTab, getDockByType} from "../../../layout/tabUtil";
|
||||
import {getActiveTab, getDockByType} from "../../../layout/tabUtil";
|
||||
import {Custom} from "../../../layout/dock/Custom";
|
||||
import {getAllModels} from "../../../layout/getAll";
|
||||
import {Files} from "../../../layout/dock/Files";
|
||||
import {Search} from "../../../search";
|
||||
import {openSetting} from "../../../config";
|
||||
import {Tab} from "../../../layout/Tab";
|
||||
/// #endif
|
||||
import {openHistory} from "../../../history/history";
|
||||
import {addEditorToDatabase, addFilesToDatabase} from "../../../protyle/render/av/addToDatabase";
|
||||
import {hasClosestByClassName} from "../../../protyle/util/hasClosest";
|
||||
import {newDailyNote} from "../../../util/mount";
|
||||
import {onluProtyleCommand} from "./protyle";
|
||||
import {editor as editorConfig} from "../../../config/editor";
|
||||
import {globalCommand} from "./global";
|
||||
|
||||
export const commandPanel = (app: App) => {
|
||||
const range = getSelection().getRangeAt(0);
|
||||
|
@ -163,139 +157,6 @@ const filterList = (inputElement: HTMLInputElement, listElement: Element) => {
|
|||
});
|
||||
};
|
||||
|
||||
const globalCommand = (command: string, app: App) => {
|
||||
/// #if MOBILE
|
||||
switch (command) {
|
||||
case "fileTree":
|
||||
openDock("file");
|
||||
return true;
|
||||
case "outline":
|
||||
case "bookmark":
|
||||
case "tag":
|
||||
case "inbox":
|
||||
openDock(command);
|
||||
return true;
|
||||
case "backlinks":
|
||||
openDock("backlink");
|
||||
return true;
|
||||
case "config":
|
||||
popMenu();
|
||||
return true;
|
||||
}
|
||||
/// #else
|
||||
switch (command) {
|
||||
case "fileTree":
|
||||
getDockByType("file").toggleModel("file");
|
||||
return true;
|
||||
case "outline":
|
||||
getDockByType("outline").toggleModel("outline");
|
||||
return true;
|
||||
case "bookmark":
|
||||
case "tag":
|
||||
case "inbox":
|
||||
getDockByType(command).toggleModel(command);
|
||||
return true;
|
||||
case "backlinks":
|
||||
getDockByType("backlink").toggleModel("backlink");
|
||||
return true;
|
||||
case "graphView":
|
||||
getDockByType("graph").toggleModel("graph");
|
||||
return true;
|
||||
case "globalGraph":
|
||||
getDockByType("globalGraph").toggleModel("globalGraph");
|
||||
return true;
|
||||
case "config":
|
||||
openSetting(app);
|
||||
return true;
|
||||
}
|
||||
if (command === "closeUnmodified") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
const unmodifiedTabs: Tab[] = [];
|
||||
tab.parent.children.forEach((item: Tab) => {
|
||||
const editor = item.model as Editor;
|
||||
if (!editor || (editor.editor?.protyle && !editor.editor?.protyle.updated)) {
|
||||
unmodifiedTabs.push(item);
|
||||
}
|
||||
});
|
||||
if (unmodifiedTabs.length > 0) {
|
||||
closeTabByType(tab, "other", unmodifiedTabs);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeTab") {
|
||||
const activeTabElement = document.querySelector(".layout__tab--active");
|
||||
if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
|
||||
let type = "";
|
||||
Array.from(activeTabElement.classList).find(item => {
|
||||
if (item.startsWith("sy__")) {
|
||||
type = item.replace("sy__", "");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (type) {
|
||||
getDockByType(type)?.toggleModel(type, false, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeOthers" || command === "closeAll") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
closeTabByType(tab, command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command === "closeLeft" || command === "closeRight") {
|
||||
const tab = getActiveTab(false);
|
||||
if (tab) {
|
||||
const leftTabs: Tab[] = [];
|
||||
const rightTabs: Tab[] = [];
|
||||
let midIndex = -1;
|
||||
tab.parent.children.forEach((item: Tab, index: number) => {
|
||||
if (item.id === tab.id) {
|
||||
midIndex = index;
|
||||
}
|
||||
if (midIndex === -1) {
|
||||
leftTabs.push(item);
|
||||
} else if (index > midIndex) {
|
||||
rightTabs.push(item);
|
||||
}
|
||||
});
|
||||
if (command === "closeLeft") {
|
||||
if (leftTabs.length > 0) {
|
||||
closeTabByType(tab, "other", leftTabs);
|
||||
}
|
||||
} else {
|
||||
if (rightTabs.length > 0) {
|
||||
closeTabByType(tab, "other", rightTabs);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// #endif
|
||||
switch (command) {
|
||||
case "dailyNote":
|
||||
newDailyNote(app);
|
||||
return true;
|
||||
case "dataHistory":
|
||||
openHistory(app);
|
||||
return true;
|
||||
case "editReadonly":
|
||||
editorConfig.setReadonly(!window.siyuan.config.editor.readOnly);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export const execByCommand = (options: {
|
||||
command: string,
|
||||
app?: App,
|
||||
|
|
Loading…
Add table
Reference in a new issue