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 { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
151 workspace.projects.Add(prj);
152 ide.findInFilesDialog.AddProjectItem(prj);
153 ide.findInFilesDialog.mode = FindInFilesMode::project;
154 ide.findInFilesDialog.currentDirectory = prj.topNode.path;
156 if(!prj.Save(prj.filePath))
158 MessageBox { type = ok, master = this, text = prj.filePath, contents = $"Error writing project file" }.Modal();
163 projectWindow = ide.CreateProjectView(workspace, fileName);
166 char newWorkingDir[MAX_LOCATION];
167 StripLastDirectory(prj.filePath, newWorkingDir);
169 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
171 StripLastDirectory(newWorkingDir, newWorkingDir);
172 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
174 ide.toolBox.visible = true;
180 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
181 EditBox editBox = codeEditor.editBox;
182 strcpy(varName, className);
183 if(islower(varName[0]))
185 memmove(varName+1, varName, strlen(varName)+1);
189 varName[0] = (char)tolower(varName[0]);
192 editBox.Printf("\n%s %s {};\n", className, varName);
194 codeEditor.EnsureUpToDate();
196 prj.Save(prj.filePath);
198 projectWindow.modifiedDocument = false;
199 prj.topNode.modified = false;
202 editBox.Printf("class FormApplication : GuiApplication\n");
203 editBox.Printf("{\n");
204 editBox.Printf(" %s %s {};\n", className, varName);
205 editBox.Printf("}\n");
209 prj.StartMonitoring();
211 if(prj && projectWindow)
213 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
214 ProjectConfig config = prj.config;
215 projectWindow.ShowOutputBuildLog(true);
216 projectWindow.DisplayCompiler(compiler, false);
217 projectWindow.ProjectPrepareCompiler(prj, compiler, false);
218 projectWindow.ProjectPrepareMakefile(prj, force, compiler, config);
221 ide.UpdateToolBarActiveConfigs(false);
227 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
228 NotifyClicked = ButtonCloseDialog;
232 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
233 isCheckbox = true, checked = true;
238 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
239 hotKey = altP, text = $"Project Name";
240 NotifyUpdate = EditBoxUpdate;
242 bool NotifyModified(EditBox editBox)
244 char name[MAX_FILENAME];
245 char tmp[MAX_FILENAME];
246 char lastPart[MAX_LOCATION];
247 const char * text = editBox.contents;
249 // drop leading path stuff that has no business here
250 GetLastDirectory(text, tmp);
251 ValidProjectNameBufCopy(name, tmp);
253 GetLastDirectory(path, lastPart);
254 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
256 if(strcmp(path, lastPart))
257 StripLastDirectory(path, path);
258 PathCatSlash(path, name);
259 locationEditBox.path = path;
261 else if(!name[0] && !strcmp(this.name, lastPart))
263 if(strcmp(path, lastPart))
264 StripLastDirectory(path, path);
265 locationEditBox.path = path;
267 else if(strcmp(name, lastPart))
269 PathCatSlash(path, name);
270 locationEditBox.path = path;
272 strcpy(this.name, name);
273 editBox.contents = name;
277 Label { this, position = { 10, 10 }, labeledWindow = projectName };
279 void EditBoxUpdate(EditBox editBox)
281 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
284 bool NotifyModifiedLocation(PathBox pathBox)
286 char location[MAX_LOCATION];
287 char lastPart[MAX_FILENAME];
290 BasicValidatePathBoxPath(pathBox);
292 text = pathBox.slashPath;
294 //replacing this: NotifyUpdate = EditBoxUpdate;
295 okBtn.disabled = !(text[0] && projectName.contents[0]);
297 strcpy(location, ideSettings.ideProjectFileDialogLocation);
298 PathCatSlash(location, text);
300 GetLastDirectory(path, lastPart);
301 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
303 char newName[MAX_FILENAME];
304 GetLastDirectory(location, newName);
305 if(strcmp(newName, location))
307 strcpy(name, newName);
308 projectName.contents = name;
311 strcpy(path, location);
318 char location[MAX_LOCATION];
320 strcpy(location, ideSettings.ideProjectFileDialogLocation);
322 locationEditBox.path = location;
323 strcpy(path, location);
328 //targetType.AddField("String", null, 0);
330 row = targetType.AddRow();
331 row.tag = TargetTypes::executable;
332 row.SetData(null, $"Executable");
334 row = targetType.AddRow();
335 row.tag = TargetTypes::sharedLibrary;
336 row.SetData(null, $"Shared Library");
338 row = targetType.AddRow();
339 row.tag = TargetTypes::staticLibrary;
340 row.SetData(null, $"Static Library");
342 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
347 class QuickProjectDialog : Window
349 background = formColor;
350 minClientSize = { 316, 110 };
351 maxClientSize = { 640, 110 };
352 borderStyle = sizable;
355 text = $"Quick Project";
357 char path[MAX_LOCATION];
358 char name[MAX_FILENAME];
360 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
362 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
363 Label { this, position = { 10, 50 }, labeledWindow = targetType };
367 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
368 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
370 char tempDir[MAX_LOCATION] = "";
371 char filePath[MAX_LOCATION];
372 char prjName[MAX_LOCATION] = "quick_project";
375 ProjectView projectWindow;
376 ProjectConfig debug, release;
378 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
380 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
384 GetLastDirectory(tempDir, prjName);
387 if((dot = strstr(prjName, ".")))
391 if(!FileExists(tempDir).isDirectory)
393 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
397 ide.tmpPrjDir = tempDir;
399 strcpy(filePath, tempDir);
400 PathCatSlash(filePath, prjName);
401 //GetExtension(filePath, extension);
403 ChangeExtension(filePath, ProjectExtension, filePath);
404 GetSystemPathBuffer(filePath, filePath);
406 debug = ProjectConfig
408 name = CopyString("Debug");
414 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
416 makingModified = true;
417 compilingModified = true;
418 linkingModified = true;
421 release = ProjectConfig
423 name = CopyString("Release");
426 optimization = speed;
430 makingModified = true;
431 compilingModified = true;
432 linkingModified = true;
438 moduleName = CopyString(prjName);
439 topNode.type = NodeTypes::project;
442 /*project.topNode.options = */project.options =
445 // TOFIX: Precomp problems withou the extra ( )
446 targetType = ((TargetTypes)targetType.GetTag());
447 targetFileName = /*CopyString(*/prjName/*)*/;
450 if(project.options.targetType != staticLibrary)
452 project.options.libraries = { [ CopyString("ecere") ] };
456 char workspaceFile[MAX_LOCATION];
457 strcpy(workspaceFile, filePath);
458 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
459 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
462 workspace.projects.Add(project);
463 ide.findInFilesDialog.AddProjectItem(project);
464 ide.findInFilesDialog.mode = FindInFilesMode::project;
465 ide.findInFilesDialog.currentDirectory = project.topNode.path;
467 // *** Don't set this directly on project, it must be set on top ProjectNode ***
468 project.topNode.configurations = { [ debug, release ] };
470 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
472 if(!project.Save(filePath))
474 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
477 ide.DestroyTemporaryProjectDir();
481 projectWindow = ide.CreateProjectView(workspace, filePath);
484 char extension[MAX_EXTENSION];
485 Window document = null;
486 for(document = ide.firstChild; document; document = document.next)
488 if(document.created && document.isDocument && document._class == class(CodeEditor))
490 const char * fileName = document.fileName;
491 if(strstr(fileName, "http://") == fileName)
493 char name[MAX_LOCATION];
494 char newFileName[MAX_LOCATION];
495 GetLastDirectory(fileName, name);
496 strcpy(newFileName, tempDir);
497 PathCat(newFileName, name);
499 // TODO: this should be in Windows::SaveAs(char* asFileName)
501 //document.saving = true;
502 if(document.OnSaveFile(newFileName))
504 document.fileName = newFileName;
505 document.NotifySaved(document.master, /*this*/document, newFileName);
507 //document.saving = false;
509 // TODO else MessageBox unable to save and cancel the whole project creation thing
510 fileName = document.fileName;
514 CodeEditor codeEditor = (CodeEditor)document;
515 ide.projectView.AddFile(project.topNode, fileName, false, false);
516 codeEditor.AdjustDebugMenus();
522 ide.toolBox.visible = true;
524 if(project.topNode.modified)
526 project.Save(filePath);
527 projectWindow.modifiedDocument = false;
528 project.topNode.modified = false;
532 // TOCHECK: Why is the Quick project creating a form???
535 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
536 EditBox editBox = codeEditor.editBox;
537 strcpy(varName, className);
538 if(islower(varName[0]))
540 memmove(varName+1, varName, strlen(varName)+1);
544 varName[0] = (char)tolower(varName[0]);
547 editBox.Printf("\n%s %s {};\n", className, varName);
549 codeEditor.EnsureUpToDate();
551 // TODO: how to save that new file?
553 project.Save(filePath);
554 projectWindow.modifiedDocument = false;
555 project.topNode.modified = false;
557 project.StartMonitoring();
561 if(project && projectWindow)
563 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
564 ProjectConfig config = project.config;
565 projectWindow.ShowOutputBuildLog(true);
566 projectWindow.DisplayCompiler(compiler, false);
567 projectWindow.ProjectPrepareCompiler(project, compiler, false);
568 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
572 ide.projectView.ProjectBuild(null, Modifiers { });
581 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
582 NotifyClicked = ButtonCloseDialog;
589 row = targetType.AddRow();
590 row.tag = TargetTypes::executable;
591 row.SetData(null, $"Executable");
593 row = targetType.AddRow();
594 row.tag = TargetTypes::sharedLibrary;
595 row.SetData(null, $"Shared Library");
597 row = targetType.AddRow();
598 row.tag = TargetTypes::staticLibrary;
599 row.SetData(null, $"Static Library");
601 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
611 void ValidProjectNameBufCopy(char *output, const char *input)
613 strcpy(output, input);
614 TrimLSpaces(output, output);
615 TrimRSpaces(output, output);
617 // todo: support '&', '.' and ' ' in project name on windows so that it may be used by all platforms.
618 const char * chars = "*|:\",<>?\\/&. ";
619 char ch, * s = output, * o = output;
620 while((ch = *s++)) { if(!strchr(chars, ch)) *o++ = ch; }