diff --git a/src/Add-on/BoardEditor/TextModifyTool.ts b/src/Add-on/BoardEditor/TextModifyTool.ts new file mode 100644 index 000000000..804e7ca57 --- /dev/null +++ b/src/Add-on/BoardEditor/TextModifyTool.ts @@ -0,0 +1,29 @@ +import { app } from "../../ApplicationServices/Application"; +import { Text } from "../../DatabaseServices/Text/Text"; +import { Command } from "../../Editor/CommandMachine"; +import { PromptStatus } from "../../Editor/PromptResult"; +import { ModalState } from "../../UI/Components/Modal/ModalInterface"; +import { ModifyTextsStore, TextModifyModal } from "../../UI/Components/Text/TextModify"; + +export class Command_TextModifyTool implements Command +{ + async exec() + { + let store = ModifyTextsStore.GetInstance(); + app.Editor.ModalManage.RenderModal(TextModifyModal, { store }); + let state = await app.Editor.ModalManage.Wait(); + if (state.Status !== ModalState.Ok) + return; + let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Text] }, UseSelect: true }); + if (ssRes.Status !== PromptStatus.OK) return; + let ents = ssRes.SelectSet.SelectEntityList as Text[]; + for (let t of ents) + { + for (const i of store.m_Option.changeTexts) + { + if (i[0] !== "") + t.TextString = t.TextString.replaceAll(i[0], i[1]); + } + } + } +} diff --git a/src/Common/CommandNames.ts b/src/Common/CommandNames.ts index d6da0486a..7dbd5796e 100644 --- a/src/Common/CommandNames.ts +++ b/src/Common/CommandNames.ts @@ -183,6 +183,7 @@ export enum CommandNames RecyleBin = "RECYCLEBIN", ChangeColorByMaterial = "CHANGECOLORBYMATERIAL",//根据板材改颜色 ChangeBoardColorByPBFace = "CHANGEBOARDCOLORBYPBFACE",//根据排版面改颜色 + TextModifyTool = "TEXTMODIFYTOOL",//批量修改文本 RestoreColor = "RESTORECOLOR", SelectAll = "SELECTALL", CheckHoles = "CHECKHOLES", diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index 751a5326f..b83ff455b 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -16,6 +16,7 @@ import { ReferenceCutting } from "../Add-on/BoardCutting/ReferenceCutting"; import { Command_ChangeBoardColorByPBFace } from "../Add-on/BoardEditor/ChangeBoardColorByPBFace"; import { Command_ClearBoard2DModeling } from "../Add-on/BoardEditor/ClearBoard2DModeling"; import { SetBoardLines } from "../Add-on/BoardEditor/SetBoardLines"; +import { Command_TextModifyTool } from "../Add-on/BoardEditor/TextModifyTool"; import { UpdateBoardInfos } from "../Add-on/BoardEditor/UpdateBoardInfos"; import { BoardFindModify } from "../Add-on/BoardFindModify"; import { IntersectionOperation, SubsractOperation, UnionOperation } from "../Add-on/BoolOperation"; @@ -609,6 +610,7 @@ export function registerCommand() commandMachine.RegisterCommand(CommandNames.ChangeColorByMaterial, new ChangeColorByMaterial()); commandMachine.RegisterCommand(CommandNames.ChangeBoardColorByPBFace, new Command_ChangeBoardColorByPBFace()); + commandMachine.RegisterCommand(CommandNames.TextModifyTool, new Command_TextModifyTool()); commandMachine.RegisterCommand(CommandNames.SelectAll, new SelectAll()); diff --git a/src/Editor/DefaultConfig.ts b/src/Editor/DefaultConfig.ts index 12b235ffc..087228037 100644 --- a/src/Editor/DefaultConfig.ts +++ b/src/Editor/DefaultConfig.ts @@ -1,4 +1,4 @@ -import { LayerBoardOption, BrRelativePos, VerticalBoardOption, BehindBoardOption, BehindHeightPositon, TBBoardOption, LayerNailOption, SingleBoardOption, ClosingStripOption, StripType, LinesType, FaceDirection, ComposingType, IBoardBatchCurtailOption, CurtailType, BoardProcessOption, SideBoardOption, BoardType } from "../UI/Store/BoardInterface"; +import { LayerBoardOption, BrRelativePos, VerticalBoardOption, BehindBoardOption, BehindHeightPositon, TBBoardOption, LayerNailOption, SingleBoardOption, ClosingStripOption, StripType, LinesType, FaceDirection, ComposingType, IBoardBatchCurtailOption, CurtailType, BoardProcessOption, SideBoardOption, BoardType, ModifyTextsConfigOption } from "../UI/Store/BoardInterface"; import { IWineRackOption, EWineRackType, EWRackArrayType, EFullType, EFullDir } from "../UI/Store/WineRackInterface"; import { IBoardFindOption, ECompareType } from "../UI/Store/BoardFindInterface"; import { ILatticeOption, ELatticeArrayType } from "../UI/Store/LatticeInterface"; @@ -155,6 +155,11 @@ export const DefaultSideBoardOption: SideBoardOption = { }; Object.freeze(DefaultSideBoardOption); +export const DefaultModifyTextsOption: ModifyTextsConfigOption = { + changeTexts: Array.from({ length: 5 }, () => ["", ""]), +}; +Object.freeze(DefaultModifyTextsOption); + export const DefaultSingleBoardOption: SingleBoardOption = { version: 1, name: "层板", diff --git a/src/UI/Components/Board/BoardModal.tsx b/src/UI/Components/Board/BoardModal.tsx index ae513786a..97d0d750f 100644 --- a/src/UI/Components/Board/BoardModal.tsx +++ b/src/UI/Components/Board/BoardModal.tsx @@ -54,6 +54,7 @@ export enum BoardModalType ParseBrName = "ParseBrName",//分析板件名 AutoDimBrs = "AutoDimBrs",//自动标注 ChangeColorByMaterial = "ChangeColorByMaterial", + ModifyTexts = "ModifyTexts",//批量修改文本 } export interface BoardModalProps { diff --git a/src/UI/Components/CommandPanel/CommandList.ts b/src/UI/Components/CommandPanel/CommandList.ts index 328402b7d..af68be575 100644 --- a/src/UI/Components/CommandPanel/CommandList.ts +++ b/src/UI/Components/CommandPanel/CommandList.ts @@ -672,6 +672,15 @@ export const CommandList: ICommand[] = [ chName: "根据排版面改颜色", chDes: "根据排版面改颜色", }, + { + typeId: "bjbj", + link: "#", + defaultCustom: CommandNames.TextModifyTool, + command: CommandNames.TextModifyTool, + type: "文本编辑", + chName: "批量修改文本", + chDes: "批量修改文本", + }, { icon: IconEnum.RestoreColor, typeId: "bjbj", diff --git a/src/UI/Components/Text/TextModify.tsx b/src/UI/Components/Text/TextModify.tsx new file mode 100644 index 000000000..d55383962 --- /dev/null +++ b/src/UI/Components/Text/TextModify.tsx @@ -0,0 +1,138 @@ +import { Button, Classes, Icon } from "@blueprintjs/core"; +import { observable, toJS } from "mobx"; +import { observer } from "mobx-react"; +import React from "react"; +import { app } from "../../../ApplicationServices/Application"; +import { DefaultModifyTextsOption } from "../../../Editor/DefaultConfig"; +import { ModifyTextsConfigOption } from "../../Store/BoardInterface"; +import { IConfigStore } from "../../Store/BoardStore"; +import { BoardModalType } from "../Board/BoardModal"; +import { IConfigOption, UserConfig } from "../Board/UserConfig"; +import { ModalState } from "../Modal/ModalInterface"; + +export class ModifyTextsStore implements IConfigStore +{ + @observable configName = "默认"; + SaveConfig() + { + //新的配置 + let newConfig: IConfigOption = {}; + newConfig.option = toJS(this.m_Option); + return newConfig; + }; + //板数据 + @observable m_Option: ModifyTextsConfigOption = { ...DefaultModifyTextsOption }; + @observable configsNames: string[] = []; + InitOption() + { + Object.assign(this.m_Option, DefaultModifyTextsOption); + } + UpdateOption(cof: IConfigOption) + { + this.m_Option.changeTexts = cof.option.changeTexts.concat(); + } + + private static _SingleInstance: ModifyTextsStore; + static GetInstance(): ModifyTextsStore + { + if (this._SingleInstance) return this._SingleInstance; + this._SingleInstance = new ModifyTextsStore; + return this._SingleInstance; + } +} + +@observer +export class TextModifyModal extends React.Component<{ store: ModifyTextsStore; }, {}> +{ + render() + { + return ( +
+
+
+ +

批量编辑文本

+
+
+ + + + + + { + this.props.store.m_Option.changeTexts.map((d, i) => + + + + ) + } +
替换的文本替换后的文本
+ d[0] = e.target.value} /> + 替换为--> + d[1] = e.target.value} />
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ ); + } +} diff --git a/src/UI/Css/blue.less b/src/UI/Css/blue.less index 5f78da258..70556aa99 100644 --- a/src/UI/Css/blue.less +++ b/src/UI/Css/blue.less @@ -184,7 +184,8 @@ } #TopPanel .bp3-navbar { - height: 27px; + padding: 0; + height : 27px; } #TopPanel .bp3-navbar-group { diff --git a/src/UI/Css/style.less b/src/UI/Css/style.less index fa325e13b..eab86609f 100644 --- a/src/UI/Css/style.less +++ b/src/UI/Css/style.less @@ -690,3 +690,46 @@ img { text-overflow: ellipsis; white-space : nowrap; } + +//批量修改文字工具命令TextModifyTool +#TextModifytModal{ + width : 520px; + + .bp3-dialog-body{ + margin: auto; + + table{ + margin-top: 10px; + } + + .bp3-input:not([type=search]){ + height: 22px; + } + + span{ + padding: 2px; + vertical-align: middle; + } + } + + .bp3-dialog-footer{ + display: block; + } + + .changeLength{ + text-align: center; + + button{ + margin: 10px; + } + } + .foot_left{ + position: absolute; + left : 3%; + + .bp3-button.bp3-intent-danger{ + margin: 0; + } + } +} +//-----批量修改文字工具结束-------- diff --git a/src/UI/Store/BoardInterface.ts b/src/UI/Store/BoardInterface.ts index 3d93b0652..e59d3f1f1 100644 --- a/src/UI/Store/BoardInterface.ts +++ b/src/UI/Store/BoardInterface.ts @@ -127,6 +127,12 @@ export interface BoardConfigOption extends IBaseOption height?: number; width?: number; } + +export interface ModifyTextsConfigOption +{ + changeTexts: [string, string][]; +} + export interface SideBoardOption extends BoardConfigOption { spaceSize?: number; //空间宽度 diff --git a/src/UI/Store/BoardStore.ts b/src/UI/Store/BoardStore.ts index 682e0f2b8..56142eac5 100644 --- a/src/UI/Store/BoardStore.ts +++ b/src/UI/Store/BoardStore.ts @@ -1,5 +1,6 @@ -import { observable, toJS, action } from 'mobx'; +import { action, observable, toJS } from 'mobx'; +import { begin } from 'xaop'; import { app } from '../../ApplicationServices/Application'; import { EBoardKeyList } from '../../Common/BoardKeyList'; import { CheckObjectType, CheckoutValid } from '../../Common/CheckoutVaildValue'; @@ -8,14 +9,13 @@ import { Singleton } from '../../Common/Singleton'; import { ClosingStripReg } from '../../Common/Utils'; import { Board } from '../../DatabaseServices/Entity/Board'; import { TemplateRecord } from '../../DatabaseServices/Template/TemplateRecord'; -import { DefaultBehindBoardConfig, DefaultLayerBoardConfig, DefaultVerticalBoardConfig, DefaultTopBoardOption, DefaultBottomBoardOption, DefaultSideBoardOption, DefaultSingleBoardOption, DefaultClosingStripOption, DefaultNailOption, DefaultBoardProcessOption } from '../../Editor/DefaultConfig'; +import { DefaultBehindBoardConfig, DefaultBoardProcessOption, DefaultBottomBoardOption, DefaultClosingStripOption, DefaultLayerBoardConfig, DefaultNailOption, DefaultSideBoardOption, DefaultSingleBoardOption, DefaultTopBoardOption, DefaultVerticalBoardConfig } from '../../Editor/DefaultConfig'; import { userConfig } from '../../Editor/UserConfig'; import { IConfigOption } from '../Components/Board/UserConfig'; import { ModalState } from '../Components/Modal/ModalInterface'; -import { BehindBoardOption, BoardConfigOption, IBaseOption, BoardProcessOption, BrRelativePos, ClosingStripOption, DrillType, FaceDirection, IGrooveOption, LayerBoardOption, LayerNailOption, SideBoardOption, SingleBoardOption, StripType, TBBoardOption, VerticalBoardOption, IUiOption, AnyObject, BoardType, IHightDrillOption, IDrawBoardAutoCutOption, BehindHeightPositon, LinesType } from './BoardInterface'; -import { begin } from 'xaop'; -import { ToasterValueError } from '../Components/Toaster'; import { IModalResult } from '../Components/Modal/ModalsManage'; +import { ToasterValueError } from '../Components/Toaster'; +import { AnyObject, BehindBoardOption, BehindHeightPositon, BoardConfigOption, BoardProcessOption, BoardType, BrRelativePos, ClosingStripOption, DrillType, FaceDirection, IBaseOption, IDrawBoardAutoCutOption, IGrooveOption, IHightDrillOption, IUiOption, LayerBoardOption, LayerNailOption, LinesType, SideBoardOption, SingleBoardOption, TBBoardOption, VerticalBoardOption } from './BoardInterface'; export interface IConfigStore