1// Copyright (C) 2020 The Android Open Source Project
2//
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 * as m from 'mithril';
16
17import {Actions} from '../../common/actions';
18import {TrackState} from '../../common/state';
19import {globals} from '../../frontend/globals';
20import {Track} from '../../frontend/track';
21import {TrackButton, TrackButtonAttrs} from '../../frontend/track_panel';
22import {trackRegistry} from '../../frontend/track_registry';
23import {ChromeSliceTrack} from '../chrome_slices/frontend';
24
25import {DEBUG_SLICE_TRACK_KIND} from './common';
26
27export class DebugSliceTrack extends ChromeSliceTrack {
28  static readonly kind = DEBUG_SLICE_TRACK_KIND;
29  static create(trackState: TrackState): Track {
30    return new DebugSliceTrack(trackState);
31  }
32
33  getTrackShellButtons(): Array<m.Vnode<TrackButtonAttrs>> {
34    const buttons: Array<m.Vnode<TrackButtonAttrs>> = [];
35    buttons.push(m(TrackButton, {
36      action: () => {
37        globals.dispatch(Actions.requestTrackReload({}));
38      },
39      i: 'refresh',
40      tooltip: 'Refresh tracks',
41      showButton: true,
42    }));
43    buttons.push(m(TrackButton, {
44      action: () => {
45        globals.dispatch(Actions.removeDebugTrack({}));
46      },
47      i: 'close',
48      tooltip: 'Close',
49      showButton: true,
50    }));
51    return buttons;
52  }
53}
54
55trackRegistry.register(DebugSliceTrack);
56