/* 
Two simple tools to encode/decode URI components.
*/

CmdUtils.CreateCommand({
  names: ["encode URI", "URI encode", "encodeURI", "URIencode"],
  arguments: {object: noun_arb_text},
  icon: "chrome://ubiquity/skin/icons/html_go.png",
  description: "URI/Percent encodes a URI",
  preview: function(pb, {object: {text}}) {
    pb.innerHTML = (text
                    ? (<>Replaces your selection with:
                       <pre>{encodeURIComponent(text)}</pre></>)
                    : this.description);
  },

  execute: function({object: {text}}) {
    if (text) {
      CmdUtils.setSelection(encodeURIComponent(text));
    } else {
      displayMessage(_("No text selected."));
    }
  }
});


CmdUtils.CreateCommand({
  names: ["decode URI", "URI decode", "decodeURI", "URIdecode"],
  arguments: {object: noun_arb_text},
  icon: "chrome://ubiquity/skin/icons/html_go.png",
  description: "URI/Percent decodes a URI",
  preview: function(pb, {object: {text}}) {
    pb.innerHTML = (text
                    ? (<>Replaces your selection with:
                       <pre>{decodeURIComponent(text)}</pre></>)
                    : this.description);
  },

  execute: function({object: {text}}) {
    if (text) {
      CmdUtils.setSelection(decodeURIComponent(text));
    } else {
      displayMessage(_("No text selected."));
    }
  }
});


