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 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);
179 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
180 EditBox editBox = codeEditor.editBox;
181 strcpy(varName, className);
182 if(islower(varName[0]))
184 memmove(varName+1, varName, strlen(varName)+1);
188 varName[0] = (char)tolower(varName[0]);
191 editBox.Printf("\n%s %s {};\n", className, varName);
193 codeEditor.EnsureUpToDate();
195 prj.Save(prj.filePath);
197 projectWindow.modifiedDocument = false;
198 prj.topNode.modified = false;
201 editBox.Printf("class FormApplication : GuiApplication\n");
202 editBox.Printf("{\n");
203 editBox.Printf(" %s %s {};\n", className, varName);
204 editBox.Printf("}\n");
208 prj.StartMonitoring();
210 if(prj && projectWindow)
212 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
213 ProjectConfig config = prj.config;
214 projectWindow.ShowOutputBuildLog(true);
215 projectWindow.DisplayCompiler(compiler, false);
216 projectWindow.ProjectPrepareCompiler(prj, compiler, false);
217 projectWindow.ProjectPrepareMakefile(prj, force, compiler, config);
220 ide.UpdateToolBarActiveConfigs(false);
226 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
227 NotifyClicked = ButtonCloseDialog;
231 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
232 isCheckbox = true, checked = true;
237 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
238 hotKey = altP, text = $"Project Name";
239 NotifyUpdate = EditBoxUpdate;
241 bool NotifyModified(EditBox editBox)
243 char name[MAX_FILENAME];
244 char tmp[MAX_FILENAME];
245 char lastPart[MAX_LOCATION];
246 char * text = editBox.contents;
248 // drop leading path stuff that has no business here
249 GetLastDirectory(text, tmp);
250 ValidProjectNameBufCopy(name, tmp);
252 GetLastDirectory(path, lastPart);
253 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
255 if(strcmp(path, lastPart))
256 StripLastDirectory(path, path);
257 PathCatSlash(path, name);
258 locationEditBox.path = path;
260 else if(!name[0] && !strcmp(this.name, lastPart))
262 if(strcmp(path, lastPart))
263 StripLastDirectory(path, path);
264 locationEditBox.path = path;
266 else if(strcmp(name, lastPart))
268 PathCatSlash(path, name);
269 locationEditBox.path = path;
271 strcpy(this.name, name);
272 editBox.contents = name;
276 Label { this, position = { 10, 10 }, labeledWindow = projectName };
278 void EditBoxUpdate(EditBox editBox)
280 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
283 bool NotifyModifiedLocation(PathBox pathBox)
285 char location[MAX_LOCATION];
286 char lastPart[MAX_FILENAME];
289 BasicValidatePathBoxPath(pathBox);
291 text = pathBox.slashPath;
293 //replacing this: NotifyUpdate = EditBoxUpdate;
294 okBtn.disabled = !(text[0] && projectName.contents[0]);
296 GetWorkingDir(location, sizeof(location) - 1);
297 PathCatSlash(location, text);
299 GetLastDirectory(path, lastPart);
300 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
302 char newName[MAX_FILENAME];
303 GetLastDirectory(location, newName);
304 if(strcmp(newName, location))
306 strcpy(name, newName);
307 projectName.contents = name;
310 strcpy(path, location);
317 char location[MAX_LOCATION];
319 if(ideSettings.ideProjectFileDialogLocation)
320 strcpy(location, ideSettings.ideProjectFileDialogLocation);
322 GetWorkingDir(location, sizeof(location) - 1);
324 locationEditBox.path = location;
325 strcpy(path, location);
330 //targetType.AddField("String", null, 0);
332 row = targetType.AddRow();
333 row.tag = TargetTypes::executable;
334 row.SetData(null, $"Executable");
336 row = targetType.AddRow();
337 row.tag = TargetTypes::sharedLibrary;
338 row.SetData(null, $"Shared Library");
340 row = targetType.AddRow();
341 row.tag = TargetTypes::staticLibrary;
342 row.SetData(null, $"Static Library");
344 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
349 class QuickProjectDialog : Window
351 background = formColor;
352 minClientSize = { 316, 110 };
353 maxClientSize = { 640, 110 };
354 borderStyle = sizable;
357 text = $"Quick Project";
359 char path[MAX_LOCATION];
360 char name[MAX_FILENAME];
362 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
364 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
365 Label { this, position = { 10, 50 }, labeledWindow = targetType };
369 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
370 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
372 char tempDir[MAX_LOCATION] = "";
373 char filePath[MAX_LOCATION];
374 char prjName[MAX_LOCATION] = "quick_project";
377 ProjectView projectWindow;
378 ProjectConfig debug, release;
380 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
382 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
386 GetLastDirectory(tempDir, prjName);
389 if((dot = strstr(prjName, ".")))
393 if(!FileExists(tempDir).isDirectory)
395 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
399 ide.tmpPrjDir = tempDir;
401 strcpy(filePath, tempDir);
402 PathCatSlash(filePath, prjName);
403 //GetExtension(filePath, extension);
405 ChangeExtension(filePath, ProjectExtension, filePath);
406 GetSystemPathBuffer(filePath, filePath);
408 debug = ProjectConfig
410 name = CopyString("Debug");
416 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
418 makingModified = true;
419 compilingModified = true;
420 linkingModified = true;
423 release = ProjectConfig
425 name = CopyString("Release");
428 optimization = speed;
432 makingModified = true;
433 compilingModified = true;
434 linkingModified = true;
440 moduleName = CopyString(prjName);
441 topNode.type = NodeTypes::project;
444 /*project.topNode.options = */project.options =
447 // TOFIX: Precomp problems withou the extra ( )
448 targetType = ((TargetTypes)targetType.GetTag());
449 targetFileName = /*CopyString(*/prjName/*)*/;
452 if(project.options.targetType != staticLibrary)
454 project.options.libraries = { [ CopyString("ecere") ] };
458 char workspaceFile[MAX_LOCATION];
459 strcpy(workspaceFile, filePath);
460 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
461 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
464 workspace.projects.Add(project);
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 char extension[MAX_EXTENSION];
487 Window document = null;
488 for(document = ide.firstChild; document; document = document.next)
490 if(document.created && document.isDocument && document._class == class(CodeEditor))
492 char * fileName = document.fileName;
493 if(strstr(fileName, "http://") == fileName)
495 char name[MAX_LOCATION];
496 char newFileName[MAX_LOCATION];
497 GetLastDirectory(fileName, name);
498 strcpy(newFileName, tempDir);
499 PathCat(newFileName, name);
501 // TODO: this should be in Windows::SaveAs(char* asFileName)
503 //document.saving = true;
504 if(document.OnSaveFile(newFileName))
506 document.fileName = newFileName;
507 document.NotifySaved(document.master, /*this*/document, newFileName);
509 //document.saving = false;
511 // TODO else MessageBox unable to save and cancel the whole project creation thing
512 fileName = document.fileName;
516 CodeEditor codeEditor = (CodeEditor)document;
517 ide.projectView.AddFile(project.topNode, fileName, false, false);
518 codeEditor.AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
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, 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 char * chars = "*|:\",<>?\\/&. ";
619 char ch, * s = output, * o = output;
620 while((ch = *s++)) { if(!strchr(chars, ch)) *o++ = ch; }