# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: 
   "cd \"$TM_DIRECTORY\"\n\nif [[ -z $TM_SELECTED_FILES ]]; then\n\tDARCSPaths=`echo \\'$TM_FILEPATH\\'`;\nelse\n\tDARCSPaths=\"$TM_SELECTED_FILES\";\nfi\nexport DARCSPaths\n\n\"${TM_RUBY:=ruby}\" <<'EOF'\nrequire 'pathname'\n\nbasedir = Pathname.new(ENV['TM_DIRECTORY']).realpath()\naddlist = Array.new()\nENV['DARCSPaths'].split(/' '/).each() { |addfile|\n  addfile = addfile[/^'?(.*?)'?$/, 1]\n  addlist << \"'\#{Pathname.new(addfile).realpath.relative_path_from(basedir).to_s.gsub(/(')/, \"\\\\\\1\")}'\"\n}\noutput = `darcs add -v -r \#{addlist.join(' ')}`\nputs(output)",
  input: "none",
  keyEquivalent: "^Z",
  name: "Add File(s) to Repository",
  output: "showAsTooltip",
  uuid: "81229AD0-DE5C-11D9-823F-000A95A51A76"},
 {beforeRunningCommand: "nop",
  command: 
   "cd \"${TM_PROJECT_DIRECTORY:=$TM_DIRECTORY}\";\n\n\"${TM_RUBY:=ruby}\" <<'EOF'\nrequire 'rexml/document'\nrequire 'time'\n\nputs(\"<html>\")\nputs(\"<head>\")\nputs(\"  <style type=\\\"text/css\\\">\")\nputs(\"    html {\")\nputs(\"      font-size: small;\")\nputs(\"    }\")\nputs(\"    body {\")\nputs(\"      border: 0px;\")\nputs(\"      margin: 0px;\")\nputs(\"    }\")\nputs(\"    .chunk {\")\nputs(\"      padding: 7px;\")\nputs(\"    }\")\nputs(\"  </style>\")\nputs(\"</head>\")\nputs(\"<body>\")\noutput = `darcs changes --xml`\nxmldoc = REXML::Document.new(output)\ncount = 0\nxmldoc.root.each_element('patch') { |patch|\n   print(\"<div class=\\\"chunk\\\" \")\n   if(count % 2 == 0)\n     print(\"style=\\\"background-color: white\\\"\")\n   else\n     print(\"style=\\\"background-color: lightblue\\\"\")\n   end\n   print(\"><tt style=\\\"color: gray\\\">\#{Time.parse(patch.attributes['local_date']).strftime(\"%m/%d/%y %I:%M %p\").downcase()}, \#{patch.attributes['author']}</tt><br/> \#{patch.elements['name'].text()}<br/>\")\n   print(\"</div>\")\n   count = count + 1\n}\nputs(\"</body>\")\nputs(\"</html>\")",
  input: "none",
  keyEquivalent: "^Z",
  name: "Changes",
  output: "showAsHTML",
  uuid: "5CEA8FE0-E28A-11D9-9477-000A95A51A76"},
 {beforeRunningCommand: "nop",
  command: 
   "cd \"$TM_DIRECTORY\"\necho \"Index: changes in working copy of $TM_FILENAME\"\ndarcs whatsnew -u \"$TM_FILENAME\"\n",
  input: "none",
  keyEquivalent: "^Z",
  name: "Diff",
  output: "openAsNewDocument",
  uuid: "627E8652-2B23-4E68-ADF9-103BA2B16074"},
 {beforeRunningCommand: "saveModifiedFiles",
  command: "cd \"${TM_PROJECT_DIRECTORY:=$TM_DIRECTORY}\"\n\ndarcs pull -a",
  input: "none",
  keyEquivalent: "^Z",
  name: "Pull From Default Repository",
  output: "showAsTooltip",
  uuid: "242ECD6E-DE5D-11D9-823F-000A95A51A76"},
 {beforeRunningCommand: "nop",
  command: "cd \"${TM_PROJECT_DIRECTORY:=$TM_DIRECTORY}\"\n\ndarcs push -a ",
  input: "none",
  keyEquivalent: "^Z",
  name: "Push to Default Repository",
  output: "showAsTooltip",
  uuid: "B2B2A814-DE60-11D9-823F-000A95A51A76"},
 {beforeRunningCommand: "saveModifiedFiles",
  command: 
   "cd \"${TM_PROJECT_DIRECTORY:=$TM_DIRECTORY}\";\n\n\"${TM_RUBY:=ruby}\" <<'RUBY'\n\nrequire \"\#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb\"\nrequire \"\#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb\"\n\noutput = TextMate::UI.request_string(\n  :title => 'Input', \n  :prompt => 'Record Message',\n  :button1 => 'Record'\n)\n\nTextMate.exit_discard if output.nil?\n\noutput = `darcs record -a -m '\#{output.strip.gsub(/(')/, '\\\\\\\\1')}'`\n\nputs(output)\n\nRUBY",
  input: "none",
  keyEquivalent: "^Z",
  name: "Record All",
  output: "showAsTooltip",
  uuid: "1C9B5F32-759D-4B3E-BA91-A83897C48026"},
 {beforeRunningCommand: "saveActiveFile",
  command: 
   "cd \"$TM_DIRECTORY\";\n\n\"${TM_RUBY:=ruby}\" <<'RUBY'\n\nrequire \"\#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb\"\nrequire \"\#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb\"\n\noutput = TextMate::UI.request_string(\n  :title => 'Input', \n  :prompt => 'Record Message',\n  :button1 => 'Record'\n)\n\nTextMate.exit_discard if output.nil?\n\noutput = `darcs record -a -m '\#{output.strip.gsub(/'/, '\\\\\\\\1')}' '\#{File.basename(ENV['TM_FILEPATH']).gsub(/(')/, '\\\\\\\\1')}'`\n\nputs(output)\n\nRUBY\n",
  input: "none",
  keyEquivalent: "^Z",
  name: "Record File",
  output: "showAsTooltip",
  uuid: "5E76D8C8-DE61-11D9-823F-000A95A51A76"},
 {beforeRunningCommand: "nop",
  command: 
   "cd \"$TM_DIRECTORY\"\ndarcs revert -a \"$TM_FILENAME\"\nrescan_project",
  input: "none",
  keyEquivalent: "^Z",
  name: "Revert",
  output: "showAsTooltip",
  uuid: "CFAAD3D2-CD4F-4F16-AB41-770AF6E460EF"},
 {beforeRunningCommand: "nop",
  command: 
   "# Source some support functions we need.\n. \"${TM_SUPPORT_PATH}/lib/html.sh\"\ncd \"${TM_PROJECT_DIRECTORY:=$TM_DIRECTORY}\";\nhtmlHeader \"Summary of Changes\"\necho \"<h3>Summary of Changes in ${TM_PROJECT_DIRECTORY}</h3>\"\n\"${TM_PYTHON:=python}\" <<'EOF'\nimport os\nimport re\nfrom struct import *\ncl = {'a':'unknown', 'M':'modified', 'D':'deleted', 'C':'conflict', '?':'unknown', 'A':'added'}\ndef percent_escape(str):\n\treturn re.sub('[\\x80-\\xff /&]', lambda x: '%%%02X' % unpack('B', x.group(0))[0], str)\n\ndef make_link(file):\n\treturn 'txmt://open?url=file:%2F%2F' + percent_escape(file)\n\ndef removeNums(s):\n    l = re.compile('^(.*?)(\\s+[-]\\d+)?(\\s+[+]\\d+\\s*)?$')\n    x = l.match(s)\n    if x:\n       return x.group(1)\n    else:\n       return s\n   \nres = os.popen('darcs whatsnew -s -l')\nprint '<table cellpadding=\"3\"><tr>'\nfor line in  res:\n    statClass = \"\"\n    if cl.has_key(line[0]):\n        statClass = cl[line[0]]\n    print '<tr>',\n    print '<td class=\"'+statClass+'\\\">', \n    print line[0], '</td><td><a href=\"',\n    fname = removeNums(line[1:-1])\n    # FIXME we should treat fname as relative to the first\n    # parent holding the _darcs directory rather than os.getcwd()\n    print make_link(os.getcwd()+fname[2:]),'\">',fname, '</a></td></tr>'\n\n\n",
  input: "none",
  keyEquivalent: "^Z",
  name: "Whats New",
  output: "showAsHTML",
  uuid: "F68A0A7A-75AF-4471-A9F8-3A618DD81306"}]
