• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import prompt from '@ohos.prompt'
16
17@CustomDialog
18export struct RenameDialog {
19  private controller: CustomDialogController
20  private action: (title: string) => void
21  @State title: string = ''
22
23  build() {
24    Column() {
25      Text($r('app.string.rename_file'))
26        .fontSize(20)
27        .fontColor(Color.Black)
28        .fontWeight(FontWeight.Bold)
29      TextInput({ placeholder: 'input new name', text: this.title })
30        .key('inputRename')
31        .type(InputType.Normal)
32        .placeholderColor(Color.Gray)
33        .maxLength(20)
34        .fontSize(19)
35        .margin({ left: 10, top: 15 })
36        .onChange((value: string) => {
37          this.title = value
38        })
39      Row() {
40        Button() {
41          Text($r('app.string.yes'))
42            .fontColor(Color.Red)
43            .fontSize(17)
44        }
45        .layoutWeight(7)
46        .backgroundColor(Color.White)
47        .margin(5)
48        .onClick(() => {
49          if (this.title === '') {
50            prompt.showToast({ message: 'please input the file name', duration: 1000 })
51            return
52          }
53          this.action(this.title)
54        })
55
56        Divider()
57          .height(30)
58          .vertical(true)
59          .strokeWidth(1)
60          .color('#8F8F8F')
61        Button() {
62          Text($r('app.string.cancel'))
63            .fontColor(Color.Blue)
64            .fontSize(17)
65        }
66        .layoutWeight(7)
67        .backgroundColor(Color.White)
68        .margin(5)
69        .onClick(() => {
70          this.controller.close()
71        })
72      }
73      .width('100%')
74      .margin({ top: '3%' })
75    }.padding(15)
76  }
77}