<commit_before>// Copyright (c) 2012 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.

'use strict';

/**
 * Namespace for utility functions.
 */
var filelist = {};

/**
 * Custom column model for advanced auto-resizing.
 *
 * @param {Array.<cr.ui.table.TableColumn>} tableColumns Table columns.
 * @extends {cr.ui.table.TableColumnModel}
 * @constructor
 */
function FileTableColumnModel(tableColumns) {
  cr.ui.table.TableColumnModel.call(this, tableColumns);
}

/**
 * Inherits from cr.ui.Table.
 */
FileTableColumnModel.prototype.__proto__ =
    cr.ui.table.TableColumnModel.prototype;

/**
 * Normalizes widths to make their sum 100% if possible. Uses the proportional
 * approach with some additional constraints.
 *
 * @param {number} contentWidth Target width.
 * @override
 */
FileTableColumnModel.prototype.normalizeWidths = function(contentWidth) {
  var fixedWidth = 0;
  var flexibleWidth = 0;
  var fixedColumns = ['size', 'selection'];

  // Some columns have fixed width.
  for (var index = 0; index < this.size; index++) {
    var column = this.columns_[index];
    if (fixedColumns.indexOf(column.id) > -1)
      fixedWidth += column.width;
    else
      flexibleWidth += column.width;
  }

  var factor = Math.max(0, contentWidth - fixedWidth) / flexibleWidth;
  for (var index = 0; index < this.size; index++) {
    var column = this.columns_[index];
    if (fixedColumns.indexOf(column.id) > -1)
      continue;
    // Limits the minimum width to 1px to avoid flexibleWidth=0.
    column.width = Math.max(1, column.width * factor);
  }
};

/**
 * File list Table View.
 * @constructor
 */
function FileTable() {
  throw new Error('Designed to decorate elements');
}

/**
 * Inherits from cr.ui.Table.
 */
FileTable.prototype.__proto__ = cr.ui.Table.prototype;

/**
 * Decorates the element.
 * @param {HTMLElement} self Table to decorate.
 * @param {MetadataCache} metadataCache To retrieve metadata.
 * @param {boolean} fullPage True if it's full page File Manager,
 *                           False if a file open/save dialog.
 */
FileTable.decorate = function(self, metadataCache, fullPage) {
  cr.ui.Table.decorate(self);
  self.__proto__ = FileTable.prototype;
  self.metadataCache_ = metadataCache;
  self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'});

  var columns = [
    new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'),
                                fullPage ? 386 : 324),
    new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'),
                                60, true),
    new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'),
                                fullPage ? 160 : 160),
    new cr.ui.table.TableColumn('modificationTime',
                                str('DATE_COLUMN_LABEL'),
                                fullPage ? 150 : 210)
  ];

  columns[0].renderFunction = self.renderName_.bind(self);
  columns[1].renderFunction = self.renderSize_.bind(self);
  columns[1].defaultOrder = 'desc';
  columns[2].renderFunction = self.renderType_.bind(self);
  columns[3].renderFunction = self.renderDate_.bind(self);
  columns[3].defaultOrder = 'desc';

  var tableColumnModelClass;
  if (util.platform.newUI()) {
    tableColumnModelClass = FileTableColumnModel;
    columns.push(new cr.ui.table.TableColumn('selection',
                                             '',
                                             50, true));
    columns[4].renderFunction = self.renderSelection_.bind(self);
    columns[4].headerRenderFunction =
        self.renderSelectionColumnHeader_.bind(self);
  } else {
    tableColumnModelClass = cr.ui.table.TableColumnModel;
    columns.push(new cr.ui.table.TableColumn('offline',
                                             str('OFFLINE_COLUMN_LABEL'),
                                             130));
    columns[4].renderFunction = self.renderOffline_.bind(self);
    columns[0].headerRenderFunction =
        self.renderNameColumnHeader_.bind(self, columns[0].name);
  }

  var columnModel = Object.create(tableColumnModelClass.prototype, {
    size: {
      get: function() {
        if (util.platform.newUI())
          return this.totalSize;
        return this.showOfflineColumn ? this.totalSize : this.totalSize - 1;
      }
    },

    totalSize: {
      get: function() {
        return columns.length;
      }
    },

    showOfflineColumn: {
      writable: true,
      value: false
    }
  });

  tableColumnModelClass.call(columnModel, columns);
  self.columnModel = columnModel;
  self.setDateTimeFormat(true);
  self.setRenderFunction(self.renderTableRow_.bind(self,
      self.getRenderFunction()));

  if (util.platform.newUI())
    ScrollBar.createVertical(self, self.list);

  var handleSelectionChange = function() {
    var selectAll = self.querySelector('#select-all-checkbox');
    if (selectAll)
      self.updateSelectAllCheckboxState_(selectAll);
  };
<commit_msg>Make selection solid and blue in Files.app.<commit_after>// Copyright (c) 2012 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.

'use strict';

/**
 * Namespace for utility functions.
 */
var filelist = {};

/**
 * Custom column model for advanced auto-resizing.
 *
 * @param {Array.<cr.ui.table.TableColumn>} tableColumns Table columns.
 * @extends {cr.ui.table.TableColumnModel}
 * @constructor
 */
function FileTableColumnModel(tableColumns) {
  cr.ui.table.TableColumnModel.call(this, tableColumns);
}

/**
 * Inherits from cr.ui.Table.
 */
FileTableColumnModel.prototype.__proto__ =
    cr.ui.table.TableColumnModel.prototype;

/**
 * Normalizes widths to make their sum 100% if possible. Uses the proportional
 * approach with some additional constraints.
 *
 * @param {number} contentWidth Target width.
 * @override
 */
FileTableColumnModel.prototype.normalizeWidths = function(contentWidth) {
  var fixedWidth = 0;
  var flexibleWidth = 0;
  var fixedColumns = ['size', 'selection'];

  // Some columns have fixed width.
  for (var index = 0; index < this.size; index++) {
    var column = this.columns_[index];
    if (fixedColumns.indexOf(column.id) > -1)
      fixedWidth += column.width;
    else
      flexibleWidth += column.width;
  }

  var factor = Math.max(0, contentWidth - fixedWidth) / flexibleWidth;
  for (var index = 0; index < this.size; index++) {
    var column = this.columns_[index];
    if (fixedColumns.indexOf(column.id) > -1)
      continue;
    // Limits the minimum width to 1px to avoid flexibleWidth=0.
    column.width = Math.max(1, column.width * factor);
  }
};

/**
 * File list Table View.
 * @constructor
 */
function FileTable() {
  throw new Error('Designed to decorate elements');
}

/**
 * Inherits from cr.ui.Table.
 */
FileTable.prototype.__proto__ = cr.ui.Table.prototype;

/**
 * Decorates the element.
 * @param {HTMLElement} self Table to decorate.
 * @param {MetadataCache} metadataCache To retrieve metadata.
 * @param {boolean} fullPage True if it's full page File Manager,
 *                           False if a file open/save dialog.
 */
FileTable.decorate = function(self, metadataCache, fullPage) {
  cr.ui.Table.decorate(self);
  self.__proto__ = FileTable.prototype;
  self.metadataCache_ = metadataCache;
  self.collator_ = v8Intl.Collator([], {numeric: true, sensitivity: 'base'});

  var columns = [
    new cr.ui.table.TableColumn('name', str('NAME_COLUMN_LABEL'),
                                fullPage ? 386 : 324),
    new cr.ui.table.TableColumn('size', str('SIZE_COLUMN_LABEL'),
                                60, true),
    new cr.ui.table.TableColumn('type', str('TYPE_COLUMN_LABEL'),
                                fullPage ? 160 : 160),
    new cr.ui.table.TableColumn('modificationTime',
                                str('DATE_COLUMN_LABEL'),
                                fullPage ? 150 : 210)
  ];

  columns[0].renderFunction = self.renderName_.bind(self);
  columns[1].renderFunction = self.renderSize_.bind(self);
  columns[1].defaultOrder = 'desc';
  columns[2].renderFunction = self.renderType_.bind(self);
  columns[3].renderFunction = self.renderDate_.bind(self);
  columns[3].defaultOrder = 'desc';

  var tableColumnModelClass;
  if (util.platform.newUI()) {
    tableColumnModelClass = FileTableColumnModel;
    columns.push(new cr.ui.table.TableColumn('selection',
                                             '',
                                             50, true));
    columns[4].renderFunction = self.renderSelection_.bind(self);
    columns[4].headerRenderFunction =
        self.renderSelectionColumnHeader_.bind(self);
  } else {
    tableColumnModelClass = cr.ui.table.TableColumnModel;
    columns.push(new cr.ui.table.TableColumn('offline',
                                             str('OFFLINE_COLUMN_LABEL'),
                                             130));
    columns[4].renderFunction = self.renderOffline_.bind(self);
    columns[0].headerRenderFunction =
        self.renderNameColumnHeader_.bind(self, columns[0].name);
  }

  var columnModel = Object.create(tableColumnModelClass.prototype, {
    size: {
      get: function() {
        if (util.platform.newUI())
          return this.totalSize;
        return this.showOfflineColumn ? this.totalSize : this.totalSize - 1;
      }
    },

    totalSize: {
      get: function() {
        return columns.length;
      }
    },

    showOfflineColumn: {
      writable: true,
      value: false
    }
  });

  tableColumnModelClass.call(columnModel, columns);
  self.columnModel = columnModel;
  self.setDateTimeFormat(true);
  self.setRenderFunction(self.renderTableRow_.bind(self,
      self.getRenderFunction()));

  if (util.platform.newUI()) {
    ScrollBar.createVertical(self, self.list);
    // Keep focus on the file list when clicking on the header.
    self.header.addEventListener('mousedown', function(e) {
      self.list.focus();
      e.preventDefault();
    });
  }

  var handleSelectionChange = function() {
    var selectAll = self.querySelector('#select-all-checkbox');
    if (selectAll)
      self.updateSelectAllCheckboxState_(selectAll);
  };

{'fraction_non_alphanumeric': 0.12308890836498199, 'fraction_numerical': 0.010711851202648748, 'mean_word_length': 2.7468077344035025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2137687', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2948, 'n_words': 667}