<commit_before>// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';
import 'package:vm_service/vm_service.dart';

import '../../devtools.dart' as devtools show version;
import '../framework/framework.dart';
import '../globals.dart';
import '../ui/analytics_platform.dart' as ga_platform;
import '../ui/elements.dart';
import '../version.dart';
import 'info_controller.dart';

class FlagDetailsUI extends CoreElement {
  FlagDetailsUI(Flag flag) : super('div', classes: 'flag-details-container') {
    final flagDescription = div(c: 'flag-details-descriptions-container')
      ..add(<CoreElement>[
        div(c: 'info-title', text: flag.name),
        span(c: 'flag-description', text: flag.comment),
      ]);

    final flagValues = div(c: 'flag-details-values-container')
      ..layoutVertical()
      ..add(<CoreElement>[
        span(c: 'flag-value', text: flag.valueAsString),
        span(c: 'flag-modified', text: flag.modified ? 'modified' : 'default')
      ]);

    add(<CoreElement>[
      flagDescription,
      flagValues,
    ]);
  }
}

class InfoScreen extends Screen {
  InfoScreen()
      : super(
          name: '',
          id: 'info',
          iconClass: 'octicon-info',
          showTab: false,
        ) {
    _controller = InfoController(
      onFlagListChanged: (FlagList flagList) {
        _flagList
          ..clear()
          ..add(flagList.flags.map((flag) => FlagDetailsUI(flag)));
      },
      onFlutterVersionChanged: (FlutterVersion version) {
        _updateFlutterVersionUI(version);
      },
    );
  }

  CoreElement _flagList;

  CoreElement _flutterVersionContainer;

  CoreElement _versionContainer;

  InfoController _controller;

  @override
  CoreElement createContent(Framework framework) {
    ga_platform.setupDimensions();
    this.framework = framework;
    final CoreElement screenDiv = div(c: 'custom-scrollbar')..layoutVertical();

    _versionContainer = div(c: 'version-container')
      ..layoutVertical()
      ..flex()
      ..add([
        _flutterVersionContainer = div()
          ..layoutVertical()
          ..hidden(true),
        _versionDisplay(
          title: 'Dart SDK:',
          value: serviceManager.sdkVersion,
        ),
        _versionDisplay(
          title: 'DevTools:',
          value: devtools.version,
          includeMargin: false,
        ),
      ]);

    screenDiv
      ..add([
        div(c: 'section')
          ..add([
            h2(text: 'Version Information'),
            _versionContainer,
          ]),
        div(c: 'section flag-section')
          ..add([
            h2(text: 'Dart VM Flag List'),
            div(c: 'flag-list-container')
              ..flex()
              ..add(_flagList = div(c: 'flag-list')..layoutVertical()),
          ]),
      ]);

    _controller.entering();
    return screenDiv;
  }

  void _updateFlutterVersionUI(FlutterVersion version) {
    if (version != null) {
      _flutterVersionContainer
        ..clear()
        ..add([
          _versionDisplay(
            title: 'Flutter:',
            value: version.flutterVersionSummary,
          ),
          _versionDisplay(
            title: 'Framework:',
            value: version.frameworkVersionSummary,
          ),
          _versionDisplay(<commit_msg>Hide Dart VM flags section if connected app is not running on Dart VM. (#1016)<commit_after>// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';
import 'package:vm_service/vm_service.dart';

import '../../devtools.dart' as devtools show version;
import '../framework/framework.dart';
import '../globals.dart';
import '../ui/analytics_platform.dart' as ga_platform;
import '../ui/elements.dart';
import '../version.dart';
import 'info_controller.dart';

class FlagDetailsUI extends CoreElement {
  FlagDetailsUI(Flag flag) : super('div', classes: 'flag-details-container') {
    final flagDescription = div(c: 'flag-details-descriptions-container')
      ..add(<CoreElement>[
        div(c: 'info-title', text: flag.name),
        span(c: 'flag-description', text: flag.comment),
      ]);

    final flagValues = div(c: 'flag-details-values-container')
      ..layoutVertical()
      ..add(<CoreElement>[
        span(c: 'flag-value', text: flag.valueAsString),
        span(c: 'flag-modified', text: flag.modified ? 'modified' : 'default')
      ]);

    add(<CoreElement>[
      flagDescription,
      flagValues,
    ]);
  }
}

class InfoScreen extends Screen {
  InfoScreen()
      : super(
          name: '',
          id: 'info',
          iconClass: 'octicon-info',
          showTab: false,
        ) {
    _controller = InfoController(
      onFlagListChanged: (FlagList flagList) {
        _flagList
          ..clear()
          ..add(flagList.flags.map((flag) => FlagDetailsUI(flag)));
      },
      onFlutterVersionChanged: (FlutterVersion version) {
        _updateFlutterVersionUI(version);
      },
    );
  }

  CoreElement _flagList;

  CoreElement _flutterVersionContainer;

  CoreElement _versionContainer;

  InfoController _controller;

  @override
  CoreElement createContent(Framework framework) {
    ga_platform.setupDimensions();
    this.framework = framework;
    final CoreElement screenDiv = div(c: 'custom-scrollbar')..layoutVertical();

    _versionContainer = div(c: 'version-container')
      ..layoutVertical()
      ..flex()
      ..add([
        _flutterVersionContainer = div()
          ..layoutVertical()
          ..hidden(true),
        _versionDisplay(
          title: 'Dart SDK:',
          value: serviceManager.sdkVersion,
        ),
        _versionDisplay(
          title: 'DevTools:',
          value: devtools.version,
          includeMargin: false,
        ),
      ]);

    screenDiv
      ..add([
        div(c: 'section')
          ..add([
            h2(text: 'Version Information'),
            _versionContainer,
          ]),
        div(c: 'section flag-section')
          ..add([
            h2(text: 'Dart VM Flag List'),
            div(c: 'flag-list-container')
              ..flex()
              ..add(_flagList = div(c: 'flag-list')..layoutVertical()),
          ])
          ..hidden(!serviceManager.connectedApp.isRunningOnDartVM)
      ]);

    _controller.entering();
    return screenDiv;
  }

  void _updateFlutterVersionUI(FlutterVersion version) {
    if (version != null) {
      _flutterVersionContainer
        ..clear()
        ..add([
          _versionDisplay(
            title: 'Flutter:',
            value: version.flutterVersionSummary,
          ),
          _versionDisplay(
            title: 'Framework:',
            value: version.frameworkVersionSummary,
          ),
          _versionDisplay(
{'fraction_non_alphanumeric': 0.13124190531011656, 'fraction_numerical': 0.00230248956684415, 'mean_word_length': 2.2644434006575858, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2486856', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1937, 'n_words': 432}