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");
87 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
89 makingModified = true;
90 compilingModified = true;
91 linkingModified = true;
94 release = ProjectConfig
96 name = CopyString("Release");
103 makingModified = true;
104 compilingModified = true;
105 linkingModified = true;
108 /* error: too few arguments to function ‘__ecereProp_DirExpression_Set_char__PTR_’ -- debug.objDir = "debug";*/
113 moduleName = CopyString(name);
114 topNode.type = NodeTypes::project;
117 /*project.topNode.options = */project.options =
120 // TOFIX: Precomp problems withou the extra ( )
121 targetType = ((TargetTypes)targetType.GetTag());
122 targetFileName = /*CopyString(*/name/*)*/;
124 if(project.options.targetType != staticLibrary)
126 project.options.libraries = { [ CopyString("ecere") ] };
130 char workspaceFile[MAX_LOCATION];
131 strcpy(workspaceFile, filePath);
132 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
133 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
135 workspace.projects.Add(project);
137 project.topNode.configurations = /*project.configurations = */{ [ debug, release ] };
138 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
140 if(!project.Save(filePath))
142 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
147 projectWindow = ide.CreateProjectView(workspace, fileName);
150 char newWorkingDir[MAX_LOCATION];
151 StripLastDirectory(filePath, newWorkingDir);
153 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
155 StripLastDirectory(newWorkingDir, newWorkingDir);
156 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
159 if(createForm.checked)
163 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
164 EditBox editBox = codeEditor.editBox;
165 strcpy(varName, className);
166 if(islower(varName[0]))
168 memmove(varName+1, varName, strlen(varName)+1);
172 varName[0] = (char)tolower(varName[0]);
175 editBox.Printf("\n%s %s {};\n", className, varName);
177 codeEditor.EnsureUpToDate();
179 project.Save(filePath);
181 projectWindow.modifiedDocument = false;
182 project.topNode.modified = false;
185 editBox.Printf("class FormApplication : GuiApplication\n");
186 editBox.Printf("{\n");
187 editBox.Printf(" %s %s {};\n", className, varName);
188 editBox.Printf("}\n");
192 project.StartMonitoring();
194 if(project && projectWindow)
196 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
197 ProjectConfig config = project.config;
198 projectWindow.ShowOutputBuildLog(true);
199 projectWindow.DisplayCompiler(compiler, false);
200 projectWindow.ProjectPrepareCompiler(project, compiler);
201 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
204 ide.UpdateToolBarActiveConfigs(false);
214 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
215 NotifyClicked = ButtonCloseDialog;
219 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
220 isCheckbox = true, checked = true;
225 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
226 hotKey = altP, text = $"Project Name";
227 NotifyUpdate = EditBoxUpdate;
229 bool NotifyModified(EditBox editBox)
231 char name[MAX_FILENAME];
232 char lastPart[MAX_LOCATION];
233 char * text = editBox.contents;
235 // drop leading path stuff that has no business here
236 GetLastDirectory(text, name);
238 GetLastDirectory(path, lastPart);
239 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
241 if(strcmp(path, lastPart))
242 StripLastDirectory(path, path);
243 PathCatSlash(path, name);
244 locationEditBox.path = path;
246 else if(!name[0] && !strcmp(this.name, lastPart))
248 if(strcmp(path, lastPart))
249 StripLastDirectory(path, path);
250 locationEditBox.path = path;
252 else if(strcmp(name, lastPart))
254 PathCatSlash(path, name);
255 locationEditBox.path = path;
257 strcpy(this.name, name);
258 editBox.contents = name;
262 Label { this, position = { 10, 10 }, labeledWindow = projectName };
264 void EditBoxUpdate(EditBox editBox)
266 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
269 bool NotifyModifiedLocation(PathBox pathBox)
271 char location[MAX_LOCATION];
272 char lastPart[MAX_FILENAME];
273 char * text = pathBox.slashPath;
275 //replacing this: NotifyUpdate = EditBoxUpdate;
276 okBtn.disabled = !(text[0] && projectName.contents[0]);
278 GetWorkingDir(location, sizeof(location) - 1);
279 PathCatSlash(location, text);
281 GetLastDirectory(path, lastPart);
282 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
284 char newName[MAX_FILENAME];
285 GetLastDirectory(location, newName);
286 if(strcmp(newName, location))
288 strcpy(name, newName);
289 projectName.contents = name;
292 strcpy(path, location);
299 char location[MAX_LOCATION];
301 if(ideSettings.ideProjectFileDialogLocation)
302 strcpy(location, ideSettings.ideProjectFileDialogLocation);
304 GetWorkingDir(location, sizeof(location) - 1);
306 locationEditBox.path = location;
307 strcpy(path, location);
312 //targetType.AddField("String", null, 0);
314 row = targetType.AddRow();
315 row.tag = TargetTypes::executable;
316 row.SetData(null, $"Executable");
318 row = targetType.AddRow();
319 row.tag = TargetTypes::sharedLibrary;
320 row.SetData(null, $"Shared Library");
322 row = targetType.AddRow();
323 row.tag = TargetTypes::staticLibrary;
324 row.SetData(null, $"Static Library");
326 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
331 class QuickProjectDialog : Window
333 background = formColor;
334 minClientSize = { 316, 110 };
335 maxClientSize = { 640, 110 };
336 borderStyle = sizable;
339 text = $"Quick Project";
341 char path[MAX_LOCATION];
342 char name[MAX_FILENAME];
344 Label message { this, position = { 10, 10 }, text = $"Do you want to quickly create a temporary project?" };
346 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
347 Label { this, position = { 10, 50 }, labeledWindow = targetType };
351 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
352 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
354 char tempDir[MAX_LOCATION] = "";
355 char filePath[MAX_LOCATION];
356 char prjName[MAX_LOCATION] = "quick_project";
359 ProjectView projectWindow;
360 ProjectConfig debug, release;
362 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
364 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
368 GetLastDirectory(tempDir, prjName);
371 if((dot = strstr(prjName, ".")))
375 if(!FileExists(tempDir).isDirectory)
377 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
381 ide.tmpPrjDir = tempDir;
383 strcpy(filePath, tempDir);
384 PathCatSlash(filePath, prjName);
385 //GetExtension(filePath, extension);
387 ChangeExtension(filePath, ProjectExtension, filePath);
388 GetSystemPathBuffer(filePath, filePath);
390 debug = ProjectConfig
392 name = CopyString("Debug");
398 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
400 makingModified = true;
401 compilingModified = true;
402 linkingModified = true;
405 release = ProjectConfig
407 name = CopyString("Release");
410 optimization = speed;
414 makingModified = true;
415 compilingModified = true;
416 linkingModified = true;
422 moduleName = CopyString(prjName);
423 topNode.type = NodeTypes::project;
426 /*project.topNode.options = */project.options =
429 // TOFIX: Precomp problems withou the extra ( )
430 targetType = ((TargetTypes)targetType.GetTag());
431 targetFileName = /*CopyString(*/prjName/*)*/;
434 if(project.options.targetType != staticLibrary)
436 project.options.libraries = { [ CopyString("ecere") ] };
440 char workspaceFile[MAX_LOCATION];
441 strcpy(workspaceFile, filePath);
442 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
443 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
446 workspace.projects.Add(project);
448 // *** Don't set this directly on project, it must be set on top ProjectNode ***
449 project.topNode.configurations = { [ debug, release ] };
451 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
453 if(!project.Save(filePath))
455 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
458 ide.DestroyTemporaryProjectDir();
462 projectWindow = ide.CreateProjectView(workspace, filePath);
465 char extension[MAX_EXTENSION];
466 Window document = null;
467 for(document = ide.firstChild; document; document = document.next)
469 if(document.created && document.isDocument && document._class == class(CodeEditor))
471 char * fileName = document.fileName;
472 if(strstr(fileName, "http://") == fileName)
474 char name[MAX_LOCATION];
475 char newFileName[MAX_LOCATION];
476 GetLastDirectory(fileName, name);
477 strcpy(newFileName, tempDir);
478 PathCat(newFileName, name);
480 // TODO: this should be in Windows::SaveAs(char* asFileName)
482 //document.saving = true;
483 if(document.OnSaveFile(newFileName))
485 document.fileName = newFileName;
486 document.NotifySaved(document.master, /*this*/document, newFileName);
488 //document.saving = false;
490 // TODO else MessageBox unable to save and cancel the whole project creation thing
491 fileName = document.fileName;
495 CodeEditor codeEditor = (CodeEditor)document;
496 ide.projectView.AddFile(project.topNode, fileName, false, false);
497 codeEditor.DebugMenusDisabled();
503 if(project.topNode.modified)
505 project.Save(filePath);
506 projectWindow.modifiedDocument = false;
507 project.topNode.modified = false;
511 // TOCHECK: Why is the Quick project creating a form???
514 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
515 EditBox editBox = codeEditor.editBox;
516 strcpy(varName, className);
517 if(islower(varName[0]))
519 memmove(varName+1, varName, strlen(varName)+1);
523 varName[0] = (char)tolower(varName[0]);
526 editBox.Printf("\n%s %s {};\n", className, varName);
528 codeEditor.EnsureUpToDate();
530 // TODO: how to save that new file?
532 project.Save(filePath);
533 projectWindow.modifiedDocument = false;
534 project.topNode.modified = false;
536 project.StartMonitoring();
540 if(project && projectWindow)
542 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
543 ProjectConfig config = project.config;
544 projectWindow.ShowOutputBuildLog(true);
545 projectWindow.DisplayCompiler(compiler, false);
546 projectWindow.ProjectPrepareCompiler(project, compiler);
547 projectWindow.ProjectPrepareMakefile(project, force, compiler, config);
551 ide.projectView.ProjectBuild(null, Modifiers { });
560 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
561 NotifyClicked = ButtonCloseDialog;
568 row = targetType.AddRow();
569 row.tag = TargetTypes::executable;
570 row.SetData(null, $"Executable");
572 row = targetType.AddRow();
573 row.tag = TargetTypes::sharedLibrary;
574 row.SetData(null, $"Shared Library");
576 row = targetType.AddRow();
577 row.tag = TargetTypes::staticLibrary;
578 row.SetData(null, $"Static Library");
580 targetType.currentRow = targetType.FindRow(TargetTypes::executable);