<commit_before>
function WinFrame(windb, title_str) { 
  this.tabArray = [];
  this.numTabs = 0;
  this.windb = windb;
  this.elem = $('<div></div>').attr('class','mwin').attr('id', ''+windb.wid);

  if(!title_str) {
    title_str = windb.title
  }
  if(title_str) {
    var text = WinFrame.createTitle(title_str);
  } else {
    var text = WinFrame.createTitle("Name this window");
  }

  var email_icon = $('<a></a>')
          .attr('class','mailtolink')
          .attr('href','')
          .append(
            $('<img/>')
            .attr('class','emailicon')
            .attr('src', WinFrame.emailIcon));

  var save_icon = $('<img/>').attr('class','saveicon')
        .attr('src', WinFrame.saveIcon)
        .click(WinFrame.saveWindow);

  var wtitle = $('<div></div>').attr('class','wtitle');
  wtitle.append(email_icon);
  wtitle.append(save_icon);
  wtitle.append(text);
  this.elem.append(wtitle);

  $('body').append(this.elem);
}

WinFrame.saveIcon = chrome.extension.getURL('images/save.png');
WinFrame.emailIcon = chrome.extension.getURL('images/email.png');

WinFrame.saveWindow = function(ev) {
  var wid = $(this).parent().parent().attr('id');
  bgport.postMessage({
    name : 'savewindow',
    wid : wid,
  });
}

WinFrame.createTitle = function(title) {
  return $('<div></div>').attr('class','text').text(title)
    .click(WinFrame.editTitle)
    .css('width',(UI.winw-150)+'px');
}

WinFrame.createTitleInput = function() {
  var inp = $('<input></input>');
  var inpw = $('<div></div>');
  inpw.append(inp);
  return { wrapper:inpw, inp:inp };
}

WinFrame.editTitle = function() {
  var p = $(this).parent();
  var oldtitle = $(this).text();
  $(this).remove();  

  var ninput = WinFrame.createTitleInput();
  p.append(ninput.wrapper);
  ninput.inp.val(oldtitle);
  ninput.inp.focus();
  ninput.inp.blur(function() {
    var p = $(this).parent().parent();
    $(this).parent().remove();    
    var newtitle = $(this).val();
    if($.trim(newtitle) == '') {
      newtitle = oldtitle;
    }
    var wtitle = WinFrame.createTitle(newtitle);
    var wid = p.parent().attr('id');
    bgport.postMessage({ 
      name : 'savewindowtitle',
      wid : wid,
      title : newtitle
    });
    /*
    window.localStorage.setItem(
      'window_title_'+wid, newtitle);
      */
    p.append(wtitle);
  });
}

WinFrame.prototype = {

  addTabs : function(tabdbarr) {
    for(var i=0; i<tabdbarr.length; i++) {
      var t = new Tab(tabdbarr[i]);

      UI.tMap[t.tabdb.tid] = t;
      t.attach();
      this.addTab(t);

    }
    this.refreshStyle();
  },
  
  addTab : function(tab) {
    this.elem.append(tab.elem);
    this.tabArray.push(tab);
    tab.parent = this;
    tab.tabdb.wid = this.windb.wid;
    this.numTabs++;
    this.updateMailToLink();
  },

  toggleTree : function(tab) {
    tab.tabdb.collapsed ? this.expandTab(tab) : this.collapseTab(tab);
  },

  expandTab : function(tab) {
    var idx = this.tabArray.indexOf(tab);
    var last = tab;
    var children = [];
    for(var i=idx+1; i < this.tabArray.length; i++) {
      var t = this.tabArray[i];
      if(t.tabdb.depth <= tab.tabdb.depth) break;
      t.elem.insertAfter(last.elem);
      t.elem.show();
      last = t;
      children.push(t.tabdb.tid);
    }<commit_msg>this is more consistent action while hiding children tabs<commit_after>
function WinFrame(windb, title_str) { 
  this.tabArray = [];
  this.numTabs = 0;
  this.windb = windb;
  this.elem = $('<div></div>').attr('class','mwin').attr('id', ''+windb.wid);

  if(!title_str) {
    title_str = windb.title
  }
  if(title_str) {
    var text = WinFrame.createTitle(title_str);
  } else {
    var text = WinFrame.createTitle("Name this window");
  }

  var email_icon = $('<a></a>')
          .attr('class','mailtolink')
          .attr('href','')
          .append(
            $('<img/>')
            .attr('class','emailicon')
            .attr('src', WinFrame.emailIcon));

  var save_icon = $('<img/>').attr('class','saveicon')
        .attr('src', WinFrame.saveIcon)
        .click(WinFrame.saveWindow);

  var wtitle = $('<div></div>').attr('class','wtitle');
  wtitle.append(email_icon);
  wtitle.append(save_icon);
  wtitle.append(text);
  this.elem.append(wtitle);

  $('body').append(this.elem);
}

WinFrame.saveIcon = chrome.extension.getURL('images/save.png');
WinFrame.emailIcon = chrome.extension.getURL('images/email.png');

WinFrame.saveWindow = function(ev) {
  var wid = $(this).parent().parent().attr('id');
  bgport.postMessage({
    name : 'savewindow',
    wid : wid,
  });
}

WinFrame.createTitle = function(title) {
  return $('<div></div>').attr('class','text').text(title)
    .click(WinFrame.editTitle)
    .css('width',(UI.winw-150)+'px');
}

WinFrame.createTitleInput = function() {
  var inp = $('<input></input>');
  var inpw = $('<div></div>');
  inpw.append(inp);
  return { wrapper:inpw, inp:inp };
}

WinFrame.editTitle = function() {
  var p = $(this).parent();
  var oldtitle = $(this).text();
  $(this).remove();  

  var ninput = WinFrame.createTitleInput();
  p.append(ninput.wrapper);
  ninput.inp.val(oldtitle);
  ninput.inp.focus();
  ninput.inp.blur(function() {
    var p = $(this).parent().parent();
    $(this).parent().remove();    
    var newtitle = $(this).val();
    if($.trim(newtitle) == '') {
      newtitle = oldtitle;
    }
    var wtitle = WinFrame.createTitle(newtitle);
    var wid = p.parent().attr('id');
    bgport.postMessage({ 
      name : 'savewindowtitle',
      wid : wid,
      title : newtitle
    });
    /*
    window.localStorage.setItem(
      'window_title_'+wid, newtitle);
      */
    p.append(wtitle);
  });
}

WinFrame.prototype = {

  addTabs : function(tabdbarr) {
    for(var i=0; i<tabdbarr.length; i++) {
      var t = new Tab(tabdbarr[i]);

      UI.tMap[t.tabdb.tid] = t;
      t.attach();
      this.addTab(t);

      if(t.tabdb.hidden) {
        t.elem.hide();
        t.elem.detach();
      }
    }
    this.refreshStyle();
  },
  
  addTab : function(tab) {
    this.elem.append(tab.elem);
    this.tabArray.push(tab);
    tab.parent = this;
    tab.tabdb.wid = this.windb.wid;
    this.numTabs++;
    this.updateMailToLink();
  },

  toggleTree : function(tab) {
    tab.tabdb.collapsed ? this.expandTab(tab) : this.collapseTab(tab);
  },

  expandTab : function(tab) {
    var idx = this.tabArray.indexOf(tab);
    var last = tab;
    var children = [];
    for(var i=idx+1; i < this.tabArray.length; i++) {
      var t = this.tabArray[i];
      if(t.tabdb.depth <= tab.tabdb.depth) break;
      t.elem.insertAfter(last.elem);
      t.elem.show();
      last = t;
      children.push(t.tabdb.tid);
    }
{'fraction_non_alphanumeric': 0.19774605559729527, 'fraction_numerical': 0.0018031555221637867, 'mean_word_length': 2.9106933019976498, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, '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': '1518670', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2393, 'n_words': 373}