<commit_before>const { ModifierType } = imports.gi.Gdk;
const { Pixbuf } = imports.gi.GdkPixbuf;
const Gtk = imports.gi.Gtk;
const { TreeIter, TreeModel, TreePath, TreeView, TreeViewColumn } = Gtk;
const assign = require("lodash/assign");
const noop = require("lodash/noop");
const { autoBind } = require("../Gjs/autoBind");
const KeyListener = require("../Gjs/KeyListener").default;
const { ListStore } = require("./ListStore");

/**
 * @typedef Col
 * @property {boolean=} expand
 * @property {number=} min_width
 * @property {any=} on_clicked
 * @property {string=} title
 * @property {any} type
 */

/**
 * @param {TreeView} node
 */
function ListTable(node) {
  ListTable.prototype.useNodeAsThis.call(node);
  return node;
}

/**
 * Cursor row index.
 * @type {number}
 */
ListTable.prototype._cursor = undefined;

/**
 * Rows per screen.
 * @type {number}
 */
ListTable.prototype.limit = undefined;

/**
 * Defined when user clicks a row, as opposed to key press.
 * @type {any}
 */
ListTable.prototype.mouseEvent = undefined;

/** @type {TreeView} */
ListTable.prototype.node = undefined;

/** @type {boolean} */
ListTable.prototype.shouldReactToCursorChanges = undefined;

/** @type {{ children: any[] }} */
ListTable.prototype.store = undefined;

/**
 * @param {{ children: any[] }} newChild
 */
ListTable.prototype.appendChild = function(newChild) {
  this.store = newChild;

  Object.defineProperties(this.store, {
    parentNode: { value: this },
  });
};

/**
 * @param {(index: number) => void} callback
 */
ListTable.prototype.setActivatedCallback = function(callback) {
  this.setActivatedCallback = noop;

  this.node.connect("row_activated", (/** @type {any} */ _, /** @type {any} */ path) => {
    const index = path.get_indices()[0];
    callback(index);
  });
};

/**
 * @param {Col[]} cols
 */
ListTable.prototype.setCols = function(cols) {
  this.setCols = (/** @type {Col[]} */ nextCols) => {
    const tvCols = this.node.get_columns();
    for (let i = 0; i < nextCols.length; i++) {
      tvCols[i].title = nextCols[i].title || "";
    }
  };

  for (let i = 0; i < cols.length; i++) {
    const col = cols[i];

    if (col.type === Pixbuf) {
      continue;
    }

    const tvCol = new TreeViewColumn();
    ListStore.bindView(tvCol, col, i);

    if (col.expand) {
      tvCol.expand = true;
    }

    if (col.min_width) {
      tvCol.min_width = col.min_width;
    }

    if (col.on_clicked) {
      tvCol.clickable = true;
      tvCol.connect("clicked", col.on_clicked);
    }

    if (col.title) {
      tvCol.title = col.title;
    }

    this.node.insert_column(tvCol, i);
  }
};

/**
 * @param {number} rowIndex
 */
ListTable.prototype.setCursor = function(rowIndex) {<commit_msg>List: Fix table column update regression<commit_after>const { ModifierType } = imports.gi.Gdk;
const { Pixbuf } = imports.gi.GdkPixbuf;
const Gtk = imports.gi.Gtk;
const { TreeIter, TreeModel, TreePath, TreeView, TreeViewColumn } = Gtk;
const assign = require("lodash/assign");
const noop = require("lodash/noop");
const { autoBind } = require("../Gjs/autoBind");
const KeyListener = require("../Gjs/KeyListener").default;
const { ListStore } = require("./ListStore");

/**
 * @typedef Col
 * @property {boolean=} expand
 * @property {number=} min_width
 * @property {any=} on_clicked
 * @property {string=} title
 * @property {any} type
 */

/**
 * @param {TreeView} node
 */
function ListTable(node) {
  ListTable.prototype.useNodeAsThis.call(node);
  return node;
}

/**
 * Cursor row index.
 * @type {number}
 */
ListTable.prototype._cursor = undefined;

/**
 * Rows per screen.
 * @type {number}
 */
ListTable.prototype.limit = undefined;

/**
 * Defined when user clicks a row, as opposed to key press.
 * @type {any}
 */
ListTable.prototype.mouseEvent = undefined;

/** @type {TreeView} */
ListTable.prototype.node = undefined;

/** @type {boolean} */
ListTable.prototype.shouldReactToCursorChanges = undefined;

/** @type {{ children: any[] }} */
ListTable.prototype.store = undefined;

/**
 * @param {{ children: any[] }} newChild
 */
ListTable.prototype.appendChild = function(newChild) {
  this.store = newChild;

  Object.defineProperties(this.store, {
    parentNode: { value: this },
  });
};

/**
 * @param {(index: number) => void} callback
 */
ListTable.prototype.setActivatedCallback = function(callback) {
  this.setActivatedCallback = noop;

  this.node.connect("row_activated", (/** @type {any} */ _, /** @type {any} */ path) => {
    const index = path.get_indices()[0];
    callback(index);
  });
};

/**
 * @param {Col[]} cols
 */
ListTable.prototype.setCols = function(cols) {
  let pixbufDelta = 0;

  this.setCols = (/** @type {Col[]} */ nextCols) => {
    const tvCols = this.node.get_columns();
    pixbufDelta = 0;

    for (let i = 0; i < nextCols.length; i++) {
      if (nextCols[i].type === Pixbuf) {
        pixbufDelta--;
        continue;
      }

      tvCols[i + pixbufDelta].title = nextCols[i].title || "";
    }
  };

  for (let i = 0; i < cols.length; i++) {
    const col = cols[i];

    if (col.type === Pixbuf) {
      pixbufDelta--;
      continue;
    }

    const tvCol = new TreeViewColumn();
    ListStore.bindView(tvCol, col, i);

    if (col.expand) {
      tvCol.expand = true;
    }

    if (col.min_width) {
      tvCol.min_width = col.min_width;
    }

    if (col.on_clicked) {
      tvCol.clickable = true;
      tvCol.connect("clicked", col.on_clicked);
    }

    if (col.title) {
      tvCol.title = col.title;
    }

    this.node.insert_column(tvCol, i + pixbufDelta);
  }
};

/**
 * @param {number} rowIndex
 */
ListTable.prototype.setCursor = function(rowIndex) {
{'fraction_non_alphanumeric': 0.17431355181576616, 'fraction_numerical': 0.00141718334809566, 'mean_word_length': 3.2451127819548873, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6783101', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1922, 'n_words': 410}