Esempio n. 1
0
  },

  confirmDelete: function(resource) {
    let deletePromptMessage = resource.isDir ?
      getLocalizedString("projecteditor.deleteFolderPromptMessage") :
      getLocalizedString("projecteditor.deleteFilePromptMessage");
    return !this.shouldConfirm || confirm(
      getLocalizedString("projecteditor.deletePromptTitle"),
      deletePromptMessage
    );
  },

  onCommand: function(cmd) {
    if (cmd === "cmd-delete") {
      let tree = this.host.projectTree;
      let resource = tree.getSelectedResource();

      if (!this.confirmDelete(resource)) {
        return;
      }

      resource.delete().then(() => {
        this.host.project.refresh();
      });
    }
  }
});

exports.DeletePlugin = DeletePlugin;
registerPlugin(DeletePlugin);
Esempio n. 2
0
          let matches = name.match(/([^\d.]*)(\d*)([^.]*)(.*)/);
          let template = matches[1] + "{1}" + matches[3] + matches[4];
          name = this.suggestName(resource, template, parseInt(matches[2]) || 2);
        }
        return parent.rename(oldName,name);
      }).then(resource => {
        this.host.project.refresh();
        tree.selectResource(resource);
        if (!resource.isDir) {
          this.host.currentEditor.focus();
        }
      }).then(null, console.error);
    }
  },

  suggestName: function(resource, template, start=1) {
    let i = start;
    let name;
    let parent = resource.parent;
    do {
      name = template.replace("\{1\}", i === 1 ? "" : i);
      i++;
    } while (parent.hasChild(name));

    return name;
  }
});

exports.RenamePlugin = RenamePlugin;
registerPlugin(RenamePlugin);
Esempio n. 3
0
    }).then(path => {
      return this.createResource(path);
    }).then(res => {
      resource = res;
      return this.saveResource(editor, resource);
    }).then(() => {
      this.host.openResource(resource);
    }).then(null, console.error);
  },

  save: function() {
    let editor = this.host.currentEditor;
    let resource = this.host.resourceFor(editor);
    if (!resource) {
      return this.saveAs();
    }

    return this.saveResource(editor, resource);
  },

  createResource: function(path) {
    return this.host.project.resourceFor(path, { create: true })
  },

  saveResource: function(editor, resource) {
    return editor.save(resource);
  }
})
exports.SavePlugin = SavePlugin;
registerPlugin(SavePlugin);
Esempio n. 4
0
  onEditorSave: function(editor) { this.onEditorChange(editor); },
  onEditorLoad: function(editor) { this.onEditorChange(editor); },

  onEditorChange: function(editor) {
    // Only run on a TextEditor
    if (!editor || !editor.editor) {
      return;
    }

    // Dont' force a refresh unless the dirty state has changed...
    let priv = this.priv(editor);
    let clean = editor.isClean()
    if (priv.isClean !== clean) {
      let resource = editor.shell.resource;
      emit(resource, "label-change", resource);
      priv.isClean = clean;
    }
  },

  onAnnotate: function(resource, editor, elt) {
    if (editor && editor.editor && !editor.editor.isClean()) {
      elt.textContent = '*' + resource.displayName;
      return true;
    }
  }
});
exports.DirtyPlugin = DirtyPlugin;

registerPlugin(DirtyPlugin);
Esempio n. 5
0
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { Cu } = require("chrome");
const { Class } = require("sdk/core/heritage");
const promise = require("projecteditor/helpers/promise");
const { ImageEditor } = require("./image-editor");
const { registerPlugin, Plugin } = require("projecteditor/plugins/core");

var ImageEditorPlugin = Class({
  extends: Plugin,

  editorForResource: function(node) {
    if (node.contentCategory === "image") {
      return ImageEditor;
    }
  },

  init: function(host) {

  }
});

exports.ImageEditorPlugin = ImageEditorPlugin;
registerPlugin(ImageEditorPlugin);
Esempio n. 6
0
        return parent.createChild(name);
      }).then(resource => {
        tree.selectResource(resource);
        this.host.currentEditor.focus();
      }).then(null, console.error);
    }
  },

  suggestName: function(parent, template, start=1) {
    let i = start;
    let name;
    do {
      name = template.replace("\{1\}", i === 1 ? "" : i);
      i++;
    } while (this.hasChild(parent, name));

    return name;
  },

  hasChild: function(resource, name) {
    for (let child of resource.children) {
      if (child.basename === name) {
        return true;
      }
    }
    return false;
  }
})
exports.NewFile = NewFile;
registerPlugin(NewFile);
Esempio n. 7
0
   */
  onTreeSelected: function(resource) {
    if (!resource || resource.isDir) {
      this.fileLabel.textContent = "";
      return;
    }
    this.fileLabel.textContent = resource.basename;
  },

  onEditorDeactivated: function(editor) {
    this.fileLabel.textContent = "";
    this.cursorPosition.value = "";
  },

  onEditorChange: function(editor, resource) {
    this.render(editor, resource);
  },

  onEditorCursorActivity: function(editor, resource) {
    this.render(editor, resource);
  },

  onEditorActivated: function(editor, resource) {
    this.render(editor, resource);
  },

});

exports.StatusBarPlugin = StatusBarPlugin;
registerPlugin(StatusBarPlugin);
Esempio n. 8
0
    }
  },
  onAnnotate: function(resource, editor, elt) {
    if (resource.parent || !this.isAppManagerProject()) {
      return;
    }

    let {appManagerOpts} = this.host.project;
    let doc = elt.ownerDocument;
    let image = doc.createElement("image");
    let label = doc.createElement("label");

    label.className = "project-name-label";
    image.className = "project-image";

    let name = appManagerOpts.name || resource.basename;
    let url = appManagerOpts.iconUrl || "icon-sample.png";

    label.textContent = name;
    image.setAttribute("src", url);

    elt.innerHTML = "";
    elt.appendChild(image);
    elt.appendChild(label);
    return true;
  }
});

exports.AppManagerRenderer = AppManagerRenderer;
registerPlugin(AppManagerRenderer);