<commit_before>// This file is concerned with altering the Firefox 4+ Add-ons Manager window,
// for those sorts of functionality we want that the API does not handle.  (As
// opposed to addons4.jsm which is responsible for what the API does handle.)
(function() {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://greasemonkey/addons4.js");

var sortersContainer;
var sortExecuteOrderButton;
var stringBundle;

window.addEventListener('load', init, false);
window.addEventListener('unload', unload, false);

// Patch the default createItem() to add our custom property.
_createItemOrig = createItem;
createItem = function GM_createItem(aObj, aIsInstall, aIsRemote) {
  var item = _createItemOrig(aObj, aIsInstall, aIsRemote);
  if ('user-script' == aObj.type) {
   // Save a reference to this richlistitem on the Addon object, so we can
   // fix the 'executionIndex' attribute if/when it changes.
   aObj.richlistitem = item;
   setRichlistitemExecutionIndex(aObj);
  }
  return item;
};

// Set up an "observer" on the config, to keep the displayed items up to date
// with their actual state.
var observer = {
 notifyEvent: function(script, event, data) {
    if ('addons://list/user-script' != gViewController.currentViewId) return;

    switch (event) {
      case 'install':
      case 'modified':
        ScriptAddonReplaceScript(script);
        break;
      case "edit-enabled":
        ScriptAddonFactoryByScript(script).userDisabled = !data;
        break;
    }

    gViewController.loadViewInternal('addons://list/user-script', null);
  }
};
<commit_msg>When the script list is reloaded in the Addons manager due to some change to the Addon objects, resort the list of scripts according to the currently selected sort criteria. Closes #1307<commit_after>// This file is concerned with altering the Firefox 4+ Add-ons Manager window,
// for those sorts of functionality we want that the API does not handle.  (As
// opposed to addons4.jsm which is responsible for what the API does handle.)
(function() {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://greasemonkey/addons4.js");

var sortersContainer;
var sortExecuteOrderButton;
var stringBundle;

window.addEventListener('load', init, false);
window.addEventListener('unload', unload, false);

// Patch the default createItem() to add our custom property.
_createItemOrig = createItem;
createItem = function GM_createItem(aObj, aIsInstall, aIsRemote) {
  var item = _createItemOrig(aObj, aIsInstall, aIsRemote);
  if ('user-script' == aObj.type) {
   // Save a reference to this richlistitem on the Addon object, so we can
   // fix the 'executionIndex' attribute if/when it changes.
   aObj.richlistitem = item;
   setRichlistitemExecutionIndex(aObj);
  }
  return item;
};

// Set up an "observer" on the config, to keep the displayed items up to date
// with their actual state.
var observer = {
 notifyEvent: function(script, event, data) {
    if ('addons://list/user-script' != gViewController.currentViewId) return;

    switch (event) {
      case 'install':
      case 'modified':
        ScriptAddonReplaceScript(script);
        break;
      case "edit-enabled":
        ScriptAddonFactoryByScript(script).userDisabled = !data;
        break;
    }

    // Apply the correct sort when the view has reloaded
    function scriptViewUpdated() {
      gViewController.currentViewObj.node
        .removeEventListener('ViewChanged', scriptViewUpdated, false);

      applySort();
    }

    // Reload the view and add a listener to notify when the load is complete
    gViewController.currentViewObj.node
      .addEventListener('ViewChanged', scriptViewUpdated, false);
    gViewController.loadViewInternal('addons://list/user-script', null);
  }
};

{'fraction_non_alphanumeric': 0.10331333159405166, 'fraction_numerical': 0.0026089225150013043, 'mean_word_length': 3.9470967741935485, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6928707', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1067, 'n_words': 359}