Skip to content

Commit

Permalink
feat(batch-rename): batch rename for multiple selected objs (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanfei authored Jan 18, 2025
1 parent 24f9db6 commit 078c1c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/lang/en/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"toggle_checkbox": "Toggle Checkbox",
"rename": "Rename",
"input_new_name": "Input new name",
"only_one-tips": "Only one object can be selected to rename",
"move": "Move",
"copy": "Copy",
"choose_dst_folder": "Select destination folder",
Expand Down
24 changes: 12 additions & 12 deletions src/pages/home/toolbar/BatchRename.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
notify,
} from "~/utils"
import { createSignal, For, onCleanup, Show } from "solid-js"
import { objStore } from "~/store"
import { selectedObjs } from "~/store"
import { RenameObj } from "~/types"
import { RenameItem } from "~/pages/home/toolbar/RenameItem"

Expand Down Expand Up @@ -72,7 +72,7 @@ export const BatchRename = () => {

let matchNames: RenameObj[]
if (type() === "1") {
matchNames = objStore.objs
matchNames = selectedObjs()
.filter((obj) => obj.name.match(srcName()))
.map((obj) => {
const renameObj: RenameObj = {
Expand All @@ -83,7 +83,7 @@ export const BatchRename = () => {
})
} else {
let tempNum = newName()
matchNames = objStore.objs.map((obj) => {
matchNames = selectedObjs().map((obj) => {
let suffix = ""
const lastDotIndex = obj.name.lastIndexOf(".")
if (lastDotIndex !== -1) {
Expand Down Expand Up @@ -121,18 +121,10 @@ export const BatchRename = () => {
<ModalOverlay />
<ModalContent>
{/* <ModalCloseButton /> */}
<Show when={type() === "1"}>
<ModalHeader>{t("home.toolbar.regular_rename")}</ModalHeader>
</Show>
<Show when={type() === "2"}>
<ModalHeader>
{t("home.toolbar.sequential_renaming_desc")}
</ModalHeader>
</Show>
<ModalHeader>{t("home.toolbar.batch_rename")}</ModalHeader>
<ModalBody>
<RadioGroup
defaultValue="1"
style={{ margin: "20px 0" }}
onChange={(event) => {
setType(event)
if (event === "1") {
Expand All @@ -148,6 +140,14 @@ export const BatchRename = () => {
</HStack>
</RadioGroup>
<VStack spacing="$2">
<p style={{ margin: "10px 0" }}>
<Show when={type() === "1"}>
{t("home.toolbar.regular_rename")}
</Show>
<Show when={type() === "2"}>
{t("home.toolbar.sequential_renaming_desc")}
</Show>
</p>
<Input
id="modal-input1" // Update id to "modal-input1" for first input
type={"string"}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/toolbar/Rename.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Rename = () => {
const handler = (name: string) => {
if (name === "rename") {
if (!oneChecked()) {
notify.warning(t("home.toolbar.only_one-tips"))
bus.emit("tool", "batchRename")
return
}
onOpen()
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/toolbar/Right.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createMemo, Show } from "solid-js"
import { RightIcon } from "./Icon"
import { CgMoreO } from "solid-icons/cg"
import { TbCheckbox } from "solid-icons/tb"
import { objStore, State, toggleCheckbox, userCan } from "~/store"
import { objStore, selectAll, State, toggleCheckbox, userCan } from "~/store"
import { bus } from "~/utils"
import { operations } from "./operations"
import { IoMagnetOutline } from "solid-icons/io"
Expand Down Expand Up @@ -100,6 +100,7 @@ export const Right = () => {
as={operations.batch_rename.icon}
tips="batch_rename"
onClick={() => {
selectAll(true)
bus.emit("tool", "batchRename")
}}
/>
Expand Down

0 comments on commit 078c1c5

Please sign in to comment.