/**
 * Returns a copy of the file with the given extension.
 *
 * @param {FileDescriptor} file
 * @param {String} extension
 *
 * @return {FileDescriptor}
 */
function withExtension(file, extension) {
  return {
    name: replaceFileExt(file.name, extension),
    path: !isUnsaved(file.path) ? replaceFileExt(file.path, extension) : file.path,
    fileType: extension
  };
}
Exemplo n.º 2
0
App.prototype._closeTab = function(tab, done) {
  var tabs = this.tabs,
      events = this.events;

  events.emit('tab:close', tab);

  var idx = tabs.indexOf(tab);

  // remove tab from selection
  tabs.splice(idx, 1);

  // if tab was active, select previous (if exists) or next tab
  if (tab === this.activeTab) {
    this.selectTab(tabs[idx - 1] || tabs[idx]);
  }

  if (!isUnsaved(tab.file)) {
    this.fileHistory.push(tab.file);
  }

  events.emit('workspace:changed');

  events.emit('changed');

  return done();
};
Exemplo n.º 3
0
App.prototype.recheckTabContent = function(tab) {

  if (isUnsaved(tab.file)) {
    return rdebug('skipping (unsaved)');
  }

  rdebug('checking');

  if (typeof tab.file.lastModified === 'undefined') {
    return rdebug('skipping (missing tab.file.lastChanged)');
  }

  var setNewFile = (file) => {
    tab.setFile(assign({}, tab.file, file));
    this.events.emit('workspace:changed');
  };

  this.fileSystem.readFileStats(tab.file, (err, statsFile) => {
    if (err) {
      return rdebug('file check error', err);
    }

    rdebug('last modified { tab: %s, stats: %s }',
      tab.file.lastModified || 0,
      statsFile.lastModified);

    if (!(statsFile.lastModified > tab.file.lastModified)) {
      return rdebug('unchanged');
    }

    rdebug('external change');

    // notifying user about external changes
    this.dialog.contentChanged((answer) => {

      if (isOk(answer)) {
        rdebug('reloading');

        this.fileSystem.readFile(tab.file, function(err, updatedFile) {
          if (err) {
            return rdebug('reloading failed', err);
          }

          setNewFile(updatedFile);
        });

      } else if (isCancel(answer)) {
        rdebug('NOT reloading');

        setNewFile(statsFile);
      }

    });

  });
};
Exemplo n.º 4
0
App.prototype.findTab = function(file) {

  if (isUnsaved(file)) {
    return null;
  }

  return find(this.tabs, function(t) {
    var tabPath = (t.file ? t.file.path : null);
    return file.path === tabPath;
  });
};
MultiEditorTab.prototype.setFile = function(file) {
  this.file = file;
  this.label = file.name;
  this.title = file.path;
  this.dirty = isUnsaved(file);

  this.editors.forEach(function(editor) {
    editor.setXML(file.contents, {});
  });

  this.events.emit('changed');
};
Exemplo n.º 6
0
  tab.save((err, file) => {
    // restore last active tab
    this.selectTab(activeTab);

    if (err) {
      return done(err);
    }

    debug('exported %s \n%s', tab.id, file.contents);

    var saveAs = isUnsaved(file) || options && options.saveAs;

    this.saveFile(file, saveAs, updateTab);
  });
Exemplo n.º 7
0
  this.tabs.forEach((tab, idx) => {

    var file = tab.file;

    // do not persist unsaved files
    if (isUnsaved(file)) {
      return;
    }

    config.tabs.push(assign({}, file));

    // store saved active tab index
    if (tab === this.activeTab) {
      config.activeTab = config.tabs.length - 1;
    }
  });
MultiEditorTab.prototype.isUnsaved = function() {
  return isUnsaved(this.file);
};