1/* 2 * Copyright (c) 2022-2023 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 { 17 BatchDeleteMenuOperation, 18 BroadCastConstants, 19 Constants, 20 Log, 21 MenuContext, 22 SelectManager 23} from '@ohos/common'; 24 25const TAG: string = 'browser_ClearRecycleMenuOperation'; 26 27export class ClearRecycleMenuOperation extends BatchDeleteMenuOperation { 28 constructor(menuContext: MenuContext) { 29 super(menuContext); 30 } 31 32 doAction(): void { 33 if (this.menuContext == null) { 34 Log.error(TAG, 'menuContext is null, return'); 35 return; 36 } 37 let selectManager: SelectManager = this.menuContext.selectManager; 38 if (selectManager == null) { 39 Log.error(TAG, 'selectManager is null, return'); 40 return; 41 } 42 selectManager.selectAllWithoutNotify(true, false); 43 this.count = selectManager.getSelectedCount(); 44 if (this.count <= 0) { 45 Log.error(TAG, 'count <= 0, return'); 46 return; 47 } 48 49 AppStorage.setOrCreate<Resource>(Constants.CONFIRM_TEXT_KEY, $r('app.string.dialog_clear')); 50 this.menuContext.broadCast.emit(BroadCastConstants.SHOW_DELETE_DIALOG, 51 [$r('app.string.recycleAlbum_clear_message'), (): void => this.confirmCallback(), (): void => this.cancelCallback()]); 52 } 53 54 cancelCallback(): void { 55 Log.info(TAG, 'Batch delete cancel'); 56 this.menuContext.selectManager.deSelectAll(); 57 } 58}