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];
18 PathBox locationEditBox
20 this, position = { 10, 80 }, size = { 120, 22 }, anchor = { left = 10, top = 80, right = 10 };
21 hotKey = altL, text = $"Location";
22 typeExpected = directory, browseDialog = fileDialog;
24 NotifyModified = NotifyModifiedLocation;
26 Label { this, position = { 10, 60 }, labeledWindow = locationEditBox };
28 DropBox targetType { this, position = { 10, 130 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
30 Label { this, position = { 10, 110 }, labeledWindow = targetType };
34 parent = this, isDefault = true, disabled = true, position = { 170, 130 }, size = { 60 }, text = $"OK";
35 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
37 char * location = locationEditBox.slashPath;
38 char * prjName = projectName.contents;
39 char filePath[MAX_LOCATION];
40 char fileName[MAX_LOCATION]; // Windows Friendly path
41 char extension[MAX_EXTENSION];
45 ProjectView projectWindow;
46 ProjectConfig debug, release;
48 if(!FileExists(location).isDirectory)
50 if(MessageBox { type = yesNo, master = this,
51 text = $"Directory doesn't exist", contents = $"Create directory?" }.Modal() == yes)
53 if(!MakeDir(location))
55 MessageBox { type = ok, master = this, text = location, contents = $"Error creating directory" }.Modal();
63 strcpy(filePath, location);
64 PathCatSlash(filePath, prjName);
65 GetExtension(filePath, extension);
67 ChangeExtension(filePath, ProjectExtension, filePath);
69 GetSystemPathBuffer(fileName, filePath);
70 exists = FileExists(filePath);
74 if(MessageBox { type = yesNo, master = this,
75 text = $"Project Already Exists", contents = $"Replace existing project?" }.Modal() == no)
81 name = CopyString("Debug");
86 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
88 makingModified = true;
89 compilingModified = true;
90 linkingModified = true;
93 release = ProjectConfig
95 name = CopyString("Release");
102 makingModified = true;
103 compilingModified = true;
104 linkingModified = true;
107 /* error: too few arguments to function ‘__ecereProp_DirExpression_Set_char__PTR_’ -- debug.objDir = "debug";*/
112 moduleName = CopyString(name);
113 topNode.type = NodeTypes::project;
116 /*project.topNode.options = */project.options =
119 // TOFIX: Precomp problems withou the extra ( )
120 targetType = ((TargetTypes)targetType.GetTag());
121 targetFileName = /*CopyString(*/name/*)*/;
123 if(project.options.targetType != staticLibrary)
125 project.options.libraries = { [ CopyString("ecere") ] };
129 char workspaceFile[MAX_LOCATION];
130 strcpy(workspaceFile, filePath);
131 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
132 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
134 workspace.projects.Add(project);
136 project.topNode.configurations = /*project.configurations = */{ [ debug, release ] };
137 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
139 if(!project.Save(filePath))
141 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
146 projectWindow = ide.CreateProjectView(workspace, fileName);
149 char newWorkingDir[MAX_LOCATION];
150 StripLastDirectory(filePath, newWorkingDir);
152 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
154 StripLastDirectory(newWorkingDir, newWorkingDir);
155 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
158 if(createForm.checked)
162 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
163 EditBox editBox = codeEditor.editBox;
164 strcpy(varName, className);
165 if(islower(varName[0]))
167 memmove(varName+1, varName, strlen(varName)+1);
171 varName[0] = (char)tolower(varName[0]);
174 editBox.Printf("\n%s %s {};\n", className, varName);
176 codeEditor.EnsureUpToDate();
178 project.Save(filePath);
180 projectWindow.modifiedDocument = false;
181 project.topNode.modified = false;
184 editBox.Printf("class FormApplication : GuiApplication\n");
185 editBox.Printf("{\n");
186 editBox.Printf(" %s %s {};\n", className, varName);
187 editBox.Printf("}\n");
191 project.StartMonitoring();
193 if(project && projectWindow)
195 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
196 ProjectConfig config = project.config;
197 projectWindow.ShowOutputBuildLog(true);
198 projectWindow.DisplayCompiler(compiler, false);
199 projectWindow.ProjectPrepareCompiler(project, compiler);
200 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
211 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
212 NotifyClicked = ButtonCloseDialog;
216 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
217 isCheckbox = true, checked = true;
222 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
223 hotKey = altP, text = $"Project Name";
224 NotifyUpdate = EditBoxUpdate;
226 bool NotifyModified(EditBox editBox)
228 char name[MAX_FILENAME];
229 char lastPart[MAX_LOCATION];
230 char * text = editBox.contents;
232 // drop leading path stuff that has no business here
233 GetLastDirectory(text, name);
235 GetLastDirectory(path, lastPart);
236 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
238 if(strcmp(path, lastPart))
239 StripLastDirectory(path, path);
240 PathCatSlash(path, name);
241 locationEditBox.path = path;
243 else if(!name[0] && !strcmp(this.name, lastPart))
245 if(strcmp(path, lastPart))
246 StripLastDirectory(path, path);
247 locationEditBox.path = path;
249 else if(strcmp(name, lastPart))
251 PathCatSlash(path, name);
252 locationEditBox.path = path;
254 strcpy(this.name, name);
255 editBox.contents = name;
259 Label { this, position = { 10, 10 }, labeledWindow = projectName };
261 void EditBoxUpdate(EditBox editBox)
263 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
266 bool NotifyModifiedLocation(PathBox pathBox)
268 char location[MAX_LOCATION];
269 char lastPart[MAX_FILENAME];
270 char * text = pathBox.slashPath;
272 //replacing this: NotifyUpdate = EditBoxUpdate;
273 okBtn.disabled = !(text[0] && projectName.contents[0]);
275 GetWorkingDir(location, sizeof(location) - 1);
276 PathCatSlash(location, text);
278 GetLastDirectory(path, lastPart);
279 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
281 char newName[MAX_FILENAME];
282 GetLastDirectory(location, newName);
283 if(strcmp(newName, location))
285 strcpy(name, newName);
286 projectName.contents = name;
289 strcpy(path, location);
296 char location[MAX_LOCATION];
298 if(ideSettings.ideProjectFileDialogLocation)
299 strcpy(location, ideSettings.ideProjectFileDialogLocation);
301 GetWorkingDir(location, sizeof(location) - 1);
303 locationEditBox.path = location;
304 strcpy(path, location);
309 //targetType.AddField("String", null, 0);
311 row = targetType.AddRow();
312 row.tag = TargetTypes::executable;
313 row.SetData(null, $"Executable");
315 row = targetType.AddRow();
316 row.tag = TargetTypes::sharedLibrary;
317 row.SetData(null, $"Shared Library");
319 row = targetType.AddRow();
320 row.tag = TargetTypes::staticLibrary;
321 row.SetData(null, $"Static Library");
323 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
328 class QuickProjectDialog : Window
330 background = formColor;
331 minClientSize = { 316, 110 };
332 maxClientSize = { 640, 110 };
333 borderStyle = sizable;
336 text = $"Quick Project";
338 char path[MAX_LOCATION];
339 char name[MAX_FILENAME];
341 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
343 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
344 Label { this, position = { 10, 50 }, labeledWindow = targetType };
348 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
349 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
351 char tempDir[MAX_LOCATION] = "";
352 char filePath[MAX_LOCATION];
353 char prjName[MAX_LOCATION] = "quick_project";
356 ProjectView projectWindow;
357 ProjectConfig debug, release;
359 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
361 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
365 GetLastDirectory(tempDir, prjName);
368 if((dot = strstr(prjName, ".")))
372 if(!FileExists(tempDir).isDirectory)
374 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
378 ide.tmpPrjDir = tempDir;
380 strcpy(filePath, tempDir);
381 PathCatSlash(filePath, prjName);
382 //GetExtension(filePath, extension);
384 ChangeExtension(filePath, ProjectExtension, filePath);
385 GetSystemPathBuffer(filePath, filePath);
387 debug = ProjectConfig
389 name = CopyString("Debug");
394 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
396 makingModified = true;
397 compilingModified = true;
398 linkingModified = true;
401 release = ProjectConfig
403 name = CopyString("Release");
406 optimization = speed;
410 makingModified = true;
411 compilingModified = true;
412 linkingModified = true;
418 moduleName = CopyString(prjName);
419 topNode.type = NodeTypes::project;
422 /*project.topNode.options = */project.options =
425 // TOFIX: Precomp problems withou the extra ( )
426 targetType = ((TargetTypes)targetType.GetTag());
427 targetFileName = /*CopyString(*/prjName/*)*/;
430 if(project.options.targetType != staticLibrary)
432 project.options.libraries = { [ CopyString("ecere") ] };
436 char workspaceFile[MAX_LOCATION];
437 strcpy(workspaceFile, filePath);
438 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
439 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
442 workspace.projects.Add(project);
444 // *** Don't set this directly on project, it must be set on top ProjectNode ***
445 project.topNode.configurations = { [ debug, release ] };
447 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
449 if(!project.Save(filePath))
451 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
454 ide.DestroyTemporaryProjectDir();
458 projectWindow = ide.CreateProjectView(workspace, filePath);
461 char extension[MAX_EXTENSION];
462 Window document = null;
463 for(document = ide.firstChild; document; document = document.next)
465 char * fileName = document.fileName;
466 if(document.isDocument && document._class == class(CodeEditor) && document.created && fileName)
468 CodeEditor codeEditor = (CodeEditor)document;
469 ide.projectView.AddFile(project.topNode, fileName, false, false);
470 codeEditor.DebugMenusDisabled();
475 if(project.topNode.modified)
477 project.Save(filePath);
478 projectWindow.modifiedDocument = false;
479 project.topNode.modified = false;
483 // TOCHECK: Why is the Quick project creating a form???
486 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
487 EditBox editBox = codeEditor.editBox;
488 strcpy(varName, className);
489 if(islower(varName[0]))
491 memmove(varName+1, varName, strlen(varName)+1);
495 varName[0] = (char)tolower(varName[0]);
498 editBox.Printf("\n%s %s {};\n", className, varName);
500 codeEditor.EnsureUpToDate();
502 // TODO: how to save that new file?
504 project.Save(filePath);
505 projectWindow.modifiedDocument = false;
506 project.topNode.modified = false;
508 project.StartMonitoring();
512 if(project && projectWindow)
514 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
515 ProjectConfig config = project.config;
516 projectWindow.ShowOutputBuildLog(true);
517 projectWindow.DisplayCompiler(compiler, false);
518 projectWindow.ProjectPrepareCompiler(project, compiler);
519 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
523 ide.projectView.ProjectBuild(null, Modifiers { });
532 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
533 NotifyClicked = ButtonCloseDialog;
540 row = targetType.AddRow();
541 row.tag = TargetTypes::executable;
542 row.SetData(null, $"Executable");
544 row = targetType.AddRow();
545 row.tag = TargetTypes::sharedLibrary;
546 row.SetData(null, $"Shared Library");
548 row = targetType.AddRow();
549 row.tag = TargetTypes::staticLibrary;
550 row.SetData(null, $"Static Library");
552 targetType.currentRow = targetType.FindRow(TargetTypes::executable);