• 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 */
15
16import { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast'
17import  screenManager  from '@ohos/base/src/main/ets/manager/ScreenManager'
18import { BroadcastConstants } from '@ohos/base/src/main/ets/constants/BroadcastConstants'
19import { Constants } from '../../model/common/Constants';
20import { DateUtil } from '@ohos/base/src/main/ets/utils/DateUtil';
21
22
23@Observed
24export class SaveDialogCallback {
25    saveAsNewCallback: Function
26    replaceOriginalCallback: Function
27}
28
29@CustomDialog
30export struct SaveDialog {
31    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
32    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
33    @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0];
34    @Consume broadCast: Broadcast;
35    @Consume saveDialogCallback: SaveDialogCallback;
36    controller: CustomDialogController;
37
38    build() {
39        Column() {
40            Text($r('app.string.save_dialog_title_text')).fontSize($r('sys.float.ohos_id_text_size_headline7'))
41                .fontColor($r('sys.color.ohos_id_color_text_primary')).fontWeight(FontWeight.Medium)
42                .height($r('app.float.title_default'))
43            Text($r('app.string.save_dialog_context_text')).fontSize($r('sys.float.ohos_id_text_size_body1'))
44                .fontColor($r('sys.color.ohos_id_color_text_primary'))
45                .margin({ bottom: $r('app.float.adjust_text_padding_bottom_isVertical') })
46            if (DateUtil.getLocales() == 'zh-CN') {
47                Stack({ alignContent: Alignment.Top }) {
48                    Row() {
49                        Column() {
50                            Button() {
51                                Text($r('app.string.save_dialog_cancel_text'))
52                                    .fontColor($r('app.color.color_control_highlight'))
53                                    .fontSize($r('sys.float.ohos_id_text_size_button1'))
54                                    .fontWeight(FontWeight.Medium)
55                            }
56                            .height($r('app.float.details_dialog_button_height'))
57                            .width('100%')
58                            .onClick(() => {
59                                this.controller.close()
60                            }).backgroundColor($r('app.color.transparent'))
61                        }
62                        .width(Constants.PERCENT_ONE_THIRD)
63                        .padding({ right: $r('app.float.details_dialog_button_margin_right') })
64
65
66                        Row() {
67                            Divider()
68                                .vertical(true)
69                                .height($r('app.float.dialog_divider_height'))
70                                .color($r('app.color.divider_vertical_color'))
71                        }
72                        .height($r('app.float.details_dialog_button_height'))
73                        .alignItems(VerticalAlign.Center)
74
75                        Column() {
76                            Button() {
77                                Text($r('app.string.save_dialog_overwrite_text'))
78                                    .fontColor($r('app.color.color_control_highlight'))
79                                    .fontSize($r('sys.float.ohos_id_text_size_button1'))
80                                    .fontWeight(FontWeight.Medium)
81                            }
82                            .height($r('app.float.details_dialog_button_height'))
83                            .width('100%')
84                            .onClick(() => {
85                                this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []);
86                                this.controller.close()
87                                this.saveDialogCallback && this.saveDialogCallback.replaceOriginalCallback()
88                            }).backgroundColor($r('app.color.transparent'))
89                        }.width(Constants.PERCENT_ONE_THIRD)
90                        .padding({
91                            left: $r('app.float.details_dialog_button_margin_left'),
92                            right: $r('app.float.details_dialog_button_margin_right')
93                        })
94
95                        Row() {
96                            Divider()
97                                .vertical(true)
98                                .height($r('app.float.dialog_divider_height'))
99                                .color($r('app.color.divider_vertical_color'))
100                        }
101                        .height($r('app.float.details_dialog_button_height'))
102                        .alignItems(VerticalAlign.Center)
103
104                        Column() {
105                            Button() {
106                                Text($r('app.string.save_dialog_save_text'))
107                                    .fontColor($r('app.color.color_control_highlight'))
108                                    .fontSize($r('sys.float.ohos_id_text_size_button1'))
109                                    .fontWeight(FontWeight.Medium)
110                            }
111                            .height($r('app.float.details_dialog_button_height'))
112                            .width('100%')
113                            .onClick(() => {
114                                this.controller.close()
115                                this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []);
116                                this.saveDialogCallback && this.saveDialogCallback.saveAsNewCallback()
117                            }).backgroundColor($r('app.color.transparent'))
118                        }
119                        .width(Constants.PERCENT_ONE_THIRD)
120                        .padding({ left: $r('app.float.details_dialog_button_margin_left') })
121                    }
122                }
123                .width('100%')
124                .height($r('app.float.details_dialog_button_area_height'))
125            } else {
126                Flex({
127                    direction: FlexDirection.Column,
128                    justifyContent: FlexAlign.Center,
129                    alignItems: ItemAlign.Center,
130                }) {
131                    Button() {
132                        Text($r('app.string.save_dialog_save_text'))
133                            .fontColor($r('app.color.color_control_highlight'))
134                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
135                            .fontWeight(FontWeight.Medium)
136                    }
137                    .height($r('app.float.details_dialog_button_height'))
138                    .margin({ bottom: $r('app.float.adjust_text_margin_bottom') })
139                    .onClick(() => {
140                        this.controller.close()
141                        this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []);
142                        this.saveDialogCallback && this.saveDialogCallback.saveAsNewCallback()
143                    }).backgroundColor($r('app.color.transparent'))
144
145                    Button() {
146                        Text($r('app.string.save_dialog_overwrite_text'))
147                            .fontColor($r('app.color.color_control_highlight'))
148                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
149                            .fontWeight(FontWeight.Medium)
150                    }
151                    .height($r('app.float.details_dialog_button_height'))
152                    .margin({ bottom: $r('app.float.adjust_text_margin_bottom') })
153                    .onClick(() => {
154                        this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []);
155                        this.controller.close()
156                        this.saveDialogCallback && this.saveDialogCallback.replaceOriginalCallback()
157                    }).backgroundColor($r('app.color.transparent'))
158
159                    Button() {
160                        Text($r('app.string.save_dialog_cancel_text'))
161                            .fontColor($r('app.color.color_control_highlight'))
162                            .fontSize($r('sys.float.ohos_id_text_size_button1'))
163                            .fontWeight(FontWeight.Medium)
164                    }
165                    .height($r('app.float.details_dialog_button_height'))
166                    .margin({ bottom: $r('app.float.adjust_text_padding_bottom_isVertical') })
167                    .onClick(() => {
168                        this.controller.close()
169                    }).backgroundColor($r('app.color.transparent'))
170                }
171                .height($r('app.float.save_dialog_height'))
172                .width('100%')
173            }
174
175        }
176        .alignItems(HorizontalAlign.Start)
177        .width(screenManager.getColumnsWidth(4))
178        .backgroundColor($r('app.color.white'))
179        .borderRadius($r('app.float.dialog_border_radius'))
180        .margin({
181            right: $r('app.float.dialog_window_margin'),
182            left: $r('app.float.dialog_window_margin'),
183            bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3])
184        })
185        .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') })
186    }
187}
188