mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 04:43:44 +08:00
feat: editor add tool-tar buttons
This commit is contained in:
parent
bf158b3bf0
commit
6f1828eabc
@ -1,16 +1,22 @@
|
|||||||
import { ReactNode, useEffect, useRef } from "react";
|
import { ReactNode, useEffect, useRef, useState } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
ButtonGroup,
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
|
IconButton,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import FormatPaintIcon from "@mui/icons-material/FormatPaint";
|
||||||
|
import OpenInFullIcon from "@mui/icons-material/OpenInFull";
|
||||||
|
import CloseFullscreenIcon from "@mui/icons-material/CloseFullscreen";
|
||||||
import { useThemeMode } from "@/services/states";
|
import { useThemeMode } from "@/services/states";
|
||||||
import { Notice } from "@/components/base";
|
import { Notice } from "@/components/base";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
import getSystem from "@/utils/get-system";
|
import getSystem from "@/utils/get-system";
|
||||||
|
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from "monaco-editor";
|
||||||
@ -73,6 +79,7 @@ const monacoInitialization = () => {
|
|||||||
export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const themeMode = useThemeMode();
|
const themeMode = useThemeMode();
|
||||||
|
const [isMaximized, setIsMaximized] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
open = false,
|
open = false,
|
||||||
@ -138,7 +145,14 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const unlistenResized = appWindow.onResized(() => {
|
||||||
|
appWindow.isMaximized().then((maximized) => {
|
||||||
|
setIsMaximized(() => maximized);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
unlistenResized.then((fn) => fn());
|
||||||
editorRef.current?.dispose();
|
editorRef.current?.dispose();
|
||||||
editorRef.current = undefined;
|
editorRef.current = undefined;
|
||||||
};
|
};
|
||||||
@ -179,6 +193,35 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
|||||||
editorDidMount={editorDidMount}
|
editorDidMount={editorDidMount}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ButtonGroup
|
||||||
|
variant="contained"
|
||||||
|
sx={{ position: "absolute", left: "14px", bottom: "8px" }}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="medium"
|
||||||
|
color="inherit"
|
||||||
|
sx={{ display: readOnly ? "none" : "" }}
|
||||||
|
title={t("Format document")}
|
||||||
|
onClick={() =>
|
||||||
|
editorRef.current
|
||||||
|
?.getAction("editor.action.formatDocument")
|
||||||
|
?.run()
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FormatPaintIcon fontSize="inherit" />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
size="medium"
|
||||||
|
color="inherit"
|
||||||
|
title={t(isMaximized ? "Minimize" : "Maximize")}
|
||||||
|
onClick={() =>
|
||||||
|
appWindow.toggleMaximize().then(() => editorRef.current?.layout())
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isMaximized ? <CloseFullscreenIcon /> : <OpenInFullIcon />}
|
||||||
|
</IconButton>
|
||||||
|
</ButtonGroup>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
"Close": "Close",
|
"Close": "Close",
|
||||||
"Cancel": "Cancel",
|
"Cancel": "Cancel",
|
||||||
"Confirm": "Confirm",
|
"Confirm": "Confirm",
|
||||||
|
"Maximize": "Maximize",
|
||||||
|
"Minimize": "Minimize",
|
||||||
|
"Format document": "Format document",
|
||||||
"Empty": "Empty",
|
"Empty": "Empty",
|
||||||
"New": "New",
|
"New": "New",
|
||||||
"Edit": "Edit",
|
"Edit": "Edit",
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
"Close": "بستن",
|
"Close": "بستن",
|
||||||
"Cancel": "لغو",
|
"Cancel": "لغو",
|
||||||
"Confirm": "تأیید",
|
"Confirm": "تأیید",
|
||||||
|
"Maximize": "بزرگنمایی",
|
||||||
|
"Minimize": "کوچکنمایی",
|
||||||
|
"Format document": "فرمتبندی سند",
|
||||||
"Empty": "خالی خالی",
|
"Empty": "خالی خالی",
|
||||||
"New": "جدید",
|
"New": "جدید",
|
||||||
"Edit": "ویرایش",
|
"Edit": "ویرایش",
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
"Close": "Закрыть",
|
"Close": "Закрыть",
|
||||||
"Cancel": "Отмена",
|
"Cancel": "Отмена",
|
||||||
"Confirm": "Подтвердить",
|
"Confirm": "Подтвердить",
|
||||||
|
"Maximize": "Развернуть",
|
||||||
|
"Minimize": "Свернуть",
|
||||||
|
"Format document": "Форматировать документ",
|
||||||
"Empty": "Пусто",
|
"Empty": "Пусто",
|
||||||
"New": "Новый",
|
"New": "Новый",
|
||||||
"Edit": "Редактировать",
|
"Edit": "Редактировать",
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
"Close": "关闭",
|
"Close": "关闭",
|
||||||
"Cancel": "取消",
|
"Cancel": "取消",
|
||||||
"Confirm": "确认",
|
"Confirm": "确认",
|
||||||
|
"Maximize": "最大化",
|
||||||
|
"Minimize": "最小化",
|
||||||
|
"Format document": "格式化文档",
|
||||||
"Empty": "空空如也",
|
"Empty": "空空如也",
|
||||||
"New": "新建",
|
"New": "新建",
|
||||||
"Edit": "编辑",
|
"Edit": "编辑",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user