all files / lib/ui/ Pane.js

67.44% Statements 29/43
42.86% Branches 6/14
50% Functions 3/6
78.38% Lines 29/37
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                      
var _ = require('lodash');
 
var util = require('slap-util');
 
var BaseWidget = require('base-widget');
 
Pane.prototype.__proto__ = BaseWidget.prototype;
function Pane (opts) {
  var self = this;
 
  Iif (!(self instanceof Pane)) return new Pane(opts);
 
  BaseWidget.call(self, _.merge({
    top:    Slap.global.header.options.headerPosition === 'top'    ? 1 : 0,
    bottom: Slap.global.header.options.headerPosition === 'bottom' ? 1 : 0,
    left: 0,
    right: 0,
  }, Slap.global.options.pane, opts));
  self.left = Slap.global.fileBrowser.visible ? Slap.global.fileBrowser.width : 0;
 
  Iif (!self.parent.panes) self.parent.panes = [];
  self.parent.panes.push(self);
}
 
Pane.prototype.getTitle = function () {
  return "Untitled pane";
};
 
Pane.prototype.setCurrent = function () {
  var self = this;
  var slap = self.screen.slap;
  var panes = slap.panes;
  var paneIndex = panes.indexOf(self);
  Iif (paneIndex === -1) { paneIndex = panes.length; panes.push(self); }
  slap.data.prevPane = slap.data.currentPane;
  slap.data.currentPane = paneIndex;
  self.focus();
  return self;
};
Pane.prototype.close = function () {
  var self = this;
 
  var slap = self.screen.slap;
  var paneIndex = slap.panes.indexOf(self);
  if (paneIndex !== -1) slap.panes.splice(paneIndex, 1);
 
  self.emit('close', paneIndex);
  self.detach();
 
  return true;
};
 
Pane.prototype._initHandlers = function () {
  var self = this;
 
  self.on('close', function () { self.screen.slap.header.message(null); });
 
  return BaseWidget.prototype._initHandlers.apply(self, arguments);
};
 
module.exports = Pane;
 
var Slap = require('./Slap');