# Code coverage report for slap/lib/ui/FileBrowser.js

## Statements: 79.41% (27 / 34) Branches: 33.33% (2 / 6) Functions: 57.14% (4 / 7) Lines: 90% (27 / 30) Ignored: none

All files » slap/lib/ui/ » FileBrowser.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    501
    1

    1
    1

    1

    1
    1

    1

    1

    1
    1

    1
    1
    1

    1

    1
    1
    1
    1
    1

    1
    1
    1

    1
    1

    1

    1
     var blessed = require('blessed');
    var _ = require('lazy.js');

    var Slap = require('./Slap');
    var BaseElement = require('./BaseElement');

    var util = require('../util');

    function FileBrowser (opts) {
      var self = this;

      Iif (!(self instanceof blessed.Node)) return new FileBrowser(opts);

      opts = _(Slap.global.options.fileBrowser).merge({
        focusable: true
      }).merge(opts || {}).toObject();
      BaseElement.call(self, opts);
      blessed.FileManager.call(self, _({
        keys: true,
        mouse: true
      }).merge(opts).toObject());
      self.refresh();
      self.data.selectedStyle = self.style.selected;
      self.data.itemStyle = self.style.item;
    }
    FileBrowser.prototype.__proto__ = blessed.FileManager.prototype;

    FileBrowser.prototype._initHandlers = function () {
      var self = this;
      self.on('element mousedown', function (el) { self.focus(); });
      self.on('file', function (path) { self.slap.open(path, true).done(); });
      self.on('cancel', function () {
        var slap = self.slap;
        var currentPane = slap.panes[slap.data.currentPane];
        if (currentPane) currentPane.focus();
      });

      self.on('focus', function () {
        self.style.selected = self.data.selectedStyle;
        self.screen.program.hideCursor();
      });
      self.on('blur', function () {
        self.style.selected = self.data.itemStyle;
      });

      return BaseElement.prototype._initHandlers.apply(self, arguments);
    };

    module.exports = FileBrowser;