{
  "keyboard_shortcut": "", 
  "name": "Count LOC", 
  "language": "JavaScript", 
  "trigger_enabled": 1, 
  "value": [
    "/**", 
    " * Adds a \"Count LOC\" menu item to items in the Places widget.", 
    " * This will run a line-counter on the selected paths and display the command output.", 
    " * Based on the \"Open Terminal Here\" macro by Nathan Rijksen.", 
    " *", 
    " * Usage: Update the \"command\" variable to contain whatever command you want to run.  The paths to the files selected", 
    " * in the places pane will be appended to this command.", 
    " *", 
    " * If the \"use_common_directory\" variable is true, then the macro will calculate the deepest common directory of all", 
    " * the selected files and will run the command from that directory, passing relative paths.  For example, if you", 
    " * select files /foo/bar/baz/buzz.js and /foo/bar/fizz/fuzz.css, the command will be run from /foo/bar and will be", 
    " * passed the paths baz/buzz.js and fizz/fuzz.css.", 
    " * If this variable is set to false, then the command will be passed the full, absolute paths to all files and no", 
    " * working directory will be specified for it.", 
    " *", 
    " * @author Peter Geer", 
    " * @contributor Nathan Rijksen", 
    " * @contributor Mathieu Strauch", 
    " * @version 0.1", 
    " */", 
    "/*global ko, extensions:true */", 
    "", 
    "// Register namespace", 
    "if ((typeof extensions) == 'undefined') {", 
    "    extensions = {};", 
    "}", 
    "extensions.CountLOC = {};", 
    "", 
    "(function() {", 
    "    ", 
    "    var command = \"cloc --by-file --force-lang=PHP,phtml\",", 
    "        use_common_directory = true,", 
    "        label = 'Count LOC',", 
    "        id = 'contextCountLOC',", 
    "        sibling,", 
    "        d,", 
    "        mi,", 
    "        callback,", 
    "        longest_common_path;", 
    "    ", 
    "    longest_common_path = function(list) {", 
    "        var longest_item = list[0].substr(0, list[0].lastIndexOf('/')),", 
    "            i = 0;", 
    "        for (i = 0; i < list.length; i++) {", 
    "            while (longest_item !== '' && list[i].indexOf(longest_item) < 0) {", 
    "                longest_item = longest_item.substr(0, longest_item.lastIndexOf('/'));", 
    "            }", 
    "            if (longest_item === '') {", 
    "                break;", 
    "            }", 
    "        }", 
    "        return longest_item;", 
    "    };", 
    "    ", 
    "    callback = function(e) {", 
    "        var i = 0,", 
    "            cmd = command,", 
    "            curr_dir = null,", 
    "            uris = ko.places.viewMgr.getSelectedURIs();", 
    "        ", 
    "        if (uris.length === 0) {", 
    "            return;", 
    "        }", 
    "        ", 
    "        // Clean up the URIs.", 
    "        for (i = 0; i < uris.length; i++) {", 
    "            uris[i] = uris[i].replace(/^[a-zA-Z]+:\\/\\//,'');", 
    "            if (uris[i].match(/^\\/[a-zA-Z]:\\//)) {", 
    "                uris[i] = uris[i].substr(1);", 
    "            }", 
    "        }", 
    "        ", 
    "        // If set, turn the absolute paths into relative paths.", 
    "        if (use_common_directory) {", 
    "            curr_dir = longest_common_path(uris);", 
    "            if (curr_dir !== '') {", 
    "                for (i = 0; i < uris.length; i++) {", 
    "                    uris[i] = uris[i].substr(curr_dir.length + 1);", 
    "                }", 
    "            } else {", 
    "                curr_dir = null;", 
    "            }", 
    "        }", 
    "", 
    "        // Prepare command for each platform", 
    "        for (i = 0; i < uris.length; i++) {", 
    "            cmd += ' ' + uris[i];", 
    "        }", 
    "", 
    "        // Run command, show output in bottom pane", 
    "        ko.run.command(cmd, {cwd: curr_dir, runIn: 'command-output-window'});", 
    "    };", 
    "    ", 
    "    // Get places pane document object", 
    "    d = document.getElementById('placesViewbox').contentDocument,", 
    "", 
    "    // Remove existing menu entry if it exists", 
    "    mi = d.getElementById(id);", 
    "    if (mi) {", 
    "        mi.parentNode.removeChild(mi);", 
    "    }", 
    "", 
    "    // Get the sibling element which we want to insert our menu item after", 
    "    sibling = d.getElementById('placesContextMenu_rename');", 
    "    ", 
    "    // Create our menu item", 
    "    mi = document.createElement(\"menuitem\");", 
    "    mi.setAttribute(\"id\", id);", 
    "    mi.setAttribute(\"label\", label);", 
    "", 
    "    // Add event listener for when the menu item is used", 
    "    mi.addEventListener('command', callback);", 
    "", 
    "    // Append menu item to popupmenu", 
    "    if (sibling && sibling.parentNode) {", 
    "        sibling.parentNode.insertBefore(mi, sibling);", 
    "    }", 
    "", 
    "}.apply(extensions.CountLOC));"
  ], 
  "version": "1.0.12", 
  "rank": 100, 
  "async": 1, 
  "type": "macro", 
  "trigger": "trigger_postopen"
}