feat: editor add tool-tar buttons

This commit is contained in:
dongchengjie 2024-07-02 23:24:44 +08:00
parent f69e1d2a0c
commit 07c145c661
5 changed files with 56 additions and 1 deletions

View File

@ -1,16 +1,22 @@
import { ReactNode, useEffect, useRef } from "react";
import { ReactNode, useEffect, useRef, useState } from "react";
import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next";
import {
Button,
ButtonGroup,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
IconButton,
} 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 { Notice } from "@/components/base";
import { nanoid } from "nanoid";
import { appWindow } from "@tauri-apps/api/window";
import getSystem from "@/utils/get-system";
import * as monaco from "monaco-editor";
@ -73,6 +79,7 @@ const monacoInitialization = () => {
export const EditorViewer = <T extends Language>(props: Props<T>) => {
const { t } = useTranslation();
const themeMode = useThemeMode();
const [isMaximized, setIsMaximized] = useState(false);
const {
open = false,
@ -138,7 +145,14 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
});
useEffect(() => {
const unlistenResized = appWindow.onResized(() => {
appWindow.isMaximized().then((maximized) => {
setIsMaximized(() => maximized);
});
});
return () => {
unlistenResized.then((fn) => fn());
editorRef.current?.dispose();
editorRef.current = undefined;
};
@ -179,6 +193,35 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
editorDidMount={editorDidMount}
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>
<DialogActions>

View File

@ -5,6 +5,9 @@
"Close": "Close",
"Cancel": "Cancel",
"Confirm": "Confirm",
"Maximize": "Maximize",
"Minimize": "Minimize",
"Format document": "Format document",
"Empty": "Empty",
"New": "New",
"Edit": "Edit",

View File

@ -5,6 +5,9 @@
"Close": "بستن",
"Cancel": "لغو",
"Confirm": "تأیید",
"Maximize": "بزرگ‌نمایی",
"Minimize": "کوچک‌نمایی",
"Format document": "فرمت‌بندی سند",
"Empty": "خالی خالی",
"New": "جدید",
"Edit": "ویرایش",

View File

@ -5,6 +5,9 @@
"Close": "Закрыть",
"Cancel": "Отмена",
"Confirm": "Подтвердить",
"Maximize": "Развернуть",
"Minimize": "Свернуть",
"Format document": "Форматировать документ",
"Empty": "Пусто",
"New": "Новый",
"Edit": "Редактировать",

View File

@ -5,6 +5,9 @@
"Close": "关闭",
"Cancel": "取消",
"Confirm": "确认",
"Maximize": "最大化",
"Minimize": "最小化",
"Format document": "格式化文档",
"Empty": "空空如也",
"New": "新建",
"Edit": "编辑",