3 import "FileSystemIterator"
5 class ImportFolderFSI : NormalFileSystemIterator
7 ProjectView projectView;
8 Array<ProjectNode> stack { };
10 bool OnFolder(const 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(const char * folderPath, bool isRoot)
25 stack.lastIterator.Remove(); //stack.Remove();
28 bool OnFile(const 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 const 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)(intptr)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", node.project.config))
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)(intptr)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)(intptr)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(const 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(const char * filePath)
576 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
577 GetLastDirectory(filePath, moduleName);
578 return project.topNode.Find(moduleName, false) != null;
581 ProjectNode GetNodeForCompilationFromWindow(Window document, bool nonExcludedFirst, bool * isExcluded, bool * isCObject)
583 ProjectNode node = null;
585 node = GetNodeFromWindow(document, null, false, false, isExcluded);
587 node = GetNodeFromWindow(document, null, true, false, isExcluded);
588 if(!node && nonExcludedFirst)
590 node = GetNodeFromWindow(document, null, false, true, isExcluded);
591 if(isCObject && node) *isCObject = true;
595 node = GetNodeFromWindow(document, null, true, true, isExcluded);
596 if(isCObject && node) *isCObject = true;
601 ProjectNode GetNodeFromWindow(Window document, Project project, bool allNodes, bool isCObject, bool * isNodeExcluded)
603 ProjectNode node = null;
604 if(document.fileName)
606 bool excluded = false;
607 char winFileName[MAX_LOCATION];
608 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
613 char name[MAX_FILENAME];
614 GetLastDirectory(documentFileName, name);
615 ChangeExtension(name, "ec", name);
616 for(p : ide.workspace.projects)
618 prj = project ? project : p;
619 if((n = prj.topNode.Find(name, false)))
621 if(allNodes || !(excluded = n.GetIsExcluded(prj.config)))
632 for(p : ide.workspace.projects)
634 prj = project ? project : p;
635 if((n = prj.topNode.FindByFullPath(documentFileName, false)))
637 if(allNodes || !(excluded = n.GetIsExcluded(prj.config)))
646 if(node && isNodeExcluded)
647 *isNodeExcluded = excluded;
652 // ((( UTILITY FUNCTIONS )))
654 // ************************************************************************
655 // *** These methods below are part of a sequence of events, and as ***
656 // *** such they must be passed the current compiler and project config ***
657 // ************************************************************************
658 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
660 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
664 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
665 CompilerConfig compiler, ProjectConfig config)
667 ShowOutputBuildLog(cleanLog);
670 DisplayCompiler(compiler, false);
672 ProjectPrepareCompiler(project, compiler, false);
673 ProjectPrepareMakefile(project, method, compiler, config);
677 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
679 if((!project.GenerateCrossPlatformMk(app.includeFile) ||
680 !project.GenerateCompilerCf(compiler, project.topNode.ContainsFilesWithExtension("ec", project.config))) && !silent)
681 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
685 // Note: Compiler is only passed in to for VisualStudio support
686 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
688 if(compiler.type.isVC)
690 // I'm guessing we'll want to support generating VS files on Linux as well...
691 ide.statusBar.text = $"Generating Visual Studio Solution...";
693 //GenerateVSSolutionFile(project, compiler);
694 ide.statusBar.text = $"Generating Visual Studio Project...";
696 //GenerateVCProjectFile(project, compiler, bitDepth);
697 ide.statusBar.text = null;
703 char makefilePath[MAX_LOCATION];
704 char makefileName[MAX_LOCATION];
706 LogBox logBox = ide.outputView.buildBox;
708 strcpy(makefilePath, project.topNode.path);
709 project.CatMakeFileName(makefileName, config);
710 PathCatSlash(makefilePath, makefileName);
712 exists = FileExists(makefilePath);
713 if(method == force ||
714 (method == forceExists && exists) ||
715 (method == normal && (!exists || (config && config.makingModified))))
719 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
722 if((method == normal && !exists) || (method == force && !exists))
723 action = $"Generating ";
724 else if(method == force)
725 action = $"Regenerating ";
726 else if(method == normal || method == forceExists)
727 action = $"Updating ";
731 reason = $"Makefile doesn't exist. ";
732 else if(project.topNode.modified)
733 reason = $"Project has been modified. ";
737 //logBox.Logf("%s\n", makefileName);
738 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
740 if(!project.GenerateMakefile(null, false, null, config, compiler.ldCommand))
741 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
743 ide.statusBar.text = null;
751 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
753 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
755 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
756 return Build(prj, buildType, compiler, config, bitDepth, justPrint);
761 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
764 // TOFIX: DebugStop is being abused and backfiring on us.
765 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
767 // configIsInDebugSession seems to be used for two OPPOSITE things:
768 // If we're debugging another config, we need to unload the executable!
769 // In building, we want to stop if we're debugging the 'same' executable
770 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
772 if(buildType == start || buildType == restart)
774 if(ide.debugger && ide.debugger.isPrepared)
775 result = DebugStop();
779 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
780 result = DebugStop();
783 app.ProcessInput(true);
784 ShowOutputBuildLog(false);
788 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
794 for(document = master.firstChild; document; document = document.next)
796 if(document.modifiedDocument)
798 ProjectNode node = GetNodeFromWindow(document, prj, true, false, null);
799 if(node && !document.MenuFileSave(null, 0))
808 DirExpression targetDir = prj.GetTargetDir(compiler, config, bitDepth);
810 DebugStopForMake(prj, buildType, compiler, config);
812 // TODO: Disabled until problems fixed... is it fixed?
813 if(buildType == rebuild || (config && config.compilingModified))
814 prj.Clean(compiler, config, bitDepth, clean, justPrint);
817 if(buildType == relink || (config && config.linkingModified))
818 prj.Clean(compiler, config, bitDepth, cleanTarget, false);
819 if(config && config.symbolGenModified)
821 DirExpression objDir = prj.GetObjDir(compiler, config, bitDepth);
822 char fileName[MAX_LOCATION];
823 char moduleName[MAX_FILENAME];
824 strcpy(fileName, prj.topNode.path);
825 PathCatSlash(fileName, objDir.dir);
826 ReplaceSpaces(moduleName, prj.moduleName);
827 strcat(moduleName, ".main.ec");
828 PathCatSlash(fileName, moduleName);
829 if(FileExists(fileName))
830 DeleteFile(fileName);
831 ChangeExtension(fileName, "c", fileName);
832 if(FileExists(fileName))
833 DeleteFile(fileName);
834 ChangeExtension(fileName, "o", fileName);
835 if(FileExists(fileName))
836 DeleteFile(fileName);
841 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
842 ide.AdjustBuildMenus();
843 ide.AdjustDebugMenus();
845 result = prj.Build(buildType, null, compiler, config, bitDepth, justPrint, normal);
849 config.compilingModified = false;
851 config.linkingModified = false;
853 config.symbolGenModified = false;
855 buildInProgress = none;
856 ide.AdjustBuildMenus();
857 ide.AdjustDebugMenus();
859 ide.workspace.modified = true;
866 // ((( USER ACTIONS )))
868 // ************************************************************************
869 // *** Methods below should atomically start a process, and as such ***
870 // *** they can query compiler and config directly from ide and project ***
871 // *** but ONLY ONCE!!! ***
872 // ************************************************************************
874 bool ProjectBuild(MenuItem selection, Modifiers mods)
876 if(buildInProgress == none)
878 Project prj = project;
879 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
880 int bitDepth = ide.workspace.bitDepth;
881 ProjectConfig config;
882 if(selection || !ide.activeClient)
884 DataRow row = fileList.currentRow;
885 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
886 if(node) prj = node.project;
890 ProjectNode node = GetNodeForCompilationFromWindow(ide.activeClient, true, null, null);
895 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
897 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
906 bool ProjectInstall(MenuItem selection, Modifiers mods)
908 Project prj = project;
909 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
910 int bitDepth = ide.workspace.bitDepth;
911 ProjectConfig config;
912 if(selection || !ide.activeClient)
914 DataRow row = fileList.currentRow;
915 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
916 if(node) prj = node.project;
920 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
925 if(!prj.GetConfigIsInDebugSession(config) ||
926 (!ide.DontTerminateDebugSession($"Project Install") && DebugStopForMake(prj, relink, compiler, config)))
928 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
929 if(ProjectPrepareForToolchain(prj, normal, false, false, compiler, config))
931 ide.outputView.buildBox.Logf($"\nInstalling project %s using the %s configuration...\n", prj.name, GetConfigName(config));
932 Build(prj, install, compiler, config, bitDepth, mods.ctrl && mods.shift);
939 bool ProjectLink(MenuItem selection, Modifiers mods)
941 Project prj = project;
942 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
943 int bitDepth = ide.workspace.bitDepth;
944 ProjectConfig config;
945 if(selection || !ide.activeClient)
947 DataRow row = fileList.currentRow;
948 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
949 if(node) prj = node.project;
953 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
958 if(!prj.GetConfigIsInDebugSession(config) ||
959 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
961 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
963 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
965 config.linkingModified = true;
966 Build(prj, relink, compiler, config, bitDepth, mods.ctrl && mods.shift);
973 bool ProjectRebuild(MenuItem selection, Modifiers mods)
975 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
976 int bitDepth = ide.workspace.bitDepth;
977 Project prj = project;
978 ProjectConfig config;
979 if(selection || !ide.activeClient)
981 DataRow row = fileList.currentRow;
982 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
983 if(node) prj = node.project;
987 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
992 if(!prj.GetConfigIsInDebugSession(config) ||
993 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
995 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
997 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
1000 config.compilingModified = true;
1001 config.makingModified = true;
1002 }*/ // -- should this still be used depite the new solution of BuildType?
1003 Build(prj, rebuild, compiler, config, bitDepth, mods.ctrl && mods.shift);
1010 bool ProjectCleanTarget(MenuItem selection, Modifiers mods)
1012 CleanProject($"Project Clean Target", $"Cleaning project %s target using the %s configuration...\n", selection, cleanTarget, mods.ctrl && mods.shift);
1016 bool ProjectClean(MenuItem selection, Modifiers mods)
1018 CleanProject($"Project Clean", $"Cleaning project %s using the %s configuration...\n", selection, clean, mods.ctrl && mods.shift);
1022 bool ProjectRealClean(MenuItem selection, Modifiers mods)
1024 CleanProject($"Project Real Clean", $"Removing intermediate objects directory for project %s using the %s configuration...\n", selection, realClean, mods.ctrl && mods.shift);
1028 void CleanProject(const char * terminateDebugSessionMessage, const char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
1030 Project prj = project;
1031 Array<Project> projects { };
1032 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1033 int bitDepth = ide.workspace.bitDepth;
1037 OldList selectedRows;
1038 fileList.GetMultiSelection(selectedRows);
1039 for(item = selectedRows.first; item; item = item.next)
1041 DataRow row = item.data;
1042 ProjectNode node = (ProjectNode)(intptr)row.tag;
1043 if(node.type == project)
1044 projects.Add(node.project);
1046 selectedRows.Free(null);
1048 if(selection || !ide.activeClient)
1050 DataRow row = fileList.currentRow;
1051 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1052 if(node) prj = node.project;
1053 if(projects.count == 0)
1058 // TODO: a file can belong to more than one project, ask which one to clean
1059 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
1060 if(node) prj = node.project;
1061 if(projects.count == 0)
1066 ProjectConfig config = prj.config;
1067 if(!prj.GetConfigIsInDebugSession(config) ||
1068 (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
1070 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1072 ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
1074 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
1075 ide.AdjustBuildMenus();
1076 ide.AdjustDebugMenus();
1078 prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
1079 buildInProgress = none;
1080 ide.AdjustBuildMenus();
1081 ide.AdjustDebugMenus();
1089 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1091 Project prj = project;
1092 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1093 ShowOutputBuildLog(true);
1094 if(selection || !ide.activeClient)
1096 DataRow row = fileList.currentRow;
1097 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1103 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
1108 DisplayCompiler(compiler, false);
1109 ProjectPrepareCompiler(project, compiler, false);
1110 ProjectPrepareMakefile(prj, force, compiler, prj.config);
1115 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1119 ProjectConfig config = project.config;
1123 for(document = ide.firstChild; document; document = document.next)
1125 if(document.modifiedDocument)
1127 ProjectNode n = GetNodeFromWindow(document, project, true, mode == cObject ? true : false, null);
1130 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1132 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1142 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1143 int bitDepth = ide.workspace.bitDepth;
1145 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1148 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1149 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name, config.name);
1151 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1152 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name);
1154 buildInProgress = compilingFile;
1155 ide.AdjustBuildMenus();
1156 result = project.Compile(nodes, compiler, config, bitDepth, justPrint, mode);
1157 buildInProgress = none;
1158 ide.AdjustBuildMenus();
1165 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1169 ProjectConfig config = project.config;
1173 for(document = ide.firstChild; document; document = document.next)
1175 if(document.modifiedDocument)
1177 ProjectNode n = GetNodeFromWindow(document, project, true, false, null);
1180 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1182 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1192 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1193 int bitDepth = ide.workspace.bitDepth;
1195 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1197 Map<String, NameCollisionInfo> namesInfo { };
1198 project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1201 if(node.GetIsExcluded(config))
1202 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1206 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s using the %s configuration...\n",
1207 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1209 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s...\n",
1210 node.type == file ? $"single file" : $"folder", node.name, project.name);
1212 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, false);
1224 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1226 DataRow row = fileList.currentRow;
1229 char fileName[1024];
1230 char filePath[MAX_LOCATION];
1231 ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
1232 ProjectNode n, fileNode;
1233 parentNode.GetFileSysMatchingPath(filePath);
1234 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1235 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1236 sprintf(fileName, $"Untitled %d", documentID);
1237 fileNode = AddFile(parentNode, fileName, n != null, true);
1238 fileNode.path = CopyUnixPath(filePath);
1241 NodeProperties nodeProperties
1244 position = { position.x + 100, position.y + 100 };
1248 nodeProperties.Create(); // not modal?
1254 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1256 DataRow row = fileList.currentRow;
1259 ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
1260 NewFolder(parentNode, null, true);
1265 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1271 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1277 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1279 DataRow row = fileList.currentRow;
1282 ProjectNode toNode = (ProjectNode)(intptr)row.tag;
1283 ImportFolder(toNode);
1288 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1290 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1291 codeEditor.EnsureUpToDate();
1292 ide.RepositionWindows(false);
1296 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1298 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1300 codeEditor.EnsureUpToDate();
1304 bool ProjectRemove(MenuItem selection, Modifiers mods)
1306 DataRow row = fileList.currentRow;
1309 ProjectNode node = (ProjectNode)(intptr)row.tag;
1310 if(node.type == project)
1311 RemoveSelectedNodes();
1316 bool ProjectUpdateMakefileForAllConfigs(Project project)
1318 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1320 // This call really does not belong here:
1321 ide.UpdateToolBarActiveConfigs(false);
1322 for(config : project.configurations)
1323 ProjectPrepareMakefile(project, forceExists, compiler, config);
1330 bool MenuSettings(MenuItem selection, Modifiers mods)
1332 ProjectNode node = GetSelectedNode(true);
1333 Project prj = node ? node.project : project;
1334 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1335 incref projectSettingsDialog;
1336 projectSettingsDialog.Modal();
1337 delete projectSettingsDialog;
1338 ide.UpdateToolBarActiveConfigs(false);
1344 bool FileProperties(MenuItem selection, Modifiers mods)
1346 DataRow row = fileList.currentRow;
1349 ProjectNode node = (ProjectNode)(intptr)row.tag;
1350 NodeProperties { parent = parent, master = this, node = node,
1351 position = { position.x + 100, position.y + 100 } }.Create();
1356 bool FileOpenFile(MenuItem selection, Modifiers mods)
1358 OpenSelectedNodes(mods.ctrl && mods.shift);
1362 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1364 RemoveSelectedNodes();
1368 bool FileCompile(MenuItem selection, Modifiers mods)
1371 OldList selectedRows;
1372 Project project = null;
1373 List<ProjectNode> nodes { };
1374 fileList.GetMultiSelection(selectedRows);
1375 for(item = selectedRows.first; item; item = item.next)
1377 DataRow row = item.data;
1378 ProjectNode node = (ProjectNode)(intptr)row.tag;
1380 project = node.project;
1381 else if(node.project != project)
1388 selectedRows.Free(null);
1390 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1392 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1397 bool FileClean(MenuItem selection, Modifiers mods)
1400 OldList selectedRows;
1401 Project project = null;
1402 List<ProjectNode> nodes { };
1403 fileList.GetMultiSelection(selectedRows);
1404 for(item = selectedRows.first; item; item = item.next)
1406 DataRow row = item.data;
1407 ProjectNode node = (ProjectNode)(intptr)row.tag;
1409 project = node.project;
1410 else if(node.project != project)
1417 selectedRows.Free(null);
1419 Clean(project, nodes, mods.ctrl && mods.shift);
1421 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1426 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1428 DataRow row = fileList.currentRow;
1429 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1432 List<ProjectNode> nodes { };
1434 if(node.type == project)
1435 ProjectBuild(selection, mods);
1438 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1444 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1446 DataRow row = fileList.currentRow;
1447 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1450 List<ProjectNode> nodes { };
1452 if(node.type == project)
1453 ProjectBuild(selection, mods);
1455 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1457 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1463 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1465 DataRow row = fileList.currentRow;
1466 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1469 List<ProjectNode> nodes { };
1471 if(node.type == project)
1472 ProjectBuild(selection, mods);
1474 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1476 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1482 Project GetSelectedProject(bool useSelection)
1484 Project prj = project;
1487 DataRow row = fileList.currentRow;
1488 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1495 void SelectNextProject(bool backwards)
1497 DataRow row = fileList.currentRow;
1499 row = backwards ? fileList.lastRow : fileList.firstRow;
1503 DataRow currentRow = row;
1504 ProjectNode node = (ProjectNode)(intptr)row.tag;
1505 if(node.type != project)
1506 row = node.project.topNode.row;
1508 row = row.previous ? row.previous : fileList.lastRow;
1510 row = row.next ? row.next : fileList.firstRow;
1511 if(row && row != currentRow)
1513 fileList.SelectRow(row);
1514 fileList.currentRow = row;
1519 ProjectNode GetSelectedNode(bool useSelection)
1521 ProjectNode node = null;
1524 DataRow row = fileList.currentRow;
1526 node = (ProjectNode)(intptr)row.tag;
1531 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1533 char folder[MAX_LOCATION];
1535 ProjectNode node = GetSelectedNode(true);
1537 node = project.topNode;
1540 strcpy(folder, prj.topNode.path);
1541 if(node != prj.topNode)
1542 PathCatSlash(folder, node.path);
1547 bool Run(MenuItem selection, Modifiers mods)
1549 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1550 ProjectConfig config = project.config;
1551 int bitDepth = ide.workspace.bitDepth;
1552 String args = new char[maxPathLen];
1554 if(ide.workspace.commandLineArgs)
1555 //ide.debugger.GetCommandLineArgs(args);
1556 strcpy(args, ide.workspace.commandLineArgs);
1557 if(ide.debugger.isActive)
1558 project.Run(args, compiler, config, bitDepth);
1559 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1560 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1561 else if(BuildInterrim(project, run, compiler, config, bitDepth, false))
1562 project.Run(args, compiler, config, bitDepth);
1570 bool result = false;
1571 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1572 ProjectConfig config = project.config;
1573 int bitDepth = ide.workspace.bitDepth;
1574 bool useValgrind = ide.workspace.useValgrind;
1575 TargetTypes targetType = project.GetTargetType(config);
1576 if(targetType == sharedLibrary || targetType == staticLibrary)
1577 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1578 else if(project.GetCompress(config))
1579 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1580 else if(project.GetDebug(config) ||
1581 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1583 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, bitDepth, false))
1585 if(compiler.type.isVC)
1587 //bool result = false;
1588 char oldwd[MAX_LOCATION];
1589 PathBackup pathBackup { };
1590 char command[MAX_LOCATION];
1592 ide.SetPath(false, compiler, config, bitDepth);
1594 GetWorkingDir(oldwd, sizeof(oldwd));
1595 ChangeWorkingDir(project.topNode.path);
1597 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1599 ChangeWorkingDir(oldwd);
1605 ide.debugger.Start(compiler, config, bitDepth, useValgrind);
1614 void GoToError(const char * line, const bool noParsing, const char * objectFileExt)
1618 while(isspace(*line)) line++;
1619 colon = strstr(line, ":");
1624 bool lookForLineNumber = true;
1626 // deal with linking error
1627 if(colon && colon[1] == ' ')
1629 colon = strstr(colon + 1, ":");
1630 if(colon && !colon[1])
1632 colon = strstr(line, ":");
1633 lookForLineNumber = false;
1635 else if(colon && !isdigit(colon[1]))
1638 colon = strstr(line, ":");
1641 // Don't be mistaken by the drive letter colon
1642 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1643 colon = strstr(colon + 1, ":");
1644 if(colon && lookForLineNumber)
1647 #if 0 // MSVS Errors -- todo fix this later
1648 char * par = RSearchString(line, "(", colon - line, true, false);
1649 if(par && strstr(par, ")"))
1651 else if((colon+1)[0] == ' ')
1653 // NOTE: This is the same thing as saying 'colon = line'
1654 for( ; colon != line; colon--)
1659 lineNumber = atoi(colon + 1);
1661 comma = strchr(colon, ',');
1663 col = atoi(comma+1);
1665 comma = strchr(colon+1, ':');
1667 col = atoi(comma+1);
1671 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION] = "";
1672 char ext[MAX_EXTENSION] = "";
1673 ProjectNode node = null;
1676 const char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1677 const char * from = strstr(line, "from ");
1678 const char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
1682 len = Min((int)(colon - start), MAX_LOCATION-1);
1684 strncpy(moduleName, start, len);
1685 moduleName[len] = '\0';
1688 strcpy(moduleName, line);
1693 if((msg = strstr(moduleName, " - ")))
1697 for(prj : ide.workspace.projects)
1699 strcpy(filePath, prj.topNode.path);
1700 PathCatSlash(filePath, moduleName);
1701 if(FileExists(filePath).isFile)
1713 else if((msg = strstr(moduleName, "...")) && (colon = strchr(moduleName, ' ')) && (++colon)[0])
1717 for(prj : ide.workspace.projects)
1719 if((node = prj.resNode.Find(colon, true)))
1721 strcpy(filePath, prj.topNode.path);
1722 PathCatSlash(filePath, node.path);
1723 PathCatSlash(filePath, node.name);
1737 // Remove stuff in brackets
1739 bracket = strstr(moduleName, "(");
1740 if(bracket) *bracket = '\0';
1742 MakeSlashPath(moduleName);
1743 GetExtension(moduleName, ext);
1745 if(!colon && !filePath[0])
1747 // Check if it's one of our modules
1748 node = project.topNode.Find(moduleName, false);
1751 strcpy(filePath, node.path);
1752 PathCatSlash(filePath, node.name);
1756 char ext[MAX_EXTENSION];
1757 GetExtension(moduleName, ext);
1759 DotMain dotMain = DotMain::FromFileName(moduleName);
1760 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
1761 ProjectConfig config = null;
1764 for(prj : ide.workspace.projects; prj.lastBuildConfigName)
1766 if((config = prj.GetConfig(prj.lastBuildConfigName)))
1767 node = prj.FindNodeByObjectFileName(moduleName, type, dotMain, config, objectFileExt);
1774 char name[MAX_FILENAME];
1775 Project project = node.project;
1776 CompilerConfig compiler = ideSettings.GetCompilerConfig(project.lastBuildCompilerName);
1779 int bitDepth = ide.workspace.bitDepth;
1780 const char * objectFileExt = compiler ? compiler.objectFileExt : objectDefaultFileExt;
1781 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
1782 strcpy(filePath, project.topNode.path);
1783 PathCatSlash(filePath, objDir.dir);
1784 node.GetObjectFileName(name, project.configsNameCollisions[config ? config.name : ""], type, dotMain, objectFileExt);
1785 PathCatSlash(filePath, name);
1795 if(!strcmp(ext, "a") || !strcmp(ext, "o") || !strcmp(ext, "lib") ||
1796 !strcmp(ext, "dll") || !strcmp(ext, "exe") || !strcmp(ext, "mo"))
1797 moduleName[0] = 0; // Avoid opening binary files
1800 CodeEditor codeEditor = null;
1802 if(ide.GoToCodeSelectFile(moduleName, null, project, null, filePath, objectFileExt))
1804 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
1811 strcpy(filePath, project.topNode.path);
1812 PathCatSlash(filePath, moduleName);
1815 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
1816 if(!codeEditor && !strcmp(ext, "c"))
1818 char ecName[MAX_LOCATION];
1819 ChangeExtension(filePath, "ec", ecName);
1820 codeEditor = (CodeEditor)ide.OpenFile(ecName, false, true, null, no, normal, noParsing);
1824 char path[MAX_LOCATION];
1825 // TOFIX: Improve on this, don't use only filename, make a function
1826 if(ide && ide.workspace)
1828 for(prj : ide.workspace.projects)
1831 MakePathRelative(filePath, prj.topNode.path, path);
1833 if((node = prj.topNode.FindWithPath(path, false)))
1835 strcpy(filePath, prj.topNode.path);
1836 PathCatSlash(filePath, node.path);
1837 PathCatSlash(filePath, node.name);
1838 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
1843 if(!codeEditor && (strchr(moduleName, '/') || strchr(moduleName, '\\')))
1845 for(prj : ide.workspace.projects)
1848 if((node = prj.topNode.FindWithPath(moduleName, false)))
1850 strcpy(filePath, prj.topNode.path);
1851 PathCatSlash(filePath, node.path);
1852 PathCatSlash(filePath, node.name);
1853 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
1861 GetLastDirectory(moduleName, moduleName);
1862 for(prj : ide.workspace.projects)
1865 if((node = prj.topNode.Find(moduleName, false)))
1867 strcpy(filePath, prj.topNode.path);
1868 PathCatSlash(filePath, node.path);
1869 PathCatSlash(filePath, node.name);
1870 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
1879 if(codeEditor && lineNumber)
1881 EditBox editBox = codeEditor.editBox;
1882 if(editBox.GoToLineNum(lineNumber - 1))
1883 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1890 bool OpenNode(ProjectNode node, bool noParsing)
1892 char filePath[MAX_LOCATION];
1893 char ext[MAX_EXTENSION];
1894 node.GetFullFilePath(filePath);
1895 GetExtension(filePath, ext);
1896 if(binaryDocExt.Find(ext))
1898 ShellOpen(filePath);
1902 return ide.OpenFile(filePath, false, true/*false Why was it opening hidden?*/, null, something, normal, noParsing) ? true : false;
1905 void AddNode(ProjectNode node, DataRow addTo)
1907 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1909 row.tag = (int64)(intptr)node;
1912 if(node.type == resources)
1915 row.SetData(null, node);
1917 if(node.files && node.files.first && node.parent &&
1918 !(!node.parent.parent &&
1919 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1920 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1921 row.collapsed = true;
1922 else if(node.type == folder)
1923 node.icon = openFolder;
1927 for(child : node.files)
1928 AddNode(child, row);
1932 void DeleteNode(ProjectNode projectNode)
1934 if(projectNode.files)
1937 while((child = projectNode.files.first))
1940 fileList.DeleteRow(projectNode.row);
1941 projectNode.Delete();
1944 bool ProjectSave(MenuItem selection, Modifiers mods)
1946 DataRow row = fileList.currentRow;
1947 ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
1948 Project prj = node ? node.project : null;
1951 prj.StopMonitoring();
1952 if(prj.Save(prj.filePath))
1954 Project modPrj = null;
1955 prj.topNode.modified = false;
1956 for(p : ide.workspace.projects)
1958 if(p.topNode.modified)
1965 modifiedDocument = false;
1968 prj.StartMonitoring();
1973 bool ShowOutputBuildLog(bool cleanLog)
1975 OutputView output = ide.outputView;
1977 output.ShowClearSelectTab(build);
1980 output.SelectTab(build);
1988 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1989 ProjectConfig config = project.config;
1990 int bitDepth = ide.workspace.bitDepth;
1991 bool useValgrind = ide.workspace.useValgrind;
1993 bool result = false;
1994 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, bitDepth, false))
1996 // For Restart, compiler and config will only be used if for
1997 // whatever reason (if at all possible) the Debugger is in a
1998 // 'terminated' or 'none' state
1999 ide.debugger.Restart(compiler, config, bitDepth, useValgrind);
2009 ide.debugger.Resume();
2015 ide.debugger.Break();
2021 ide.debugger.Stop();
2025 bool DebugStepInto()
2027 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2028 ProjectConfig config = project.config;
2029 int bitDepth = ide.workspace.bitDepth;
2030 bool useValgrind = ide.workspace.useValgrind;
2032 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2033 ide.debugger.StepInto(compiler, config, bitDepth, useValgrind);
2038 bool DebugStepOver(bool skip)
2040 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2041 ProjectConfig config = project.config;
2042 int bitDepth = ide.workspace.bitDepth;
2043 bool useValgrind = ide.workspace.useValgrind;
2045 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2046 ide.debugger.StepOver(compiler, config, bitDepth, useValgrind, skip);
2052 bool DebugStepUntil(bool skip)
2054 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2055 ProjectConfig config = project.config;
2056 int bitDepth = ide.workspace.bitDepth;
2057 bool useValgrind = ide.workspace.useValgrind;
2059 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2060 ide.debugger.StepUntil(compiler, config, bitDepth, useValgrind, skip);
2066 bool DebugStepOut(bool skip)
2068 ide.debugger.StepOut(skip);
2072 void ImportFolder(ProjectNode toNode)
2076 char path[MAX_LOCATION];
2077 char currentDir[MAX_LOCATION];
2078 ProjectNode node = toNode;
2079 FileDialog fileDialog = importFileDialog;
2080 fileDialog.master = parent;
2083 node.GetFullFilePath(path);
2086 StripLastDirectory(path, path);
2087 if(FileExists(path).isDirectory) break;
2089 if(path[0] || node == toNode.project.topNode)
2092 node = toNode.project.topNode;
2094 MakeSystemPath(path);
2095 StripLastDirectory(path, currentDir);
2096 fileDialog.currentDirectory = currentDir[0] ? currentDir : path;
2097 fileDialog.filePath = path;
2098 if(fileDialog.Modal() == ok)
2100 ImportFolderFSI fsi { projectView = this };
2101 fsi.stack.Add(toNode);
2102 fsi.Iterate(fileDialog.filePath);
2108 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
2112 ProjectNode folderNode;
2113 Project prj = parentNode.project;
2115 ProjectNode after = null;
2116 for(node : parentNode.files)
2118 if(node.type != folder)
2124 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
2127 for(c = 0; c < 100; c++)
2130 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
2131 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
2138 NodeProperties nodeProperties;
2141 modifiedDocument = true;
2142 prj.topNode.modified = true;
2145 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2146 folderNode.row.tag = (int64)(intptr)folderNode;
2148 folderNode.row.SetData(null, folderNode);
2149 fileList.currentRow = folderNode.row;
2153 nodeProperties = NodeProperties
2155 parent, this, mode = newFolder, node = folderNode;
2156 position = { position.x + 100, position.y + 100 };
2158 nodeProperties.Create(); // Modal?
2166 void AddFiles(bool resources)
2168 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
2169 fileDialog.type = multiOpen;
2170 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
2171 fileDialog.master = parent;
2173 if(fileDialog.Modal() == ok)
2176 DataRow row = fileList.currentRow;
2177 ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
2178 bool addFailed = false;
2179 int numSelections = fileDialog.numSelections;
2180 const char * const * multiFilePaths = fileDialog.multiFilePaths;
2182 Array<String> nameConflictFiles { };
2184 for(c = 0; c < numSelections; c++)
2186 const char * filePath = multiFilePaths[c];
2187 FileAttribs exists = FileExists(filePath);
2188 bool addThisFile = true;
2190 if(exists.isDirectory)
2191 addThisFile = false;
2194 if(MessageBox { master = ide, type = yesNo, text = filePath,
2195 contents = $"File doesn't exist. Create?" }.Modal() == yes)
2197 File f = FileOpen(filePath, write);
2205 MessageBox { master = ide, type = ok, text = filePath,
2206 contents = $"Couldn't create file."}.Modal();
2207 addThisFile = false;
2214 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
2216 nameConflictFiles.Add(CopyString(filePath));
2224 const char * part1 = $"The following file";
2225 const char * opt1 = $" was ";
2226 const char * opt2 = $"s were ";
2227 const char * part2 = $"not added because of identical file name conflict within the project.\n\n";
2229 len += strlen(part1);
2230 len += strlen(part2);
2231 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
2232 for(s : nameConflictFiles)
2233 len += strlen(s) + 1;
2234 message = new char[len + 1];
2235 strcpy(message, part1);
2236 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
2237 strcat(message, part2);
2238 for(s : nameConflictFiles)
2241 strcat(message, "\n");
2243 MessageBox { master = ide, type = ok, text = $"Name Conflict",
2244 contents = message }.Modal();
2247 nameConflictFiles.Free();
2248 delete nameConflictFiles;
2252 ProjectNode AddFile(ProjectNode parentNode, const char * filePath, bool resources, bool isTemporary)
2254 ProjectNode result = null;
2255 ProjectNode after = null;
2256 for(node : parentNode.files)
2258 if(node.type != folder && node.type != file && node.type)
2263 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
2269 modifiedDocument = true;
2270 parentNode.project.topNode.modified = true;
2271 parentNode.project.ModifiedAllConfigs(true, false, true, true);
2274 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
2275 result.row.tag = (int64)(intptr)result;
2276 result.row.SetData(null, result);
2281 CodeEditor CreateNew(const char * upper, const char * lower, const char * base, char * className)
2283 CodeEditor codeEditor = null;
2284 ProjectNode projectNode;
2285 ProjectNode after = null;
2286 DataRow row = fileList.currentRow;
2287 ProjectNode parentNode;
2290 if(!row) row = project.topNode.row;
2292 parentNode = (ProjectNode)(intptr)row.tag;
2294 for(node : parentNode.files)
2296 if(node.type != folder && node.type != file && node.type)
2300 for(c = 1; c < 100; c++)
2303 sprintf(string, "%s%d.ec", lower, c);
2304 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
2310 char filePath[MAX_LOCATION];
2312 modifiedDocument = true;
2313 project.topNode.modified = true;
2315 project.ModifiedAllConfigs(true, false, false, true);
2316 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2317 projectNode.row.tag = (int64)(intptr)projectNode;
2319 projectNode.row.SetData(null, projectNode);
2320 fileList.currentRow = projectNode.row;
2322 strcpy(filePath, project.topNode.path);
2323 PathCat(filePath, projectNode.path);
2324 PathCat(filePath, projectNode.name);
2326 codeEditor = (CodeEditor)ide.FindWindow(filePath);
2329 Class baseClass = eSystem_FindClass(__thisModule, base);
2330 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
2333 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, false, null, whatever, normal, false);
2334 strcpy(name, projectNode.name);
2335 sprintf(name, "%s%d", upper, c);
2337 strcpy(className, name);
2339 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2341 //codeEditor.modifiedDocument = false;
2342 //codeEditor.designer.modifiedDocument = false;
2344 //Code_EnsureUpToDate(codeEditor);
2347 else // TODO: fix no symbols generated when ommiting {} for following else
2349 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, false, null, whatever, normal, false);
2351 ide.sheet.visible = true;
2352 ide.sheet.Activate();
2355 codeEditor.ViewDesigner();
2356 codeEditor.codeModified = true;
2363 // Returns true if we opened something
2364 bool OpenSelectedNodes(bool noParsing)
2366 bool result = false;
2370 fileList.GetMultiSelection(selection);
2371 for(item = selection.first; item; item = item.next)
2373 DataRow row = item.data;
2374 ProjectNode node = (ProjectNode)(intptr)row.tag;
2375 if(node.type == file)
2377 OpenNode(node, noParsing);
2381 selection.Free(null);
2382 ide.RepositionWindows(false);
2386 void RemoveSelectedNodes()
2391 fileList.GetMultiSelection(selection);
2393 // Remove children of parents we're deleting
2394 for(item = selection.first; item; item = next)
2397 DataRow row = item.data;
2398 ProjectNode n, node = (ProjectNode)(intptr)row.tag;
2399 bool remove = false;
2402 for(i = selection.first; i && !remove; i = i.next)
2404 ProjectNode iNode = (ProjectNode)(intptr)((DataRow)i.data).tag;
2405 for(n = node.parent; n; n = n.parent)
2415 selection.Delete(item);
2418 for(item = selection.first; item; item = item.next)
2420 DataRow row = item.data;
2421 ProjectNode node = (ProjectNode)(intptr)row.tag;
2422 ProjectNode resNode;
2423 for(resNode = node.parent; resNode; resNode = resNode.parent)
2424 if(resNode.type == resources)
2426 if(node.type == file)
2428 Project prj = node.project;
2430 modifiedDocument = true;
2431 prj.topNode.modified = true;
2433 prj.ModifiedAllConfigs(true, false, true, true);
2435 else if(node.type == folder)
2438 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2439 "and all of its contents from the project?", node.name);
2440 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2442 Project prj = node.project;
2443 if(node.containsFile)
2444 prj.ModifiedAllConfigs(true, false, true, true);
2446 modifiedDocument = true;
2447 prj.topNode.modified = true;
2450 else if(node.type == project && node != project.topNode && !buildInProgress)
2454 for(p : workspace.projects)
2456 if(p.topNode == node)
2462 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2463 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2468 workspace.RemoveProject(prj);
2469 //modifiedDocument = true; // when project view is a workspace view
2473 selection.Free(null);