3 import "FileSystemIterator"
5 class ImportFolderFSI : NormalFileSystemIterator
7 ProjectView projectView;
8 Array<ProjectNode> stack { };
10 bool OnFolder(char * folderPath)
12 char name[MAX_LOCATION];
13 ProjectNode parentNode = stack.lastIterator.data;
15 GetLastDirectory(folderPath, name);
16 folder = parentNode.FindSpecial(name, false, true, true);
18 folder = projectView.NewFolder(parentNode, name, false);
23 void OutFolder(char * folderPath, bool isRoot)
25 stack.lastIterator.Remove(); //stack.Remove();
28 bool OnFile(char * filePath)
30 ProjectNode parentNode = stack.lastIterator.data;
31 projectView.AddFile(parentNode, filePath, parentNode.isInResources);
36 static FileFilter fileFilters[] =
39 "EC/C/C++ Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)",
40 "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx"
43 "EC/C/C++ Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)",
44 "ec, eh, c, cpp, cc, cxx"
47 "Header Files for eC/C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)",
53 static FileFilter resourceFilters[] =
56 "Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png,*.gif)",
57 "jpg, jpeg, bmp, pcx, png, gif"
60 "3D Studio Model Files (*.3ds)",
66 static FileType fileTypes[] =
68 { "Based on extension", null },
71 { "3D Studio Model", "3ds" }
74 static FileFilter projectFilters[] =
76 { "Project Files (*.epj)", ProjectExtension },
77 { "Workspace Files (*.ews)", WorkspaceExtension }
80 static FileType projectTypes[] =
82 { "ECERE Project", ProjectExtension },
83 { "ECERE Workspace", WorkspaceExtension }
86 static char * iconNames[] =
88 "<:ecere>mimeTypes/file.png", /*genFile*/
89 "<:ecere>mimeTypes/textEcereWorkspace.png", /*ewsFile*/
90 "<:ecere>mimeTypes/textEcereProject.png", /*epjFile*/
91 "<:ecere>places/folder.png", /*folder*/
92 "<:ecere>status/folderOpen.png", /*openFolder*/
93 "<:ecere>mimeTypes/textEcereSource.png", /*ecFile*/
94 "<:ecere>mimeTypes/textEcereHeader.png", /*ehFile*/
95 "<:ecere>mimeTypes/textCSource.png", /*cFile*/
96 "<:ecere>mimeTypes/textCHeader.png", /*hFile*/
97 "<:ecere>mimeTypes/textC++Source.png", /*cppFile*/
98 "<:ecere>mimeTypes/textC++Header.png", /*hppFile*/
99 "<:ecere>mimeTypes/text.png", /*textFile*/
100 "<:ecere>mimeTypes/textHyperTextMarkup.png", /*webFile*/
101 "<:ecere>mimeTypes/image.png", /*pictureFile*/
102 "<:ecere>status/audioVolumeHigh.png", /*soundFile*/
103 "<:ecere>mimeTypes/package.png", /*archiveFile*/
104 "<:ecere>mimeTypes/packageSoftware.png", /*packageFile*/
105 "<:ecere>mimeTypes/packageOpticalDisc.png" /*opticalMediaImageFile*/
108 enum PrepareMakefileMethod { normal, force, forceExists };
110 enum BuildType { build, rebuild, relink, run, debug };
112 class ProjectView : Window
115 //hasMinimize = true;
117 borderStyle = sizable;
118 hasHorzScroll = true;
119 hasVertScroll = true;
122 anchor = Anchor { left = 0, top = 0, bottom = 0 };
125 //hasMinimize = true;
126 saveDialog = projectFileDialog;
129 bool buildInProgress;
130 BitmapResource icons[NodeIcons];
133 property Workspace workspace
139 for(prj : workspace.projects)
141 DeleteNode(prj.topNode);
143 workspace.projects.Free();
144 ide.debugger.CleanUp();
149 fileDialog.currentDirectory = workspace.workspaceDir;
150 resourceFileDialog.currentDirectory = workspace.workspaceDir;
151 for(prj : workspace.projects)
152 AddNode(prj.topNode, null);
153 ide.statusBar.text = "Generating Makefile & Dependencies...";
155 for(prj : workspace.projects)
156 prj.ModifiedAllConfigs(true, false, false, false);
157 ide.statusBar.text = "Initializing Debugger"; app.UpdateDisplay();
158 ide.statusBar.text = null;
162 get { return workspace; }
165 /*property Project project
171 DeleteNode(project.topNode);
177 AddNode(project.topNode, null);
178 fileDialog.currentDirectory = project.topNode.path;
179 resourceFileDialog.currentDirectory = project.topNode.path;
181 // Make sure this is done already...
183 char filePath[MAX_LOCATION];
184 strcpy(filePath, project.topNode.path);
185 PathCat(filePath, project.topNode.name);
186 strcat(filePath, ".epj");
190 ide.statusBar.text = "Generating Makefile & Dependencies...";
192 // REDJ set makefile generation flag so generation occurs only when compiling instead of generating on the spot
193 project.config.makingModified = true;
194 ide.statusBar.text = "Initializing Debugger";
195 ide.statusBar.text = null;
199 get { return project; }
202 bool drawingInProjectSettingsDialog;
203 bool drawingInProjectSettingsDialogHeader;
204 ProjectSettings projectSettingsDialog;
208 multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
209 borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
210 anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
212 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
214 if(!active) Update(null);
215 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
218 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
224 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
226 DataRow row = listBox.currentRow;
229 ProjectNode node = (ProjectNode)row.tag;
230 if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
233 Menu popupContent { };
235 if(node.type == NodeTypes::project)
237 //if(node == ((Project)workspace.projects.first).topNode)
239 MenuItem { popupContent, "Build", b, NotifySelect = ProjectBuild }.disabled = buildInProgress;
240 MenuItem { popupContent, "Relink", l, NotifySelect = ProjectLink }.disabled = buildInProgress;
241 MenuItem { popupContent, "Rebuild", r, NotifySelect = ProjectRebuild }.disabled = buildInProgress;
242 MenuItem { popupContent, "Clean", c, NotifySelect = ProjectClean }.disabled = buildInProgress;
243 MenuItem { popupContent, "Regenerate Makefile", m, NotifySelect = ProjectRegenerate }.disabled = buildInProgress;
244 MenuDivider { popupContent };
246 MenuItem { popupContent, "New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
247 MenuItem { popupContent, "Import Folder...", f, NotifySelect = ProjectImportFolder };
248 MenuItem { popupContent, "Add Files to Project...", f, NotifySelect = ProjectAddFiles };
249 MenuDivider { popupContent };
250 MenuItem { popupContent, "Add New Form...", o, NotifySelect = ProjectAddNewForm };
251 // MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
252 MenuDivider { popupContent };
253 if(node != ((Project)workspace.projects.first).topNode)
255 MenuItem { popupContent, "Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = buildInProgress;
256 MenuDivider { popupContent };
258 MenuItem { popupContent, "Active Configuration...", s, Key { f5, alt = true } , NotifySelect = MenuConfig };
259 MenuItem { popupContent, "Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
260 MenuDivider { popupContent };
261 MenuItem { popupContent, "Browse Folder", w, NotifySelect = MenuBrowseFolder };
262 MenuDivider { popupContent };
263 MenuItem { popupContent, "Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
264 MenuDivider { popupContent };
265 MenuItem { popupContent, "Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
267 else if(node.type == resources)
269 MenuItem { popupContent, "New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
270 MenuItem { popupContent, "Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
271 MenuItem { popupContent, "Browse Folder", w, NotifySelect = MenuBrowseFolder };
272 MenuDivider { popupContent };
273 MenuItem { popupContent, "Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
274 MenuItem { popupContent, "Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
276 else if(node.type == file)
278 MenuItem { popupContent, "Open", o, NotifySelect = FileOpenFile };
279 MenuItem { popupContent, "Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildInProgress;
280 MenuDivider { popupContent };
281 MenuItem { popupContent, "Remove", r, NotifySelect = FileRemoveFile };
282 MenuDivider { popupContent };
283 MenuItem { popupContent, "Browse Folder", w, NotifySelect = MenuBrowseFolder };
284 MenuDivider { popupContent };
285 MenuItem { popupContent, "Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
286 MenuItem { popupContent, "Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
288 else if(node.type == folder)
290 bool isInResources = node.isInResources;
292 MenuItem { popupContent, "New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
293 MenuItem { popupContent, "Import Folder...", f, NotifySelect = ProjectImportFolder };
296 MenuItem { popupContent, "Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
300 MenuItem { popupContent, "Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
304 MenuDivider { popupContent };
305 MenuItem { popupContent, "Add New Form...", o, NotifySelect = ProjectAddNewForm };
306 MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
308 MenuDivider { popupContent };
309 MenuItem { popupContent, "Remove", r, NotifySelect = FileRemoveFile };
310 MenuDivider { popupContent };
311 MenuItem { popupContent, "Browse Folder", w, NotifySelect = MenuBrowseFolder };
312 MenuDivider { popupContent };
313 MenuItem { popupContent, "Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
314 MenuItem { popupContent, "Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
319 master = this, menu = popupContent;
321 x + clientStart.x + absPosition.x - app.desktop.position.x,
322 y + clientStart.y + absPosition.y - app.desktop.position.y };
330 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
334 ProjectNode node = (ProjectNode)row.tag;
337 case altEnter: case Key { keyPadEnter, alt = true }:
339 NodeProperties { parent = parent, master = this,
340 position = { position.x + 100, position.y + 100 }, node = node }.Create();
343 case enter: case keyPadEnter:
346 for(resNode = node.parent; resNode; resNode = resNode.parent)
347 if(resNode.type == resources)
349 if(node.type == project || (node.type == folder && !resNode))
354 else if(node.type == resources || node.type == folder)
363 if(node.type == project || node.type == folder || node.type == resources)
372 if(node.type == project || node.type == folder || node.type == resources)
374 NewFolder(node, null, true);
381 if(node.type == file)
383 FileCompile(null, (Modifiers)key);
388 case Key { space, shift = true }:
391 if(node.type == NodeTypes::project)
394 for(p : workspace.projects)
396 if(p.topNode == node)
402 prj.RotateActiveConfig(!key.shift);
404 ide.UpdateDisabledMenus();
413 case enter: case keyPadEnter: OpenSelectedNodes(); break;
414 case del: RemoveSelectedNodes(); break;
417 Window activeClient = ide.activeClient;
419 activeClient.Activate();
421 ide.RepositionWindows(true);
428 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
430 ProjectNode node = (ProjectNode)row.tag;
431 if(node.type == folder)
432 node.icon = collapsed ? folder : openFolder;
437 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = "Import Folder" };
438 FileDialog projectFileDialog
440 autoCreate = false, filters = projectFilters, sizeFilters = sizeof(projectFilters);
441 types = projectTypes, sizeTypes = sizeof(projectTypes);
443 FileDialog fileDialog
445 autoCreate = false, mayNotExist = true, filters = fileFilters, sizeFilters = sizeof(fileFilters);
446 types = fileTypes, sizeTypes = sizeof(fileTypes);
448 FileDialog resourceFileDialog
450 autoCreate = false, mayNotExist = true, filters = resourceFilters, sizeFilters = sizeof(resourceFilters);
451 types = fileTypes, sizeTypes = sizeof(fileTypes);
454 Menu fileMenu { menu, "File", f };
455 MenuItem { fileMenu, "Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
456 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
458 bool OnClose(bool parentClosing)
460 if(!parentClosing && visible)
472 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
473 // ide.findInFilesDialog.SearchStop();
475 ide.outputView.buildBox.Clear();
476 ide.outputView.debugBox.Clear();
477 //ide.outputView.findBox.Clear();
478 ide.callStackView.Clear();
479 ide.watchesView.Clear();
480 ide.threadsView.Clear();
481 ide.breakpointsView.Clear();
482 ide.outputView.ShowClearSelectTab(find); // why this?
485 bool OnSaveFile(char * fileName)
487 for(prj : ide.workspace.projects)
489 if(prj.topNode.modified && prj.Save(prj.filePath))
491 // ProjectUpdateMakefileForAllConfigs(prj, true, true);
492 prj.topNode.modified = false;
495 modifiedDocument = false;
500 bool IsModuleInProject(char * filePath)
502 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
503 GetLastDirectory(filePath, moduleName);
504 return project.topNode.Find(moduleName, false) != null;
507 bool GetRelativePath(char * filePath, char * relativePath)
510 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
511 GetLastDirectory(filePath, moduleName);
513 // try with workspace dir first?
514 if((node = project.topNode.Find(moduleName, false)))
516 strcpy(relativePath, node.path);
517 PathCatSlash(relativePath, node.name);
520 // WARNING: On failure, relative path is uninitialized
522 return project.GetRelativePath(filePath, relativePath);
525 ProjectNode GetNodeFromWindow(Window document, Project project)
527 if(document.fileName)
529 char winFileName[MAX_LOCATION];
530 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
531 for(p : ide.workspace.projects)
533 Project prj = project ? project : p;
535 char moduleName[MAX_FILENAME], modulePath[MAX_LOCATION];
536 GetLastDirectory(document.fileName, moduleName);
538 if((node = prj.topNode.Find(moduleName, false)))
540 strcpy(modulePath, prj.topNode.path);
541 PathCatSlash(modulePath, node.path);
542 PathCatSlash(modulePath, node.name);
543 if(!fstrcmp(documentFileName, modulePath))
554 void Compile(ProjectNode node)
556 char fileName[MAX_LOCATION];
557 char extension[MAX_EXTENSION];
559 Project prj = node.project;
560 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
561 DirExpression objDir = prj.objDir;
563 strcpy(fileName, prj.topNode.path);
564 PathCatSlash(fileName, objDir.dir);
565 PathCatSlash(fileName, node.name);
566 StripExtension(fileName);
567 strcat(fileName, ".o");
568 if(FileExists(fileName))
569 DeleteFile(fileName);
571 GetExtension(node.name, extension);
572 if(!strcmp(extension, "ec"))
574 // Delete generated C file
575 strcpy(fileName, prj.topNode.path);
576 PathCat(fileName, objDir.dir);
577 PathCat(fileName, node.name);
578 StripExtension(fileName);
579 strcat(fileName, ".c");
580 if(FileExists(fileName))
581 DeleteFile(fileName);
583 // Delete symbol file
584 strcpy(fileName, prj.topNode.path);
585 PathCat(fileName, node.path);
586 PathCat(fileName, node.name);
587 StripExtension(fileName);
588 strcat(fileName, ".sym");
589 if(FileExists(fileName))
590 DeleteFile(fileName);
593 ide.StopBuild(false);
595 // Check if we have to save
596 strcpy(fileName, prj.topNode.path);
597 PathCatSlash(fileName, node.path);
598 PathCatSlash(fileName, node.name);
599 for(document = ide.firstChild; document; document = document.next)
601 if(document.modifiedDocument)
603 char documentFileName[MAX_LOCATION];
604 if(!fstrcmp(GetSlashPathBuffer(documentFileName, document.fileName), fileName))
605 if(!document.MenuFileSave(null, 0))
610 if(ProjectPrepareForToolchain(prj, normal, true, true))
614 buildInProgress = true;
616 //ide.outputView.ShowClearSelectTab(build);
617 // this stuff doesn't even appear
618 //ide.outputView.buildBox.Logf("%s Compiler\n", compiler.name);
620 ide.outputView.buildBox.Logf("Compiling single file %s in project %s using the %s configuration...\n", node.name, prj.name, prj.config.name);
622 ide.outputView.buildBox.Logf("Compiling single file %s in project %s...\n", node.name, prj.name);
624 ide.DisableBuildItems(true, false);
626 ide.DisableBuildItems(false, false);
627 buildInProgress = false;
630 ide.outputView.buildBox.Logf("File %s is excluded from current build configuration.\n", node.name);
636 void GoToError(const char * line)
640 while(isspace(*line)) line++;
641 colon = strstr(line, ":");
646 bool lookForLineNumber = true;
648 // deal with linking error
649 if(colon && colon[1] == ' ')
651 colon = strstr(colon + 1, ":");
652 if(colon && !colon[1])
654 colon = strstr(line, ":");
655 lookForLineNumber = false;
657 else if(colon && !isdigit(colon[1]))
660 colon = strstr(line, ":");
663 // Don't be mistaken by the drive letter colon
664 if(colon && (colon[1] == '/' || colon[1] == '\\'))
665 colon = strstr(colon + 1, ":");
666 if(colon && lookForLineNumber)
670 char * par = RSearchString(line, "(", colon - line, true, false);
671 if(par && strstr(par, ")"))
673 else if((colon+1)[0] == ' ')
675 // NOTE: This is the same thing as saying 'colon = line'
676 for( ; colon != line; colon--)
680 lineNumber = atoi(colon + 1);
682 comma = strchr(colon, ',');
686 comma = strchr(colon+1, ':');
692 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
697 strncpy(moduleName, line, colon - line);
698 moduleName[colon - line] = '\0';
701 strcpy(moduleName, line);
703 // Remove stuff in brackets
705 bracket = strstr(moduleName, "(");
706 if(bracket) *bracket = '\0';
708 MakeSlashPath(moduleName);
712 // Check if it's one of our modules
713 ProjectNode node = project.topNode.Find(moduleName, false);
716 strcpy(moduleName, node.path);
717 PathCatSlash(moduleName, node.name);
720 moduleName[0] = '\0';
724 CodeEditor codeEditor;
725 strcpy(filePath, project.topNode.path);
726 PathCatSlash(filePath, moduleName);
728 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
731 char name[MAX_LOCATION];
732 // TOFIX: Improve on this, don't use only filename, make a function
733 if(ide && ide.workspace)
735 for(prj : ide.workspace.projects)
737 if(prj.topNode.FindWithPath(moduleName, false))
739 strcpy(filePath, prj.topNode.path);
740 PathCatSlash(filePath, moduleName);
741 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
748 if(codeEditor && lineNumber)
750 EditBox editBox = codeEditor.editBox;
751 editBox.GoToLineNum(lineNumber - 1);
752 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
759 bool OpenNode(ProjectNode node)
761 char filePath[MAX_LOCATION];
762 ProjectNode nodeRoot;
764 for(nodeRoot = node; nodeRoot.parent; nodeRoot = nodeRoot.parent) { }
766 strcpy(filePath, nodeRoot.path);
767 PathCat(filePath, node.path);
768 PathCat(filePath, node.name);
770 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
773 void AddNode(ProjectNode node, DataRow addTo)
775 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
780 if(node.type == resources)
783 row.SetData(null, node);
785 if(node.files && node.files.first && node.parent &&
786 !(!node.parent.parent &&
787 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
788 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
789 row.collapsed = true;
790 else if(node.type == folder)
791 node.icon = openFolder;
795 for(child : node.files)
800 void DeleteNode(ProjectNode projectNode)
802 if(projectNode.files)
805 while(child = projectNode.files.first)
808 fileList.DeleteRow(projectNode.row);
809 projectNode.Delete();
815 for(c = 0; c < NodeIcons::enumSize; c++)
817 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
818 AddResource(icons[c]);
820 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
826 ide.DestroyTemporaryProjectDir();
834 bool ProjectSave(MenuItem selection, Modifiers mods)
836 DataRow row = fileList.currentRow;
837 ProjectNode node = row ? (ProjectNode)row.tag : null;
838 Project prj = node ? node.project : null;
841 if(prj.Save(prj.filePath))
843 // ProjectUpdateMakefileForAllConfigs(prj, true, true);
844 prj.topNode.modified = false;
846 for(p : ide.workspace.projects)
848 if(p.topNode.modified)
855 modifiedDocument = false;
862 bool ShowOutputBuildLog(bool cleanLog)
864 OutputView output = ide.outputView;
866 output.ShowClearSelectTab(build);
869 output.SelectTab(build);
874 bool DisplayCompiler(bool cleanLog)
876 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
877 LogBox logBox = ide.outputView.buildBox;
878 ShowOutputBuildLog(cleanLog);
879 logBox.Logf("%s Compiler\n", compiler ? compiler.name : "{problem with compiler selection}");
883 bool ProjectUpdateMakefileForAllConfigs(Project project, bool cleanLog, bool displayCompiler)
885 ProjectConfig currentConfig = project.config;
886 ShowOutputBuildLog(cleanLog);
889 DisplayCompiler(false);
891 for(config : project.configurations)
893 project.config = config;
894 ProjectPrepareMakefile(project, forceExists, false, false);
897 project.config = currentConfig;
902 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler)
905 char message[MAX_F_STRING];
906 LogBox logBox = ide.outputView.buildBox;
908 ShowOutputBuildLog(cleanLog);
911 DisplayCompiler(false);
913 ProjectPrepareMakefile(project, method, false, false);
917 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler)
919 char makefilePath[MAX_LOCATION];
920 char makefileName[MAX_LOCATION];
922 LogBox logBox = ide.outputView.buildBox;
924 ShowOutputBuildLog(cleanLog);
927 DisplayCompiler(false);
929 strcpy(makefilePath, project.topNode.path);
930 project.CatMakeFileName(makefileName);
931 PathCatSlash(makefilePath, makefileName);
933 exists = FileExists(makefilePath);
934 if((method == normal && (!exists || project.config.makingModified/*|| project.topNode.modified*/)) ||
935 (method == forceExists && exists) ||
936 method == force) // || project.config.makingModified || makefileDirty
940 ide.statusBar.text = "Generating Makefile & Dependencies..."; // Dependencies?
943 if((method == normal && !exists) || (method == force && !exists))
944 action = "Generating ";
945 else if(method == force)
946 action = "Regenerating ";
947 else if(method == normal || method == forceExists)
948 action = "Updating ";
952 reason = "Makefile doesn't exist. ";
953 else if(project.topNode.modified)
954 reason = "Project has been modified. ";
958 //logBox.Logf("%s\n", makefileName);
959 logBox.Logf("%s - %s%smakefile for %s config...\n", makefileName, reason, action, project.configName);
960 project.GenerateMakefile(null, false, null);
962 ide.statusBar.text = null;
969 bool ProjectBuild(MenuItem selection, Modifiers mods)
971 Project prj = project;
972 if(selection || !ide.activeClient || activeClient == this)
974 DataRow row = fileList.currentRow;
975 ProjectNode node = row ? (ProjectNode)row.tag : null;
976 if(node) prj = node.project;
978 // Added this code here until dependencies work:
979 else //if(ide.activeClient)
981 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
985 if(/*prj != project || */!prj.configIsInDebugSession || !ide.DontTerminateDebugSession("Project Build"))
986 BuildInterrim(prj, build, false);
990 bool BuildInterrim(Project prj, BuildType buildType, bool disableDebugStart)
992 if(ProjectPrepareForToolchain(prj, normal, true, true))
994 ide.outputView.buildBox.Logf("Building project %s using the %s configuration...\n", prj.name, prj.configName);
995 return Build(prj, buildType, disableDebugStart);
1000 bool ProjectLink(MenuItem selection, Modifiers mods)
1002 Project prj = project;
1003 if(selection || !ide.activeClient || activeClient == this)
1005 DataRow row = fileList.currentRow;
1006 ProjectNode node = row ? (ProjectNode)row.tag : null;
1007 if(node) prj = node.project;
1009 // Added this code here until dependencies work:
1010 else //if(ide.activeClient)
1012 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
1016 if(ProjectPrepareForToolchain(prj, normal, true, true))
1018 ide.outputView.buildBox.Logf("Relinking project %s using the %s configuration...\n", prj.name, prj.configName);
1020 prj.config.linkingModified = true;
1021 Build(prj, relink, false);
1026 bool ProjectRebuild(MenuItem selection, Modifiers mods)
1028 Project prj = GetSelectedProject((bool)selection);
1029 if(ProjectPrepareForToolchain(prj, normal, true, true))
1031 ide.outputView.buildBox.Logf("Rebuilding project %s using the %s configuration...\n", prj.name, prj.configName);
1034 prj.config.compilingModified = true;
1035 prj.config.makingModified = true;
1036 }*/ // -- should this still be used depite the new solution of BuildType?
1037 Build(prj, rebuild, false);
1042 bool ProjectClean(MenuItem selection, Modifiers mods)
1044 Project prj = GetSelectedProject((bool)selection);
1045 if(ProjectPrepareForToolchain(prj, normal, true, true))
1047 ide.outputView.buildBox.Logf("Cleaning project %s using the %s configuration...\n", prj.name, prj.configName);
1049 buildInProgress = true;
1050 ide.DisableBuildItems(true, false);
1053 ide.DisableBuildItems(false, false);
1054 buildInProgress = false;
1059 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1061 Project prj = project;
1062 if(selection || !ide.activeClient || activeClient == this)
1064 DataRow row = fileList.currentRow;
1065 ProjectNode node = row ? (ProjectNode)row.tag : null;
1069 // Added this code here until dependencies work:
1070 else //if(ide.activeClient)
1072 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
1077 ProjectPrepareMakefile(prj, force, true, true);
1081 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1083 DataRow row = fileList.currentRow;
1086 ProjectNode parentNode = (ProjectNode)row.tag;
1087 NewFolder(parentNode, null, true);
1092 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1098 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1104 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1106 DataRow row = fileList.currentRow;
1109 ProjectNode toNode = (ProjectNode)row.tag;
1110 ImportFolder(toNode);
1115 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1117 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1118 codeEditor.EnsureUpToDate();
1122 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1124 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1126 codeEditor.EnsureUpToDate();
1130 bool ProjectRemove(MenuItem selection, Modifiers mods)
1132 DataRow row = fileList.currentRow;
1135 ProjectNode node = (ProjectNode)row.tag;
1136 if(node.type == project)
1137 RemoveSelectedNodes();
1142 bool MenuConfig(MenuItem selection, Modifiers mods)
1144 if(ProjectActiveConfig { parent = parent.parent, master = parent, project = project }.Modal() == ok)
1145 ide.UpdateDisabledMenus();
1149 bool MenuCompiler(MenuItem selection, Modifiers mods)
1151 ActiveCompilerDialog compilerDialog
1153 parent = parent.parent, master = parent;
1154 ideSettings = ideSettings, workspaceActiveCompiler = ide.workspace.compiler;
1156 incref compilerDialog;
1157 if(compilerDialog.Modal() == ok && strcmp(compilerDialog.workspaceActiveCompiler, ide.workspace.compiler))
1159 ide.workspace.compiler = compilerDialog.workspaceActiveCompiler;
1160 for(prj : ide.workspace.projects)
1161 ide.projectView.ProjectUpdateMakefileForAllConfigs(prj, true, true);
1163 delete compilerDialog;
1167 bool MenuSettings(MenuItem selection, Modifiers mods)
1169 ProjectNode node = GetSelectedNode(true);
1170 Project prj = node ? node.project : project;
1171 projectSettingsDialog = ProjectSettings { parent = parent.parent, master = parent, project = prj, projectNode = node };
1172 projectSettingsDialog.Modal();
1175 ide.UpdateDisabledMenus();
1179 bool FileProperties(MenuItem selection, Modifiers mods)
1181 DataRow row = fileList.currentRow;
1184 ProjectNode node = (ProjectNode)row.tag;
1185 NodeProperties { parent = parent, master = this, node = node,
1186 position = { position.x + 100, position.y + 100 } }.Create();
1191 bool FileOpenFile(MenuItem selection, Modifiers mods)
1193 OpenSelectedNodes();
1197 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1199 RemoveSelectedNodes();
1203 bool FileCompile(MenuItem selection, Modifiers mods)
1205 DataRow row = fileList.currentRow;
1208 ProjectNode node = (ProjectNode)row.tag;
1214 /*bool IsProjectModified()
1218 for(document = master.firstChild; document; document = document.next)
1220 if(document.modifiedDocument)
1221 if(GetNodeFromWindow(document), project)
1228 bool Build(Project prj, BuildType buildType, bool disableDebugStart)
1233 ide.StopBuild(false);
1234 for(document = master.firstChild; document; document = document.next)
1236 if(document.modifiedDocument)
1238 ProjectNode node = GetNodeFromWindow(document, prj);
1239 if(node && !document.MenuFileSave(null, 0))
1248 DirExpression targetDir = prj.targetDir;
1250 if(buildType != run/* && prj == project*/ && prj.configIsInDebugSession)
1253 // TODO: Disabled until problems fixed... is it fixed?
1254 if(buildType == rebuild || (prj.config && prj.config.compilingModified))
1258 if(buildType == relink || (prj.config && prj.config.linkingModified))
1260 char target[MAX_LOCATION];
1262 strcpy(target, prj.topNode.path);
1263 PathCat(target, targetDir.dir);
1264 prj.CatTargetFileName(target);
1265 if(FileExists(target))
1268 if(prj.config && prj.config.symbolGenModified)
1270 DirExpression objDir = prj.objDir;
1271 char fileName[MAX_LOCATION];
1272 char moduleName[MAX_FILENAME];
1273 strcpy(fileName, prj.topNode.path);
1274 PathCatSlash(fileName, objDir.dir);
1275 strcpy(moduleName, prj.moduleName);
1276 strcat(moduleName, ".main.ec");
1277 PathCatSlash(fileName, moduleName);
1278 if(FileExists(fileName))
1279 DeleteFile(fileName);
1280 ChangeExtension(fileName, "c", fileName);
1281 if(FileExists(fileName))
1282 DeleteFile(fileName);
1283 ChangeExtension(fileName, "o", fileName);
1284 if(FileExists(fileName))
1285 DeleteFile(fileName);
1290 buildInProgress = true;
1291 //if(prj == project) // Why did we put these here? There was nothing to prevent building an added project multiple times at once
1292 ide.DisableBuildItems(true, true);
1294 result = prj.Build(buildType == run, null);
1298 prj.config.compilingModified = false;
1299 if(!ide.ShouldStopBuild())
1300 prj.config.linkingModified = false;
1302 prj.config.symbolGenModified = false;
1304 //if(prj == project)
1305 ide.DisableBuildItems(false, disableDebugStart);
1306 buildInProgress = false;
1308 ide.workspace.modified = true;
1315 Project GetSelectedProject(bool useSelection)
1317 Project prj = project;
1320 DataRow row = fileList.currentRow;
1321 ProjectNode node = row ? (ProjectNode)row.tag : null;
1328 ProjectNode GetSelectedNode(bool useSelection)
1330 ProjectNode node = null;
1333 DataRow row = fileList.currentRow;
1335 node = (ProjectNode)row.tag;
1340 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1342 char folder[MAX_LOCATION];
1344 ProjectNode node = GetSelectedNode(true);
1346 node = project.topNode;
1349 strcpy(folder, prj.topNode.path);
1350 if(node != prj.topNode)
1351 PathCatSlash(folder, node.path);
1355 bool Run(MenuItem selection, Modifiers mods)
1357 char args[MAX_LOCATION * 64];
1359 if(ide.workspace.commandLineArgs)
1360 //ide.debugger.GetCommandLineArgs(args);
1361 strcpy(args, ide.workspace.commandLineArgs);
1362 if(ide.debugger.isInDebugMode)
1364 /*else if(project.config.targetType == sharedLibrary || project.config.targetType == staticLibrary)
1365 MessageBox { type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1366 else if(BuildInterrim(project, run, false))
1373 bool result = false;
1374 if(project.targetType == sharedLibrary || project.targetType == staticLibrary)
1375 MessageBox { type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();
1376 else if(project.compress)
1377 MessageBox { text = "Starting Debug", contents = "Debugging compressed applications is not supported\n" }.Modal();
1378 else if(project.debug ||
1379 MessageBox { type = okCancel, text = "Starting Debug", contents = "Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1381 if(/*!IsProjectModified() ||*/ BuildInterrim(project, debug, true))
1383 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1384 if(compiler.type.isVC)
1386 //bool result = false;
1387 char oldwd[MAX_LOCATION];
1388 char oldPath[MAX_LOCATION * 65];
1389 char command[MAX_LOCATION];
1391 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1392 ide.SetPath(false); //true
1394 GetWorkingDir(oldwd, sizeof(oldwd));
1395 ChangeWorkingDir(project.topNode.path);
1397 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, project.config.name, "Debug.Start");
1398 //ide.outputView.buildBox.Logf("command: %s\n", command);
1400 ChangeWorkingDir(oldwd);
1401 SetEnvironment("PATH", oldPath);
1405 ide.debugger.Start();
1417 if(/*!IsProjectModified() ||*/ BuildInterrim(project, debug, true))
1419 ide.debugger.Restart();
1427 ide.debugger.Resume();
1433 ide.debugger.Break();
1439 ide.debugger.Stop();
1443 bool DebugStepInto()
1445 if((ide.debugger.isInDebugMode) || (!buildInProgress && BuildInterrim(project, debug, true)))
1446 ide.debugger.StepInto();
1450 bool DebugStepOver(bool skip)
1452 if((ide.debugger.isInDebugMode) || (!buildInProgress && BuildInterrim(project, debug, true)))
1453 ide.debugger.StepOver(skip);
1457 bool DebugStepOut(bool skip)
1459 ide.debugger.StepOut(skip);
1463 void ImportFolder(ProjectNode toNode)
1467 //bool isFolder = toNode.type == folder;
1468 //bool isRes = toNode.isInResources;
1470 FileDialog fileDialog = importFileDialog;
1471 fileDialog.parent = parent;
1472 if(fileDialog.Modal() == ok)
1474 ImportFolderFSI fsi { projectView = this };
1475 fsi.stack.Add(toNode);
1476 fsi.Iterate(fileDialog.filePath);
1482 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1486 ProjectNode folderNode;
1487 Project prj = parentNode.project;
1489 ProjectNode after = null;
1490 for(node : parentNode.files)
1492 if(node.type != folder)
1498 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1501 for(c = 0; c < 100; c++)
1504 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1505 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1512 NodeProperties nodeProperties;
1513 modifiedDocument = true;
1514 prj.topNode.modified = true;
1516 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1517 folderNode.row.tag = (int)folderNode;
1519 folderNode.row.SetData(null, folderNode);
1520 fileList.currentRow = folderNode.row;
1524 nodeProperties = NodeProperties
1526 parent = parent, master = this, position = { position.x + 100, position.y + 100 };
1527 node = folderNode, text = "New Folder";
1529 nodeProperties.Create(); // Modal?
1537 void AddFiles(bool resources)
1539 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1540 fileDialog.type = multiOpen;
1541 fileDialog.text = !resources ? "Add Files to Project" : "Add Resources to Project";
1542 fileDialog.parent = parent;
1543 if(fileDialog.Modal() == ok)
1546 DataRow row = fileList.currentRow;
1547 ProjectNode parentNode = (ProjectNode)row.tag;
1548 bool addFailed = false;
1549 int numSelections = fileDialog.numSelections;
1550 char ** multiFilePaths = fileDialog.multiFilePaths;
1552 Array<String> nameConflictFiles { };
1554 for(c = 0; c < numSelections; c++)
1556 char * filePath = multiFilePaths[c];
1557 FileAttribs exists = FileExists(filePath);
1558 bool addThisFile = true;
1560 if(exists.isDirectory)
1561 addThisFile = false;
1564 if(MessageBox { type = yesNo, parent = parent, master = this, text = filePath,
1565 contents = "File doesn't exist. Create?" }.Modal() == yes)
1567 File f = FileOpen(filePath, write);
1575 MessageBox { type = ok, parent = parent, master = this, text = filePath,
1576 contents = "Couldn't create file."}.Modal();
1577 addThisFile = false;
1584 /*addFailed = */if(!AddFile(parentNode, filePath, resources))//;
1586 nameConflictFiles.Add(CopyString(filePath));
1594 char * part1 = "The following file";
1595 char * opt1 = " was ";
1596 char * opt2 = "s were ";
1597 char * part2 = "not added because of identical file name conflict within the project.\n\n";
1599 len += strlen(part1);
1600 len += strlen(part2);
1601 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1602 for(s : nameConflictFiles)
1603 len += strlen(s) + 1;
1604 message = new char[len + 1];
1605 strcpy(message, part1);
1606 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1607 strcat(message, part2);
1608 for(s : nameConflictFiles)
1611 strcat(message, "\n");
1613 MessageBox { type = ok, parent = parent, master = this, text = "Name Conflict",
1614 contents = message }.Modal();
1617 nameConflictFiles.Free();
1618 delete nameConflictFiles;
1622 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources)
1624 ProjectNode result = null;
1625 ProjectNode after = null;
1626 for(node : parentNode.files)
1628 if(node.type != folder && node.type != file && node.type)
1633 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
1637 modifiedDocument = true;
1638 parentNode.project.topNode.modified = true;
1640 project.ModifiedAllConfigs(true, false, true, true);
1641 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
1642 result.row.tag = (int)result;
1643 result.row.SetData(null, result);
1648 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
1650 CodeEditor codeEditor = null;
1651 ProjectNode projectNode;
1652 ProjectNode after = null;
1653 DataRow row = fileList.currentRow;
1654 ProjectNode parentNode;
1657 if(!row) row = project.topNode.row;
1659 parentNode = (ProjectNode)row.tag;
1661 for(node : parentNode.files)
1663 if(node.type != folder && node.type != file && node.type)
1667 for(c = 1; c < 100; c++)
1670 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
1671 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
1677 char filePath[MAX_LOCATION];
1679 modifiedDocument = true;
1680 project.topNode.modified = true;
1682 project.ModifiedAllConfigs(true, false, false, true);
1683 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1684 projectNode.row.tag =(int)projectNode;
1686 projectNode.row.SetData(null, projectNode);
1687 fileList.currentRow = projectNode.row;
1689 strcpy(filePath, project.topNode.path);
1690 PathCat(filePath, projectNode.path);
1691 PathCat(filePath, projectNode.name);
1693 codeEditor = (CodeEditor)ide.FindWindow(filePath);
1696 Class baseClass = eSystem_FindClass(__thisModule, base);
1697 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
1700 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1701 strcpy(name, projectNode.name);
1702 sprintf(name, "%s%d", upper, c);
1704 strcpy(className, name);
1706 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
1708 //codeEditor.modifiedDocument = false;
1709 //codeEditor.designer.modifiedDocument = false;
1711 //Code_EnsureUpToDate(codeEditor);
1714 else // TODO: fix no symbols generated when ommiting {} for following else
1716 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1720 codeEditor.ViewDesigner();
1721 codeEditor.codeModified = true;
1728 void OpenSelectedNodes()
1733 fileList.GetMultiSelection(selection);
1734 for(item = selection.first; item; item = item.next)
1736 DataRow row = item.data;
1737 ProjectNode node = (ProjectNode)row.tag;
1738 if(node.type == file)
1741 selection.Free(null);
1744 void RemoveSelectedNodes()
1749 fileList.GetMultiSelection(selection);
1751 // Remove children of parents we're deleting
1752 for(item = selection.first; item; item = next)
1755 DataRow row = item.data;
1756 ProjectNode n, node = (ProjectNode)row.tag;
1757 bool remove = false;
1760 for(i = selection.first; i && !remove; i = i.next)
1762 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
1763 for(n = node.parent; n; n = n.parent)
1773 selection.Delete(item);
1776 for(item = selection.first; item; item = item.next)
1778 DataRow row = item.data;
1779 ProjectNode node = (ProjectNode)row.tag;
1780 ProjectNode resNode;
1781 for(resNode = node.parent; resNode; resNode = resNode.parent)
1782 if(resNode.type == resources)
1784 if(node.type == file)
1786 Project prj = node.project;
1788 modifiedDocument = true;
1789 prj.topNode.modified = true;
1791 prj.ModifiedAllConfigs(true, false, true, true);
1793 else if(node.type == folder)
1796 sprintf(message, "Are you sure you want to remove the folder \"%s\"\n"
1797 "and all of its contents from the project?", node.name);
1798 if(MessageBox { type = yesNo, parent = parent, master = null,
1799 text = "Delete Folder", contents = message }.Modal() == yes)
1801 Project prj = node.project;
1803 modifiedDocument = true;
1804 prj.topNode.modified = true;
1805 //project.ModifiedAllConfigs(true, false, true, true);
1808 else if(node.type == project && node != project.topNode && !buildInProgress)
1812 for(p : workspace.projects)
1814 if(p.topNode == node)
1820 sprintf(message, "Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
1821 if(MessageBox { type = yesNo, parent = parent, master = null,
1822 text = "Remove Project", contents = message }.Modal() == yes)
1827 workspace.RemoveProject(prj);
1828 //modifiedDocument = true; // when project view is a workspace view
1832 selection.Free(null);