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 AppStorage.SetOrCreate(Constants.EDIT_REPLACE, 1); 89 }).backgroundColor($r('app.color.transparent')) 90 }.width(Constants.PERCENT_ONE_THIRD) 91 .padding({ 92 left: $r('app.float.details_dialog_button_margin_left'), 93 right: $r('app.float.details_dialog_button_margin_right') 94 }) 95 96 Row() { 97 Divider() 98 .vertical(true) 99 .height($r('app.float.dialog_divider_height')) 100 .color($r('app.color.divider_vertical_color')) 101 } 102 .height($r('app.float.details_dialog_button_height')) 103 .alignItems(VerticalAlign.Center) 104 105 Column() { 106 Button() { 107 Text($r('app.string.save_dialog_save_text')) 108 .fontColor($r('app.color.color_control_highlight')) 109 .fontSize($r('sys.float.ohos_id_text_size_button1')) 110 .fontWeight(FontWeight.Medium) 111 } 112 .height($r('app.float.details_dialog_button_height')) 113 .width('100%') 114 .onClick(() => { 115 this.controller.close() 116 this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []); 117 this.saveDialogCallback && this.saveDialogCallback.saveAsNewCallback() 118 AppStorage.SetOrCreate(Constants.EDIT_REPLACE, 1); 119 }).backgroundColor($r('app.color.transparent')) 120 } 121 .width(Constants.PERCENT_ONE_THIRD) 122 .padding({ left: $r('app.float.details_dialog_button_margin_left') }) 123 } 124 } 125 .width('100%') 126 .height($r('app.float.details_dialog_button_area_height')) 127 } else { 128 Flex({ 129 direction: FlexDirection.Column, 130 justifyContent: FlexAlign.Center, 131 alignItems: ItemAlign.Center, 132 }) { 133 Button() { 134 Text($r('app.string.save_dialog_save_text')) 135 .fontColor($r('app.color.color_control_highlight')) 136 .fontSize($r('sys.float.ohos_id_text_size_button1')) 137 .fontWeight(FontWeight.Medium) 138 } 139 .height($r('app.float.details_dialog_button_height')) 140 .margin({ bottom: $r('app.float.adjust_text_margin_bottom') }) 141 .onClick(() => { 142 this.controller.close() 143 this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []); 144 this.saveDialogCallback && this.saveDialogCallback.saveAsNewCallback() 145 AppStorage.SetOrCreate(Constants.EDIT_REPLACE, 1); 146 }).backgroundColor($r('app.color.transparent')) 147 148 Button() { 149 Text($r('app.string.save_dialog_overwrite_text')) 150 .fontColor($r('app.color.color_control_highlight')) 151 .fontSize($r('sys.float.ohos_id_text_size_button1')) 152 .fontWeight(FontWeight.Medium) 153 } 154 .height($r('app.float.details_dialog_button_height')) 155 .margin({ bottom: $r('app.float.adjust_text_margin_bottom') }) 156 .onClick(() => { 157 this.broadCast.emit(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG, []); 158 this.controller.close() 159 this.saveDialogCallback && this.saveDialogCallback.replaceOriginalCallback() 160 AppStorage.SetOrCreate(Constants.EDIT_REPLACE, 1); 161 }).backgroundColor($r('app.color.transparent')) 162 163 Button() { 164 Text($r('app.string.save_dialog_cancel_text')) 165 .fontColor($r('app.color.color_control_highlight')) 166 .fontSize($r('sys.float.ohos_id_text_size_button1')) 167 .fontWeight(FontWeight.Medium) 168 } 169 .height($r('app.float.details_dialog_button_height')) 170 .margin({ bottom: $r('app.float.adjust_text_padding_bottom_isVertical') }) 171 .onClick(() => { 172 this.controller.close() 173 }).backgroundColor($r('app.color.transparent')) 174 } 175 .height($r('app.float.save_dialog_height')) 176 .width('100%') 177 } 178 179 } 180 .alignItems(HorizontalAlign.Start) 181 .width(screenManager.getColumnsWidth(4)) 182 .backgroundColor($r('app.color.white')) 183 .borderRadius($r('app.float.dialog_border_radius')) 184 .margin({ 185 right: $r('app.float.dialog_window_margin'), 186 left: $r('app.float.dialog_window_margin'), 187 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3]) 188 }) 189 .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') }) 190 } 191} 192