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", 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)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 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)
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)
635 prj = project ? project : p;
636 if((n = prj.topNode.FindByFullPath(documentFileName, false)))
638 if(allNodes || !(excluded = n.GetIsExcluded(prj.config)))
647 if(node && isNodeExcluded)
648 *isNodeExcluded = excluded;
653 // ((( UTILITY FUNCTIONS )))
655 // ************************************************************************
656 // *** These methods below are part of a sequence of events, and as ***
657 // *** such they must be passed the current compiler and project config ***
658 // ************************************************************************
659 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
661 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
665 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
666 CompilerConfig compiler, ProjectConfig config)
669 char message[MAX_F_STRING];
670 LogBox logBox = ide.outputView.buildBox;
672 ShowOutputBuildLog(cleanLog);
675 DisplayCompiler(compiler, false);
677 ProjectPrepareCompiler(project, compiler, false);
678 ProjectPrepareMakefile(project, method, compiler, config);
682 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
684 if((!project.GenerateCrossPlatformMk(app.includeFile) ||
685 !project.GenerateCompilerCf(compiler, project.topNode.ContainsFilesWithExtension("ec", project.config))) && !silent)
686 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
690 // Note: Compiler is only passed in to for VisualStudio support
691 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
693 if(compiler.type.isVC)
695 // I'm guessing we'll want to support generating VS files on Linux as well...
696 ide.statusBar.text = $"Generating Visual Studio Solution...";
698 //GenerateVSSolutionFile(project, compiler);
699 ide.statusBar.text = $"Generating Visual Studio Project...";
701 //GenerateVCProjectFile(project, compiler, bitDepth);
702 ide.statusBar.text = null;
708 char makefilePath[MAX_LOCATION];
709 char makefileName[MAX_LOCATION];
711 LogBox logBox = ide.outputView.buildBox;
713 strcpy(makefilePath, project.topNode.path);
714 project.CatMakeFileName(makefileName, config);
715 PathCatSlash(makefilePath, makefileName);
717 exists = FileExists(makefilePath);
718 if(method == force ||
719 (method == forceExists && exists) ||
720 (method == normal && (!exists || (config && config.makingModified))))
724 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
727 if((method == normal && !exists) || (method == force && !exists))
728 action = $"Generating ";
729 else if(method == force)
730 action = $"Regenerating ";
731 else if(method == normal || method == forceExists)
732 action = $"Updating ";
736 reason = $"Makefile doesn't exist. ";
737 else if(project.topNode.modified)
738 reason = $"Project has been modified. ";
742 //logBox.Logf("%s\n", makefileName);
743 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
745 if(!project.GenerateMakefile(null, false, null, config))
746 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
748 ide.statusBar.text = null;
756 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
758 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
760 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
761 return Build(prj, buildType, compiler, config, bitDepth, justPrint);
766 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
769 // TOFIX: DebugStop is being abused and backfiring on us.
770 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
772 // configIsInDebugSession seems to be used for two OPPOSITE things:
773 // If we're debugging another config, we need to unload the executable!
774 // In building, we want to stop if we're debugging the 'same' executable
775 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
777 if(buildType == start || buildType == restart)
779 if(ide.debugger && ide.debugger.isPrepared)
780 result = DebugStop();
784 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
785 result = DebugStop();
791 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
797 for(document = master.firstChild; document; document = document.next)
799 if(document.modifiedDocument)
801 ProjectNode node = GetNodeFromWindow(document, prj, true, false, null);
802 if(node && !document.MenuFileSave(null, 0))
811 DirExpression targetDir = prj.GetTargetDir(compiler, config, bitDepth);
813 DebugStopForMake(prj, buildType, compiler, config);
815 // TODO: Disabled until problems fixed... is it fixed?
816 if(buildType == rebuild || (config && config.compilingModified))
817 prj.Clean(compiler, config, bitDepth, clean, justPrint);
820 if(buildType == relink || (config && config.linkingModified))
821 prj.Clean(compiler, config, bitDepth, cleanTarget, false);
822 if(config && config.symbolGenModified)
824 DirExpression objDir = prj.GetObjDir(compiler, config, bitDepth);
825 char fileName[MAX_LOCATION];
826 char moduleName[MAX_FILENAME];
827 strcpy(fileName, prj.topNode.path);
828 PathCatSlash(fileName, objDir.dir);
829 ReplaceSpaces(moduleName, prj.moduleName);
830 strcat(moduleName, ".main.ec");
831 PathCatSlash(fileName, moduleName);
832 if(FileExists(fileName))
833 DeleteFile(fileName);
834 ChangeExtension(fileName, "c", fileName);
835 if(FileExists(fileName))
836 DeleteFile(fileName);
837 ChangeExtension(fileName, "o", fileName);
838 if(FileExists(fileName))
839 DeleteFile(fileName);
844 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
845 ide.AdjustBuildMenus();
846 ide.AdjustDebugMenus();
848 result = prj.Build(buildType, null, compiler, config, bitDepth, justPrint, normal);
852 config.compilingModified = false;
854 config.linkingModified = false;
856 config.symbolGenModified = false;
858 buildInProgress = none;
859 ide.AdjustBuildMenus();
860 ide.AdjustDebugMenus();
862 ide.workspace.modified = true;
869 // ((( USER ACTIONS )))
871 // ************************************************************************
872 // *** Methods below should atomically start a process, and as such ***
873 // *** they can query compiler and config directly from ide and project ***
874 // *** but ONLY ONCE!!! ***
875 // ************************************************************************
877 bool ProjectBuild(MenuItem selection, Modifiers mods)
879 if(buildInProgress == none)
881 Project prj = project;
882 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
883 int bitDepth = ide.workspace.bitDepth;
884 ProjectConfig config;
885 if(selection || !ide.activeClient)
887 DataRow row = fileList.currentRow;
888 ProjectNode node = row ? (ProjectNode)row.tag : null;
889 if(node) prj = node.project;
893 ProjectNode node = GetNodeForCompilationFromWindow(ide.activeClient, true, null, null);
898 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
900 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
909 bool ProjectInstall(MenuItem selection, Modifiers mods)
911 Project prj = project;
912 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
913 int bitDepth = ide.workspace.bitDepth;
914 ProjectConfig config;
915 if(selection || !ide.activeClient)
917 DataRow row = fileList.currentRow;
918 ProjectNode node = row ? (ProjectNode)row.tag : null;
919 if(node) prj = node.project;
923 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
928 if(!prj.GetConfigIsInDebugSession(config) ||
929 (!ide.DontTerminateDebugSession($"Project Install") && DebugStopForMake(prj, relink, compiler, config)))
931 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
932 if(ProjectPrepareForToolchain(prj, normal, false, false, compiler, config))
934 ide.outputView.buildBox.Logf($"\nInstalling project %s using the %s configuration...\n", prj.name, GetConfigName(config));
935 Build(prj, install, compiler, config, bitDepth, mods.ctrl && mods.shift);
942 bool ProjectLink(MenuItem selection, Modifiers mods)
944 Project prj = project;
945 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
946 int bitDepth = ide.workspace.bitDepth;
947 ProjectConfig config;
948 if(selection || !ide.activeClient)
950 DataRow row = fileList.currentRow;
951 ProjectNode node = row ? (ProjectNode)row.tag : null;
952 if(node) prj = node.project;
956 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
961 if(!prj.GetConfigIsInDebugSession(config) ||
962 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
964 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
966 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
968 config.linkingModified = true;
969 Build(prj, relink, compiler, config, bitDepth, mods.ctrl && mods.shift);
976 bool ProjectRebuild(MenuItem selection, Modifiers mods)
978 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
979 int bitDepth = ide.workspace.bitDepth;
980 Project prj = project;
981 ProjectConfig config;
982 if(selection || !ide.activeClient)
984 DataRow row = fileList.currentRow;
985 ProjectNode node = row ? (ProjectNode)row.tag : null;
986 if(node) prj = node.project;
990 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
995 if(!prj.GetConfigIsInDebugSession(config) ||
996 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
998 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1000 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
1003 config.compilingModified = true;
1004 config.makingModified = true;
1005 }*/ // -- should this still be used depite the new solution of BuildType?
1006 Build(prj, rebuild, compiler, config, bitDepth, mods.ctrl && mods.shift);
1013 bool ProjectCleanTarget(MenuItem selection, Modifiers mods)
1015 CleanProject($"Project Clean Target", $"Cleaning project %s target using the %s configuration...\n", selection, cleanTarget, mods.ctrl && mods.shift);
1019 bool ProjectClean(MenuItem selection, Modifiers mods)
1021 CleanProject($"Project Clean", $"Cleaning project %s using the %s configuration...\n", selection, clean, mods.ctrl && mods.shift);
1025 bool ProjectRealClean(MenuItem selection, Modifiers mods)
1027 CleanProject($"Project Real Clean", $"Removing intermediate objects directory for project %s using the %s configuration...\n", selection, realClean, mods.ctrl && mods.shift);
1031 void CleanProject(char * terminateDebugSessionMessage, char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
1033 Project prj = project;
1034 Array<Project> projects { };
1035 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1036 int bitDepth = ide.workspace.bitDepth;
1040 OldList selectedRows;
1041 List<ProjectNode> nodes { };
1042 fileList.GetMultiSelection(selectedRows);
1043 for(item = selectedRows.first; item; item = item.next)
1046 DataRow row = item.data;
1047 ProjectNode node = (ProjectNode)row.tag;
1048 if(node.type == project)
1049 projects.Add(node.project);
1051 selectedRows.Free(null);
1053 if(selection || !ide.activeClient)
1055 DataRow row = fileList.currentRow;
1056 ProjectNode node = row ? (ProjectNode)row.tag : null;
1057 if(node) prj = node.project;
1058 if(projects.count == 0)
1063 // TODO: a file can belong to more than one project, ask which one to clean
1064 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
1065 if(node) prj = node.project;
1066 if(projects.count == 0)
1071 ProjectConfig config = prj.config;
1072 if(!prj.GetConfigIsInDebugSession(config) ||
1073 (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
1075 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1077 ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
1079 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
1080 ide.AdjustBuildMenus();
1081 ide.AdjustDebugMenus();
1083 prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
1084 buildInProgress = none;
1085 ide.AdjustBuildMenus();
1086 ide.AdjustDebugMenus();
1094 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1096 Project prj = project;
1097 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1098 ShowOutputBuildLog(true);
1099 if(selection || !ide.activeClient)
1101 DataRow row = fileList.currentRow;
1102 ProjectNode node = row ? (ProjectNode)row.tag : null;
1108 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
1113 DisplayCompiler(compiler, false);
1114 ProjectPrepareCompiler(project, compiler, false);
1115 ProjectPrepareMakefile(prj, force, compiler, prj.config);
1120 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1123 char fileName[MAX_LOCATION];
1125 ProjectConfig config = project.config;
1129 for(document = ide.firstChild; document; document = document.next)
1131 if(document.modifiedDocument)
1133 ProjectNode n = GetNodeFromWindow(document, project, true, mode == cObject ? true : false, null);
1136 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1138 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1148 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1149 int bitDepth = ide.workspace.bitDepth;
1151 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1154 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1155 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name, config.name);
1157 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1158 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name);
1160 buildInProgress = compilingFile;
1161 ide.AdjustBuildMenus();
1162 result = project.Compile(nodes, compiler, config, bitDepth, justPrint, mode);
1163 buildInProgress = none;
1164 ide.AdjustBuildMenus();
1171 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1174 char fileName[MAX_LOCATION];
1176 ProjectConfig config = project.config;
1180 for(document = ide.firstChild; document; document = document.next)
1182 if(document.modifiedDocument)
1184 ProjectNode n = GetNodeFromWindow(document, project, true, false, null);
1187 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1189 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1199 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1200 int bitDepth = ide.workspace.bitDepth;
1202 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1204 Map<String, NameCollisionInfo> namesInfo { };
1205 project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1208 if(node.GetIsExcluded(config))
1209 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1213 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s using the %s configuration...\n",
1214 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1216 ide.outputView.buildBox.Logf($"Deleting intermediate objects for %s %s in project %s...\n",
1217 node.type == file ? $"single file" : $"folder", node.name, project.name);
1219 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, false);
1231 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1233 DataRow row = fileList.currentRow;
1236 char fileName[1024];
1237 char filePath[MAX_LOCATION];
1238 ProjectNode parentNode = (ProjectNode)row.tag;
1239 ProjectNode n, fileNode;
1240 parentNode.GetFileSysMatchingPath(filePath);
1241 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1242 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1243 sprintf(fileName, $"Untitled %d", documentID);
1244 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1245 fileNode.path = CopyUnixPath(filePath);
1248 NodeProperties nodeProperties
1251 position = { position.x + 100, position.y + 100 };
1255 nodeProperties.Create(); // not modal?
1261 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1263 DataRow row = fileList.currentRow;
1266 ProjectNode parentNode = (ProjectNode)row.tag;
1267 NewFolder(parentNode, null, true);
1272 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1278 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1284 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1286 DataRow row = fileList.currentRow;
1289 ProjectNode toNode = (ProjectNode)row.tag;
1290 ImportFolder(toNode);
1295 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1297 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1298 codeEditor.EnsureUpToDate();
1302 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1304 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1306 codeEditor.EnsureUpToDate();
1310 bool ProjectRemove(MenuItem selection, Modifiers mods)
1312 DataRow row = fileList.currentRow;
1315 ProjectNode node = (ProjectNode)row.tag;
1316 if(node.type == project)
1317 RemoveSelectedNodes();
1322 bool ProjectUpdateMakefileForAllConfigs(Project project)
1324 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1326 // This call really does not belong here:
1327 ide.UpdateToolBarActiveConfigs(false);
1328 for(config : project.configurations)
1329 ProjectPrepareMakefile(project, forceExists, compiler, config);
1336 bool MenuSettings(MenuItem selection, Modifiers mods)
1338 ProjectNode node = GetSelectedNode(true);
1339 Project prj = node ? node.project : project;
1340 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1341 incref projectSettingsDialog;
1342 projectSettingsDialog.Modal();
1343 delete projectSettingsDialog;
1344 ide.UpdateToolBarActiveConfigs(false);
1350 bool FileProperties(MenuItem selection, Modifiers mods)
1352 DataRow row = fileList.currentRow;
1355 ProjectNode node = (ProjectNode)row.tag;
1356 NodeProperties { parent = parent, master = this, node = node,
1357 position = { position.x + 100, position.y + 100 } }.Create();
1362 bool FileOpenFile(MenuItem selection, Modifiers mods)
1364 OpenSelectedNodes(mods.ctrl && mods.shift);
1368 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1370 RemoveSelectedNodes();
1374 bool FileCompile(MenuItem selection, Modifiers mods)
1377 OldList selectedRows;
1378 Project project = null;
1379 List<ProjectNode> nodes { };
1380 fileList.GetMultiSelection(selectedRows);
1381 for(item = selectedRows.first; item; item = item.next)
1384 DataRow row = item.data;
1385 ProjectNode node = (ProjectNode)row.tag;
1387 project = node.project;
1388 else if(node.project != project)
1395 selectedRows.Free(null);
1397 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1399 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1404 bool FileClean(MenuItem selection, Modifiers mods)
1407 OldList selectedRows;
1408 Project project = null;
1409 List<ProjectNode> nodes { };
1410 fileList.GetMultiSelection(selectedRows);
1411 for(item = selectedRows.first; item; item = item.next)
1414 DataRow row = item.data;
1415 ProjectNode node = (ProjectNode)row.tag;
1417 project = node.project;
1418 else if(node.project != project)
1425 selectedRows.Free(null);
1427 Clean(project, nodes, mods.ctrl && mods.shift);
1429 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1434 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1436 DataRow row = fileList.currentRow;
1437 ProjectNode node = row ? (ProjectNode)row.tag : null;
1440 List<ProjectNode> nodes { };
1442 if(node.type == project)
1443 ProjectBuild(selection, mods);
1446 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1452 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1454 DataRow row = fileList.currentRow;
1455 ProjectNode node = row ? (ProjectNode)row.tag : null;
1458 List<ProjectNode> nodes { };
1460 if(node.type == project)
1461 ProjectBuild(selection, mods);
1463 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1465 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1471 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1473 DataRow row = fileList.currentRow;
1474 ProjectNode node = row ? (ProjectNode)row.tag : null;
1477 List<ProjectNode> nodes { };
1479 if(node.type == project)
1480 ProjectBuild(selection, mods);
1482 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1484 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1490 Project GetSelectedProject(bool useSelection)
1492 Project prj = project;
1495 DataRow row = fileList.currentRow;
1496 ProjectNode node = row ? (ProjectNode)row.tag : null;
1503 void SelectNextProject(bool backwards)
1505 DataRow row = fileList.currentRow;
1506 DataRow currentRow = row;
1507 ProjectNode node = (ProjectNode)row.tag;
1508 if(node.type != project)
1509 row = node.project.topNode.row;
1511 row = row.previous ? row.previous : fileList.lastRow;
1513 row = row.next ? row.next : fileList.firstRow;
1514 if(row && row != currentRow)
1516 fileList.SelectRow(row);
1517 fileList.currentRow = row;
1521 ProjectNode GetSelectedNode(bool useSelection)
1523 ProjectNode node = null;
1526 DataRow row = fileList.currentRow;
1528 node = (ProjectNode)row.tag;
1533 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1535 char folder[MAX_LOCATION];
1537 ProjectNode node = GetSelectedNode(true);
1539 node = project.topNode;
1542 strcpy(folder, prj.topNode.path);
1543 if(node != prj.topNode)
1544 PathCatSlash(folder, node.path);
1549 bool Run(MenuItem selection, Modifiers mods)
1551 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1552 ProjectConfig config = project.config;
1553 int bitDepth = ide.workspace.bitDepth;
1554 String args = new char[maxPathLen];
1556 if(ide.workspace.commandLineArgs)
1557 //ide.debugger.GetCommandLineArgs(args);
1558 strcpy(args, ide.workspace.commandLineArgs);
1559 if(ide.debugger.isActive)
1560 project.Run(args, compiler, config, bitDepth);
1561 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1562 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1563 else if(BuildInterrim(project, run, compiler, config, bitDepth, false))
1564 project.Run(args, compiler, config, bitDepth);
1572 bool result = false;
1573 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1574 ProjectConfig config = project.config;
1575 int bitDepth = ide.workspace.bitDepth;
1576 bool useValgrind = ide.workspace.useValgrind;
1577 TargetTypes targetType = project.GetTargetType(config);
1578 if(targetType == sharedLibrary || targetType == staticLibrary)
1579 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1580 else if(project.GetCompress(config))
1581 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1582 else if(project.GetDebug(config) ||
1583 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1585 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, bitDepth, false))
1587 if(compiler.type.isVC)
1589 //bool result = false;
1590 char oldwd[MAX_LOCATION];
1591 PathBackup pathBackup { };
1592 char command[MAX_LOCATION];
1594 ide.SetPath(false, compiler, config, bitDepth);
1596 GetWorkingDir(oldwd, sizeof(oldwd));
1597 ChangeWorkingDir(project.topNode.path);
1599 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1601 ChangeWorkingDir(oldwd);
1607 ide.debugger.Start(compiler, config, bitDepth, useValgrind);
1616 void GoToError(const char * line, const bool noParsing)
1620 while(isspace(*line)) line++;
1621 colon = strstr(line, ":");
1626 bool lookForLineNumber = true;
1628 // deal with linking error
1629 if(colon && colon[1] == ' ')
1631 colon = strstr(colon + 1, ":");
1632 if(colon && !colon[1])
1634 colon = strstr(line, ":");
1635 lookForLineNumber = false;
1637 else if(colon && !isdigit(colon[1]))
1640 colon = strstr(line, ":");
1643 // Don't be mistaken by the drive letter colon
1644 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1645 colon = strstr(colon + 1, ":");
1646 if(colon && lookForLineNumber)
1649 #if 0 // MSVS Errors -- todo fix this later
1650 char * par = RSearchString(line, "(", colon - line, true, false);
1651 if(par && strstr(par, ")"))
1653 else if((colon+1)[0] == ' ')
1655 // NOTE: This is the same thing as saying 'colon = line'
1656 for( ; colon != line; colon--)
1661 lineNumber = atoi(colon + 1);
1663 comma = strchr(colon, ',');
1665 col = atoi(comma+1);
1667 comma = strchr(colon+1, ':');
1669 col = atoi(comma+1);
1673 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION] = "";
1674 char ext[MAX_EXTENSION] = "";
1676 ProjectNode node = null;
1679 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1680 char * from = strstr(line, "from ");
1681 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
1685 len = Min((int)(colon - start), MAX_LOCATION-1);
1687 strncpy(moduleName, start, len);
1688 moduleName[len] = '\0';
1691 strcpy(moduleName, line);
1696 if((msg = strstr(moduleName, " - ")))
1700 for(prj : ide.workspace.projects)
1702 strcpy(filePath, prj.topNode.path);
1703 PathCatSlash(filePath, moduleName);
1704 if(FileExists(filePath).isFile)
1716 else if((msg = strstr(moduleName, "...")) && (colon = strchr(moduleName, ' ')) && (++colon)[0])
1720 for(prj : ide.workspace.projects)
1722 if((node = prj.resNode.Find(colon, true)))
1724 strcpy(filePath, prj.topNode.path);
1725 PathCatSlash(filePath, node.path);
1726 PathCatSlash(filePath, node.name);
1740 // Remove stuff in brackets
1742 bracket = strstr(moduleName, "(");
1743 if(bracket) *bracket = '\0';
1745 MakeSlashPath(moduleName);
1746 GetExtension(moduleName, ext);
1748 if(!colon && !filePath[0])
1750 // Check if it's one of our modules
1751 node = project.topNode.Find(moduleName, false);
1754 strcpy(filePath, node.path);
1755 PathCatSlash(filePath, node.name);
1759 char ext[MAX_EXTENSION];
1760 GetExtension(fileName, ext);
1762 DotMain dotMain = DotMain::FromFileName(moduleName);
1763 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
1764 ProjectConfig config = null;
1767 for(prj : ide.workspace.projects; prj.lastBuildConfigName)
1769 if((config = prj.GetConfig(prj.lastBuildConfigName)))
1770 node = prj.FindNodeByObjectFileName(moduleName, type, dotMain, config);
1777 char name[MAX_FILENAME];
1778 Project project = node.project;
1779 CompilerConfig compiler = ideSettings.GetCompilerConfig(project.lastBuildCompilerName);
1782 int bitDepth = ide.workspace.bitDepth;
1783 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
1784 strcpy(filePath, project.topNode.path);
1785 PathCatSlash(filePath, objDir.dir);
1786 node.GetObjectFileName(name, project.configsNameCollisions[config ? config.name : ""], type, dotMain);
1787 PathCatSlash(filePath, name);
1797 if(!strcmp(ext, "a") || !strcmp(ext, "o") || !strcmp(ext, "lib") ||
1798 !strcmp(ext, "dll") || !strcmp(ext, "exe") || !strcmp(ext, "mo"))
1799 moduleName[0] = 0; // Avoid opening binary files
1802 CodeEditor codeEditor;
1805 strcpy(filePath, project.topNode.path);
1806 PathCatSlash(filePath, moduleName);
1809 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1810 if(!codeEditor && !strcmp(ext, "c"))
1812 char ecName[MAX_LOCATION];
1813 ChangeExtension(filePath, "ec", ecName);
1814 codeEditor = (CodeEditor)ide.OpenFile(ecName, normal, true, null, no, normal, noParsing);
1818 char path[MAX_LOCATION];
1819 // TOFIX: Improve on this, don't use only filename, make a function
1820 if(ide && ide.workspace)
1822 for(prj : ide.workspace.projects)
1825 MakePathRelative(filePath, prj.topNode.path, path);
1827 if((node = prj.topNode.FindWithPath(path, false)))
1829 strcpy(filePath, prj.topNode.path);
1830 PathCatSlash(filePath, node.path);
1831 PathCatSlash(filePath, node.name);
1832 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1837 if(!codeEditor && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1839 for(prj : ide.workspace.projects)
1842 if((node = prj.topNode.Find(moduleName, false)))
1844 strcpy(filePath, prj.topNode.path);
1845 PathCatSlash(filePath, node.path);
1846 PathCatSlash(filePath, node.name);
1847 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
1855 if(codeEditor && lineNumber)
1857 EditBox editBox = codeEditor.editBox;
1858 editBox.GoToLineNum(lineNumber - 1);
1859 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1866 bool OpenNode(ProjectNode node, bool noParsing)
1868 char filePath[MAX_LOCATION];
1869 node.GetFullFilePath(filePath);
1870 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal, noParsing) ? true : false;
1873 void AddNode(ProjectNode node, DataRow addTo)
1875 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1877 row.tag = (int64)node;
1880 if(node.type == resources)
1883 row.SetData(null, node);
1885 if(node.files && node.files.first && node.parent &&
1886 !(!node.parent.parent &&
1887 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1888 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1889 row.collapsed = true;
1890 else if(node.type == folder)
1891 node.icon = openFolder;
1895 for(child : node.files)
1896 AddNode(child, row);
1900 void DeleteNode(ProjectNode projectNode)
1902 if(projectNode.files)
1905 while(child = projectNode.files.first)
1908 fileList.DeleteRow(projectNode.row);
1909 projectNode.Delete();
1912 bool ProjectSave(MenuItem selection, Modifiers mods)
1914 DataRow row = fileList.currentRow;
1915 ProjectNode node = row ? (ProjectNode)row.tag : null;
1916 Project prj = node ? node.project : null;
1919 prj.StopMonitoring();
1920 if(prj.Save(prj.filePath))
1922 Project modPrj = null;
1923 prj.topNode.modified = false;
1924 for(p : ide.workspace.projects)
1926 if(p.topNode.modified)
1933 modifiedDocument = false;
1936 prj.StartMonitoring();
1941 bool ShowOutputBuildLog(bool cleanLog)
1943 OutputView output = ide.outputView;
1945 output.ShowClearSelectTab(build);
1948 output.SelectTab(build);
1956 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1957 ProjectConfig config = project.config;
1958 int bitDepth = ide.workspace.bitDepth;
1959 bool useValgrind = ide.workspace.useValgrind;
1961 bool result = false;
1962 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, bitDepth, false))
1964 // For Restart, compiler and config will only be used if for
1965 // whatever reason (if at all possible) the Debugger is in a
1966 // 'terminated' or 'none' state
1967 ide.debugger.Restart(compiler, config, bitDepth, useValgrind);
1977 ide.debugger.Resume();
1983 ide.debugger.Break();
1989 ide.debugger.Stop();
1993 bool DebugStepInto()
1995 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1996 ProjectConfig config = project.config;
1997 int bitDepth = ide.workspace.bitDepth;
1998 bool useValgrind = ide.workspace.useValgrind;
2000 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2001 ide.debugger.StepInto(compiler, config, bitDepth, useValgrind);
2006 bool DebugStepOver(bool skip)
2008 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2009 ProjectConfig config = project.config;
2010 int bitDepth = ide.workspace.bitDepth;
2011 bool useValgrind = ide.workspace.useValgrind;
2013 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2014 ide.debugger.StepOver(compiler, config, bitDepth, useValgrind, skip);
2020 bool DebugStepUntil(bool skip)
2022 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2023 ProjectConfig config = project.config;
2024 int bitDepth = ide.workspace.bitDepth;
2025 bool useValgrind = ide.workspace.useValgrind;
2027 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
2028 ide.debugger.StepUntil(compiler, config, bitDepth, useValgrind, skip);
2034 bool DebugStepOut(bool skip)
2036 ide.debugger.StepOut(skip);
2040 void ImportFolder(ProjectNode toNode)
2044 //bool isFolder = toNode.type == folder;
2045 //bool isRes = toNode.isInResources;
2047 FileDialog fileDialog = importFileDialog;
2048 fileDialog.master = parent;
2049 if(fileDialog.Modal() == ok)
2051 ImportFolderFSI fsi { projectView = this };
2052 fsi.stack.Add(toNode);
2053 fsi.Iterate(fileDialog.filePath);
2059 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
2063 ProjectNode folderNode;
2064 Project prj = parentNode.project;
2066 ProjectNode after = null;
2067 for(node : parentNode.files)
2069 if(node.type != folder)
2075 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
2078 for(c = 0; c < 100; c++)
2081 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
2082 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
2089 NodeProperties nodeProperties;
2092 modifiedDocument = true;
2093 prj.topNode.modified = true;
2096 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2097 folderNode.row.tag = (int64)folderNode;
2099 folderNode.row.SetData(null, folderNode);
2100 fileList.currentRow = folderNode.row;
2104 nodeProperties = NodeProperties
2106 parent, this, mode = newFolder, node = folderNode;
2107 position = { position.x + 100, position.y + 100 };
2109 nodeProperties.Create(); // Modal?
2117 void AddFiles(bool resources)
2119 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
2120 fileDialog.type = multiOpen;
2121 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
2122 fileDialog.master = parent;
2124 if(fileDialog.Modal() == ok)
2127 DataRow row = fileList.currentRow;
2128 ProjectNode parentNode = (ProjectNode)row.tag;
2129 bool addFailed = false;
2130 int numSelections = fileDialog.numSelections;
2131 char ** multiFilePaths = fileDialog.multiFilePaths;
2133 Array<String> nameConflictFiles { };
2135 for(c = 0; c < numSelections; c++)
2137 char * filePath = multiFilePaths[c];
2138 FileAttribs exists = FileExists(filePath);
2139 bool addThisFile = true;
2141 if(exists.isDirectory)
2142 addThisFile = false;
2145 if(MessageBox { master = ide, type = yesNo, text = filePath,
2146 contents = $"File doesn't exist. Create?" }.Modal() == yes)
2148 File f = FileOpen(filePath, write);
2156 MessageBox { master = ide, type = ok, text = filePath,
2157 contents = $"Couldn't create file."}.Modal();
2158 addThisFile = false;
2165 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
2167 nameConflictFiles.Add(CopyString(filePath));
2175 char * part1 = $"The following file";
2176 char * opt1 = $" was ";
2177 char * opt2 = $"s were ";
2178 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
2180 len += strlen(part1);
2181 len += strlen(part2);
2182 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
2183 for(s : nameConflictFiles)
2184 len += strlen(s) + 1;
2185 message = new char[len + 1];
2186 strcpy(message, part1);
2187 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
2188 strcat(message, part2);
2189 for(s : nameConflictFiles)
2192 strcat(message, "\n");
2194 MessageBox { master = ide, type = ok, text = $"Name Conflict",
2195 contents = message }.Modal();
2198 nameConflictFiles.Free();
2199 delete nameConflictFiles;
2203 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
2205 ProjectNode result = null;
2206 ProjectNode after = null;
2207 for(node : parentNode.files)
2209 if(node.type != folder && node.type != file && node.type)
2214 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
2220 modifiedDocument = true;
2221 parentNode.project.topNode.modified = true;
2222 parentNode.project.ModifiedAllConfigs(true, false, true, true);
2225 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
2226 result.row.tag = (int64)result;
2227 result.row.SetData(null, result);
2232 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
2234 CodeEditor codeEditor = null;
2235 ProjectNode projectNode;
2236 ProjectNode after = null;
2237 DataRow row = fileList.currentRow;
2238 ProjectNode parentNode;
2241 if(!row) row = project.topNode.row;
2243 parentNode = (ProjectNode)row.tag;
2245 for(node : parentNode.files)
2247 if(node.type != folder && node.type != file && node.type)
2251 for(c = 1; c < 100; c++)
2254 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
2255 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
2261 char filePath[MAX_LOCATION];
2263 modifiedDocument = true;
2264 project.topNode.modified = true;
2266 project.ModifiedAllConfigs(true, false, false, true);
2267 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2268 projectNode.row.tag =(int64)projectNode;
2270 projectNode.row.SetData(null, projectNode);
2271 fileList.currentRow = projectNode.row;
2273 strcpy(filePath, project.topNode.path);
2274 PathCat(filePath, projectNode.path);
2275 PathCat(filePath, projectNode.name);
2277 codeEditor = (CodeEditor)ide.FindWindow(filePath);
2280 Class baseClass = eSystem_FindClass(__thisModule, base);
2281 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
2284 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
2285 strcpy(name, projectNode.name);
2286 sprintf(name, "%s%d", upper, c);
2288 strcpy(className, name);
2290 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2292 //codeEditor.modifiedDocument = false;
2293 //codeEditor.designer.modifiedDocument = false;
2295 //Code_EnsureUpToDate(codeEditor);
2298 else // TODO: fix no symbols generated when ommiting {} for following else
2300 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
2302 ide.sheet.visible = true;
2303 ide.sheet.Activate();
2306 codeEditor.ViewDesigner();
2307 codeEditor.codeModified = true;
2314 // Returns true if we opened something
2315 bool OpenSelectedNodes(bool noParsing)
2317 bool result = false;
2321 fileList.GetMultiSelection(selection);
2322 for(item = selection.first; item; item = item.next)
2324 DataRow row = item.data;
2325 ProjectNode node = (ProjectNode)row.tag;
2326 if(node.type == file)
2328 OpenNode(node, noParsing);
2332 selection.Free(null);
2333 ide.RepositionWindows(false);
2337 void RemoveSelectedNodes()
2342 fileList.GetMultiSelection(selection);
2344 // Remove children of parents we're deleting
2345 for(item = selection.first; item; item = next)
2348 DataRow row = item.data;
2349 ProjectNode n, node = (ProjectNode)row.tag;
2350 bool remove = false;
2353 for(i = selection.first; i && !remove; i = i.next)
2355 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2356 for(n = node.parent; n; n = n.parent)
2366 selection.Delete(item);
2369 for(item = selection.first; item; item = item.next)
2371 DataRow row = item.data;
2372 ProjectNode node = (ProjectNode)row.tag;
2373 ProjectNode resNode;
2374 for(resNode = node.parent; resNode; resNode = resNode.parent)
2375 if(resNode.type == resources)
2377 if(node.type == file)
2379 Project prj = node.project;
2381 modifiedDocument = true;
2382 prj.topNode.modified = true;
2384 prj.ModifiedAllConfigs(true, false, true, true);
2386 else if(node.type == folder)
2389 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2390 "and all of its contents from the project?", node.name);
2391 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2393 Project prj = node.project;
2394 if(node.containsFile)
2395 prj.ModifiedAllConfigs(true, false, true, true);
2397 modifiedDocument = true;
2398 prj.topNode.modified = true;
2401 else if(node.type == project && node != project.topNode && !buildInProgress)
2405 for(p : workspace.projects)
2407 if(p.topNode == node)
2413 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2414 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2419 workspace.RemoveProject(prj);
2420 //modifiedDocument = true; // when project view is a workspace view
2424 selection.Free(null);