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 { Action, Log } from '@ohos/common'; 17import { ToolBar } from '@ohos/common/CommonComponents'; 18 19const TAG: string = 'timeline_TimelinePageToolBar'; 20 21@Component 22export struct TimelinePageToolBar { 23 @Consume @Watch('updateToolbar') isSelectedMode: boolean; 24 @Consume @Watch('updateToolbar') isAllSelected: boolean; 25 @Link @Watch('updateToolbar') totalSelectedCount: number; 26 @Provide selectedCount: number = 0; 27 onMenuClicked: Function = (): void => {}; 28 @Provide toolMenuList: Array<Action> = new Array<Action>(); 29 @Consume moreMenuList: Action[]; 30 @Consume hidePopup: boolean; 31 32 aboutToAppear(): void { 33 this.updateToolbar(); 34 } 35 36 build() { 37 ToolBar({ 38 onMenuClicked: this.onMenuClicked 39 }) 40 } 41 42 private updateToolbar(): void { 43 Log.info(TAG, 'updateToolbar'); 44 this.selectedCount = this.totalSelectedCount; 45 if (this.isSelectedMode) { 46 Log.info(TAG, 'pushActionToolbar'); 47 this.toolMenuList = []; 48 this.toolMenuList.push( 49 this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL, 50 Boolean(this.selectedCount) ? Action.DELETE : Action.DELETE_INVALID, Action.MORE); 51 } 52 } 53}