Skip to content

Commit

Permalink
feat: 新增 剪贴板 > 内容设置 > 删除确认 配置项 (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb authored Dec 20, 2024
1 parent f133105 commit a4535d0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@
"favorite": "Favorite",
"delete": "Delete"
},
"auto_favorite": "Auto Favorite"
"auto_favorite": "Auto Favorite",
"delete_confirm": "Delete Confirmation"
},
"hints": {
"auto_paste": "Quickly paste content to the input field when using the left mouse button",
"image_ocr": "Note: Please be sure to download the",
"copy_as_plain": "Rich text and HTML formats retain only plain text content when copied",
"paste_as_plain": "Rich text and HTML formatting retains only plain text content when pasting",
"operation_button": "Customize icon buttons to operate on clipboard content",
"auto_favorite": "Auto-favorite after adding or editing a note"
"auto_favorite": "Auto-favorite after adding or editing a note",
"delete_confirm": "Pop-up confirmation dialog when deleting clipboard contents"
}
}
},
Expand Down Expand Up @@ -283,7 +285,8 @@
"n_chars": "{{0}} Character(s)"
},
"hints": {
"search_placeholder": "Search..."
"search_placeholder": "Search...",
"delete_modal_content": "Are you sure you want to delete this?"
}
},
"component": {
Expand Down
9 changes: 6 additions & 3 deletions src/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@
"favorite": "お気に入り",
"delete": "削除"
},
"auto_favorite": "自動コレクション"
"auto_favorite": "自動コレクション",
"delete_confirm": "削除確認"
},
"hints": {
"auto_paste": "左クリック時に、内容を素早く入力フィールドに貼り付けます",
"image_ocr": "注意:ご使用前に必ずダウンロードしてください。",
"copy_as_plain": "リッチテキストとHTML形式は、コピーしてもプレーンテキストの内容しか保持しない",
"paste_as_plain": "リッチテキストとHTMLの書式設定は、貼り付け時にプレーンテキストの内容だけを保持する",
"operation_button": "クリップボード内容を操作するためのアイコンボタンをカスタマイズします",
"auto_favorite": "メモの追加・編集後に自動お気に入り登録"
"auto_favorite": "メモの追加・編集後に自動お気に入り登録",
"delete_confirm": "クリップボードの内容を削除する際のポップアップ確認ダイアログ"
}
}
},
Expand Down Expand Up @@ -283,7 +285,8 @@
"n_chars": "{{0}} 文字"
},
"hints": {
"search_placeholder": "検索"
"search_placeholder": "検索",
"delete_modal_content": "本当に削除しますか?"
}
},
"component": {
Expand Down
9 changes: 6 additions & 3 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@
"favorite": "收藏",
"delete": "删除"
},
"auto_favorite": "自动收藏"
"auto_favorite": "自动收藏",
"delete_confirm": "删除确认"
},
"hints": {
"auto_paste": "鼠标左键操作时,快速粘贴内容至输入位置",
"image_ocr": "注意:使用前请务必先下载",
"copy_as_plain": "富文本和HTML格式在复制时仅保留纯文本内容",
"paste_as_plain": "富文本和HTML格式在粘贴时仅保留纯文本内容",
"operation_button": "自定义操作剪贴板内容的图标按钮",
"auto_favorite": "新增或编辑备注后自动收藏"
"auto_favorite": "新增或编辑备注后自动收藏",
"delete_confirm": "删除剪贴板内容时弹出确认对话框"
}
}
},
Expand Down Expand Up @@ -283,7 +285,8 @@
"n_chars": "{{0}}个字符"
},
"hints": {
"search_placeholder": "搜索"
"search_placeholder": "搜索",
"delete_modal_content": "确定要删除此项吗?"
}
},
"component": {
Expand Down
9 changes: 6 additions & 3 deletions src/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@
"favorite": "收藏",
"delete": "刪除"
},
"auto_favorite": "自動收藏"
"auto_favorite": "自動收藏",
"delete_confirm": "删除確認"
},
"hints": {
"auto_paste": "當使用滑鼠左鍵時,快速將內容貼上到輸入位置",
"image_ocr": "注意:使用前請務必先下載",
"copy_as_plain": "富文字和HTML格式在複製時僅保留純文字內容",
"paste_as_plain": "富文字和HTML格式在粘貼時僅保留純文字內容",
"operation_button": "自定義操作剪貼簿內容的圖示按鈕",
"auto_favorite": "新增或編輯備註後自動收藏"
"auto_favorite": "新增或編輯備註後自動收藏",
"delete_confirm": "删除剪貼板內容時彈出確認對話方塊"
}
}
},
Expand Down Expand Up @@ -283,7 +285,8 @@
"n_chars": "{{0}}個字元"
},
"hints": {
"search_placeholder": "搜尋"
"search_placeholder": "搜尋",
"delete_modal_content": "確定要删除此項嗎?"
}
},
"component": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { downloadDir, resolveResource } from "@tauri-apps/api/path";
import { copyFile, writeTextFile } from "@tauri-apps/plugin-fs";
import { open } from "@tauri-apps/plugin-shell";
import { Flex, type FlexProps, message } from "antd";
import type { HookAPI } from "antd/es/modal/useModal";
import clsx from "clsx";
import { find, isNil, remove } from "lodash-es";
import type { DragEvent, FC, MouseEvent } from "react";
Expand All @@ -22,6 +23,7 @@ import Text from "./components/Text";
interface ItemProps extends Partial<FlexProps> {
index: number;
data: HistoryTablePayload;
deleteModal: HookAPI;
openNoteModel: () => void;
}

Expand All @@ -30,7 +32,7 @@ interface ContextMenuItem extends MenuItemOptions {
}

const Item: FC<ItemProps> = (props) => {
const { index, data, className, openNoteModel, ...rest } = props;
const { index, data, className, deleteModal, openNoteModel, ...rest } = props;
const { id, type, value, search, group, favorite, note, subtype } = data;
const { state } = useContext(ClipboardPanelContext);
const { t } = useTranslation();
Expand Down Expand Up @@ -130,7 +132,22 @@ const Item: FC<ItemProps> = (props) => {
};

// 删除条目
const deleteItem = () => {
const deleteItem = async () => {
let confirmed = true;

if (clipboardStore.content.deleteConfirm) {
confirmed = await deleteModal.confirm({
centered: true,
content: t("clipboard.hints.delete_modal_content"),
afterClose() {
// 关闭确认框后焦点还在,需要手动取消焦点
(document.activeElement as HTMLElement)?.blur();
},
});
}

if (!confirmed) return;

if (state.activeId === id) {
const nextIndex = selectNextOrPrev();

Expand Down
8 changes: 6 additions & 2 deletions src/pages/Clipboard/Panel/components/List/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Scrollbar from "@/components/Scrollbar";
import { ClipboardPanelContext } from "@/pages/Clipboard/Panel";
import { useVirtualizer } from "@tanstack/react-virtual";
import { FloatButton } from "antd";
import { FloatButton, Modal } from "antd";
import { findIndex } from "lodash-es";
import Item from "./components/Item";
import NoteModal, { type NoteModalRef } from "./components/NoteModal";
Expand All @@ -10,6 +10,7 @@ const List = () => {
const { state, getList } = useContext(ClipboardPanelContext);
const outerRef = useRef<HTMLDivElement>(null);
const noteModelRef = useRef<NoteModalRef>(null);
const [deleteModal, contextHolder] = Modal.useModal();

const rowVirtualizer = useVirtualizer({
count: state.list.length,
Expand Down Expand Up @@ -123,8 +124,9 @@ const List = () => {
key={key}
index={index}
data={{ ...data, value }}
style={{ height: size, transform: `translateY(${start}px)` }}
deleteModal={deleteModal}
openNoteModel={() => noteModelRef.current?.open()}
style={{ height: size, transform: `translateY(${start}px)` }}
/>
);
})}
Expand All @@ -138,6 +140,8 @@ const List = () => {
/>

<NoteModal ref={noteModelRef} />

{contextHolder}
</>
);
};
Expand Down
13 changes: 13 additions & 0 deletions src/pages/Clipboard/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ const ClipboardSettings = () => {
clipboardStore.content.autoFavorite = value;
}}
/>

<ProSwitch
title={t(
"preference.clipboard.content_settings.label.delete_confirm",
)}
description={t(
"preference.clipboard.content_settings.hints.delete_confirm",
)}
value={content.deleteConfirm}
onChange={(value) => {
clipboardStore.content.deleteConfirm = value;
}}
/>
</ProList>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/stores/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const clipboardStore = proxy<ClipboardStore>({
pastePlain: false,
operationButtons: ["copy", "star", "delete"],
autoFavorite: false,
deleteConfirm: true,
},

history: {
Expand Down
1 change: 1 addition & 0 deletions src/types/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ClipboardStore {
pastePlain: boolean;
operationButtons: OperationButton[];
autoFavorite: boolean;
deleteConfirm: boolean;
};

// 历史记录
Expand Down

0 comments on commit a4535d0

Please sign in to comment.