<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 private_scope() {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("chrome://greasemonkey-modules/content/addons4.js");
Components.utils.import("chrome://greasemonkey-modules/content/prefmanager.js");
Components.utils.import('chrome://greasemonkey-modules/content/third-party/droppedUrls.js');
Components.utils.import('chrome://greasemonkey-modules/content/util.js');

var userScriptViewId = 'addons://list/greasemonkey-user-script';

var sortByValueDef = 'uiState,name';
var sortByCheckStateReverse = '!';
var sortByCheckStateValueAscending = '2';
var sortByCheckStateValueDescending = '1';

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

var stringBundle = Components
    .classes["@mozilla.org/intl/stringbundle;1"]
    .getService(Components.interfaces.nsIStringBundleService)
    .createBundle("chrome://greasemonkey/locale/gm-addons.properties");

// Patch the default createItem() to add our custom property.
var _createItemOrig = createItem;
createItem = function GM_createItem(aObj, aIsInstall, aIsRemote) {
  var item = _createItemOrig(aObj, aIsInstall, aIsRemote);
  if (SCRIPT_ADDON_TYPE == 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;
};

// Patch the default onDrop() to make user script installation work.
var _gDragDrop_onDrop_Orig = gDragDrop.onDrop;
gDragDrop.onDrop = function GM_onDrop(aEvent) {
  var urls = droppedUrls(aEvent);

  var droppedNonUserScript = false;
  for (var i = urls.length - 1, url = null; url = urls[i]; i--) {
    if (url.match(/\.user\.js$/)) {
      GM_util.showInstallDialog(url, GM_util.getBrowserWindow().gBrowser);
    } else {
      droppedNonUserScript = true;
    }
  }

  // Pass call through to the original handler, if any non-user-script
  // was part of this drop action.
  if (droppedNonUserScript) {
    _gDragDrop_onDrop_Orig(aEvent);
  }
  else {
    aEvent.preventDefault();
  }
};

// Set up an "observer" on the config, to keep the displayed items up to date
// with their actual state.
var observer = {
  notifyEvent: function observer_notifyEvent(script, event, data) {
    if (!isScriptView()) return;

    var addon = ScriptAddonFactoryByScript(script);
    switch (event) {
      case 'uninstall':
        gListView.removeItem(addon);
        setEmptyWarningVisible();
        break;
      case 'install':
        gListView.addItem(addon);
        setEmptyWarningVisible();
        break;
      case 'edit-enabled':
        var item = gListView.getListItemForID(addon.id);
        var callback = data? item.onEnabled : item.onDisabled;
        if (!callback) {
          // This observer triggers in the case of an uninstall undo.  But
          // does not need to -- and can not -- run.  Ignore this case.
          break;
        }
        item.userDisabled = !data;
        callback.call(item);
        break;
      case 'modified':
        if (!data) break;
        var oldAddon = ScriptAddonFactoryByScript({'id': data});
        if (!oldAddon) break;
        addon = ScriptAddonFactoryByScript(script, true);

        // Use old and new the addon references to update the view.
        var item = createItem(addon);
        var oldItem = gListView.getListItemForID(oldAddon.id);
        oldItem.parentNode.replaceChild(item, oldItem);
        break;
    }
  }
};<commit_msg>Update the AOM UI based on the kind of uninstall happening.<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 private_scope() {
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("chrome://greasemonkey-modules/content/addons4.js");
Components.utils.import("chrome://greasemonkey-modules/content/prefmanager.js");
Components.utils.import('chrome://greasemonkey-modules/content/third-party/droppedUrls.js');
Components.utils.import('chrome://greasemonkey-modules/content/util.js');

var userScriptViewId = 'addons://list/greasemonkey-user-script';

var sortByValueDef = 'uiState,name';
var sortByCheckStateReverse = '!';
var sortByCheckStateValueAscending = '2';
var sortByCheckStateValueDescending = '1';

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

var stringBundle = Components
    .classes["@mozilla.org/intl/stringbundle;1"]
    .getService(Components.interfaces.nsIStringBundleService)
    .createBundle("chrome://greasemonkey/locale/gm-addons.properties");

// Patch the default createItem() to add our custom property.
var _createItemOrig = createItem;
createItem = function GM_createItem(aObj, aIsInstall, aIsRemote) {
  var item = _createItemOrig(aObj, aIsInstall, aIsRemote);
  if (SCRIPT_ADDON_TYPE == 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;
};

// Patch the default onDrop() to make user script installation work.
var _gDragDrop_onDrop_Orig = gDragDrop.onDrop;
gDragDrop.onDrop = function GM_onDrop(aEvent) {
  var urls = droppedUrls(aEvent);

  var droppedNonUserScript = false;
  for (var i = urls.length - 1, url = null; url = urls[i]; i--) {
    if (url.match(/\.user\.js$/)) {
      GM_util.showInstallDialog(url, GM_util.getBrowserWindow().gBrowser);
    } else {
      droppedNonUserScript = true;
    }
  }

  // Pass call through to the original handler, if any non-user-script
  // was part of this drop action.
  if (droppedNonUserScript) {
    _gDragDrop_onDrop_Orig(aEvent);
  }
  else {
    aEvent.preventDefault();
  }
};

// Set up an "observer" on the config, to keep the displayed items up to date
// with their actual state.
var observer = {
  notifyEvent: function observer_notifyEvent(script, event, data) {
    if (!isScriptView()) return;

    var addon = ScriptAddonFactoryByScript(script);
    switch (event) {
      case 'uninstall':
        if (!data) {
          // In this observer context, `data` is a boolean, true means the
          // uninstall happened "for update".  If it was _not_ for update,
          // remove this item from the UI.
          gListView.removeItem(addon);
        }
        setEmptyWarningVisible();
        break;
      case 'install':
        gListView.addItem(addon);
        setEmptyWarningVisible();
        break;
      case 'edit-enabled':
        var item = gListView.getListItemForID(addon.id);
        var callback = data? item.onEnabled : item.onDisabled;
        if (!callback) {
          // This observer triggers in the case of an uninstall undo.  But
          // does not need to -- and can not -- run.  Ignore this case.
          break;
        }
        item.userDisabled = !data;
        callback.call(item);
        break;
      case 'modified':
        if (!data) break;
        var oldAddon = ScriptAddonFactoryByScript({'id': data});
        if (!oldAddon) break;
        addon = ScriptAddonFactoryByScript(script, true);

        // Use old and new the addon references to update the view.
        var item = createItem(addon);
        var oldItem = gListView.getListItemForID(oldAddon.id);
        oldItem.parentNode.replaceChild(item, oldItem);
        break;
    }
  }
};
{'fraction_non_alphanumeric': 0.1141959798994975, 'fraction_numerical': 0.0017587939698492463, 'mean_word_length': 3.3478973238667393, 'pattern_counts': {'":': 0, '<': 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': '6856366', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2380, 'n_words': 645}