Skip to content

Commit 8b891d1

Browse files
committed
feat: add create file copy button
1 parent ff2095d commit 8b891d1

File tree

9 files changed

+209
-101
lines changed

9 files changed

+209
-101
lines changed

packages/origine2/src/api/Api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export interface TemplateFontConfigDto {
6464
type: string;
6565
}
6666

67+
export interface CopyFileWithIncrementDto {
68+
/** The source path of the file to be copied */
69+
source: string;
70+
}
71+
6772
export interface TemplateConfigDto {
6873
/** The name of the template */
6974
name: string;
@@ -563,6 +568,26 @@ export class Api<
563568
...params,
564569
}),
565570

571+
/**
572+
* No description
573+
*
574+
* @tags Assets
575+
* @name AssetsControllerCopyFileWithIncrement
576+
* @summary Copy File With Increment
577+
* @request POST:/api/assets/copyFileWithIncrement
578+
*/
579+
assetsControllerCopyFileWithIncrement: (
580+
data: CopyFileWithIncrementDto,
581+
params: RequestParams = {},
582+
) =>
583+
this.request<void, void>({
584+
path: `/api/assets/copyFileWithIncrement`,
585+
method: "POST",
586+
body: data,
587+
type: ContentType.Json,
588+
...params,
589+
}),
590+
566591
/**
567592
* No description
568593
*

packages/origine2/src/components/Assets/Assets.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type IFileConfig = Map<
3737
export interface IFileFunction {
3838
open?: (file: IFile, type: 'scene' | 'asset') => Promise<void>,
3939
create?: (source: string, name: string, type: 'file' | 'dir') => Promise<void>,
40+
backup?: (source: string) => Promise<void>,
4041
rename?: (source: string, newName: string) => Promise<void>,
4142
delete?: (source: string) => Promise<void>,
4243
};
@@ -219,6 +220,12 @@ export default function Assets(
219220
handleRefresh();
220221
};
221222

223+
const handleBackupFile = async (source: string) => {
224+
await api.assetsControllerCopyFileWithIncrement({ source });
225+
fileFunction?.backup && await fileFunction.backup(source);
226+
handleRefresh();
227+
};
228+
222229
const handleRenameFile = async (source: string, newName: string) => {
223230
await api.assetsControllerRename({ source, newName });
224231
fileFunction?.rename && await fileFunction.rename(source, newName);
@@ -561,6 +568,7 @@ export default function Assets(
561568
desc={fileConfig?.get(sortedFiles[fileIndex].path)?.desc ?? undefined}
562569
isProtected={fileConfig?.get(sortedFiles[fileIndex].path)?.isProtected ?? isProtected}
563570
handleOpenFile={handleOpenFile}
571+
handleBackupFile={handleBackupFile}
564572
handleRenameFile={handleRenameFile}
565573
handleDeleteFile={handleDeleteFile}
566574
checkHasFile={checkHasFile}

packages/origine2/src/components/Assets/FileElement.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { checkFileName } from "@/utils/checkFileName";
22
import { extractExtension, getDirIcon, getFileIcon } from "@/utils/getFileIcon";
33
import { Button, Input, Popover, PopoverSurface, PopoverTrigger, Subtitle2, Text, Tooltip } from '@fluentui/react-components';
4-
import { bundleIcon, DeleteFilled, DeleteRegular, RenameFilled, RenameRegular } from "@fluentui/react-icons";
4+
import { bundleIcon, DeleteFilled, DeleteRegular, RenameFilled, RenameRegular, SaveCopyFilled, SaveCopyRegular } from "@fluentui/react-icons";
55
import { t } from "@lingui/macro";
66
import { useRef } from "react";
77
import { useValue } from '../../hooks/useValue';
88
import IconWrapper from "../iconWrapper/IconWrapper";
99
import { IFile, IViewType } from "./Assets";
1010
import styles from "./FileElement.module.scss";
1111

12+
const SaveCopyIcon = bundleIcon(SaveCopyFilled, SaveCopyRegular);
1213
const RenameIcon = bundleIcon(RenameFilled, RenameRegular);
1314
const DeleteIcon = bundleIcon(DeleteFilled, DeleteRegular);
1415

@@ -21,6 +22,7 @@ export default function FileElement(
2122
desc,
2223
isProtected,
2324
handleOpenFile,
25+
handleBackupFile,
2426
handleRenameFile,
2527
handleDeleteFile,
2628
checkHasFile,
@@ -32,6 +34,7 @@ export default function FileElement(
3234
desc?: string,
3335
isProtected?: boolean,
3436
handleOpenFile: (file: IFile) => Promise<void>,
37+
handleBackupFile: (source: string) => Promise<void>,
3538
handleRenameFile: (source: string, newName: string) => Promise<void>,
3639
handleDeleteFile: (source: string) => Promise<void>,
3740
checkHasFile: (fileNmae: string) => boolean,
@@ -137,6 +140,22 @@ export default function FileElement(
137140
{desc && <span style={{ color: 'var(--text-weak)', fontSize: '12px', fontStyle: 'italic', paddingRight: '2px' }}>{desc}</span>}
138141

139142
<div className={styles.fileAction}>
143+
{
144+
!file.isDir &&
145+
<Tooltip content={t`创建副本`} relationship="label" positioning="below">
146+
<Button
147+
icon={<SaveCopyIcon style={{ width: '16px' }} />}
148+
size='small'
149+
appearance='subtle'
150+
onClick={
151+
(e) => {
152+
e.stopPropagation();
153+
handleBackupFile(filePath);
154+
}
155+
}
156+
/>
157+
</Tooltip>
158+
}
140159
{
141160
!isProtected &&
142161
<>

packages/origine2/src/locales/en.po

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ msgstr "Always Show Toolbar"
232232
msgid "上一步"
233233
msgstr "Previous"
234234

235-
#: src/components/Assets/Assets.tsx:625
236-
#: src/components/Assets/Assets.tsx:626
235+
#: src/components/Assets/Assets.tsx:633
236+
#: src/components/Assets/Assets.tsx:634
237237
msgid "上传"
238238
msgstr "Upload"
239239

240240
#: src/pages/templateEditor/TemplateEditorSidebar/TemplateConfigDialog.tsx:272
241241
msgid "上传字体文件"
242242
msgstr "Upload font file"
243243

244-
#: src/components/Assets/Assets.tsx:445
245-
#: src/components/Assets/Assets.tsx:451
244+
#: src/components/Assets/Assets.tsx:452
245+
#: src/components/Assets/Assets.tsx:458
246246
msgid "上传资源"
247247
msgstr "Upload asset"
248248

@@ -412,7 +412,7 @@ msgstr "Failed to save template configuration, please try again later"
412412
msgid "保持闭眼(毫秒)"
413413
msgstr "Closed duration (ms)"
414414

415-
#: src/components/Assets/Assets.tsx:498
415+
#: src/components/Assets/Assets.tsx:505
416416
msgid "修改时间"
417417
msgstr "Last modified"
418418

@@ -581,17 +581,21 @@ msgstr "Change background"
581581
msgid "切换背景图片"
582582
msgstr "Change background image"
583583

584-
#: src/components/Assets/Assets.tsx:461
584+
#: src/components/Assets/Assets.tsx:468
585585
msgid "列表视图"
586586
msgstr "List view"
587587

588-
#: src/components/Assets/Assets.tsx:383
589-
#: src/components/Assets/Assets.tsx:435
588+
#: src/components/Assets/Assets.tsx:390
589+
#: src/components/Assets/Assets.tsx:442
590590
#: src/pages/dashboard/Sidebar.tsx:134
591591
#: src/pages/dashboard/TemplateSidebar.tsx:78
592592
msgid "创建"
593593
msgstr "Create"
594594

595+
#: src/components/Assets/FileElement.tsx:145
596+
msgid "创建副本"
597+
msgstr "Create a copy"
598+
595599
#: src/pages/dashboard/TemplateSidebar.tsx:57
596600
msgid "创建新模板"
597601
msgstr "Create new template"
@@ -600,9 +604,9 @@ msgstr "Create new template"
600604
msgid "创建新游戏"
601605
msgstr "Create new game"
602606

603-
#: src/components/Assets/FileElement.tsx:202
604-
#: src/components/Assets/FileElement.tsx:219
605-
#: src/components/Assets/FileElement.tsx:227
607+
#: src/components/Assets/FileElement.tsx:221
608+
#: src/components/Assets/FileElement.tsx:238
609+
#: src/components/Assets/FileElement.tsx:246
606610
#: src/pages/dashboard/GameElement.tsx:154
607611
#: src/pages/dashboard/TemplateElement.tsx:133
608612
#: src/pages/editor/GraphicalEditor/SentenceEditor/Intro.tsx:206
@@ -634,7 +638,7 @@ msgstr "Delete template"
634638
msgid "删除游戏"
635639
msgstr "Delete game"
636640

637-
#: src/components/Assets/Assets.tsx:476
641+
#: src/components/Assets/Assets.tsx:483
638642
msgid "刷新"
639643
msgstr "Refresh"
640644

@@ -810,7 +814,7 @@ msgstr "Rounded rectangle"
810814
msgid "在对话框的左下角显示一个小头像"
811815
msgstr "Display a small avatar in the lower left corner of the dialog box"
812816

813-
#: src/components/Assets/Assets.tsx:477
817+
#: src/components/Assets/Assets.tsx:484
814818
#: src/pages/dashboard/GameElement.tsx:96
815819
#: src/pages/dashboard/TemplateElement.tsx:90
816820
msgid "在文件管理器中打开"
@@ -1058,9 +1062,9 @@ msgstr "Left align"
10581062
msgid "已创建"
10591063
msgstr "Created"
10601064

1061-
#: src/components/Assets/Assets.tsx:354
1062-
#: src/components/Assets/Assets.tsx:413
1063-
#: src/components/Assets/FileElement.tsx:172
1065+
#: src/components/Assets/Assets.tsx:361
1066+
#: src/components/Assets/Assets.tsx:420
1067+
#: src/components/Assets/FileElement.tsx:191
10641068
msgid "已存在文件或文件夹 {0},请输入其他名称"
10651069
msgstr "File or folder already exists {0}, please enter another name"
10661070

@@ -1160,7 +1164,7 @@ msgstr "Open effect editor"
11601164
msgid "执行到此句"
11611165
msgstr "Execute to this sentence"
11621166

1163-
#: src/components/Assets/Assets.tsx:368
1167+
#: src/components/Assets/Assets.tsx:375
11641168
msgid "扩展名"
11651169
msgstr "Extension name"
11661170

@@ -1185,7 +1189,7 @@ msgstr "Concat mode"
11851189
msgid "指针"
11861190
msgstr "Pointer"
11871191

1188-
#: src/components/Assets/Assets.tsx:480
1192+
#: src/components/Assets/Assets.tsx:487
11891193
msgid "排序方式"
11901194
msgstr "Sort by"
11911195

@@ -1309,15 +1313,15 @@ msgstr "Sound effect file"
13091313
#~ msgid "文件"
13101314
#~ msgstr "File"
13111315

1312-
#: src/components/Assets/Assets.tsx:486
1316+
#: src/components/Assets/Assets.tsx:493
13131317
msgid "文件名"
13141318
msgstr "File name"
13151319

1316-
#: src/components/Assets/FileElement.tsx:166
1320+
#: src/components/Assets/FileElement.tsx:185
13171321
msgid "文件名不可包含特殊符号: '/\\\\:*?\"<>|'"
13181322
msgstr ""
13191323

1320-
#: src/components/Assets/Assets.tsx:492
1324+
#: src/components/Assets/Assets.tsx:499
13211325
msgid "文件大小"
13221326
msgstr "File size"
13231327

@@ -1385,13 +1389,13 @@ msgstr "Document"
13851389
msgid "新增字体"
13861390
msgstr "Add font"
13871391

1388-
#: src/components/Assets/Assets.tsx:337
1389-
#: src/components/Assets/Assets.tsx:352
1392+
#: src/components/Assets/Assets.tsx:344
1393+
#: src/components/Assets/Assets.tsx:359
13901394
msgid "新建文件"
13911395
msgstr "Create new file"
13921396

1393-
#: src/components/Assets/Assets.tsx:396
1394-
#: src/components/Assets/Assets.tsx:411
1397+
#: src/components/Assets/Assets.tsx:403
1398+
#: src/components/Assets/Assets.tsx:418
13951399
msgid "新建文件夹"
13961400
msgstr "Create new folder"
13971401

@@ -1403,11 +1407,11 @@ msgstr "Create new template"
14031407
msgid "新建游戏"
14041408
msgstr "Create new game"
14051409

1406-
#: src/components/Assets/Assets.tsx:361
1410+
#: src/components/Assets/Assets.tsx:368
14071411
msgid "新文件名"
14081412
msgstr "New file name"
14091413

1410-
#: src/components/Assets/Assets.tsx:420
1414+
#: src/components/Assets/Assets.tsx:427
14111415
msgid "新文件夹名"
14121416
msgstr "New folder name"
14131417

@@ -1456,7 +1460,7 @@ msgstr "Rotation(radian)"
14561460
msgid "旋转(角度)"
14571461
msgstr "Rotation(angle)"
14581462

1459-
#: src/components/Assets/Assets.tsx:370
1463+
#: src/components/Assets/Assets.tsx:377
14601464
#: src/pages/templateEditor/TemplateGraphicalEditor/WebgalClassEditor/propertyEditor/WGCursor.tsx:16
14611465
msgid "无"
14621466
msgstr "None"
@@ -1479,7 +1483,7 @@ msgstr "Pin popup"
14791483
msgid "是否自定义分隔符"
14801484
msgstr "Use custom separator"
14811485

1482-
#: src/components/Assets/FileElement.tsx:220
1486+
#: src/components/Assets/FileElement.tsx:239
14831487
msgid "是否要删除 \"{0}\" ?"
14841488
msgstr "Are you sure you want to delete \"{0}\"?"
14851489

@@ -2052,7 +2056,7 @@ msgstr "Traditional Chinese"
20522056
msgid "缩放"
20532057
msgstr "Scale"
20542058

2055-
#: src/components/Assets/Assets.tsx:461
2059+
#: src/components/Assets/Assets.tsx:468
20562060
msgid "网格视图"
20572061
msgstr "Grid view"
20582062

@@ -2401,7 +2405,7 @@ msgstr "Enter Target ID"
24012405
msgid "过渡时间(单位为毫秒)"
24022406
msgstr "Transition duration (milliseconds)"
24032407

2404-
#: src/components/Assets/Assets.tsx:306
2408+
#: src/components/Assets/Assets.tsx:313
24052409
msgid "过滤文件"
24062410
msgstr "Filter files"
24072411

@@ -2591,9 +2595,9 @@ msgstr "Configuration"
25912595
msgid "配置模板"
25922596
msgstr "Configure template"
25932597

2594-
#: src/components/Assets/FileElement.tsx:145
25952598
#: src/components/Assets/FileElement.tsx:164
2596-
#: src/components/Assets/FileElement.tsx:195
2599+
#: src/components/Assets/FileElement.tsx:183
2600+
#: src/components/Assets/FileElement.tsx:214
25972601
#: src/pages/dashboard/GameElement.tsx:124
25982602
#: src/pages/dashboard/TemplateElement.tsx:118
25992603
msgid "重命名"

0 commit comments

Comments
 (0)