3 FileDialog fileDialog { type = selectDir, text = $"Select project directory" };
5 class NewProjectDialog : Window
7 background = formColor;
8 minClientSize = { 316, 170 };
9 maxClientSize = { 640, 170 };
10 borderStyle = sizable;
13 text = $"New Project";
15 char path[MAX_LOCATION];
16 char name[MAX_FILENAME];
21 char projectLocation[MAX_LOCATION];
22 bool createFormOption;
24 PathBox locationEditBox
26 this, position = { 10, 80 }, size = { 120, 22 }, anchor = { left = 10, top = 80, right = 10 };
27 hotKey = altL, text = $"Location";
28 typeExpected = directory, browseDialog = fileDialog;
30 NotifyModified = NotifyModifiedLocation;
32 Label { this, position = { 10, 60 }, labeledWindow = locationEditBox };
34 DropBox targetType { this, position = { 10, 130 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
36 Label { this, position = { 10, 110 }, labeledWindow = targetType };
40 parent = this, isDefault = true, disabled = true, position = { 170, 130 }, size = { 60 }, text = $"OK";
41 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
43 const char * prjName = projectName.contents;
44 char filePath[MAX_LOCATION];
45 char extension[MAX_EXTENSION];
46 ProjectConfig debug, release;
48 strcpy(projectLocation, locationEditBox.slashPath);
49 strcpy(filePath, projectLocation);
50 PathCatSlash(filePath, prjName);
51 GetExtension(filePath, extension);
53 ChangeExtension(filePath, ProjectExtension, filePath);
57 name = CopyString("Debug");
63 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
65 makingModified = true;
66 compilingModified = true;
67 linkingModified = true;
70 release = ProjectConfig
72 name = CopyString("Release");
79 makingModified = true;
80 compilingModified = true;
81 linkingModified = true;
84 /* error: too few arguments to function ‘__ecereProp_DirExpression_Set_char__PTR_’ -- debug.objDir = "debug";*/
88 property::filePath = filePath;
89 moduleName = CopyString(name);
90 topNode.type = NodeTypes::project;
93 /*project.topNode.options = */project.options =
96 // TOFIX: Precomp problems withou the extra ( )
97 targetType = ((TargetTypes)targetType.GetTag());
98 targetFileName = /*CopyString(*/name/*)*/;
100 if(project.options.targetType != staticLibrary)
102 project.options.libraries = { [ CopyString("ecere") ] };
105 project.topNode.configurations = /*project.configurations = */{ [ debug, release ] };
106 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
108 createFormOption = createForm.checked;
110 Destroy(DialogResult::ok);
115 void CreateNewProject()
117 char fileName[MAX_LOCATION]; // Windows Friendly path
118 ProjectView projectWindow;
119 Project prj = project;
121 if(!FileExists(projectLocation).isDirectory)
123 if(MessageBox { type = yesNo, master = ide,
124 text = $"Directory doesn't exist", contents = $"Create directory?" }.Modal() == yes)
126 if(!MakeDir(projectLocation))
128 MessageBox { type = ok, master = ide, text = projectLocation, contents = $"Error creating directory" }.Modal();
136 GetSystemPathBuffer(fileName, prj.filePath);
138 if(FileExists(prj.filePath))
140 if(MessageBox { type = yesNo, master = ide,
141 text = $"Project Already Exists", contents = $"Replace existing project?" }.Modal() == no)
146 char workspaceFile[MAX_LOCATION];
147 strcpy(workspaceFile, prj.filePath);
148 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
149 workspace = Workspace { activeCompiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
152 workspace.AddProject(prj, null);
153 ide.findInFilesDialog.AddProjectItem(prj);
154 ide.findInFilesDialog.mode = FindInFilesMode::project;
155 ide.findInFilesDialog.currentDirectory = prj.topNode.path;
157 if(!prj.Save(prj.filePath))
159 MessageBox { type = ok, master = this, text = prj.filePath, contents = $"Error writing project file" }.Modal();
164 projectWindow = ide.CreateProjectView(workspace, fileName);
167 char newWorkingDir[MAX_LOCATION];
168 StripLastDirectory(prj.filePath, newWorkingDir);
170 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
172 StripLastDirectory(newWorkingDir, newWorkingDir);
173 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
175 ide.toolBox.visible = true;
181 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
182 EditBox editBox = codeEditor.editBox;
183 strcpy(varName, className);
184 if(islower(varName[0]))
186 memmove(varName+1, varName, strlen(varName)+1);
190 varName[0] = (char)tolower(varName[0]);
193 editBox.Printf("\n%s %s {};\n", className, varName);
195 codeEditor.EnsureUpToDate();
197 prj.Save(prj.filePath);
199 projectWindow.modifiedDocument = false;
200 prj.topNode.modified = false;
203 editBox.Printf("class FormApplication : GuiApplication\n");
204 editBox.Printf("{\n");
205 editBox.Printf(" %s %s {};\n", className, varName);
206 editBox.Printf("}\n");
210 prj.StartMonitoring();
212 if(prj && projectWindow)
214 CompilerConfig compiler = ideConfig.compilers.GetCompilerConfig(ide.workspace.activeCompiler);
215 ProjectConfig config = prj.config;
216 projectWindow.ShowOutputBuildLog(true);
217 projectWindow.DisplayCompiler(compiler, false);
218 projectWindow.ProjectPrepareCompiler(prj, compiler, false);
219 projectWindow.ProjectPrepareMakefile(prj, force, compiler, config);
222 ide.UpdateToolBarActiveConfigs(false);
228 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
229 NotifyClicked = ButtonCloseDialog;
233 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
234 isCheckbox = true, checked = true;
239 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
240 hotKey = altP, text = $"Project Name";
241 NotifyUpdate = EditBoxUpdate;
243 bool NotifyModified(EditBox editBox)
245 char name[MAX_FILENAME];
246 char tmp[MAX_FILENAME];
247 char lastPart[MAX_LOCATION];
248 const char * text = editBox.contents;
250 // drop leading path stuff that has no business here
251 GetLastDirectory(text, tmp);
252 ValidProjectNameBufCopy(name, tmp);
254 GetLastDirectory(path, lastPart);
255 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
257 if(strcmp(path, lastPart))
258 StripLastDirectory(path, path);
259 PathCatSlash(path, name);
260 locationEditBox.path = path;
262 else if(!name[0] && !strcmp(this.name, lastPart))
264 if(strcmp(path, lastPart))
265 StripLastDirectory(path, path);
266 locationEditBox.path = path;
268 else if(strcmp(name, lastPart))
270 PathCatSlash(path, name);
271 locationEditBox.path = path;
273 strcpy(this.name, name);
274 editBox.contents = name;
278 Label { this, position = { 10, 10 }, labeledWindow = projectName };
280 void EditBoxUpdate(EditBox editBox)
282 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
285 bool NotifyModifiedLocation(PathBox pathBox)
287 char location[MAX_LOCATION];
288 char lastPart[MAX_FILENAME];
291 BasicValidatePathBoxPath(pathBox);
293 text = pathBox.slashPath;
295 //replacing this: NotifyUpdate = EditBoxUpdate;
296 okBtn.disabled = !(text[0] && projectName.contents[0]);
298 strcpy(location, ideSettings.ideProjectFileDialogLocation);
299 PathCatSlash(location, text);
301 GetLastDirectory(path, lastPart);
302 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
304 char newName[MAX_FILENAME];
305 GetLastDirectory(location, newName);
306 if(strcmp(newName, location))
308 strcpy(name, newName);
309 projectName.contents = name;
312 strcpy(path, location);
319 char location[MAX_LOCATION];
321 strcpy(location, ideSettings.ideProjectFileDialogLocation);
323 locationEditBox.path = location;
324 strcpy(path, location);
329 //targetType.AddField("String", null, 0);
331 row = targetType.AddRow();
332 row.tag = TargetTypes::executable;
333 row.SetData(null, $"Executable");
335 row = targetType.AddRow();
336 row.tag = TargetTypes::sharedLibrary;
337 row.SetData(null, $"Shared Library");
339 row = targetType.AddRow();
340 row.tag = TargetTypes::staticLibrary;
341 row.SetData(null, $"Static Library");
343 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
348 class QuickProjectDialog : Window
350 background = formColor;
351 minClientSize = { 316, 110 };
352 maxClientSize = { 640, 110 };
353 borderStyle = sizable;
356 text = $"Quick Project";
358 char path[MAX_LOCATION];
359 char name[MAX_FILENAME];
361 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
363 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
364 Label { this, position = { 10, 50 }, labeledWindow = targetType };
368 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
369 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
371 char tempDir[MAX_LOCATION] = "";
372 char filePath[MAX_LOCATION];
373 char prjName[MAX_LOCATION] = "quick_project";
376 ProjectView projectWindow;
377 ProjectConfig debug, release;
379 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
381 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
385 GetLastDirectory(tempDir, prjName);
388 if((dot = strstr(prjName, ".")))
392 if(!FileExists(tempDir).isDirectory)
394 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
398 ide.tmpPrjDir = tempDir;
400 strcpy(filePath, tempDir);
401 PathCatSlash(filePath, prjName);
402 //GetExtension(filePath, extension);
404 ChangeExtension(filePath, ProjectExtension, filePath);
405 GetSystemPathBuffer(filePath, filePath);
407 debug = ProjectConfig
409 name = CopyString("Debug");
415 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
417 makingModified = true;
418 compilingModified = true;
419 linkingModified = true;
422 release = ProjectConfig
424 name = CopyString("Release");
427 optimization = speed;
431 makingModified = true;
432 compilingModified = true;
433 linkingModified = true;
439 moduleName = CopyString(prjName);
440 topNode.type = NodeTypes::project;
443 /*project.topNode.options = */project.options =
446 // TOFIX: Precomp problems withou the extra ( )
447 targetType = ((TargetTypes)targetType.GetTag());
448 targetFileName = /*CopyString(*/prjName/*)*/;
451 if(project.options.targetType != staticLibrary)
453 project.options.libraries = { [ CopyString("ecere") ] };
457 char workspaceFile[MAX_LOCATION];
458 strcpy(workspaceFile, filePath);
459 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
460 workspace = Workspace { activeCompiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
464 workspace.AddProject(project, null);
465 ide.findInFilesDialog.AddProjectItem(project);
466 ide.findInFilesDialog.mode = FindInFilesMode::project;
467 ide.findInFilesDialog.currentDirectory = project.topNode.path;
469 // *** Don't set this directly on project, it must be set on top ProjectNode ***
470 project.topNode.configurations = { [ debug, release ] };
472 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
474 if(!project.Save(filePath))
476 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
479 ide.DestroyTemporaryProjectDir();
483 projectWindow = ide.CreateProjectView(workspace, filePath);
486 Window document = null;
487 for(document = ide.firstChild; document; document = document.next)
489 if(document.created && document.isDocument && document._class == class(CodeEditor))
491 const char * fileName = document.fileName;
492 if(strstr(fileName, "http://") == fileName)
494 char name[MAX_LOCATION];
495 char newFileName[MAX_LOCATION];
496 GetLastDirectory(fileName, name);
497 strcpy(newFileName, tempDir);
498 PathCat(newFileName, name);
500 // TODO: this should be in Windows::SaveAs(char* asFileName)
502 //document.saving = true;
503 if(document.OnSaveFile(newFileName))
505 document.fileName = newFileName;
506 document.NotifySaved(document.master, /*this*/document, newFileName);
508 //document.saving = false;
510 // TODO else MessageBox unable to save and cancel the whole project creation thing
511 fileName = document.fileName;
515 CodeEditor codeEditor = (CodeEditor)document;
516 ide.projectView.AddFile(project.topNode, fileName, false, false);
517 codeEditor.AdjustDebugMenus();
523 ide.toolBox.visible = true;
525 if(project.topNode.modified)
527 project.Save(filePath);
528 projectWindow.modifiedDocument = false;
529 project.topNode.modified = false;
533 // TOCHECK: Why is the Quick project creating a form???
536 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
537 EditBox editBox = codeEditor.editBox;
538 strcpy(varName, className);
539 if(islower(varName[0]))
541 memmove(varName+1, varName, strlen(varName)+1);
545 varName[0] = (char)tolower(varName[0]);
548 editBox.Printf("\n%s %s {};\n", className, varName);
550 codeEditor.EnsureUpToDate();
552 // TODO: how to save that new file?
554 project.Save(filePath);
555 projectWindow.modifiedDocument = false;
556 project.topNode.modified = false;
558 project.StartMonitoring();
562 if(project && projectWindow)
564 CompilerConfig compiler = ideConfig.compilers.GetCompilerConfig(ide.workspace.activeCompiler);
565 ProjectConfig config = project.config;
566 projectWindow.ShowOutputBuildLog(true);
567 projectWindow.DisplayCompiler(compiler, false);
568 projectWindow.ProjectPrepareCompiler(project, compiler, false);
569 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
573 ide.projectView.ProjectBuild(null, Modifiers { });
582 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
583 NotifyClicked = ButtonCloseDialog;
590 row = targetType.AddRow();
591 row.tag = TargetTypes::executable;
592 row.SetData(null, $"Executable");
594 row = targetType.AddRow();
595 row.tag = TargetTypes::sharedLibrary;
596 row.SetData(null, $"Shared Library");
598 row = targetType.AddRow();
599 row.tag = TargetTypes::staticLibrary;
600 row.SetData(null, $"Static Library");
602 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
612 void ValidProjectNameBufCopy(char *output, const char *input)
614 strcpy(output, input);
615 TrimLSpaces(output, output);
616 TrimRSpaces(output, output);
618 // todo: support '&', '.' and ' ' in project name on windows so that it may be used by all platforms.
619 const char * chars = "*|:\",<>?\\/&. ";
620 char ch, * s = output, * o = output;
621 while((ch = *s++)) { if(!strchr(chars, ch)) *o++ = ch; }