<commit_before>// Copyright 2018 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 'dart:html' as html;

import '../globals.dart';
import 'elements.dart';
import 'primer.dart';

// TODO(kenzie): perhaps add same icons we use in IntelliJ to these buttons.
// This would help to build icon familiarity.
PButton createExtensionButton(String text, String extensionName) {
  final PButton button = new PButton(text)..small();

  button.click(() {
    final bool wasSelected = button.element.classes.contains('selected');
    serviceManager.serviceExtensionManager
        .setServiceExtensionState(extensionName, !wasSelected, !wasSelected);
  });

  // Disable button for unavailable service extensions.
  serviceManager.serviceExtensionManager.hasServiceExtension(
      extensionName, (available) => button.disabled = !available);

  // Select button whose state is already enabled.
  serviceManager.serviceExtensionManager.getServiceExtensionState(
      extensionName, (state) => button.toggleClass('selected', state.enabled));

  return button;
}

CoreElement createExtensionCheckBox(String extensionName) {
  final CoreElement input = checkbox();

  serviceManager.serviceExtensionManager.hasServiceExtension(
      extensionName, (available) => input.disabled = !available);

  serviceManager.serviceExtensionManager.getServiceExtensionState(extensionName,
      (state) => input.toggleAttribute('checked', state.value ?? false));

  input.element.onChange.listen((_) {
    final html.InputElement e = input.element;
    serviceManager.serviceExtensionManager
        .setServiceExtensionState(extensionName, e.checked, e.checked);
  });

  return div(c: 'form-checkbox')
    ..add(new CoreElement('label')
      ..add(<CoreElement>[
        input,
        span(text: extensionName),
      ]));
}<commit_msg>Modify checked property instead of attribute for extension checkboxes. (#74)<commit_after>// Copyright 2018 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 'dart:html' as html;

import '../globals.dart';
import 'elements.dart';
import 'primer.dart';

// TODO(kenzie): perhaps add same icons we use in IntelliJ to these buttons.
// This would help to build icon familiarity.
PButton createExtensionButton(String text, String extensionName) {
  final PButton button = new PButton(text)..small();

  button.click(() {
    final bool wasSelected = button.element.classes.contains('selected');
    serviceManager.serviceExtensionManager
        .setServiceExtensionState(extensionName, !wasSelected, !wasSelected);
  });

  // Disable button for unavailable service extensions.
  serviceManager.serviceExtensionManager.hasServiceExtension(
      extensionName, (available) => button.disabled = !available);

  // Select button whose state is already enabled.
  serviceManager.serviceExtensionManager.getServiceExtensionState(
      extensionName, (state) => button.toggleClass('selected', state.enabled));

  return button;
}

CoreElement createExtensionCheckBox(String extensionName) {
  final CoreElement input = checkbox();

  serviceManager.serviceExtensionManager.hasServiceExtension(
      extensionName, (available) => input.disabled = !available);

  serviceManager.serviceExtensionManager.getServiceExtensionState(extensionName,
      (state) {
    final html.InputElement e = input.element;
    e.checked = state.value;
  });

  input.element.onChange.listen((_) {
    final html.InputElement e = input.element;
    serviceManager.serviceExtensionManager
        .setServiceExtensionState(extensionName, e.checked, e.checked);
  });

  return div(c: 'form-checkbox')
    ..add(new CoreElement('label')
      ..add(<CoreElement>[
        input,
        span(text: extensionName),
      ]));
}
{'fraction_non_alphanumeric': 0.10691502934422047, 'fraction_numerical': 0.0025516713447307987, 'mean_word_length': 4.340599455040872, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '4471378', 'n_tokens_mistral': 1044, 'n_tokens_neox': 999, 'n_words': 284}