CreateProject.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import EditorUI = require("../EditorUI");
  2. import ModalWindow = require("./ModalWindow");
  3. class CreateProject extends ModalWindow {
  4. constructor(templateSourceDir: string, imagePath: string = "") {
  5. super();
  6. this.templateSourceDir = templateSourceDir;
  7. this.init("Create Project", "AtomicEditor/editor/ui/createproject.tb.txt");
  8. this.projectPathField = <Atomic.UIEditField> this.getWidget("project_path");
  9. this.projectNameField = <Atomic.UIEditField> this.getWidget("project_name");
  10. this.image = <Atomic.UIImageWidget> this.getWidget("project_image");
  11. if (!imagePath)
  12. this.image.visibility = Atomic.UI_WIDGET_VISIBILITY_GONE;
  13. else
  14. this.image.image = imagePath;
  15. var fileSystem = Atomic.getFileSystem();
  16. var userDocuments = fileSystem.userDocumentsDir;
  17. if (Atomic.platform == "MacOSX") {
  18. userDocuments += "Documents/AtomicProjects";
  19. } else {
  20. userDocuments += "AtomicProjects";
  21. }
  22. this.projectPathField.text = userDocuments;
  23. this.resizeToFitContent();
  24. this.center();
  25. }
  26. checkProjectCreate(): boolean {
  27. var name = this.projectNameField.text.trim();
  28. if (!name) {
  29. EditorUI.showModalError("New Project Editor Error", "Please enter a project name");
  30. return false;
  31. }
  32. var folder = this.projectPathField.text.trim();
  33. if (!folder)
  34. {
  35. EditorUI.showModalError("New Project Editor Error", "Please choose a root project folder");
  36. return false;
  37. }
  38. return true;
  39. }
  40. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  41. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  42. var id = ev.target.id;
  43. if (id == "cancel") {
  44. this.hide();
  45. return true;
  46. }
  47. else if (id == "choose_path") {
  48. var utils = new Editor.FileUtils();
  49. var path = utils.newProjectFileDialog();
  50. if (path.length)
  51. this.projectPathField.text = path;
  52. return true;
  53. }
  54. else if (id == "create") {
  55. if (this.checkProjectCreate()) {
  56. }
  57. return true;
  58. }
  59. }
  60. }
  61. projectPathField: Atomic.UIEditField;
  62. projectNameField: Atomic.UIEditField;
  63. image: Atomic.UIImageWidget;
  64. templateSourceDir: string;
  65. }
  66. export = CreateProject;