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);
153 if(!prj.Save(prj.filePath))
155 MessageBox { type = ok, master = this, text = prj.filePath, contents = $"Error writing project file" }.Modal();
160 projectWindow = ide.CreateProjectView(workspace, fileName);
163 char newWorkingDir[MAX_LOCATION];
164 StripLastDirectory(prj.filePath, newWorkingDir);
166 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
168 StripLastDirectory(newWorkingDir, newWorkingDir);
169 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
176 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
177 EditBox editBox = codeEditor.editBox;
178 strcpy(varName, className);
179 if(islower(varName[0]))
181 memmove(varName+1, varName, strlen(varName)+1);
185 varName[0] = (char)tolower(varName[0]);
188 editBox.Printf("\n%s %s {};\n", className, varName);
190 codeEditor.EnsureUpToDate();
192 prj.Save(prj.filePath);
194 projectWindow.modifiedDocument = false;
195 prj.topNode.modified = false;
198 editBox.Printf("class FormApplication : GuiApplication\n");
199 editBox.Printf("{\n");
200 editBox.Printf(" %s %s {};\n", className, varName);
201 editBox.Printf("}\n");
205 prj.StartMonitoring();
207 if(prj && projectWindow)
209 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
210 ProjectConfig config = prj.config;
211 projectWindow.ShowOutputBuildLog(true);
212 projectWindow.DisplayCompiler(compiler, false);
213 projectWindow.ProjectPrepareCompiler(prj, compiler, false);
214 projectWindow.ProjectPrepareMakefile(prj, force, compiler, config);
217 ide.UpdateToolBarActiveConfigs(false);
223 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
224 NotifyClicked = ButtonCloseDialog;
228 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
229 isCheckbox = true, checked = true;
234 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
235 hotKey = altP, text = $"Project Name";
236 NotifyUpdate = EditBoxUpdate;
238 bool NotifyModified(EditBox editBox)
240 char name[MAX_FILENAME];
241 char lastPart[MAX_LOCATION];
242 char * text = editBox.contents;
244 // drop leading path stuff that has no business here
245 GetLastDirectory(text, name);
247 GetLastDirectory(path, lastPart);
248 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
250 if(strcmp(path, lastPart))
251 StripLastDirectory(path, path);
252 PathCatSlash(path, name);
253 locationEditBox.path = path;
255 else if(!name[0] && !strcmp(this.name, lastPart))
257 if(strcmp(path, lastPart))
258 StripLastDirectory(path, path);
259 locationEditBox.path = path;
261 else if(strcmp(name, lastPart))
263 PathCatSlash(path, name);
264 locationEditBox.path = path;
266 strcpy(this.name, name);
267 editBox.contents = name;
271 Label { this, position = { 10, 10 }, labeledWindow = projectName };
273 void EditBoxUpdate(EditBox editBox)
275 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
278 bool NotifyModifiedLocation(PathBox pathBox)
280 char location[MAX_LOCATION];
281 char lastPart[MAX_FILENAME];
282 char * text = pathBox.slashPath;
284 //replacing this: NotifyUpdate = EditBoxUpdate;
285 okBtn.disabled = !(text[0] && projectName.contents[0]);
287 GetWorkingDir(location, sizeof(location) - 1);
288 PathCatSlash(location, text);
290 GetLastDirectory(path, lastPart);
291 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
293 char newName[MAX_FILENAME];
294 GetLastDirectory(location, newName);
295 if(strcmp(newName, location))
297 strcpy(name, newName);
298 projectName.contents = name;
301 strcpy(path, location);
308 char location[MAX_LOCATION];
310 if(ideSettings.ideProjectFileDialogLocation)
311 strcpy(location, ideSettings.ideProjectFileDialogLocation);
313 GetWorkingDir(location, sizeof(location) - 1);
315 locationEditBox.path = location;
316 strcpy(path, location);
321 //targetType.AddField("String", null, 0);
323 row = targetType.AddRow();
324 row.tag = TargetTypes::executable;
325 row.SetData(null, $"Executable");
327 row = targetType.AddRow();
328 row.tag = TargetTypes::sharedLibrary;
329 row.SetData(null, $"Shared Library");
331 row = targetType.AddRow();
332 row.tag = TargetTypes::staticLibrary;
333 row.SetData(null, $"Static Library");
335 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
340 class QuickProjectDialog : Window
342 background = formColor;
343 minClientSize = { 316, 110 };
344 maxClientSize = { 640, 110 };
345 borderStyle = sizable;
348 text = $"Quick Project";
350 char path[MAX_LOCATION];
351 char name[MAX_FILENAME];
353 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
355 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
356 Label { this, position = { 10, 50 }, labeledWindow = targetType };
360 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
361 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
363 char tempDir[MAX_LOCATION] = "";
364 char filePath[MAX_LOCATION];
365 char prjName[MAX_LOCATION] = "quick_project";
368 ProjectView projectWindow;
369 ProjectConfig debug, release;
371 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
373 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
377 GetLastDirectory(tempDir, prjName);
380 if((dot = strstr(prjName, ".")))
384 if(!FileExists(tempDir).isDirectory)
386 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
390 ide.tmpPrjDir = tempDir;
392 strcpy(filePath, tempDir);
393 PathCatSlash(filePath, prjName);
394 //GetExtension(filePath, extension);
396 ChangeExtension(filePath, ProjectExtension, filePath);
397 GetSystemPathBuffer(filePath, filePath);
399 debug = ProjectConfig
401 name = CopyString("Debug");
407 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
409 makingModified = true;
410 compilingModified = true;
411 linkingModified = true;
414 release = ProjectConfig
416 name = CopyString("Release");
419 optimization = speed;
423 makingModified = true;
424 compilingModified = true;
425 linkingModified = true;
431 moduleName = CopyString(prjName);
432 topNode.type = NodeTypes::project;
435 /*project.topNode.options = */project.options =
438 // TOFIX: Precomp problems withou the extra ( )
439 targetType = ((TargetTypes)targetType.GetTag());
440 targetFileName = /*CopyString(*/prjName/*)*/;
443 if(project.options.targetType != staticLibrary)
445 project.options.libraries = { [ CopyString("ecere") ] };
449 char workspaceFile[MAX_LOCATION];
450 strcpy(workspaceFile, filePath);
451 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
452 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
455 workspace.projects.Add(project);
457 // *** Don't set this directly on project, it must be set on top ProjectNode ***
458 project.topNode.configurations = { [ debug, release ] };
460 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
462 if(!project.Save(filePath))
464 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
467 ide.DestroyTemporaryProjectDir();
471 projectWindow = ide.CreateProjectView(workspace, filePath);
474 char extension[MAX_EXTENSION];
475 Window document = null;
476 for(document = ide.firstChild; document; document = document.next)
478 if(document.created && document.isDocument && document._class == class(CodeEditor))
480 char * fileName = document.fileName;
481 if(strstr(fileName, "http://") == fileName)
483 char name[MAX_LOCATION];
484 char newFileName[MAX_LOCATION];
485 GetLastDirectory(fileName, name);
486 strcpy(newFileName, tempDir);
487 PathCat(newFileName, name);
489 // TODO: this should be in Windows::SaveAs(char* asFileName)
491 //document.saving = true;
492 if(document.OnSaveFile(newFileName))
494 document.fileName = newFileName;
495 document.NotifySaved(document.master, /*this*/document, newFileName);
497 //document.saving = false;
499 // TODO else MessageBox unable to save and cancel the whole project creation thing
500 fileName = document.fileName;
504 CodeEditor codeEditor = (CodeEditor)document;
505 ide.projectView.AddFile(project.topNode, fileName, false, false);
506 codeEditor.AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
512 if(project.topNode.modified)
514 project.Save(filePath);
515 projectWindow.modifiedDocument = false;
516 project.topNode.modified = false;
520 // TOCHECK: Why is the Quick project creating a form???
523 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
524 EditBox editBox = codeEditor.editBox;
525 strcpy(varName, className);
526 if(islower(varName[0]))
528 memmove(varName+1, varName, strlen(varName)+1);
532 varName[0] = (char)tolower(varName[0]);
535 editBox.Printf("\n%s %s {};\n", className, varName);
537 codeEditor.EnsureUpToDate();
539 // TODO: how to save that new file?
541 project.Save(filePath);
542 projectWindow.modifiedDocument = false;
543 project.topNode.modified = false;
545 project.StartMonitoring();
549 if(project && projectWindow)
551 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
552 ProjectConfig config = project.config;
553 projectWindow.ShowOutputBuildLog(true);
554 projectWindow.DisplayCompiler(compiler, false);
555 projectWindow.ProjectPrepareCompiler(project, compiler, false);
556 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
560 ide.projectView.ProjectBuild(null, Modifiers { });
569 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
570 NotifyClicked = ButtonCloseDialog;
577 row = targetType.AddRow();
578 row.tag = TargetTypes::executable;
579 row.SetData(null, $"Executable");
581 row = targetType.AddRow();
582 row.tag = TargetTypes::sharedLibrary;
583 row.SetData(null, $"Shared Library");
585 row = targetType.AddRow();
586 row.tag = TargetTypes::staticLibrary;
587 row.SetData(null, $"Static Library");
589 targetType.currentRow = targetType.FindRow(TargetTypes::executable);