From 6f1828eabcff1d7fc07ca7065e9f2fc2c3d97bbf Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:24:44 +0800 Subject: [PATCH] feat: editor add tool-tar buttons --- src/components/profile/editor-viewer.tsx | 45 +++++++++++++++++++++++- src/locales/en.json | 3 ++ src/locales/fa.json | 3 ++ src/locales/ru.json | 3 ++ src/locales/zh.json | 3 ++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/components/profile/editor-viewer.tsx b/src/components/profile/editor-viewer.tsx index e4951735..33e73c50 100644 --- a/src/components/profile/editor-viewer.tsx +++ b/src/components/profile/editor-viewer.tsx @@ -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 = (props: Props) => { const { t } = useTranslation(); const themeMode = useThemeMode(); + const [isMaximized, setIsMaximized] = useState(false); const { open = false, @@ -138,7 +145,14 @@ export const EditorViewer = (props: Props) => { }); 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 = (props: Props) => { editorDidMount={editorDidMount} onChange={handleChange} /> + + + + editorRef.current + ?.getAction("editor.action.formatDocument") + ?.run() + } + > + + + + appWindow.toggleMaximize().then(() => editorRef.current?.layout()) + } + > + {isMaximized ? : } + + diff --git a/src/locales/en.json b/src/locales/en.json index 94d3c24d..4d706fe9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -5,6 +5,9 @@ "Close": "Close", "Cancel": "Cancel", "Confirm": "Confirm", + "Maximize": "Maximize", + "Minimize": "Minimize", + "Format document": "Format document", "Empty": "Empty", "New": "New", "Edit": "Edit", diff --git a/src/locales/fa.json b/src/locales/fa.json index 640944af..b5a80a03 100644 --- a/src/locales/fa.json +++ b/src/locales/fa.json @@ -5,6 +5,9 @@ "Close": "بستن", "Cancel": "لغو", "Confirm": "تأیید", + "Maximize": "بزرگ‌نمایی", + "Minimize": "کوچک‌نمایی", + "Format document": "فرمت‌بندی سند", "Empty": "خالی خالی", "New": "جدید", "Edit": "ویرایش", diff --git a/src/locales/ru.json b/src/locales/ru.json index faa882ae..72ab09ad 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -5,6 +5,9 @@ "Close": "Закрыть", "Cancel": "Отмена", "Confirm": "Подтвердить", + "Maximize": "Развернуть", + "Minimize": "Свернуть", + "Format document": "Форматировать документ", "Empty": "Пусто", "New": "Новый", "Edit": "Редактировать", diff --git a/src/locales/zh.json b/src/locales/zh.json index cd499219..a2d65b42 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -5,6 +5,9 @@ "Close": "关闭", "Cancel": "取消", "Confirm": "确认", + "Maximize": "最大化", + "Minimize": "最小化", + "Format document": "格式化文档", "Empty": "空空如也", "New": "新建", "Edit": "编辑",