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)
639 char * parenthesisOpen;
640 char * parenthesisClose;
642 while(isspace(*line)) line++;
643 colon = strstr(line, ":");
644 parenthesisOpen = strstr(line, "(");
647 parenthesisClose = strstr(parenthesisOpen, ")");
648 if(parenthesisOpen && parenthesisClose)
650 int len = parenthesisOpen - line;
651 char * errorFilePath = new char[len+1];
652 int lineNumber = atoi(parenthesisOpen+1);
653 char filePath[MAX_LOCATION];
654 strncpy(errorFilePath, line, len);
655 errorFilePath[len] = '\0';
656 GetWorkingDir(filePath, sizeof(filePath));
657 strcpy(filePath, project.topNode.path);
658 MakeSlashPath(errorFilePath);
659 PathCatSlash(filePath, errorFilePath);
660 if(FileExists(filePath).isFile)
662 CodeEditor codeEditor;
663 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
665 PrintLn("Could not open ", filePath, " file."); // might want to add added project support here
666 if(codeEditor && lineNumber)
668 EditBox editBox = codeEditor.editBox;
669 editBox.GoToLineNum(lineNumber - 1);
670 //editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
673 delete errorFilePath;
681 bool lookForLineNumber = true;
683 // deal with linking error
684 if(colon && colon[1] == ' ')
686 colon = strstr(colon + 1, ":");
687 if(colon && !colon[1])
689 colon = strstr(line, ":");
690 lookForLineNumber = false;
692 else if(colon && !isdigit(colon[1]))
695 colon = strstr(line, ":");
698 // Don't be mistaken by the drive letter colon
699 if(colon && (colon[1] == '/' || colon[1] == '\\'))
700 colon = strstr(colon + 1, ":");
701 if(colon && lookForLineNumber)
704 if((colon+1)[0] == ' ')
706 // NOTE: This is the same thing as saying 'colon = line'
707 for( ; colon != line; colon--)
711 lineNumber = atoi(colon + 1);
713 comma = strchr(colon, ',');
717 comma = strchr(colon+1, ':');
723 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
728 strncpy(moduleName, line, colon - line);
729 moduleName[colon - line] = '\0';
732 strcpy(moduleName, line);
734 // Remove stuff in brackets
736 bracket = strstr(moduleName, "(");
737 if(bracket) *bracket = '\0';
739 MakeSlashPath(moduleName);
743 // Check if it's one of our modules
744 ProjectNode node = project.topNode.Find(moduleName, false);
747 strcpy(moduleName, node.path);
748 PathCatSlash(moduleName, node.name);
751 moduleName[0] = '\0';
755 CodeEditor codeEditor;
756 strcpy(filePath, project.topNode.path);
757 PathCatSlash(filePath, moduleName);
759 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
762 char name[MAX_LOCATION];
763 // TOFIX: Improve on this, don't use only filename, make a function
764 if(ide && ide.workspace)
766 for(prj : ide.workspace.projects)
768 if(prj.topNode.FindWithPath(moduleName, false))
770 strcpy(filePath, prj.topNode.path);
771 PathCatSlash(filePath, moduleName);
772 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
779 if(codeEditor && lineNumber)
781 EditBox editBox = codeEditor.editBox;
782 editBox.GoToLineNum(lineNumber - 1);
783 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
790 bool OpenNode(ProjectNode node)
792 char filePath[MAX_LOCATION];
793 ProjectNode nodeRoot;
795 for(nodeRoot = node; nodeRoot.parent; nodeRoot = nodeRoot.parent) { }
797 strcpy(filePath, nodeRoot.path);
798 PathCat(filePath, node.path);
799 PathCat(filePath, node.name);
801 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
804 void AddNode(ProjectNode node, DataRow addTo)
806 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
811 if(node.type == resources)
814 row.SetData(null, node);
816 if(node.files && node.files.first && node.parent &&
817 !(!node.parent.parent &&
818 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
819 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
820 row.collapsed = true;
821 else if(node.type == folder)
822 node.icon = openFolder;
826 for(child : node.files)
831 void DeleteNode(ProjectNode projectNode)
833 if(projectNode.files)
836 while(child = projectNode.files.first)
839 fileList.DeleteRow(projectNode.row);
840 projectNode.Delete();
846 for(c = 0; c < NodeIcons::enumSize; c++)
848 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
849 AddResource(icons[c]);
851 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
857 ide.DestroyTemporaryProjectDir();
865 bool ProjectSave(MenuItem selection, Modifiers mods)
867 DataRow row = fileList.currentRow;
868 ProjectNode node = row ? (ProjectNode)row.tag : null;
869 Project prj = node ? node.project : null;
872 if(prj.Save(prj.filePath))
874 // ProjectUpdateMakefileForAllConfigs(prj, true, true);
875 prj.topNode.modified = false;
877 for(p : ide.workspace.projects)
879 if(p.topNode.modified)
886 modifiedDocument = false;
893 bool ShowOutputBuildLog(bool cleanLog)
895 OutputView output = ide.outputView;
897 output.ShowClearSelectTab(build);
900 output.SelectTab(build);
905 bool DisplayCompiler(bool cleanLog)
907 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
908 LogBox logBox = ide.outputView.buildBox;
909 ShowOutputBuildLog(cleanLog);
910 logBox.Logf("%s Compiler\n", compiler ? compiler.name : "{problem with compiler selection}");
914 bool ProjectUpdateMakefileForAllConfigs(Project project, bool cleanLog, bool displayCompiler)
916 ProjectConfig currentConfig = project.config;
917 ShowOutputBuildLog(cleanLog);
920 DisplayCompiler(false);
922 for(config : project.configurations)
924 project.config = config;
925 ProjectPrepareMakefile(project, forceExists, false, false);
928 project.config = currentConfig;
933 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler)
936 char message[MAX_F_STRING];
937 LogBox logBox = ide.outputView.buildBox;
939 ShowOutputBuildLog(cleanLog);
942 DisplayCompiler(false);
944 ProjectPrepareMakefile(project, method, false, false);
948 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler)
950 char makefilePath[MAX_LOCATION];
951 char makefileName[MAX_LOCATION];
953 LogBox logBox = ide.outputView.buildBox;
955 ShowOutputBuildLog(cleanLog);
958 DisplayCompiler(false);
960 strcpy(makefilePath, project.topNode.path);
961 project.CatMakeFileName(makefileName);
962 PathCatSlash(makefilePath, makefileName);
964 exists = FileExists(makefilePath);
965 if((method == normal && (!exists || project.config.makingModified/*|| project.topNode.modified*/)) ||
966 (method == forceExists && exists) ||
967 method == force) // || project.config.makingModified || makefileDirty
971 ide.statusBar.text = "Generating Makefile & Dependencies..."; // Dependencies?
974 if((method == normal && !exists) || (method == force && !exists))
975 action = "Generating ";
976 else if(method == force)
977 action = "Regenerating ";
978 else if(method == normal || method == forceExists)
979 action = "Updating ";
983 reason = "Makefile doesn't exist. ";
984 else if(project.topNode.modified)
985 reason = "Project has been modified. ";
989 //logBox.Logf("%s\n", makefileName);
990 logBox.Logf("%s - %s%smakefile for %s config...\n", makefileName, reason, action, project.configName);
991 project.GenerateMakefile(null, false, null);
993 ide.statusBar.text = null;
1000 bool ProjectBuild(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(prj != project || !ide.DontTerminateDebugSession("Project Build"))
1017 BuildInterrim(prj, build, false);
1021 bool BuildInterrim(Project prj, BuildType buildType, bool disableDebugStart)
1023 if(ProjectPrepareForToolchain(prj, normal, true, true))
1025 ide.outputView.buildBox.Logf("Building project %s using the %s configuration...\n", prj.name, prj.configName);
1026 return Build(prj, buildType, disableDebugStart);
1031 bool ProjectLink(MenuItem selection, Modifiers mods)
1033 Project prj = project;
1034 if(selection || !ide.activeClient || activeClient == this)
1036 DataRow row = fileList.currentRow;
1037 ProjectNode node = row ? (ProjectNode)row.tag : null;
1038 if(node) prj = node.project;
1040 // Added this code here until dependencies work:
1041 else //if(ide.activeClient)
1043 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
1047 if(ProjectPrepareForToolchain(prj, normal, true, true))
1049 ide.outputView.buildBox.Logf("Relinking project %s using the %s configuration...\n", prj.name, prj.configName);
1051 prj.config.linkingModified = true;
1052 Build(prj, relink, false);
1057 bool ProjectRebuild(MenuItem selection, Modifiers mods)
1059 Project prj = GetSelectedProject((bool)selection);
1060 if(ProjectPrepareForToolchain(prj, normal, true, true))
1062 ide.outputView.buildBox.Logf("Rebuilding project %s using the %s configuration...\n", prj.name, prj.configName);
1065 prj.config.compilingModified = true;
1066 prj.config.makingModified = true;
1067 }*/ // -- should this still be used depite the new solution of BuildType?
1068 Build(prj, rebuild, false);
1073 bool ProjectClean(MenuItem selection, Modifiers mods)
1075 Project prj = GetSelectedProject((bool)selection);
1076 if(ProjectPrepareForToolchain(prj, normal, true, true))
1078 ide.outputView.buildBox.Logf("Cleaning project %s using the %s configuration...\n", prj.name, prj.configName);
1080 buildInProgress = true;
1081 ide.DisableBuildItems(true, false);
1084 ide.DisableBuildItems(false, false);
1085 buildInProgress = false;
1090 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1092 Project prj = project;
1093 if(selection || !ide.activeClient || activeClient == this)
1095 DataRow row = fileList.currentRow;
1096 ProjectNode node = row ? (ProjectNode)row.tag : null;
1100 // Added this code here until dependencies work:
1101 else //if(ide.activeClient)
1103 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
1108 ProjectPrepareMakefile(prj, force, true, true);
1112 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1114 DataRow row = fileList.currentRow;
1117 ProjectNode parentNode = (ProjectNode)row.tag;
1118 NewFolder(parentNode, null, true);
1123 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1129 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1135 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1137 DataRow row = fileList.currentRow;
1140 ProjectNode toNode = (ProjectNode)row.tag;
1141 ImportFolder(toNode);
1146 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1148 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1149 codeEditor.EnsureUpToDate();
1153 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1155 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1157 codeEditor.EnsureUpToDate();
1161 bool ProjectRemove(MenuItem selection, Modifiers mods)
1163 DataRow row = fileList.currentRow;
1166 ProjectNode node = (ProjectNode)row.tag;
1167 if(node.type == project)
1168 RemoveSelectedNodes();
1173 bool MenuConfig(MenuItem selection, Modifiers mods)
1175 if(ProjectActiveConfig { parent = parent.parent, master = parent, project = project }.Modal() == ok)
1176 ide.UpdateDisabledMenus();
1180 bool MenuCompiler(MenuItem selection, Modifiers mods)
1182 ActiveCompilerDialog compilerDialog
1184 parent = parent.parent, master = parent;
1185 ideSettings = ideSettings, workspaceActiveCompiler = ide.workspace.compiler;
1187 incref compilerDialog;
1188 if(compilerDialog.Modal() == ok && strcmp(compilerDialog.workspaceActiveCompiler, ide.workspace.compiler))
1190 ide.workspace.compiler = compilerDialog.workspaceActiveCompiler;
1191 for(prj : ide.workspace.projects)
1192 ide.projectView.ProjectUpdateMakefileForAllConfigs(prj, true, true);
1194 delete compilerDialog;
1198 bool MenuSettings(MenuItem selection, Modifiers mods)
1200 ProjectNode node = GetSelectedNode(true);
1201 Project prj = node ? node.project : project;
1202 projectSettingsDialog = ProjectSettings { parent = parent.parent, master = parent, project = prj, projectNode = node };
1203 projectSettingsDialog.Modal();
1206 ide.UpdateDisabledMenus();
1210 bool FileProperties(MenuItem selection, Modifiers mods)
1212 DataRow row = fileList.currentRow;
1215 ProjectNode node = (ProjectNode)row.tag;
1216 NodeProperties { parent = parent, master = this, node = node,
1217 position = { position.x + 100, position.y + 100 } }.Create();
1222 bool FileOpenFile(MenuItem selection, Modifiers mods)
1224 OpenSelectedNodes();
1228 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1230 RemoveSelectedNodes();
1234 bool FileCompile(MenuItem selection, Modifiers mods)
1236 DataRow row = fileList.currentRow;
1239 ProjectNode node = (ProjectNode)row.tag;
1245 /*bool IsProjectModified()
1249 for(document = master.firstChild; document; document = document.next)
1251 if(document.modifiedDocument)
1252 if(GetNodeFromWindow(document), project)
1259 bool Build(Project prj, BuildType buildType, bool disableDebugStart)
1264 ide.StopBuild(false);
1265 for(document = master.firstChild; document; document = document.next)
1267 if(document.modifiedDocument)
1269 ProjectNode node = GetNodeFromWindow(document, prj);
1270 if(node && !document.MenuFileSave(null, 0))
1279 DirExpression targetDir = prj.targetDir;
1281 if(buildType != run && prj == project)
1282 ide.debugger.Stop();
1284 // TODO: Disabled until problems fixed... is it fixed?
1285 if(buildType == rebuild || (prj.config && prj.config.compilingModified))
1289 if(buildType == relink || (prj.config && prj.config.linkingModified))
1291 char target[MAX_LOCATION];
1293 strcpy(target, prj.topNode.path);
1294 PathCat(target, targetDir.dir);
1295 prj.CatTargetFileName(target);
1296 if(FileExists(target))
1299 if(prj.config && prj.config.symbolGenModified)
1301 DirExpression objDir = prj.objDir;
1302 char fileName[MAX_LOCATION];
1303 char moduleName[MAX_FILENAME];
1304 strcpy(fileName, prj.topNode.path);
1305 PathCatSlash(fileName, objDir.dir);
1306 strcpy(moduleName, prj.moduleName);
1307 strcat(moduleName, ".main.ec");
1308 PathCatSlash(fileName, moduleName);
1309 if(FileExists(fileName))
1310 DeleteFile(fileName);
1311 ChangeExtension(fileName, "c", fileName);
1312 if(FileExists(fileName))
1313 DeleteFile(fileName);
1314 ChangeExtension(fileName, "o", fileName);
1315 if(FileExists(fileName))
1316 DeleteFile(fileName);
1321 buildInProgress = true;
1322 //if(prj == project) // Why did we put these here? There was nothing to prevent building an added project multiple times at once
1323 ide.DisableBuildItems(true, true);
1325 result = prj.Build(buildType == run, null);
1329 prj.config.compilingModified = false;
1330 if(!ide.ShouldStopBuild())
1331 prj.config.linkingModified = false;
1333 prj.config.symbolGenModified = false;
1335 //if(prj == project)
1336 ide.DisableBuildItems(false, disableDebugStart);
1337 buildInProgress = false;
1339 ide.workspace.modified = true;
1346 Project GetSelectedProject(bool useSelection)
1348 Project prj = project;
1351 DataRow row = fileList.currentRow;
1352 ProjectNode node = row ? (ProjectNode)row.tag : null;
1359 ProjectNode GetSelectedNode(bool useSelection)
1361 ProjectNode node = null;
1364 DataRow row = fileList.currentRow;
1366 node = (ProjectNode)row.tag;
1371 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1373 char folder[MAX_LOCATION];
1375 ProjectNode node = GetSelectedNode(true);
1377 node = project.topNode;
1380 strcpy(folder, prj.topNode.path);
1381 if(node != prj.topNode)
1382 PathCatSlash(folder, node.path);
1386 bool Run(MenuItem selection, Modifiers mods)
1388 char args[MAX_LOCATION * 64];
1390 if(ide.workspace.commandLineArgs)
1391 //ide.debugger.GetCommandLineArgs(args);
1392 strcpy(args, ide.workspace.commandLineArgs);
1393 if(ide.debugger.isInDebugMode)
1395 /*else if(project.config.targetType == sharedLibrary || project.config.targetType == staticLibrary)
1396 MessageBox { type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1397 else if(BuildInterrim(project, run, false))
1404 bool result = false;
1405 if(project.targetType == sharedLibrary || project.targetType == staticLibrary)
1406 MessageBox { type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();
1407 else if(project.compress)
1408 MessageBox { text = "Starting Debug", contents = "Debugging compressed applications is not supported\n" }.Modal();
1409 else if(project.debug ||
1410 MessageBox { type = okCancel, text = "Starting Debug", contents = "Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1412 if(/*!IsProjectModified() ||*/ BuildInterrim(project, debug, true))
1414 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1415 if(compiler.type.isVC)
1417 //bool result = false;
1418 char oldwd[MAX_LOCATION];
1419 char oldPath[MAX_LOCATION * 65];
1420 char command[MAX_LOCATION];
1422 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1423 ide.SetPath(false); //true
1425 GetWorkingDir(oldwd, sizeof(oldwd));
1426 ChangeWorkingDir(project.topNode.path);
1428 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, project.config.name, "Debug.Start");
1429 //ide.outputView.buildBox.Logf("command: %s\n", command);
1431 ChangeWorkingDir(oldwd);
1432 SetEnvironment("PATH", oldPath);
1436 ide.debugger.Start();
1448 if(/*!IsProjectModified() ||*/ BuildInterrim(project, debug, true))
1450 ide.debugger.Restart();
1458 ide.debugger.Resume();
1464 ide.debugger.Break();
1470 ide.debugger.Stop();
1474 bool DebugStepInto()
1476 if((ide.debugger.isInDebugMode) || (!buildInProgress && BuildInterrim(project, debug, true)))
1477 ide.debugger.StepInto();
1481 bool DebugStepOver(bool skip)
1483 if((ide.debugger.isInDebugMode) || (!buildInProgress && BuildInterrim(project, debug, true)))
1484 ide.debugger.StepOver(skip);
1488 bool DebugStepOut(bool skip)
1490 ide.debugger.StepOut(skip);
1494 void ImportFolder(ProjectNode toNode)
1498 //bool isFolder = toNode.type == folder;
1499 //bool isRes = toNode.isInResources;
1501 FileDialog fileDialog = importFileDialog;
1502 fileDialog.parent = parent;
1503 if(fileDialog.Modal() == ok)
1505 ImportFolderFSI fsi { projectView = this };
1506 fsi.stack.Add(toNode);
1507 fsi.Iterate(fileDialog.filePath);
1513 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1517 ProjectNode folderNode;
1518 Project prj = parentNode.project;
1520 ProjectNode after = null;
1521 for(node : parentNode.files)
1523 if(node.type != folder)
1529 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1532 for(c = 0; c < 100; c++)
1535 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1536 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1543 NodeProperties nodeProperties;
1544 modifiedDocument = true;
1545 prj.topNode.modified = true;
1547 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1548 folderNode.row.tag = (int)folderNode;
1550 folderNode.row.SetData(null, folderNode);
1551 fileList.currentRow = folderNode.row;
1555 nodeProperties = NodeProperties
1557 parent = parent, master = this, position = { position.x + 100, position.y + 100 };
1558 node = folderNode, text = "New Folder";
1560 nodeProperties.Create(); // Modal?
1568 void AddFiles(bool resources)
1570 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1571 fileDialog.type = multiOpen;
1572 fileDialog.text = !resources ? "Add Files to Project" : "Add Resources to Project";
1573 fileDialog.parent = parent;
1574 if(fileDialog.Modal() == ok)
1577 DataRow row = fileList.currentRow;
1578 ProjectNode parentNode = (ProjectNode)row.tag;
1579 bool addFailed = false;
1580 int numSelections = fileDialog.numSelections;
1581 char ** multiFilePaths = fileDialog.multiFilePaths;
1583 Array<String> nameConflictFiles { };
1585 for(c = 0; c < numSelections; c++)
1587 char * filePath = multiFilePaths[c];
1588 FileAttribs exists = FileExists(filePath);
1589 bool addThisFile = true;
1591 if(exists.isDirectory)
1592 addThisFile = false;
1595 if(MessageBox { type = yesNo, parent = parent, master = this, text = filePath,
1596 contents = "File doesn't exist. Create?" }.Modal() == yes)
1598 File f = FileOpen(filePath, write);
1606 MessageBox { type = ok, parent = parent, master = this, text = filePath,
1607 contents = "Couldn't create file."}.Modal();
1608 addThisFile = false;
1615 /*addFailed = */if(!AddFile(parentNode, filePath, resources))//;
1617 nameConflictFiles.Add(CopyString(filePath));
1625 char * part1 = "The following file";
1626 char * opt1 = " was ";
1627 char * opt2 = "s were ";
1628 char * part2 = "not added because of identical file name conflict within the project.\n\n";
1630 len += strlen(part1);
1631 len += strlen(part2);
1632 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1633 for(s : nameConflictFiles)
1634 len += strlen(s) + 1;
1635 message = new char[len + 1];
1636 strcpy(message, part1);
1637 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1638 strcat(message, part2);
1639 for(s : nameConflictFiles)
1642 strcat(message, "\n");
1644 MessageBox { type = ok, parent = parent, master = this, text = "Name Conflict",
1645 contents = message }.Modal();
1648 nameConflictFiles.Free();
1649 delete nameConflictFiles;
1653 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources)
1655 ProjectNode result = null;
1656 ProjectNode after = null;
1657 for(node : parentNode.files)
1659 if(node.type != folder && node.type != file && node.type)
1664 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
1668 modifiedDocument = true;
1669 parentNode.project.topNode.modified = true;
1671 project.ModifiedAllConfigs(true, false, true, true);
1672 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
1673 result.row.tag = (int)result;
1674 result.row.SetData(null, result);
1679 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
1681 CodeEditor codeEditor = null;
1682 ProjectNode projectNode;
1683 ProjectNode after = null;
1684 DataRow row = fileList.currentRow;
1685 ProjectNode parentNode;
1688 if(!row) row = project.topNode.row;
1690 parentNode = (ProjectNode)row.tag;
1692 for(node : parentNode.files)
1694 if(node.type != folder && node.type != file && node.type)
1698 for(c = 1; c < 100; c++)
1701 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
1702 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
1708 char filePath[MAX_LOCATION];
1710 modifiedDocument = true;
1711 project.topNode.modified = true;
1713 project.ModifiedAllConfigs(true, false, false, true);
1714 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1715 projectNode.row.tag =(int)projectNode;
1717 projectNode.row.SetData(null, projectNode);
1718 fileList.currentRow = projectNode.row;
1720 strcpy(filePath, project.topNode.path);
1721 PathCat(filePath, projectNode.path);
1722 PathCat(filePath, projectNode.name);
1724 codeEditor = (CodeEditor)ide.FindWindow(filePath);
1727 Class baseClass = eSystem_FindClass(__thisModule, base);
1728 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
1731 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1732 strcpy(name, projectNode.name);
1733 sprintf(name, "%s%d", upper, c);
1735 strcpy(className, name);
1737 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
1739 //codeEditor.modifiedDocument = false;
1740 //codeEditor.designer.modifiedDocument = false;
1742 //Code_EnsureUpToDate(codeEditor);
1745 else // TODO: fix no symbols generated when ommiting {} for following else
1747 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1751 codeEditor.ViewDesigner();
1752 codeEditor.codeModified = true;
1759 void OpenSelectedNodes()
1764 fileList.GetMultiSelection(selection);
1765 for(item = selection.first; item; item = item.next)
1767 DataRow row = item.data;
1768 ProjectNode node = (ProjectNode)row.tag;
1769 if(node.type == file)
1772 selection.Free(null);
1775 void RemoveSelectedNodes()
1780 fileList.GetMultiSelection(selection);
1782 // Remove children of parents we're deleting
1783 for(item = selection.first; item; item = next)
1786 DataRow row = item.data;
1787 ProjectNode n, node = (ProjectNode)row.tag;
1788 bool remove = false;
1791 for(i = selection.first; i && !remove; i = i.next)
1793 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
1794 for(n = node.parent; n; n = n.parent)
1804 selection.Delete(item);
1807 for(item = selection.first; item; item = item.next)
1809 DataRow row = item.data;
1810 ProjectNode node = (ProjectNode)row.tag;
1811 ProjectNode resNode;
1812 for(resNode = node.parent; resNode; resNode = resNode.parent)
1813 if(resNode.type == resources)
1815 if(node.type == file)
1817 Project prj = node.project;
1819 modifiedDocument = true;
1820 prj.topNode.modified = true;
1822 prj.ModifiedAllConfigs(true, false, true, true);
1824 else if(node.type == folder)
1827 sprintf(message, "Are you sure you want to remove the folder \"%s\"\n"
1828 "and all of its contents from the project?", node.name);
1829 if(MessageBox { type = yesNo, parent = parent, master = null,
1830 text = "Delete Folder", contents = message }.Modal() == yes)
1832 Project prj = node.project;
1834 modifiedDocument = true;
1835 prj.topNode.modified = true;
1836 //project.ModifiedAllConfigs(true, false, true, true);
1839 else if(node.type == project && node != project.topNode && !buildInProgress)
1843 for(p : workspace.projects)
1845 if(p.topNode == node)
1851 sprintf(message, "Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
1852 if(MessageBox { type = yesNo, parent = parent, master = null,
1853 text = "Remove Project", contents = message }.Modal() == yes)
1858 workspace.RemoveProject(prj);
1859 //modifiedDocument = true; // when project view is a workspace view
1863 selection.Free(null);