3 FileDialog fileDialog { type = selectDir, text = $"Select project directory" };
5 class NewProjectDialog : Window
7 background = activeBorder;
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 //NotifyUpdate = EditBoxUpdate;
26 bool NotifyModified(PathBox pathBox)
28 char location[MAX_LOCATION];
29 char lastPart[MAX_FILENAME];
30 char * text = pathBox.slashPath;
32 //replacing this: NotifyUpdate = EditBoxUpdate;
33 okBtn.disabled = !(text[0] && projectName.contents[0]);
35 GetWorkingDir(location, sizeof(location) - 1);
36 PathCatSlash(location, text);
38 GetLastDirectory(path, lastPart);
39 /*if(text[0] && (!name[0] || !strcmp(lastPart, name)))
41 char newName[MAX_FILENAME];
42 GetLastDirectory(location, newName);
43 if(strcmp(newName, location))
45 strcpy(name, newName);
46 projectName.contents = name;
49 strcpy(path, location);
54 Label { this, position = { 10, 60 }, labeledWindow = locationEditBox };
56 DropBox targetType { this, position = { 10, 130 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
58 Label { this, position = { 10, 110 }, labeledWindow = targetType };
62 parent = this, isDefault = true, disabled = true, position = { 170, 130 }, size = { 60 }, text = $"OK";
63 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
65 char * location = locationEditBox.slashPath;
66 char * prjName = projectName.contents;
67 char filePath[MAX_LOCATION];
68 char fileName[MAX_LOCATION]; // Windows Friendly path
69 char extension[MAX_EXTENSION];
73 ProjectView projectWindow;
74 ProjectConfig debug, release;
76 if(!FileExists(location).isDirectory)
78 if(MessageBox { type = yesNo, master = this,
79 text = $"Directory doesn't exist", contents = $"Create directory?" }.Modal() == yes)
81 if(!MakeDir(location))
83 MessageBox { type = ok, master = this, text = location, contents = $"Error creating directory" }.Modal();
91 strcpy(filePath, location);
92 PathCatSlash(filePath, prjName);
93 GetExtension(filePath, extension);
95 ChangeExtension(filePath, ProjectExtension, filePath);
97 GetSystemPathBuffer(fileName, filePath);
98 exists = FileExists(filePath);
102 if(MessageBox { type = yesNo, master = this,
103 text = $"Project Already Exists", contents = $"Replace existing project?" }.Modal() == no)
107 debug = ProjectConfig
109 name = CopyString("Debug");
114 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
116 makingModified = true;
117 compilingModified = true;
118 linkingModified = true;
121 release = ProjectConfig
123 name = CopyString("Release");
126 optimization = speed;
129 makingModified = true;
130 compilingModified = true;
131 linkingModified = true;
134 /* error: too few arguments to function ‘__ecereProp_DirExpression_Set_char__PTR_’ -- debug.objDir = "debug";*/
139 moduleName = CopyString(name);
140 topNode.type = NodeTypes::project;
143 /*project.topNode.options = */project.options =
146 // TOFIX: Precomp problems withou the extra ( )
147 targetType = ((TargetTypes)targetType.GetTag());
148 targetFileName = /*CopyString(*/name/*)*/;
150 if(project.options.targetType != staticLibrary)
152 project.options.libraries = { [ CopyString("ecere") ] };
156 char workspaceFile[MAX_LOCATION];
157 strcpy(workspaceFile, filePath);
158 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
159 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
161 workspace.projects.Add(project);
163 project.topNode.configurations = project.configurations = { [ debug, release ] };
164 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
166 if(!project.Save(filePath))
168 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
173 projectWindow = ide.CreateProjectView(workspace, fileName);
176 char newWorkingDir[MAX_LOCATION];
177 StripLastDirectory(filePath, newWorkingDir);
179 ide.ChangeFileDialogsDirectory(newWorkingDir, false);
181 StripLastDirectory(newWorkingDir, newWorkingDir);
182 ide.ChangeProjectFileDialogDirectory(newWorkingDir);
185 if(createForm.checked)
189 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
190 EditBox editBox = codeEditor.editBox;
191 strcpy(varName, className);
192 if(islower(varName[0]))
194 memmove(varName+1, varName, strlen(varName)+1);
198 varName[0] = (char)tolower(varName[0]);
201 editBox.Printf("\n%s %s {};\n", className, varName);
203 codeEditor.EnsureUpToDate();
205 project.Save(filePath);
207 projectWindow.modifiedDocument = false;
208 project.topNode.modified = false;
211 editBox.Printf("class FormApplication : GuiApplication\n");
212 editBox.Printf("{\n");
213 editBox.Printf(" %s %s {};\n", className, varName);
214 editBox.Printf("}\n");
219 if(project && projectWindow)
221 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
222 ProjectConfig config = project.config;
223 projectWindow.ProjectPrepareMakefile(project, force, true, true, compiler, config);
234 parent = this, position = { 240, 130 }, size = { 60 }, hotKey = escape, text = $"Cancel";
235 NotifyClicked = ButtonCloseDialog;
239 parent = this, text = $"Create Form", hotKey = altF, position = { 200, 30 };
240 isCheckbox = true, checked = true;
245 parent = this, textHorzScroll = true, position = { 10, 30 }, size = { 160 };
246 hotKey = altP, text = $"Project Name";
247 NotifyUpdate = EditBoxUpdate;
249 bool NotifyModified(EditBox editBox)
251 char name[MAX_FILENAME];
252 char lastPart[MAX_LOCATION];
253 char * text = editBox.contents;
255 // drop leading path stuff that has no business here
256 GetLastDirectory(text, name);
258 GetLastDirectory(path, lastPart);
259 if(name[0] && (!strcmp(path, lastPart) || !path[0] || !strcmp(this.name, lastPart)))
261 if(strcmp(path, lastPart))
262 StripLastDirectory(path, path);
263 PathCatSlash(path, name);
264 locationEditBox.path = path;
266 else if(!name[0] && !strcmp(this.name, lastPart))
268 if(strcmp(path, lastPart))
269 StripLastDirectory(path, path);
270 locationEditBox.path = path;
272 else if(strcmp(name, lastPart))
274 PathCatSlash(path, name);
275 locationEditBox.path = path;
277 strcpy(this.name, name);
278 editBox.contents = name;
282 Label { this, position = { 10, 10 }, labeledWindow = projectName };
284 void EditBoxUpdate(EditBox editBox)
286 okBtn.disabled = !(locationEditBox.path[0] && projectName.contents[0]);
291 char location[MAX_LOCATION];
293 if(ideSettings.ideProjectFileDialogLocation)
294 strcpy(location, ideSettings.ideProjectFileDialogLocation);
296 GetWorkingDir(location, sizeof(location) - 1);
298 locationEditBox.path = location;
299 strcpy(path, location);
304 //targetType.AddField("String", null, 0);
306 row = targetType.AddRow();
307 row.tag = TargetTypes::executable;
308 row.SetData(null, $"Executable");
310 row = targetType.AddRow();
311 row.tag = TargetTypes::sharedLibrary;
312 row.SetData(null, $"Shared Library");
314 row = targetType.AddRow();
315 row.tag = TargetTypes::staticLibrary;
316 row.SetData(null, $"Static Library");
318 targetType.currentRow = targetType.FindRow(TargetTypes::executable);
323 class QuickProjectDialog : Window
325 background = activeBorder;
326 minClientSize = { 316, 110 };
327 maxClientSize = { 640, 110 };
328 borderStyle = sizable;
331 text = $"Quick Project";
333 char path[MAX_LOCATION];
334 char name[MAX_FILENAME];
336 Label message { this, position = { 10, 10 }, size = { 200 }, text = $"Do you want to quickly create a temporary project?" };
338 DropBox targetType { this, position = { 10, 70 }, size = { 130 }, hotKey = altT, text = $"Target Type" };
339 Label { this, position = { 10, 50 }, labeledWindow = targetType };
343 parent = this, isDefault = true, position = { 170, 70 }, size = { 60 }, text = $"OK";
344 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
346 char tempDir[MAX_LOCATION] = "";
347 char filePath[MAX_LOCATION];
348 char prjName[MAX_LOCATION] = "quick_project";
351 ProjectView projectWindow;
352 ProjectConfig debug, release;
354 /*if(!*/CreateTemporaryDir(tempDir, "ecereide");/*)
356 MessageBox { type = ok, master = this, text = tempDir, contents = "Error creating temporary directory." }.Modal();
360 GetLastDirectory(tempDir, prjName);
363 if((dot = strstr(prjName, ".")))
367 if(!FileExists(tempDir).isDirectory)
369 MessageBox { type = ok, master = this, text = tempDir, contents = $"Temporary directory does not exist." }.Modal();
373 ide.tmpPrjDir = tempDir;
375 strcpy(filePath, tempDir);
376 PathCatSlash(filePath, prjName);
377 //GetExtension(filePath, extension);
379 ChangeExtension(filePath, ProjectExtension, filePath);
380 GetSystemPathBuffer(filePath, filePath);
382 debug = ProjectConfig
384 name = CopyString("Debug");
389 preprocessorDefinitions = { [ CopyString("_DEBUG") ] };
391 makingModified = true;
392 compilingModified = true;
393 linkingModified = true;
396 release = ProjectConfig
398 name = CopyString("Release");
401 optimization = speed;
404 makingModified = true;
405 compilingModified = true;
406 linkingModified = true;
412 moduleName = CopyString(prjName);
413 topNode.type = NodeTypes::project;
416 /*project.topNode.options = */project.options =
419 // TOFIX: Precomp problems withou the extra ( )
420 targetType = ((TargetTypes)targetType.GetTag());
421 targetFileName = /*CopyString(*/prjName/*)*/;
424 if(project.options.targetType != staticLibrary)
426 project.options.libraries = { [ CopyString("ecere") ] };
430 char workspaceFile[MAX_LOCATION];
431 strcpy(workspaceFile, filePath);
432 ChangeExtension(workspaceFile, WorkspaceExtension, workspaceFile);
433 workspace = Workspace { compiler = ideSettings.defaultCompiler, workspaceFile = workspaceFile };
436 workspace.projects.Add(project);
438 project.topNode.configurations = project.configurations = { [ debug, release ] };
439 project.resNode = project.topNode.Add(project, "Resources", null, resources, archiveFile, false);
441 if(!project.Save(filePath))
443 MessageBox { type = ok, master = this, text = filePath, contents = $"Error writing project file" }.Modal();
446 ide.DestroyTemporaryProjectDir();
450 projectWindow = ide.CreateProjectView(workspace, filePath);
453 char extension[MAX_EXTENSION];
454 Window document = null;
455 for(document = ide.firstChild; document; document = document.next)
457 char * fileName = document.fileName;
458 if(document.isDocument && document._class == class(CodeEditor) && document.created && fileName)
460 CodeEditor codeEditor = (CodeEditor)document;
461 ide.projectView.AddFile(project.topNode, fileName, false, false);
462 codeEditor.DebugMenusDisabled();
467 if(project.topNode.modified)
469 project.Save(filePath);
470 projectWindow.modifiedDocument = false;
471 project.topNode.modified = false;
477 CodeEditor codeEditor = projectWindow.CreateNew("Form", "form", "Window", className);
478 EditBox editBox = codeEditor.editBox;
479 strcpy(varName, className);
480 if(islower(varName[0]))
482 memmove(varName+1, varName, strlen(varName)+1);
486 varName[0] = (char)tolower(varName[0]);
489 editBox.Printf("\n%s %s {};\n", className, varName);
491 codeEditor.EnsureUpToDate();
493 // TODO: how to save that new file?
495 project.Save(filePath);
496 projectWindow.modifiedDocument = false;
497 project.topNode.modified = false;
502 if(project && projectWindow)
504 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
505 ProjectConfig config = project.config;
506 projectWindow.ProjectPrepareMakefile(project, force, true, true, compiler, config);
510 ide.projectView.ProjectBuild(null, Modifiers { });
519 parent = this, position = { 240, 70 }, size = { 60 }, hotKey = escape, text = $"Cancel";
520 NotifyClicked = ButtonCloseDialog;
527 row = targetType.AddRow();
528 row.tag = TargetTypes::executable;
529 row.SetData(null, $"Executable");
531 row = targetType.AddRow();
532 row.tag = TargetTypes::sharedLibrary;
533 row.SetData(null, $"Shared Library");
535 row = targetType.AddRow();
536 row.tag = TargetTypes::staticLibrary;
537 row.SetData(null, $"Static Library");
539 targetType.currentRow = targetType.FindRow(TargetTypes::executable);