# Code coverage report for lib/ui/SaveAsForm.js

## Statements: 63.64% (21 / 33) Branches: 42.86% (6 / 14) Functions: 40% (2 / 5) Lines: 65.63% (21 / 32) Ignored: none

All files » lib/ui/ » SaveAsForm.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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    711
    1
    1

    1
    1
    1
    1

    1
    1
    4

    4

    4

    4

    4

    1

    1
    4
    4

    4

    4

    1
     var blessed = require('blessed');
    var _ = require('lazy.js');
    var Point = require('text-buffer/lib/point');

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

    SaveAsForm._label = " save as: ";
    function SaveAsForm (opts) {
      var self = this;

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

      BaseForm.call(self, _(Slap.global.options.form.saveAs)
        .merge({
          field: {left: SaveAsForm._label.length}
        })
        .merge(opts || {})
        .toObject());

      self.saveAsLabel = new BaseElement(_({
          parent: self,
          tags: true,
          content: SaveAsForm._label,
          top: 0,
          height: 1,
          left: 0,
          width: SaveAsForm._label.length,
          style: self.options.style
        })
        .merge(self.options.saveAsLabel || {})
        .toObject());

      self.pathField = new Field(_({
          parent: self,
          top: 0,
          left: SaveAsForm._label.length,
          right: 0
        })
        .merge(self.options.pathField || {})
        .toObject());
    }
    SaveAsForm.prototype.__proto__ = BaseForm.prototype;

    SaveAsForm.prototype._initHandlers = function () {
      var self = this;
      self.on('show', function () {
        self.pathField.textBuf.setText(self.pane.editor.textBuf.getPath() || '');
        self.pathField.selection.setHeadPosition(new Point(0, Infinity));
        self.pathField.focus();
      });
      self.on('submit', function () {
        var path = self.pathField.textBuf.getText();
        if (!path) {
          self.slap.header.message("couldn't save, no filename passed", 'error');
          return;
        }
        self.pane.editor.save(path).done(function (newPath) {
          if (newPath) {
            self.hide();
            self.emit('save', newPath);
          }
        });
      });
      return BaseForm.prototype._initHandlers.apply(self, arguments);
    }

    module.exports = SaveAsForm;