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 if(!projectView.AddFile(parentNode, filePath, parentNode.isInResources, false))
33 char * msg = PrintString($"This file can't be imported due to a conflict.\n\n", filePath,
34 "\n\nThis occurs with identical file paths and with conflicting file names.\n");
35 MessageBox { master = ide, type = ok, text = "Import File Conflict", contents = msg }.Modal();
42 static Array<FileFilter> fileFilters
44 { $"eC/C/C++ Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
45 { $"eC/C/C++ Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, eh, c, cpp, cc, cxx" },
46 { $"Header Files for eC/C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
47 { $"All files", null }
50 static Array<FileFilter> resourceFilters
52 { $"Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png,*.gif)", "jpg, jpeg, bmp, pcx, png, gif" },
53 { $"3D Studio Model Files (*.3ds)", "3ds" },
54 { $"Translations (*.mo)", "mo" },
55 { $"All files", null }
58 static Array<FileFilter> projectFilters
60 { $"Project Files (*.epj)", ProjectExtension },
61 { $"Workspace Files (*.ews)", WorkspaceExtension }
64 static Array<FileType> projectTypes
66 { $"Ecere IDE Project", ProjectExtension },
67 { $"Ecere IDE Workspace", WorkspaceExtension }
70 static char * iconNames[] =
72 "<:ecere>mimeTypes/file.png", /*genFile*/
73 "<:ecere>mimeTypes/textEcereWorkspace.png", /*ewsFile*/
74 "<:ecere>mimeTypes/textEcereProject.png", /*epjFile*/
75 "<:ecere>places/folder.png", /*folder*/
76 "<:ecere>status/folderOpen.png", /*openFolder*/
77 "<:ecere>mimeTypes/textEcereSource.png", /*ecFile*/
78 "<:ecere>mimeTypes/textEcereHeader.png", /*ehFile*/
79 "<:ecere>mimeTypes/textCSource.png", /*sFile*/ // TODO: change sFile icon to differentiate from cFile icon
80 "<:ecere>mimeTypes/textCSource.png", /*cFile*/
81 "<:ecere>mimeTypes/textCHeader.png", /*hFile*/
82 "<:ecere>mimeTypes/textC++Source.png", /*cppFile*/
83 "<:ecere>mimeTypes/textC++Header.png", /*hppFile*/
84 "<:ecere>mimeTypes/text.png", /*textFile*/
85 "<:ecere>mimeTypes/textHyperTextMarkup.png", /*webFile*/
86 "<:ecere>mimeTypes/image.png", /*pictureFile*/
87 "<:ecere>status/audioVolumeHigh.png", /*soundFile*/
88 "<:ecere>mimeTypes/package.png", /*archiveFile*/
89 "<:ecere>mimeTypes/packageSoftware.png", /*packageFile*/
90 "<:ecere>mimeTypes/packageOpticalDisc.png", /*opticalMediaImageFile*/
91 "<:ecere>mimeTypes/file.png", /*mFile*/ //TODO: create icon for .m file
92 "<:ecere>mimeTypes/file.png" /*mmFile*/ //TODO: create icon for .mm file
95 enum PrepareMakefileMethod { normal, force, forceExists };
97 enum CleanType { clean, realClean, cleanTarget };
98 enum BuildType { build, rebuild, relink, run, start, restart, clean, install };
101 none, buildingMainProject, buildingSecondaryProject, compilingFile;
103 property bool { get { return this != none; } }
104 //property bool actualBuild { get { return this == buildingMainProject || this == buildingSecondaryProject; } }
107 class ProjectView : Window
110 //hasMinimize = true;
112 borderStyle = sizable;
113 hasHorzScroll = true;
114 hasVertScroll = true;
117 anchor = Anchor { left = 0, top = 0, bottom = 0 };
120 //hasMinimize = true;
121 saveDialog = projectFileDialog;
124 BuildState buildInProgress;
125 BitmapResource icons[NodeIcons];
128 property Workspace workspace
134 for(prj : workspace.projects)
136 DeleteNode(prj.topNode);
138 workspace.projects.Free();
139 ide.debugger.CleanUp();
144 fileDialog.currentDirectory = workspace.workspaceDir;
145 resourceFileDialog.currentDirectory = workspace.workspaceDir;
146 for(prj : workspace.projects)
147 AddNode(prj.topNode, null);
148 ide.statusBar.text = $"Generating Makefile & Dependencies...";
150 for(prj : workspace.projects)
151 prj.ModifiedAllConfigs(true, false, false, false);
152 ide.statusBar.text = $"Initializing Debugger"; app.UpdateDisplay();
153 ide.statusBar.text = null;
157 get { return workspace; }
160 bool drawingInProjectSettingsDialog;
161 bool drawingInProjectSettingsDialogHeader;
162 ProjectSettings projectSettingsDialog;
170 for(c = 0; c < NodeIcons::enumSize; c++)
172 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
173 AddResource(icons[c]);
175 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
181 ide.DestroyTemporaryProjectDir();
191 multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
192 borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
193 anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
195 background = projectViewBackground;
196 foreground = projectViewText;
197 selectionColor = selectionColor, selectionText = selectionText;
198 stippleColor = skyBlue;
200 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
202 if(!active) Update(null);
203 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
206 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
208 // Prevent the double click from reactivating the project view (returns false if we opened something)
209 return !OpenSelectedNodes(mods.ctrl && mods.shift);
212 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
214 DataRow row = listBox.currentRow;
217 bool showDebuggingMenuItems = mods.ctrl && mods.shift;
218 bool showInstallMenuItem = mods.ctrl && mods.shift;
219 ProjectNode node = (ProjectNode)row.tag;
220 #ifdef IDE_SHOW_INSTALL_MENU_BUTTON
221 showInstallMenuItem = true;
223 if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
225 bool na = buildInProgress; // N/A - buildMenuUnavailable
228 if(node.type == NodeTypes::project)
231 mi = ide.projectBuildItem;
232 MenuItem { pop, $"Build" , b, f7 , NotifySelect = ProjectBuild , bitmap = mi.bitmap }.disabled = na; mi = ide.projectLinkItem;
233 MenuItem { pop, $"Relink" , l , NotifySelect = ProjectLink , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRebuildItem;
234 MenuItem { pop, $"Rebuild" , r, shiftF7, NotifySelect = ProjectRebuild , bitmap = mi.bitmap }.disabled = na; mi = ide.projectCleanTargetItem;
235 MenuItem { pop, $"Clean Target" , g , NotifySelect = ProjectCleanTarget, bitmap = mi.bitmap }.disabled = na; mi = ide.projectCleanItem;
236 MenuItem { pop, $"Clean" , c , NotifySelect = ProjectClean , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRealCleanItem;
237 MenuItem { pop, $"Real Clean" , NotifySelect = ProjectRealClean , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRegenerateItem;
238 MenuItem { pop, $"Regenerate Makefile", m , NotifySelect = ProjectRegenerate , bitmap = mi.bitmap }.disabled = na;
239 if(showInstallMenuItem)
241 mi = ide.projectInstallItem;
242 MenuItem { pop, $"Install" , t , NotifySelect = ProjectInstall , bitmap = mi.bitmap }.disabled = na;
244 if(showDebuggingMenuItems && node.ContainsFilesWithExtension("ec"))
247 MenuItem { pop, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = na;
248 MenuItem { pop, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = na;
249 MenuItem { pop, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = na;
252 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
253 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
254 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
255 MenuItem { pop, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
257 MenuItem { pop, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
258 // MenuItem { pop, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
260 if(node != ((Project)workspace.projects.first).topNode)
262 MenuItem { pop, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = na;
265 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
267 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
269 MenuItem { pop, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
271 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
273 else if(node.type == resources)
275 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
276 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
277 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
278 MenuItem { pop, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
279 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
281 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
282 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
284 else if(node.type == file)
286 MenuItem { pop, $"Open", o, NotifySelect = FileOpenFile };
288 MenuItem { pop, $"Clean", l, NotifySelect = FileClean, bitmap = ide.projectCleanItem.bitmap }.disabled = na;
289 MenuItem { pop, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile, bitmap = ide.projectBuildItem.bitmap }.disabled = na;
290 if(showDebuggingMenuItems)
292 char extension[MAX_EXTENSION];
293 GetExtension(node.name, extension);
294 if(!strcmpi(extension, "ec"))
297 MenuItem { pop, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = na;
298 MenuItem { pop, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = na;
302 MenuItem { pop, $"Remove", r, NotifySelect = FileRemoveFile };
304 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
306 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
307 MenuItem { pop, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
309 else if(node.type == folder)
311 bool isInResources = node.isInResources;
313 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
314 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
315 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
318 MenuItem { pop, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
322 MenuItem { pop, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
327 MenuItem { pop, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
328 // MenuItem { pop, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
331 MenuItem { pop, $"Clean", l, NotifySelect = FileClean, bitmap = ide.projectCleanItem.bitmap }.disabled = na;
332 MenuItem { pop, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile, bitmap = ide.projectBuildItem.bitmap }.disabled = na;
334 MenuItem { pop, $"Remove", r, NotifySelect = FileRemoveFile };
336 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
338 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
339 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
344 master = this, menu = pop;
346 x + clientStart.x + absPosition.x - app.desktop.position.x,
347 y + clientStart.y + absPosition.y - app.desktop.position.y };
349 void NotifyDestroyed(Window window, DialogResult result)
355 ide.AdjustPopupBuildMenus();
361 bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
363 if(key == altUp || key == altDown)
365 SelectNextProject(key == altUp);
371 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
375 ProjectNode node = (ProjectNode)row.tag;
378 case altEnter: case Key { keyPadEnter, alt = true }:
380 NodeProperties { parent = parent, master = this,
381 position = { position.x + 100, position.y + 100 }, node = node }.Create();
384 case enter: case keyPadEnter:
387 for(resNode = node.parent; resNode; resNode = resNode.parent)
388 if(resNode.type == resources)
390 if(node.type == project || (node.type == folder && !resNode))
395 else if(node.type == resources || node.type == folder)
404 if(node.type == project || node.type == folder || node.type == resources)
413 if(node.type == project || node.type == folder || node.type == resources)
415 NewFolder(node, null, true);
422 if(node.type == file)
424 FileCompile(null, (Modifiers)key);
429 case Key { space, false, true }:
430 case Key { space, true, true }:
431 case Key { space, true }:
434 if(node.type == NodeTypes::project)
437 for(p : workspace.projects)
439 if(p.topNode == node)
445 prj.RotateActiveConfig(!key.shift, key.ctrl);
456 case Key { enter, true, true }: OpenSelectedNodes(true); break;
457 case Key { keyPadEnter, true, true }: OpenSelectedNodes(true); break;
458 case enter: case keyPadEnter: OpenSelectedNodes(false); break;
459 case del: RemoveSelectedNodes(); break;
462 Window activeClient = ide.activeClient;
464 activeClient.Activate();
466 ide.RepositionWindows(true);
473 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
475 ProjectNode node = (ProjectNode)row.tag;
476 if(node.type == folder)
477 node.icon = collapsed ? folder : openFolder;
482 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
483 FileDialog projectFileDialog
485 autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
486 types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
488 FileDialog fileDialog
490 autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
492 FileDialog resourceFileDialog
494 autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
497 Menu fileMenu { menu, $"File", f };
498 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
499 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
501 bool OnClose(bool parentClosing)
503 if(!parentClosing && visible)
513 DialogResult dialogRes;
516 strcpy(msg, $"You have modified projects.\nSave changes to ");
517 for(p : ide.workspace.projects)
519 if(p.topNode.modified)
521 if(!first) strcat(msg, ", ");
528 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
532 // TOFIX: Precomp error if brackets are taken out
533 return (DialogResult)MenuFileSave(null, 0) != cancel;
535 else if(dialogRes == cancel)
537 modifiedDocument = false;
544 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
545 // ide.findInFilesDialog.SearchStop();
547 ide.outputView.buildBox.Clear();
548 ide.outputView.debugBox.Clear();
549 //ide.outputView.findBox.Clear();
550 ide.callStackView.Clear();
551 ide.watchesView.Clear();
552 ide.threadsView.Clear();
553 ide.breakpointsView.Clear();
554 ide.outputView.ShowClearSelectTab(find); // why this?
557 bool OnSaveFile(char * fileName)
559 for(prj : ide.workspace.projects)
561 if(prj.topNode.modified)
563 prj.StopMonitoring();
564 if(prj.Save(prj.filePath))
565 prj.topNode.modified = false;
566 prj.StartMonitoring();
569 modifiedDocument = false;
574 bool IsModuleInProject(char * filePath)
576 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
577 GetLastDirectory(filePath, moduleName);
578 return project.topNode.Find(moduleName, false) != null;
581 ProjectNode GetNodeFromWindow(Window document, Project project, bool isCObject)
583 if(document.fileName)
585 char winFileName[MAX_LOCATION];
586 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
591 char name[MAX_FILENAME];
592 GetLastDirectory(documentFileName, name);
593 ChangeExtension(name, "ec", name);
594 for(p : ide.workspace.projects)
596 prj = project ? project : p;
597 if((node = prj.topNode.Find(name, false)))
604 for(p : ide.workspace.projects)
606 prj = project ? project : p;
607 if((node = prj.topNode.FindByFullPath(documentFileName, false)))
616 // ((( UTILITY FUNCTIONS )))
618 // ************************************************************************
619 // *** These methods below are part of a sequence of events, and as ***
620 // *** such they must be passed the current compiler and project config ***
621 // ************************************************************************
622 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
624 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
628 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
629 CompilerConfig compiler, ProjectConfig config)
632 char message[MAX_F_STRING];
633 LogBox logBox = ide.outputView.buildBox;
635 ShowOutputBuildLog(cleanLog);
638 DisplayCompiler(compiler, false);
640 ProjectPrepareCompiler(project, compiler, false);
641 ProjectPrepareMakefile(project, method, compiler, config);
645 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
647 if((!project.GenerateCrossPlatformMk(app.includeFile) || !project.GenerateCompilerCf(compiler)) && !silent)
648 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
652 // Note: Compiler is only passed in to for VisualStudio support
653 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
655 if(compiler.type.isVC)
657 // I'm guessing we'll want to support generating VS files on Linux as well...
658 ide.statusBar.text = $"Generating Visual Studio Solution...";
660 //GenerateVSSolutionFile(project, compiler);
661 ide.statusBar.text = $"Generating Visual Studio Project...";
663 //GenerateVCProjectFile(project, compiler, bitDepth);
664 ide.statusBar.text = null;
670 char makefilePath[MAX_LOCATION];
671 char makefileName[MAX_LOCATION];
673 LogBox logBox = ide.outputView.buildBox;
675 strcpy(makefilePath, project.topNode.path);
676 project.CatMakeFileName(makefileName, config);
677 PathCatSlash(makefilePath, makefileName);
679 exists = FileExists(makefilePath);
680 if(method == force ||
681 (method == forceExists && exists) ||
682 (method == normal && (!exists || (config && config.makingModified))))
686 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
689 if((method == normal && !exists) || (method == force && !exists))
690 action = $"Generating ";
691 else if(method == force)
692 action = $"Regenerating ";
693 else if(method == normal || method == forceExists)
694 action = $"Updating ";
698 reason = $"Makefile doesn't exist. ";
699 else if(project.topNode.modified)
700 reason = $"Project has been modified. ";
704 //logBox.Logf("%s\n", makefileName);
705 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
707 if(!project.GenerateMakefile(null, false, null, config))
708 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
710 ide.statusBar.text = null;
718 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
720 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
722 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
723 return Build(prj, buildType, compiler, config, bitDepth, justPrint);
728 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
731 // TOFIX: DebugStop is being abused and backfiring on us.
732 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
734 // configIsInDebugSession seems to be used for two OPPOSITE things:
735 // If we're debugging another config, we need to unload the executable!
736 // In building, we want to stop if we're debugging the 'same' executable
737 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
739 if(buildType == start || buildType == restart)
741 if(ide.debugger && ide.debugger.isPrepared)
742 result = DebugStop();
746 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
747 result = DebugStop();
753 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
759 for(document = master.firstChild; document; document = document.next)
761 if(document.modifiedDocument)
763 ProjectNode node = GetNodeFromWindow(document, prj, false);
764 if(node && !document.MenuFileSave(null, 0))
773 DirExpression targetDir = prj.GetTargetDir(compiler, config, bitDepth);
775 DebugStopForMake(prj, buildType, compiler, config);
777 // TODO: Disabled until problems fixed... is it fixed?
778 if(buildType == rebuild || (config && config.compilingModified))
779 prj.Clean(compiler, config, bitDepth, clean, justPrint);
782 if(buildType == relink || (config && config.linkingModified))
783 prj.Clean(compiler, config, bitDepth, cleanTarget, false);
784 if(config && config.symbolGenModified)
786 DirExpression objDir = prj.GetObjDir(compiler, config, bitDepth);
787 char fileName[MAX_LOCATION];
788 char moduleName[MAX_FILENAME];
789 strcpy(fileName, prj.topNode.path);
790 PathCatSlash(fileName, objDir.dir);
791 ReplaceSpaces(moduleName, prj.moduleName);
792 strcat(moduleName, ".main.ec");
793 PathCatSlash(fileName, moduleName);
794 if(FileExists(fileName))
795 DeleteFile(fileName);
796 ChangeExtension(fileName, "c", fileName);
797 if(FileExists(fileName))
798 DeleteFile(fileName);
799 ChangeExtension(fileName, "o", fileName);
800 if(FileExists(fileName))
801 DeleteFile(fileName);
806 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
807 ide.AdjustBuildMenus();
808 ide.AdjustDebugMenus();
810 result = prj.Build(buildType, null, compiler, config, bitDepth, justPrint, normal);
814 config.compilingModified = false;
816 config.linkingModified = false;
818 config.symbolGenModified = false;
820 buildInProgress = none;
821 ide.AdjustBuildMenus();
822 ide.AdjustDebugMenus();
824 ide.workspace.modified = true;
831 // ((( USER ACTIONS )))
833 // ************************************************************************
834 // *** Methods below should atomically start a process, and as such ***
835 // *** they can query compiler and config directly from ide and project ***
836 // *** but ONLY ONCE!!! ***
837 // ************************************************************************
839 bool ProjectBuild(MenuItem selection, Modifiers mods)
841 if(buildInProgress == none)
843 Project prj = project;
844 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
845 int bitDepth = ide.workspace.bitDepth;
846 ProjectConfig config;
847 if(selection || !ide.activeClient)
849 DataRow row = fileList.currentRow;
850 ProjectNode node = row ? (ProjectNode)row.tag : null;
851 if(node) prj = node.project;
855 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
860 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
862 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
871 bool ProjectInstall(MenuItem selection, Modifiers mods)
873 Project prj = project;
874 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
875 int bitDepth = ide.workspace.bitDepth;
876 ProjectConfig config;
877 if(selection || !ide.activeClient)
879 DataRow row = fileList.currentRow;
880 ProjectNode node = row ? (ProjectNode)row.tag : null;
881 if(node) prj = node.project;
885 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
890 if(!prj.GetConfigIsInDebugSession(config) ||
891 (!ide.DontTerminateDebugSession($"Project Install") && DebugStopForMake(prj, relink, compiler, config)))
893 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
894 if(ProjectPrepareForToolchain(prj, normal, false, false, compiler, config))
896 ide.outputView.buildBox.Logf($"\nInstalling project %s using the %s configuration...\n", prj.name, GetConfigName(config));
897 Build(prj, install, compiler, config, bitDepth, mods.ctrl && mods.shift);
904 bool ProjectLink(MenuItem selection, Modifiers mods)
906 Project prj = project;
907 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
908 int bitDepth = ide.workspace.bitDepth;
909 ProjectConfig config;
910 if(selection || !ide.activeClient)
912 DataRow row = fileList.currentRow;
913 ProjectNode node = row ? (ProjectNode)row.tag : null;
914 if(node) prj = node.project;
918 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
923 if(!prj.GetConfigIsInDebugSession(config) ||
924 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
926 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
928 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
930 config.linkingModified = true;
931 Build(prj, relink, compiler, config, bitDepth, mods.ctrl && mods.shift);
938 bool ProjectRebuild(MenuItem selection, Modifiers mods)
940 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
941 int bitDepth = ide.workspace.bitDepth;
942 Project prj = project;
943 ProjectConfig config;
944 if(selection || !ide.activeClient)
946 DataRow row = fileList.currentRow;
947 ProjectNode node = row ? (ProjectNode)row.tag : null;
948 if(node) prj = node.project;
952 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
957 if(!prj.GetConfigIsInDebugSession(config) ||
958 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
960 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
962 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
965 config.compilingModified = true;
966 config.makingModified = true;
967 }*/ // -- should this still be used depite the new solution of BuildType?
968 Build(prj, rebuild, compiler, config, bitDepth, mods.ctrl && mods.shift);
975 bool ProjectCleanTarget(MenuItem selection, Modifiers mods)
977 CleanProject($"Project Clean Target", $"Cleaning project %s target using the %s configuration...\n", selection, cleanTarget, mods.ctrl && mods.shift);
981 bool ProjectClean(MenuItem selection, Modifiers mods)
983 CleanProject($"Project Clean", $"Cleaning project %s using the %s configuration...\n", selection, clean, mods.ctrl && mods.shift);
987 bool ProjectRealClean(MenuItem selection, Modifiers mods)
989 CleanProject($"Project Real Clean", $"Removing intermediate objects directory for project %s using the %s configuration...\n", selection, realClean, mods.ctrl && mods.shift);
993 void CleanProject(char * terminateDebugSessionMessage, char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
995 Project prj = project;
996 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
997 ProjectConfig config;
998 int bitDepth = ide.workspace.bitDepth;
999 if(selection || !ide.activeClient)
1001 DataRow row = fileList.currentRow;
1002 ProjectNode node = row ? (ProjectNode)row.tag : null;
1003 if(node) prj = node.project;
1007 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
1008 if(node) prj = node.project;
1010 config = prj.config;
1011 if(!prj.GetConfigIsInDebugSession(config) ||
1012 (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
1014 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1016 ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
1018 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
1019 ide.AdjustBuildMenus();
1020 ide.AdjustDebugMenus();
1022 prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
1023 buildInProgress = none;
1024 ide.AdjustBuildMenus();
1025 ide.AdjustDebugMenus();
1031 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1033 Project prj = project;
1034 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1035 ShowOutputBuildLog(true);
1036 if(selection || !ide.activeClient)
1038 DataRow row = fileList.currentRow;
1039 ProjectNode node = row ? (ProjectNode)row.tag : null;
1045 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
1050 DisplayCompiler(compiler, false);
1051 ProjectPrepareCompiler(project, compiler, false);
1052 ProjectPrepareMakefile(prj, force, compiler, prj.config);
1057 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1060 char fileName[MAX_LOCATION];
1062 ProjectConfig config = project.config;
1066 for(document = ide.firstChild; document; document = document.next)
1068 if(document.modifiedDocument)
1070 ProjectNode n = GetNodeFromWindow(document, project, mode == cObject ? true : false);
1073 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1075 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1085 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1086 int bitDepth = ide.workspace.bitDepth;
1088 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1091 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1092 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name, config.name);
1094 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1095 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name);
1097 buildInProgress = compilingFile;
1098 ide.AdjustBuildMenus();
1099 result = project.Compile(nodes, compiler, config, bitDepth, justPrint, mode);
1100 buildInProgress = none;
1101 ide.AdjustBuildMenus();
1108 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1111 char fileName[MAX_LOCATION];
1113 ProjectConfig config = project.config;
1117 for(document = ide.firstChild; document; document = document.next)
1119 if(document.modifiedDocument)
1121 ProjectNode n = GetNodeFromWindow(document, project, false);
1124 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1126 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1136 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1137 int bitDepth = ide.workspace.bitDepth;
1139 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1141 Map<String, NameCollisionInfo> namesInfo { };
1142 project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1145 if(node.GetIsExcluded(config))
1146 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1150 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s using the %s configuration...\n",
1151 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1153 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s...\n",
1154 node.type == file ? $"single file" : $"folder", node.name, project.name);
1156 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, false);
1168 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1170 DataRow row = fileList.currentRow;
1173 char fileName[1024];
1174 char filePath[MAX_LOCATION];
1175 ProjectNode parentNode = (ProjectNode)row.tag;
1176 ProjectNode n, fileNode;
1177 parentNode.GetFileSysMatchingPath(filePath);
1178 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1179 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1180 sprintf(fileName, $"Untitled %d", documentID);
1181 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1182 fileNode.path = CopyUnixPath(filePath);
1185 NodeProperties nodeProperties
1188 position = { position.x + 100, position.y + 100 };
1192 nodeProperties.Create(); // not modal?
1198 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1200 DataRow row = fileList.currentRow;
1203 ProjectNode parentNode = (ProjectNode)row.tag;
1204 NewFolder(parentNode, null, true);
1209 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1215 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1221 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1223 DataRow row = fileList.currentRow;
1226 ProjectNode toNode = (ProjectNode)row.tag;
1227 ImportFolder(toNode);
1232 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1234 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1235 codeEditor.EnsureUpToDate();
1239 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1241 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1243 codeEditor.EnsureUpToDate();
1247 bool ProjectRemove(MenuItem selection, Modifiers mods)
1249 DataRow row = fileList.currentRow;
1252 ProjectNode node = (ProjectNode)row.tag;
1253 if(node.type == project)
1254 RemoveSelectedNodes();
1259 bool ProjectUpdateMakefileForAllConfigs(Project project)
1261 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1263 // This call really does not belong here:
1264 ide.UpdateToolBarActiveConfigs(false);
1265 for(config : project.configurations)
1266 ProjectPrepareMakefile(project, forceExists, compiler, config);
1273 bool MenuSettings(MenuItem selection, Modifiers mods)
1275 ProjectNode node = GetSelectedNode(true);
1276 Project prj = node ? node.project : project;
1277 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1278 incref projectSettingsDialog;
1279 projectSettingsDialog.Modal();
1280 delete projectSettingsDialog;
1281 ide.UpdateToolBarActiveConfigs(false);
1287 bool FileProperties(MenuItem selection, Modifiers mods)
1289 DataRow row = fileList.currentRow;
1292 ProjectNode node = (ProjectNode)row.tag;
1293 NodeProperties { parent = parent, master = this, node = node,
1294 position = { position.x + 100, position.y + 100 } }.Create();
1299 bool FileOpenFile(MenuItem selection, Modifiers mods)
1301 OpenSelectedNodes(mods.ctrl && mods.shift);
1305 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1307 RemoveSelectedNodes();
1311 bool FileCompile(MenuItem selection, Modifiers mods)
1314 OldList selectedRows;
1315 Project project = null;
1316 List<ProjectNode> nodes { };
1317 fileList.GetMultiSelection(selectedRows);
1318 for(item = selectedRows.first; item; item = item.next)
1321 DataRow row = item.data;
1322 ProjectNode node = (ProjectNode)row.tag;
1324 project = node.project;
1325 else if(node.project != project)
1332 selectedRows.Free(null);
1334 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1336 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1341 bool FileClean(MenuItem selection, Modifiers mods)
1344 OldList selectedRows;
1345 Project project = null;
1346 List<ProjectNode> nodes { };
1347 fileList.GetMultiSelection(selectedRows);
1348 for(item = selectedRows.first; item; item = item.next)
1351 DataRow row = item.data;
1352 ProjectNode node = (ProjectNode)row.tag;
1354 project = node.project;
1355 else if(node.project != project)
1362 selectedRows.Free(null);
1364 Clean(project, nodes, mods.ctrl && mods.shift);
1366 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1371 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1373 DataRow row = fileList.currentRow;
1374 ProjectNode node = row ? (ProjectNode)row.tag : null;
1377 List<ProjectNode> nodes { };
1379 if(node.type == project)
1380 ProjectBuild(selection, mods);
1383 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1389 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1391 DataRow row = fileList.currentRow;
1392 ProjectNode node = row ? (ProjectNode)row.tag : null;
1395 List<ProjectNode> nodes { };
1397 if(node.type == project)
1398 ProjectBuild(selection, mods);
1400 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1402 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1408 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1410 DataRow row = fileList.currentRow;
1411 ProjectNode node = row ? (ProjectNode)row.tag : null;
1414 List<ProjectNode> nodes { };
1416 if(node.type == project)
1417 ProjectBuild(selection, mods);
1419 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1421 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1427 Project GetSelectedProject(bool useSelection)
1429 Project prj = project;
1432 DataRow row = fileList.currentRow;
1433 ProjectNode node = row ? (ProjectNode)row.tag : null;
1440 void SelectNextProject(bool backwards)
1442 DataRow row = fileList.currentRow;
1443 DataRow currentRow = row;
1444 ProjectNode node = (ProjectNode)row.tag;
1445 if(node.type != project)
1446 row = node.project.topNode.row;
1448 row = row.previous ? row.previous : fileList.lastRow;
1450 row = row.next ? row.next : fileList.firstRow;
1451 if(row && row != currentRow)
1453 fileList.SelectRow(row);
1454 fileList.currentRow = row;
1458 ProjectNode GetSelectedNode(bool useSelection)
1460 ProjectNode node = null;
1463 DataRow row = fileList.currentRow;
1465 node = (ProjectNode)row.tag;
1470 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1472 char folder[MAX_LOCATION];
1474 ProjectNode node = GetSelectedNode(true);
1476 node = project.topNode;
1479 strcpy(folder, prj.topNode.path);
1480 if(node != prj.topNode)
1481 PathCatSlash(folder, node.path);
1486 bool Run(MenuItem selection, Modifiers mods)
1488 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1489 ProjectConfig config = project.config;
1490 int bitDepth = ide.workspace.bitDepth;
1491 String args = new char[maxPathLen];
1493 if(ide.workspace.commandLineArgs)
1494 //ide.debugger.GetCommandLineArgs(args);
1495 strcpy(args, ide.workspace.commandLineArgs);
1496 if(ide.debugger.isActive)
1497 project.Run(args, compiler, config, bitDepth);
1498 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1499 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1500 else if(BuildInterrim(project, run, compiler, config, bitDepth, false))
1501 project.Run(args, compiler, config, bitDepth);
1509 bool result = false;
1510 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1511 ProjectConfig config = project.config;
1512 int bitDepth = ide.workspace.bitDepth;
1513 bool useValgrind = ide.workspace.useValgrind;
1514 TargetTypes targetType = project.GetTargetType(config);
1515 if(targetType == sharedLibrary || targetType == staticLibrary)
1516 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1517 else if(project.GetCompress(config))
1518 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1519 else if(project.GetDebug(config) ||
1520 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1522 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, bitDepth, false))
1524 if(compiler.type.isVC)
1526 //bool result = false;
1527 char oldwd[MAX_LOCATION];
1528 PathBackup pathBackup { };
1529 char command[MAX_LOCATION];
1531 ide.SetPath(false, compiler, config, bitDepth);
1533 GetWorkingDir(oldwd, sizeof(oldwd));
1534 ChangeWorkingDir(project.topNode.path);
1536 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1538 ChangeWorkingDir(oldwd);
1544 ide.debugger.Start(compiler, config, bitDepth, useValgrind);
1553 void GoToError(const char * line, const bool noParsing)
1557 while(isspace(*line)) line++;
1558 colon = strstr(line, ":");
1563 bool lookForLineNumber = true;
1565 // deal with linking error
1566 if(colon && colon[1] == ' ')
1568 colon = strstr(colon + 1, ":");
1569 if(colon && !colon[1])
1571 colon = strstr(line, ":");
1572 lookForLineNumber = false;
1574 else if(colon && !isdigit(colon[1]))
1577 colon = strstr(line, ":");
1580 // Don't be mistaken by the drive letter colon
1581 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1582 colon = strstr(colon + 1, ":");
1583 if(colon && lookForLineNumber)
1586 #if 0 // MSVS Errors -- todo fix this later
1587 char * par = RSearchString(line, "(", colon - line, true, false);
1588 if(par && strstr(par, ")"))
1590 else if((colon+1)[0] == ' ')
1592 // NOTE: This is the same thing as saying 'colon = line'
1593 for( ; colon != line; colon--)
1598 lineNumber = atoi(colon + 1);
1600 comma = strchr(colon, ',');
1602 col = atoi(comma+1);
1604 comma = strchr(colon+1, ':');
1606 col = atoi(comma+1);
1610 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION] = "";
1611 char ext[MAX_EXTENSION] = "";
1613 ProjectNode node = null;
1616 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1617 char * from = strstr(line, "from ");
1618 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
1622 len = Min((int)(colon - start), MAX_LOCATION-1);
1624 strncpy(moduleName, start, len);
1625 moduleName[len] = '\0';
1628 strcpy(moduleName, line);
1633 if((msg = strstr(moduleName, " - ")))
1637 for(prj : ide.workspace.projects)
1639 strcpy(filePath, prj.topNode.path);
1640 PathCatSlash(filePath, moduleName);
1641 if(FileExists(filePath).isFile)
1653 else if((msg = strstr(moduleName, "...")) && (colon = strchr(moduleName, ' ')) && (++colon)[0])
1657 for(prj : ide.workspace.projects)
1659 if((node = prj.resNode.Find(colon, true)))
1661 strcpy(filePath, prj.topNode.path);
1662 PathCatSlash(filePath, node.path);
1663 PathCatSlash(filePath, node.name);
1677 // Remove stuff in brackets
1679 bracket = strstr(moduleName, "(");
1680 if(bracket) *bracket = '\0';
1682 MakeSlashPath(moduleName);
1683 GetExtension(moduleName, ext);
1685 if(!colon && !filePath[0])
1687 bool dotMain = false;
1688 // Check if it's one of our modules
1689 node = project.topNode.Find(moduleName, false);
1692 strcpy(filePath, node.path);
1693 PathCatSlash(filePath, node.name);
1697 IntermediateFileType type = none;
1698 ProjectConfig config;
1701 char ext2[MAX_EXTENSION];
1702 char stripExt[MAX_LOCATION];
1703 strcpy(stripExt, moduleName);
1704 StripExtension(stripExt);
1705 GetExtension(stripExt, ext2);
1706 if(ext2[0] && !strcmp(ext2, "main"))
1708 if(!strcmp(ext, "ec"))
1710 else if(!strcmp(ext, "c"))
1712 else if(!strcmp(ext, "sym"))
1714 else if(!strcmp(ext, "imp"))
1716 else if(!strcmp(ext, "bowl"))
1718 else if(!strcmp(ext, "o"))
1723 for(prj : ide.workspace.projects; prj.lastBuildConfigName)
1725 if((config = prj.GetConfig(prj.lastBuildConfigName)))
1726 node = prj.FindNodeByObjectFileName(moduleName, type, dotMain, config);
1734 char name[MAX_FILENAME];
1735 Project project = node.project;
1736 CompilerConfig compiler = ideSettings.GetCompilerConfig(project.lastBuildCompilerName);
1739 int bitDepth = ide.workspace.bitDepth;
1740 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
1741 strcpy(filePath, project.topNode.path);
1742 PathCatSlash(filePath, objDir.dir);
1743 node.GetObjectFileName(name, project.lastBuildNamesInfo, type, dotMain);
1744 PathCatSlash(filePath, name);
1753 if(!strcmp(ext, "a") || !strcmp(ext, "o") || !strcmp(ext, "lib") ||
1754 !strcmp(ext, "dll") || !strcmp(ext, "exe") || !strcmp(ext, "mo"))
1755 moduleName[0] = 0; // Avoid opening binary files
1758 CodeEditor codeEditor;
1761 strcpy(filePath, project.topNode.path);
1762 PathCatSlash(filePath, moduleName);
1765 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1766 if(!codeEditor && !strcmp(ext, "c"))
1768 char ecName[MAX_LOCATION];
1769 ChangeExtension(filePath, "ec", ecName);
1770 codeEditor = (CodeEditor)ide.OpenFile(ecName, normal, true, null, no, normal, noParsing);
1774 char path[MAX_LOCATION];
1775 // TOFIX: Improve on this, don't use only filename, make a function
1776 if(ide && ide.workspace)
1778 for(prj : ide.workspace.projects)
1781 MakePathRelative(filePath, prj.topNode.path, path);
1783 if((node = prj.topNode.FindWithPath(path, false)))
1785 strcpy(filePath, prj.topNode.path);
1786 PathCatSlash(filePath, node.path);
1787 PathCatSlash(filePath, node.name);
1788 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1793 if(!codeEditor && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1795 for(prj : ide.workspace.projects)
1798 if((node = prj.topNode.Find(moduleName, false)))
1800 strcpy(filePath, prj.topNode.path);
1801 PathCatSlash(filePath, node.path);
1802 PathCatSlash(filePath, node.name);
1803 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1811 if(codeEditor && lineNumber)
1813 EditBox editBox = codeEditor.editBox;
1814 editBox.GoToLineNum(lineNumber - 1);
1815 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1822 bool OpenNode(ProjectNode node, bool noParsing)
1824 char filePath[MAX_LOCATION];
1825 node.GetFullFilePath(filePath);
1826 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal, noParsing) ? true : false;
1829 void AddNode(ProjectNode node, DataRow addTo)
1831 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1833 row.tag = (int64)node;
1836 if(node.type == resources)
1839 row.SetData(null, node);
1841 if(node.files && node.files.first && node.parent &&
1842 !(!node.parent.parent &&
1843 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1844 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1845 row.collapsed = true;
1846 else if(node.type == folder)
1847 node.icon = openFolder;
1851 for(child : node.files)
1852 AddNode(child, row);
1856 void DeleteNode(ProjectNode projectNode)
1858 if(projectNode.files)
1861 while(child = projectNode.files.first)
1864 fileList.DeleteRow(projectNode.row);
1865 projectNode.Delete();
1868 bool ProjectSave(MenuItem selection, Modifiers mods)
1870 DataRow row = fileList.currentRow;
1871 ProjectNode node = row ? (ProjectNode)row.tag : null;
1872 Project prj = node ? node.project : null;
1875 prj.StopMonitoring();
1876 if(prj.Save(prj.filePath))
1878 Project modPrj = null;
1879 prj.topNode.modified = false;
1880 for(p : ide.workspace.projects)
1882 if(p.topNode.modified)
1889 modifiedDocument = false;
1892 prj.StartMonitoring();
1897 bool ShowOutputBuildLog(bool cleanLog)
1899 OutputView output = ide.outputView;
1901 output.ShowClearSelectTab(build);
1904 output.SelectTab(build);
1912 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1913 ProjectConfig config = project.config;
1914 int bitDepth = ide.workspace.bitDepth;
1915 bool useValgrind = ide.workspace.useValgrind;
1917 bool result = false;
1918 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, bitDepth, false))
1920 // For Restart, compiler and config will only be used if for
1921 // whatever reason (if at all possible) the Debugger is in a
1922 // 'terminated' or 'none' state
1923 ide.debugger.Restart(compiler, config, bitDepth, useValgrind);
1933 ide.debugger.Resume();
1939 ide.debugger.Break();
1945 ide.debugger.Stop();
1949 bool DebugStepInto()
1951 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1952 ProjectConfig config = project.config;
1953 int bitDepth = ide.workspace.bitDepth;
1954 bool useValgrind = ide.workspace.useValgrind;
1956 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1957 ide.debugger.StepInto(compiler, config, bitDepth, useValgrind);
1962 bool DebugStepOver(bool skip)
1964 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1965 ProjectConfig config = project.config;
1966 int bitDepth = ide.workspace.bitDepth;
1967 bool useValgrind = ide.workspace.useValgrind;
1969 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1970 ide.debugger.StepOver(compiler, config, bitDepth, useValgrind, skip);
1976 bool DebugStepOut(bool skip)
1978 ide.debugger.StepOut(skip);
1982 void ImportFolder(ProjectNode toNode)
1986 //bool isFolder = toNode.type == folder;
1987 //bool isRes = toNode.isInResources;
1989 FileDialog fileDialog = importFileDialog;
1990 fileDialog.master = parent;
1991 if(fileDialog.Modal() == ok)
1993 ImportFolderFSI fsi { projectView = this };
1994 fsi.stack.Add(toNode);
1995 fsi.Iterate(fileDialog.filePath);
2001 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
2005 ProjectNode folderNode;
2006 Project prj = parentNode.project;
2008 ProjectNode after = null;
2009 for(node : parentNode.files)
2011 if(node.type != folder)
2017 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
2020 for(c = 0; c < 100; c++)
2023 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
2024 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
2031 NodeProperties nodeProperties;
2034 modifiedDocument = true;
2035 prj.topNode.modified = true;
2038 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2039 folderNode.row.tag = (int64)folderNode;
2041 folderNode.row.SetData(null, folderNode);
2042 fileList.currentRow = folderNode.row;
2046 nodeProperties = NodeProperties
2048 parent, this, mode = newFolder, node = folderNode;
2049 position = { position.x + 100, position.y + 100 };
2051 nodeProperties.Create(); // Modal?
2059 void AddFiles(bool resources)
2061 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
2062 fileDialog.type = multiOpen;
2063 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
2064 fileDialog.master = parent;
2066 if(fileDialog.Modal() == ok)
2069 DataRow row = fileList.currentRow;
2070 ProjectNode parentNode = (ProjectNode)row.tag;
2071 bool addFailed = false;
2072 int numSelections = fileDialog.numSelections;
2073 char ** multiFilePaths = fileDialog.multiFilePaths;
2075 Array<String> nameConflictFiles { };
2077 for(c = 0; c < numSelections; c++)
2079 char * filePath = multiFilePaths[c];
2080 FileAttribs exists = FileExists(filePath);
2081 bool addThisFile = true;
2083 if(exists.isDirectory)
2084 addThisFile = false;
2087 if(MessageBox { master = ide, type = yesNo, text = filePath,
2088 contents = $"File doesn't exist. Create?" }.Modal() == yes)
2090 File f = FileOpen(filePath, write);
2098 MessageBox { master = ide, type = ok, text = filePath,
2099 contents = $"Couldn't create file."}.Modal();
2100 addThisFile = false;
2107 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
2109 nameConflictFiles.Add(CopyString(filePath));
2117 char * part1 = $"The following file";
2118 char * opt1 = $" was ";
2119 char * opt2 = $"s were ";
2120 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
2122 len += strlen(part1);
2123 len += strlen(part2);
2124 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
2125 for(s : nameConflictFiles)
2126 len += strlen(s) + 1;
2127 message = new char[len + 1];
2128 strcpy(message, part1);
2129 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
2130 strcat(message, part2);
2131 for(s : nameConflictFiles)
2134 strcat(message, "\n");
2136 MessageBox { master = ide, type = ok, text = $"Name Conflict",
2137 contents = message }.Modal();
2140 nameConflictFiles.Free();
2141 delete nameConflictFiles;
2145 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
2147 ProjectNode result = null;
2148 ProjectNode after = null;
2149 for(node : parentNode.files)
2151 if(node.type != folder && node.type != file && node.type)
2156 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
2162 modifiedDocument = true;
2163 parentNode.project.topNode.modified = true;
2164 parentNode.project.ModifiedAllConfigs(true, false, true, true);
2167 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
2168 result.row.tag = (int64)result;
2169 result.row.SetData(null, result);
2174 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
2176 CodeEditor codeEditor = null;
2177 ProjectNode projectNode;
2178 ProjectNode after = null;
2179 DataRow row = fileList.currentRow;
2180 ProjectNode parentNode;
2183 if(!row) row = project.topNode.row;
2185 parentNode = (ProjectNode)row.tag;
2187 for(node : parentNode.files)
2189 if(node.type != folder && node.type != file && node.type)
2193 for(c = 1; c < 100; c++)
2196 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
2197 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
2203 char filePath[MAX_LOCATION];
2205 modifiedDocument = true;
2206 project.topNode.modified = true;
2208 project.ModifiedAllConfigs(true, false, false, true);
2209 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2210 projectNode.row.tag =(int64)projectNode;
2212 projectNode.row.SetData(null, projectNode);
2213 fileList.currentRow = projectNode.row;
2215 strcpy(filePath, project.topNode.path);
2216 PathCat(filePath, projectNode.path);
2217 PathCat(filePath, projectNode.name);
2219 codeEditor = (CodeEditor)ide.FindWindow(filePath);
2222 Class baseClass = eSystem_FindClass(__thisModule, base);
2223 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
2226 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
2227 strcpy(name, projectNode.name);
2228 sprintf(name, "%s%d", upper, c);
2230 strcpy(className, name);
2232 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2234 //codeEditor.modifiedDocument = false;
2235 //codeEditor.designer.modifiedDocument = false;
2237 //Code_EnsureUpToDate(codeEditor);
2240 else // TODO: fix no symbols generated when ommiting {} for following else
2242 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
2244 ide.sheet.visible = true;
2245 ide.sheet.Activate();
2248 codeEditor.ViewDesigner();
2249 codeEditor.codeModified = true;
2256 // Returns true if we opened something
2257 bool OpenSelectedNodes(bool noParsing)
2259 bool result = false;
2263 fileList.GetMultiSelection(selection);
2264 for(item = selection.first; item; item = item.next)
2266 DataRow row = item.data;
2267 ProjectNode node = (ProjectNode)row.tag;
2268 if(node.type == file)
2270 OpenNode(node, noParsing);
2274 selection.Free(null);
2275 ide.RepositionWindows(false);
2279 void RemoveSelectedNodes()
2284 fileList.GetMultiSelection(selection);
2286 // Remove children of parents we're deleting
2287 for(item = selection.first; item; item = next)
2290 DataRow row = item.data;
2291 ProjectNode n, node = (ProjectNode)row.tag;
2292 bool remove = false;
2295 for(i = selection.first; i && !remove; i = i.next)
2297 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2298 for(n = node.parent; n; n = n.parent)
2308 selection.Delete(item);
2311 for(item = selection.first; item; item = item.next)
2313 DataRow row = item.data;
2314 ProjectNode node = (ProjectNode)row.tag;
2315 ProjectNode resNode;
2316 for(resNode = node.parent; resNode; resNode = resNode.parent)
2317 if(resNode.type == resources)
2319 if(node.type == file)
2321 Project prj = node.project;
2323 modifiedDocument = true;
2324 prj.topNode.modified = true;
2326 prj.ModifiedAllConfigs(true, false, true, true);
2328 else if(node.type == folder)
2331 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2332 "and all of its contents from the project?", node.name);
2333 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2335 Project prj = node.project;
2336 if(node.containsFile)
2337 prj.ModifiedAllConfigs(true, false, true, true);
2339 modifiedDocument = true;
2340 prj.topNode.modified = true;
2343 else if(node.type == project && node != project.topNode && !buildInProgress)
2347 for(p : workspace.projects)
2349 if(p.topNode == node)
2355 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2356 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2361 workspace.RemoveProject(prj);
2362 //modifiedDocument = true; // when project view is a workspace view
2366 selection.Free(null);