3 import "FileSystemIterator"
5 class ImportFolderFSI : NormalFileSystemIterator
7 ProjectView projectView;
8 Array<ProjectNode> stack { };
10 bool OnFolder(char * folderPath)
12 char name[MAX_LOCATION];
13 ProjectNode parentNode = stack.lastIterator.data;
15 GetLastDirectory(folderPath, name);
16 folder = parentNode.FindSpecial(name, false, true, true);
18 folder = projectView.NewFolder(parentNode, name, false);
23 void OutFolder(char * folderPath, bool isRoot)
25 stack.lastIterator.Remove(); //stack.Remove();
28 bool OnFile(char * filePath)
30 ProjectNode parentNode = stack.lastIterator.data;
31 projectView.AddFile(parentNode, filePath, parentNode.isInResources, false);
36 static Array<FileFilter> fileFilters
38 { $"eC/C/C++ Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
39 { $"eC/C/C++ Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, eh, c, cpp, cc, cxx" },
40 { $"Header Files for eC/C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
41 { $"All files", null }
44 static Array<FileFilter> resourceFilters
46 { $"Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png,*.gif)", "jpg, jpeg, bmp, pcx, png, gif" },
47 { $"3D Studio Model Files (*.3ds)", "3ds" },
48 { $"Translations (*.mo)", "mo" },
49 { $"All files", null }
52 static Array<FileFilter> projectFilters
54 { $"Project Files (*.epj)", ProjectExtension },
55 { $"Workspace Files (*.ews)", WorkspaceExtension }
58 static Array<FileType> projectTypes
60 { $"Ecere IDE Project", ProjectExtension },
61 { $"Ecere IDE Workspace", WorkspaceExtension }
64 static char * iconNames[] =
66 "<:ecere>mimeTypes/file.png", /*genFile*/
67 "<:ecere>mimeTypes/textEcereWorkspace.png", /*ewsFile*/
68 "<:ecere>mimeTypes/textEcereProject.png", /*epjFile*/
69 "<:ecere>places/folder.png", /*folder*/
70 "<:ecere>status/folderOpen.png", /*openFolder*/
71 "<:ecere>mimeTypes/textEcereSource.png", /*ecFile*/
72 "<:ecere>mimeTypes/textEcereHeader.png", /*ehFile*/
73 "<:ecere>mimeTypes/textCSource.png", /*sFile*/ // TODO: change sFile icon to differentiate from cFile icon
74 "<:ecere>mimeTypes/textCSource.png", /*cFile*/
75 "<:ecere>mimeTypes/textCHeader.png", /*hFile*/
76 "<:ecere>mimeTypes/textC++Source.png", /*cppFile*/
77 "<:ecere>mimeTypes/textC++Header.png", /*hppFile*/
78 "<:ecere>mimeTypes/text.png", /*textFile*/
79 "<:ecere>mimeTypes/textHyperTextMarkup.png", /*webFile*/
80 "<:ecere>mimeTypes/image.png", /*pictureFile*/
81 "<:ecere>status/audioVolumeHigh.png", /*soundFile*/
82 "<:ecere>mimeTypes/package.png", /*archiveFile*/
83 "<:ecere>mimeTypes/packageSoftware.png", /*packageFile*/
84 "<:ecere>mimeTypes/packageOpticalDisc.png", /*opticalMediaImageFile*/
85 "<:ecere>mimeTypes/file.png", /*mFile*/ //TODO: create icon for .m file
86 "<:ecere>mimeTypes/file.png" /*mmFile*/ //TODO: create icon for .mm file
89 enum PrepareMakefileMethod { normal, force, forceExists };
91 enum CleanType { clean, realClean, cleanTarget };
92 enum BuildType { build, rebuild, relink, run, start, restart, clean };
95 none, buildingMainProject, buildingSecondaryProject, compilingFile;
97 property bool { get { return this != none; } }
98 //property bool actualBuild { get { return this == buildingMainProject || this == buildingSecondaryProject; } }
101 class ProjectView : Window
104 //hasMinimize = true;
106 borderStyle = sizable;
107 hasHorzScroll = true;
108 hasVertScroll = true;
111 anchor = Anchor { left = 0, top = 0, bottom = 0 };
114 //hasMinimize = true;
115 saveDialog = projectFileDialog;
118 BuildState buildInProgress;
119 BitmapResource icons[NodeIcons];
122 property Workspace workspace
128 for(prj : workspace.projects)
130 DeleteNode(prj.topNode);
132 workspace.projects.Free();
133 ide.debugger.CleanUp();
138 fileDialog.currentDirectory = workspace.workspaceDir;
139 resourceFileDialog.currentDirectory = workspace.workspaceDir;
140 for(prj : workspace.projects)
141 AddNode(prj.topNode, null);
142 ide.statusBar.text = $"Generating Makefile & Dependencies...";
144 for(prj : workspace.projects)
145 prj.ModifiedAllConfigs(true, false, false, false);
146 ide.statusBar.text = $"Initializing Debugger"; app.UpdateDisplay();
147 ide.statusBar.text = null;
151 get { return workspace; }
154 bool drawingInProjectSettingsDialog;
155 bool drawingInProjectSettingsDialogHeader;
156 ProjectSettings projectSettingsDialog;
164 for(c = 0; c < NodeIcons::enumSize; c++)
166 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
167 AddResource(icons[c]);
169 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
175 ide.DestroyTemporaryProjectDir();
185 multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
186 borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
187 anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
189 background = projectViewBackground;
190 foreground = projectViewText;
191 selectionColor = selectionColor, selectionText = selectionText;
192 stippleColor = skyBlue;
194 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
196 if(!active) Update(null);
197 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
200 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
202 // Prevent the double click from reactivating the project view (returns false if we opened something)
203 return !OpenSelectedNodes();
206 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
208 DataRow row = listBox.currentRow;
211 bool showDebuggingMenuItems = mods.ctrl && mods.shift;
212 ProjectNode node = (ProjectNode)row.tag;
213 if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
215 bool na = buildInProgress; // N/A - buildMenuUnavailable
218 if(node.type == NodeTypes::project)
221 mi = ide.projectBuildItem;
222 MenuItem { pop, $"Build" , b, f7 , NotifySelect = ProjectBuild , bitmap = mi.bitmap }.disabled = na; mi = ide.projectLinkItem;
223 MenuItem { pop, $"Relink" , l , NotifySelect = ProjectLink , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRebuildItem;
224 MenuItem { pop, $"Rebuild" , r, shiftF7, NotifySelect = ProjectRebuild , bitmap = mi.bitmap }.disabled = na; mi = ide.projectCleanTargetItem;
225 MenuItem { pop, $"Clean Target" , g , NotifySelect = ProjectCleanTarget, bitmap = mi.bitmap }.disabled = na; mi = ide.projectCleanItem;
226 MenuItem { pop, $"Clean" , c , NotifySelect = ProjectClean , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRealCleanItem;
227 MenuItem { pop, $"Real Clean" , NotifySelect = ProjectRealClean , bitmap = mi.bitmap }.disabled = na; mi = ide.projectRegenerateItem;
228 MenuItem { pop, $"Regenerate Makefile", m , NotifySelect = ProjectRegenerate , bitmap = mi.bitmap }.disabled = na;
230 if(showDebuggingMenuItems && node.ContainsFilesWithExtension("ec"))
233 MenuItem { pop, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = na;
234 MenuItem { pop, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = na;
235 MenuItem { pop, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = na;
238 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
239 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
240 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
241 MenuItem { pop, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
243 MenuItem { pop, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
244 // MenuItem { pop, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
246 if(node != ((Project)workspace.projects.first).topNode)
248 MenuItem { pop, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = na;
251 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
253 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
255 MenuItem { pop, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
257 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
259 else if(node.type == resources)
261 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
262 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
263 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
264 MenuItem { pop, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
265 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
267 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
268 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
270 else if(node.type == file)
272 MenuItem { pop, $"Open", o, NotifySelect = FileOpenFile };
274 MenuItem { pop, $"Clean", l, NotifySelect = FileClean, bitmap = ide.projectCleanItem.bitmap }.disabled = na;
275 MenuItem { pop, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile, bitmap = ide.projectBuildItem.bitmap }.disabled = na;
276 if(showDebuggingMenuItems)
278 char extension[MAX_EXTENSION];
279 GetExtension(node.name, extension);
280 if(!strcmpi(extension, "ec"))
283 MenuItem { pop, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = na;
284 MenuItem { pop, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = na;
288 MenuItem { pop, $"Remove", r, NotifySelect = FileRemoveFile };
290 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
292 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
293 MenuItem { pop, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
295 else if(node.type == folder)
297 bool isInResources = node.isInResources;
299 MenuItem { pop, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
300 MenuItem { pop, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
301 MenuItem { pop, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
304 MenuItem { pop, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
308 MenuItem { pop, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
313 MenuItem { pop, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
314 // MenuItem { pop, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
317 MenuItem { pop, $"Clean", l, NotifySelect = FileClean, bitmap = ide.projectCleanItem.bitmap }.disabled = na;
318 MenuItem { pop, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile, bitmap = ide.projectBuildItem.bitmap }.disabled = na;
320 MenuItem { pop, $"Remove", r, NotifySelect = FileRemoveFile };
322 MenuItem { pop, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
324 MenuItem { pop, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
325 MenuItem { pop, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
330 master = this, menu = pop;
332 x + clientStart.x + absPosition.x - app.desktop.position.x,
333 y + clientStart.y + absPosition.y - app.desktop.position.y };
335 void NotifyDestroyed(Window window, DialogResult result)
341 ide.AdjustPopupBuildMenus();
347 bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
349 if(key == altUp || key == altDown)
351 SelectNextProject(key == altUp);
357 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
361 ProjectNode node = (ProjectNode)row.tag;
364 case altEnter: case Key { keyPadEnter, alt = true }:
366 NodeProperties { parent = parent, master = this,
367 position = { position.x + 100, position.y + 100 }, node = node }.Create();
370 case enter: case keyPadEnter:
373 for(resNode = node.parent; resNode; resNode = resNode.parent)
374 if(resNode.type == resources)
376 if(node.type == project || (node.type == folder && !resNode))
381 else if(node.type == resources || node.type == folder)
390 if(node.type == project || node.type == folder || node.type == resources)
399 if(node.type == project || node.type == folder || node.type == resources)
401 NewFolder(node, null, true);
408 if(node.type == file)
410 FileCompile(null, (Modifiers)key);
415 case Key { space, shift = true }:
418 if(node.type == NodeTypes::project)
421 for(p : workspace.projects)
423 if(p.topNode == node)
429 prj.RotateActiveConfig(!key.shift);
440 case enter: case keyPadEnter: OpenSelectedNodes(); break;
441 case del: RemoveSelectedNodes(); break;
444 Window activeClient = ide.activeClient;
446 activeClient.Activate();
448 ide.RepositionWindows(true);
455 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
457 ProjectNode node = (ProjectNode)row.tag;
458 if(node.type == folder)
459 node.icon = collapsed ? folder : openFolder;
464 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
465 FileDialog projectFileDialog
467 autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
468 types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
470 FileDialog fileDialog
472 autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
474 FileDialog resourceFileDialog
476 autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
479 Menu fileMenu { menu, $"File", f };
480 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
481 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
483 bool OnClose(bool parentClosing)
485 if(!parentClosing && visible)
495 DialogResult dialogRes;
498 strcpy(msg, $"You have modified projects.\nSave changes to ");
499 for(p : ide.workspace.projects)
501 if(p.topNode.modified)
503 if(!first) strcat(msg, ", ");
510 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
514 // TOFIX: Precomp error if brackets are taken out
515 return (DialogResult)MenuFileSave(null, 0) != cancel;
517 else if(dialogRes == cancel)
519 modifiedDocument = false;
526 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
527 // ide.findInFilesDialog.SearchStop();
529 ide.outputView.buildBox.Clear();
530 ide.outputView.debugBox.Clear();
531 //ide.outputView.findBox.Clear();
532 ide.callStackView.Clear();
533 ide.watchesView.Clear();
534 ide.threadsView.Clear();
535 ide.breakpointsView.Clear();
536 ide.outputView.ShowClearSelectTab(find); // why this?
539 bool OnSaveFile(char * fileName)
541 for(prj : ide.workspace.projects)
543 if(prj.topNode.modified)
545 prj.StopMonitoring();
546 if(prj.Save(prj.filePath))
547 prj.topNode.modified = false;
548 prj.StartMonitoring();
551 modifiedDocument = false;
556 bool IsModuleInProject(char * filePath)
558 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
559 GetLastDirectory(filePath, moduleName);
560 return project.topNode.Find(moduleName, false) != null;
563 bool GetRelativePath(char * filePath, char * relativePath)
565 return project.GetRelativePath(filePath, relativePath);
568 ProjectNode GetNodeFromWindow(Window document, Project project, bool isCObject)
570 if(document.fileName)
572 char winFileName[MAX_LOCATION];
573 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
578 char name[MAX_FILENAME];
579 GetLastDirectory(documentFileName, name);
580 ChangeExtension(name, "ec", name);
581 for(p : ide.workspace.projects)
583 prj = project ? project : p;
584 if((node = prj.topNode.Find(name, false)))
591 for(p : ide.workspace.projects)
593 prj = project ? project : p;
594 if((node = prj.topNode.FindByFullPath(documentFileName, false)))
603 // ((( UTILITY FUNCTIONS )))
605 // ************************************************************************
606 // *** These methods below are part of a sequence of events, and as ***
607 // *** such they must be passed the current compiler and project config ***
608 // ************************************************************************
609 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
611 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
615 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
616 CompilerConfig compiler, ProjectConfig config)
619 char message[MAX_F_STRING];
620 LogBox logBox = ide.outputView.buildBox;
622 ShowOutputBuildLog(cleanLog);
625 DisplayCompiler(compiler, false);
627 ProjectPrepareCompiler(project, compiler, false);
628 ProjectPrepareMakefile(project, method, compiler, config);
632 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
634 if((!project.GenerateCrossPlatformMk(app.includeFile) || !project.GenerateCompilerCf(compiler)) && !silent)
635 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
639 // Note: Compiler is only passed in to for VisualStudio support
640 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
642 if(compiler.type.isVC)
644 // I'm guessing we'll want to support generating VS files on Linux as well...
645 ide.statusBar.text = $"Generating Visual Studio Solution...";
647 //GenerateVSSolutionFile(project, compiler);
648 ide.statusBar.text = $"Generating Visual Studio Project...";
650 //GenerateVCProjectFile(project, compiler, bitDepth);
651 ide.statusBar.text = null;
657 char makefilePath[MAX_LOCATION];
658 char makefileName[MAX_LOCATION];
660 LogBox logBox = ide.outputView.buildBox;
662 strcpy(makefilePath, project.topNode.path);
663 project.CatMakeFileName(makefileName, config);
664 PathCatSlash(makefilePath, makefileName);
666 exists = FileExists(makefilePath);
667 if(method == force ||
668 (method == forceExists && exists) ||
669 (method == normal && (!exists || (config && config.makingModified))))
673 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
676 if((method == normal && !exists) || (method == force && !exists))
677 action = $"Generating ";
678 else if(method == force)
679 action = $"Regenerating ";
680 else if(method == normal || method == forceExists)
681 action = $"Updating ";
685 reason = $"Makefile doesn't exist. ";
686 else if(project.topNode.modified)
687 reason = $"Project has been modified. ";
691 //logBox.Logf("%s\n", makefileName);
692 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
694 if(!project.GenerateMakefile(null, false, null, config))
695 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
697 ide.statusBar.text = null;
705 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
707 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
709 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
710 return Build(prj, buildType, compiler, config, bitDepth, justPrint);
715 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
718 // TOFIX: DebugStop is being abused and backfiring on us.
719 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
721 // configIsInDebugSession seems to be used for two OPPOSITE things:
722 // If we're debugging another config, we need to unload the executable!
723 // In building, we want to stop if we're debugging the 'same' executable
724 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
726 if(buildType == start || buildType == restart)
728 if(ide.debugger && ide.debugger.isPrepared)
729 result = DebugStop();
733 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
734 result = DebugStop();
740 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
746 for(document = master.firstChild; document; document = document.next)
748 if(document.modifiedDocument)
750 ProjectNode node = GetNodeFromWindow(document, prj, false);
751 if(node && !document.MenuFileSave(null, 0))
760 DirExpression targetDir = prj.GetTargetDir(compiler, config, bitDepth);
762 DebugStopForMake(prj, buildType, compiler, config);
764 // TODO: Disabled until problems fixed... is it fixed?
765 if(buildType == rebuild || (config && config.compilingModified))
766 prj.Clean(compiler, config, bitDepth, clean, justPrint);
769 if(buildType == relink || (config && config.linkingModified))
770 prj.Clean(compiler, config, bitDepth, cleanTarget, false);
771 if(config && config.symbolGenModified)
773 DirExpression objDir = prj.GetObjDir(compiler, config, bitDepth);
774 char fileName[MAX_LOCATION];
775 char moduleName[MAX_FILENAME];
776 strcpy(fileName, prj.topNode.path);
777 PathCatSlash(fileName, objDir.dir);
778 strcpy(moduleName, prj.moduleName);
779 strcat(moduleName, ".main.ec");
780 PathCatSlash(fileName, moduleName);
781 if(FileExists(fileName))
782 DeleteFile(fileName);
783 ChangeExtension(fileName, "c", fileName);
784 if(FileExists(fileName))
785 DeleteFile(fileName);
786 ChangeExtension(fileName, "o", fileName);
787 if(FileExists(fileName))
788 DeleteFile(fileName);
793 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
794 ide.AdjustBuildMenus();
795 ide.AdjustDebugMenus();
797 result = prj.Build(buildType == run, null, compiler, config, bitDepth, justPrint, normal);
801 config.compilingModified = false;
803 config.linkingModified = false;
805 config.symbolGenModified = false;
807 buildInProgress = none;
808 ide.AdjustBuildMenus();
809 ide.AdjustDebugMenus();
811 ide.workspace.modified = true;
818 // ((( USER ACTIONS )))
820 // ************************************************************************
821 // *** Methods below should atomically start a process, and as such ***
822 // *** they can query compiler and config directly from ide and project ***
823 // *** but ONLY ONCE!!! ***
824 // ************************************************************************
826 bool ProjectBuild(MenuItem selection, Modifiers mods)
828 if(buildInProgress == none)
830 Project prj = project;
831 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
832 int bitDepth = ide.workspace.bitDepth;
833 ProjectConfig config;
834 if(selection || !ide.activeClient)
836 DataRow row = fileList.currentRow;
837 ProjectNode node = row ? (ProjectNode)row.tag : null;
838 if(node) prj = node.project;
842 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
847 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
849 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
858 bool ProjectLink(MenuItem selection, Modifiers mods)
860 Project prj = project;
861 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
862 int bitDepth = ide.workspace.bitDepth;
863 ProjectConfig config;
864 if(selection || !ide.activeClient)
866 DataRow row = fileList.currentRow;
867 ProjectNode node = row ? (ProjectNode)row.tag : null;
868 if(node) prj = node.project;
872 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
877 if(!prj.GetConfigIsInDebugSession(config) ||
878 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
880 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
882 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
884 config.linkingModified = true;
885 Build(prj, relink, compiler, config, bitDepth, mods.ctrl && mods.shift);
892 bool ProjectRebuild(MenuItem selection, Modifiers mods)
894 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
895 int bitDepth = ide.workspace.bitDepth;
896 Project prj = project;
897 ProjectConfig config;
898 if(selection || !ide.activeClient)
900 DataRow row = fileList.currentRow;
901 ProjectNode node = row ? (ProjectNode)row.tag : null;
902 if(node) prj = node.project;
906 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
911 if(!prj.GetConfigIsInDebugSession(config) ||
912 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
914 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
916 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
919 config.compilingModified = true;
920 config.makingModified = true;
921 }*/ // -- should this still be used depite the new solution of BuildType?
922 Build(prj, rebuild, compiler, config, bitDepth, mods.ctrl && mods.shift);
929 bool ProjectCleanTarget(MenuItem selection, Modifiers mods)
931 CleanProject($"Project Clean Target", $"Cleaning project %s target using the %s configuration...\n", selection, cleanTarget, mods.ctrl && mods.shift);
935 bool ProjectClean(MenuItem selection, Modifiers mods)
937 CleanProject($"Project Clean", $"Cleaning project %s using the %s configuration...\n", selection, clean, mods.ctrl && mods.shift);
941 bool ProjectRealClean(MenuItem selection, Modifiers mods)
943 CleanProject($"Project Real Clean", $"Removing intermediate objects directory for project %s using the %s configuration...\n", selection, realClean, mods.ctrl && mods.shift);
947 void CleanProject(char * terminateDebugSessionMessage, char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
949 Project prj = project;
950 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
951 ProjectConfig config;
952 int bitDepth = ide.workspace.bitDepth;
953 if(selection || !ide.activeClient)
955 DataRow row = fileList.currentRow;
956 ProjectNode node = row ? (ProjectNode)row.tag : null;
957 if(node) prj = node.project;
961 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
962 if(node) prj = node.project;
965 if(!prj.GetConfigIsInDebugSession(config) ||
966 (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
968 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
970 ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
972 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
973 ide.AdjustBuildMenus();
974 ide.AdjustDebugMenus();
976 prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
977 buildInProgress = none;
978 ide.AdjustBuildMenus();
979 ide.AdjustDebugMenus();
985 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
987 Project prj = project;
988 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
989 ShowOutputBuildLog(true);
990 if(selection || !ide.activeClient)
992 DataRow row = fileList.currentRow;
993 ProjectNode node = row ? (ProjectNode)row.tag : null;
999 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
1004 DisplayCompiler(compiler, false);
1005 ProjectPrepareCompiler(project, compiler, false);
1006 ProjectPrepareMakefile(prj, force, compiler, prj.config);
1011 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1014 char fileName[MAX_LOCATION];
1016 ProjectConfig config = project.config;
1020 for(document = ide.firstChild; document; document = document.next)
1022 if(document.modifiedDocument)
1024 ProjectNode n = GetNodeFromWindow(document, project, mode == cObject ? true : false);
1027 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1029 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1039 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1040 int bitDepth = ide.workspace.bitDepth;
1042 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1045 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1046 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name, config.name);
1048 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1049 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name);
1051 buildInProgress = compilingFile;
1052 ide.AdjustBuildMenus();
1053 result = project.Compile(nodes, compiler, config, bitDepth, justPrint, mode);
1054 buildInProgress = none;
1055 ide.AdjustBuildMenus();
1062 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1065 char fileName[MAX_LOCATION];
1067 ProjectConfig config = project.config;
1071 for(document = ide.firstChild; document; document = document.next)
1073 if(document.modifiedDocument)
1075 ProjectNode n = GetNodeFromWindow(document, project, false);
1078 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1080 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1090 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1091 int bitDepth = ide.workspace.bitDepth;
1093 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1095 Map<String, NameCollisionInfo> namesInfo { };
1096 project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1099 if(node.GetIsExcluded(config))
1100 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1104 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s using the %s configuration...\n",
1105 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1107 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s...\n",
1108 node.type == file ? $"single file" : $"folder", node.name, project.name);
1110 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, false);
1122 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1124 DataRow row = fileList.currentRow;
1127 char fileName[1024];
1128 char filePath[MAX_LOCATION];
1129 ProjectNode parentNode = (ProjectNode)row.tag;
1130 ProjectNode n, fileNode;
1131 parentNode.GetFileSysMatchingPath(filePath);
1132 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1133 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1134 sprintf(fileName, $"Untitled %d", documentID);
1135 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1136 fileNode.path = CopyUnixPath(filePath);
1139 NodeProperties nodeProperties
1142 position = { position.x + 100, position.y + 100 };
1146 nodeProperties.Create(); // not modal?
1152 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1154 DataRow row = fileList.currentRow;
1157 ProjectNode parentNode = (ProjectNode)row.tag;
1158 NewFolder(parentNode, null, true);
1163 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1169 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1175 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1177 DataRow row = fileList.currentRow;
1180 ProjectNode toNode = (ProjectNode)row.tag;
1181 ImportFolder(toNode);
1186 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1188 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1189 codeEditor.EnsureUpToDate();
1193 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1195 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1197 codeEditor.EnsureUpToDate();
1201 bool ProjectRemove(MenuItem selection, Modifiers mods)
1203 DataRow row = fileList.currentRow;
1206 ProjectNode node = (ProjectNode)row.tag;
1207 if(node.type == project)
1208 RemoveSelectedNodes();
1213 bool ProjectUpdateMakefileForAllConfigs(Project project)
1215 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1217 // This call really does not belong here:
1218 ide.UpdateToolBarActiveConfigs(false);
1219 for(config : project.configurations)
1220 ProjectPrepareMakefile(project, forceExists, compiler, config);
1227 bool MenuSettings(MenuItem selection, Modifiers mods)
1229 ProjectNode node = GetSelectedNode(true);
1230 Project prj = node ? node.project : project;
1231 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1232 incref projectSettingsDialog;
1233 projectSettingsDialog.Modal();
1234 delete projectSettingsDialog;
1235 ide.UpdateToolBarActiveConfigs(false);
1241 bool FileProperties(MenuItem selection, Modifiers mods)
1243 DataRow row = fileList.currentRow;
1246 ProjectNode node = (ProjectNode)row.tag;
1247 NodeProperties { parent = parent, master = this, node = node,
1248 position = { position.x + 100, position.y + 100 } }.Create();
1253 bool FileOpenFile(MenuItem selection, Modifiers mods)
1255 OpenSelectedNodes();
1259 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1261 RemoveSelectedNodes();
1265 bool FileCompile(MenuItem selection, Modifiers mods)
1268 OldList selectedRows;
1269 Project project = null;
1270 List<ProjectNode> nodes { };
1271 fileList.GetMultiSelection(selectedRows);
1272 for(item = selectedRows.first; item; item = item.next)
1275 DataRow row = item.data;
1276 ProjectNode node = (ProjectNode)row.tag;
1278 project = node.project;
1279 else if(node.project != project)
1286 selectedRows.Free(null);
1288 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1290 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1295 bool FileClean(MenuItem selection, Modifiers mods)
1298 OldList selectedRows;
1299 Project project = null;
1300 List<ProjectNode> nodes { };
1301 fileList.GetMultiSelection(selectedRows);
1302 for(item = selectedRows.first; item; item = item.next)
1305 DataRow row = item.data;
1306 ProjectNode node = (ProjectNode)row.tag;
1308 project = node.project;
1309 else if(node.project != project)
1316 selectedRows.Free(null);
1318 Clean(project, nodes, mods.ctrl && mods.shift);
1320 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1325 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1327 DataRow row = fileList.currentRow;
1328 ProjectNode node = row ? (ProjectNode)row.tag : null;
1331 List<ProjectNode> nodes { };
1333 if(node.type == project)
1334 ProjectBuild(selection, mods);
1337 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1343 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1345 DataRow row = fileList.currentRow;
1346 ProjectNode node = row ? (ProjectNode)row.tag : null;
1349 List<ProjectNode> nodes { };
1351 if(node.type == project)
1352 ProjectBuild(selection, mods);
1354 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1356 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1362 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1364 DataRow row = fileList.currentRow;
1365 ProjectNode node = row ? (ProjectNode)row.tag : null;
1368 List<ProjectNode> nodes { };
1370 if(node.type == project)
1371 ProjectBuild(selection, mods);
1373 Compile(node.project, nodes, mods.ctrl && mods.shift, normal);
1375 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1381 Project GetSelectedProject(bool useSelection)
1383 Project prj = project;
1386 DataRow row = fileList.currentRow;
1387 ProjectNode node = row ? (ProjectNode)row.tag : null;
1394 void SelectNextProject(bool backwards)
1396 DataRow row = fileList.currentRow;
1397 DataRow currentRow = row;
1398 ProjectNode node = (ProjectNode)row.tag;
1399 if(node.type != project)
1400 row = node.project.topNode.row;
1402 row = row.previous ? row.previous : fileList.lastRow;
1404 row = row.next ? row.next : fileList.firstRow;
1405 if(row && row != currentRow)
1407 fileList.SelectRow(row);
1408 fileList.currentRow = row;
1412 ProjectNode GetSelectedNode(bool useSelection)
1414 ProjectNode node = null;
1417 DataRow row = fileList.currentRow;
1419 node = (ProjectNode)row.tag;
1424 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1426 char folder[MAX_LOCATION];
1428 ProjectNode node = GetSelectedNode(true);
1430 node = project.topNode;
1433 strcpy(folder, prj.topNode.path);
1434 if(node != prj.topNode)
1435 PathCatSlash(folder, node.path);
1440 bool Run(MenuItem selection, Modifiers mods)
1442 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1443 ProjectConfig config = project.config;
1444 int bitDepth = ide.workspace.bitDepth;
1445 String args = new char[maxPathLen];
1447 if(ide.workspace.commandLineArgs)
1448 //ide.debugger.GetCommandLineArgs(args);
1449 strcpy(args, ide.workspace.commandLineArgs);
1450 if(ide.debugger.isActive)
1451 project.Run(args, compiler, config, bitDepth);
1452 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1453 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1454 else if(BuildInterrim(project, run, compiler, config, bitDepth, false))
1455 project.Run(args, compiler, config, bitDepth);
1463 bool result = false;
1464 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1465 ProjectConfig config = project.config;
1466 int bitDepth = ide.workspace.bitDepth;
1467 TargetTypes targetType = project.GetTargetType(config);
1468 if(targetType == sharedLibrary || targetType == staticLibrary)
1469 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1470 else if(project.GetCompress(config))
1471 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1472 else if(project.GetDebug(config) ||
1473 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1475 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, bitDepth, false))
1477 if(compiler.type.isVC)
1479 //bool result = false;
1480 char oldwd[MAX_LOCATION];
1481 PathBackup pathBackup { };
1482 char command[MAX_LOCATION];
1484 ide.SetPath(false, compiler, config, bitDepth);
1486 GetWorkingDir(oldwd, sizeof(oldwd));
1487 ChangeWorkingDir(project.topNode.path);
1489 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1491 ChangeWorkingDir(oldwd);
1497 ide.debugger.Start(compiler, config, bitDepth);
1506 void GoToError(const char * line)
1510 while(isspace(*line)) line++;
1511 colon = strstr(line, ":");
1516 bool lookForLineNumber = true;
1518 // deal with linking error
1519 if(colon && colon[1] == ' ')
1521 colon = strstr(colon + 1, ":");
1522 if(colon && !colon[1])
1524 colon = strstr(line, ":");
1525 lookForLineNumber = false;
1527 else if(colon && !isdigit(colon[1]))
1530 colon = strstr(line, ":");
1533 // Don't be mistaken by the drive letter colon
1534 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1535 colon = strstr(colon + 1, ":");
1536 if(colon && lookForLineNumber)
1540 char * par = RSearchString(line, "(", colon - line, true, false);
1541 if(par && strstr(par, ")"))
1543 else if((colon+1)[0] == ' ')
1545 // NOTE: This is the same thing as saying 'colon = line'
1546 for( ; colon != line; colon--)
1550 lineNumber = atoi(colon + 1);
1552 comma = strchr(colon, ',');
1554 col = atoi(comma+1);
1556 comma = strchr(colon+1, ':');
1558 col = atoi(comma+1);
1562 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
1563 char ext[MAX_EXTENSION];
1567 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1568 char * from = strstr(line, "from ");
1569 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
1573 len = Min((int)(colon - start), MAX_LOCATION-1);
1575 strncpy(moduleName, start, len);
1576 moduleName[len] = '\0';
1579 strcpy(moduleName, line);
1581 // Remove stuff in brackets
1583 bracket = strstr(moduleName, "(");
1584 if(bracket) *bracket = '\0';
1586 MakeSlashPath(moduleName);
1590 // Check if it's one of our modules
1591 ProjectNode node = project.topNode.Find(moduleName, false);
1594 strcpy(moduleName, node.path);
1595 PathCatSlash(moduleName, node.name);
1598 moduleName[0] = '\0';
1600 GetExtension(moduleName, ext);
1601 if(!strcmp(ext, "a") || !strcmp(ext, "o") || !strcmp(ext, "lib") || !strcmp(ext, "dll"))
1602 moduleName[0] = 0; // Avoid opening binary files
1605 CodeEditor codeEditor;
1606 strcpy(filePath, project.topNode.path);
1607 PathCatSlash(filePath, moduleName);
1609 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1610 if(!codeEditor && !strcmp(ext, "c"))
1612 char ecName[MAX_LOCATION];
1613 ChangeExtension(filePath, "ec", ecName);
1614 codeEditor = (CodeEditor)ide.OpenFile(ecName, normal, true, null, no, normal);
1618 char path[MAX_LOCATION];
1619 // TOFIX: Improve on this, don't use only filename, make a function
1620 if(ide && ide.workspace)
1622 for(prj : ide.workspace.projects)
1625 MakePathRelative(filePath, prj.topNode.path, path);
1627 if((node = prj.topNode.FindWithPath(path, false)))
1629 strcpy(filePath, prj.topNode.path);
1630 PathCatSlash(filePath, node.path);
1631 PathCatSlash(filePath, node.name);
1632 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1637 if(!codeEditor && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1639 for(prj : ide.workspace.projects)
1642 if((node = prj.topNode.Find(moduleName, false)))
1644 strcpy(filePath, prj.topNode.path);
1645 PathCatSlash(filePath, node.path);
1646 PathCatSlash(filePath, node.name);
1647 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1655 if(codeEditor && lineNumber)
1657 EditBox editBox = codeEditor.editBox;
1658 editBox.GoToLineNum(lineNumber - 1);
1659 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1666 bool OpenNode(ProjectNode node)
1668 char filePath[MAX_LOCATION];
1669 node.GetFullFilePath(filePath);
1670 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
1673 void AddNode(ProjectNode node, DataRow addTo)
1675 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1677 row.tag = (int64)node;
1680 if(node.type == resources)
1683 row.SetData(null, node);
1685 if(node.files && node.files.first && node.parent &&
1686 !(!node.parent.parent &&
1687 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1688 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1689 row.collapsed = true;
1690 else if(node.type == folder)
1691 node.icon = openFolder;
1695 for(child : node.files)
1696 AddNode(child, row);
1700 void DeleteNode(ProjectNode projectNode)
1702 if(projectNode.files)
1705 while(child = projectNode.files.first)
1708 fileList.DeleteRow(projectNode.row);
1709 projectNode.Delete();
1712 bool ProjectSave(MenuItem selection, Modifiers mods)
1714 DataRow row = fileList.currentRow;
1715 ProjectNode node = row ? (ProjectNode)row.tag : null;
1716 Project prj = node ? node.project : null;
1719 prj.StopMonitoring();
1720 if(prj.Save(prj.filePath))
1722 Project modPrj = null;
1723 prj.topNode.modified = false;
1724 for(p : ide.workspace.projects)
1726 if(p.topNode.modified)
1733 modifiedDocument = false;
1736 prj.StartMonitoring();
1741 bool ShowOutputBuildLog(bool cleanLog)
1743 OutputView output = ide.outputView;
1745 output.ShowClearSelectTab(build);
1748 output.SelectTab(build);
1756 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1757 ProjectConfig config = project.config;
1758 int bitDepth = ide.workspace.bitDepth;
1760 bool result = false;
1761 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, bitDepth, false))
1763 // For Restart, compiler and config will only be used if for
1764 // whatever reason (if at all possible) the Debugger is in a
1765 // 'terminated' or 'none' state
1766 ide.debugger.Restart(compiler, config, bitDepth);
1776 ide.debugger.Resume();
1782 ide.debugger.Break();
1788 ide.debugger.Stop();
1792 bool DebugStepInto()
1794 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1795 ProjectConfig config = project.config;
1796 int bitDepth = ide.workspace.bitDepth;
1798 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1799 ide.debugger.StepInto(compiler, config, bitDepth);
1804 bool DebugStepOver(bool skip)
1806 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1807 ProjectConfig config = project.config;
1808 int bitDepth = ide.workspace.bitDepth;
1810 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1811 ide.debugger.StepOver(compiler, config, bitDepth, skip);
1817 bool DebugStepOut(bool skip)
1819 ide.debugger.StepOut(skip);
1823 void ImportFolder(ProjectNode toNode)
1827 //bool isFolder = toNode.type == folder;
1828 //bool isRes = toNode.isInResources;
1830 FileDialog fileDialog = importFileDialog;
1831 fileDialog.master = parent;
1832 if(fileDialog.Modal() == ok)
1834 ImportFolderFSI fsi { projectView = this };
1835 fsi.stack.Add(toNode);
1836 fsi.Iterate(fileDialog.filePath);
1842 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1846 ProjectNode folderNode;
1847 Project prj = parentNode.project;
1849 ProjectNode after = null;
1850 for(node : parentNode.files)
1852 if(node.type != folder)
1858 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1861 for(c = 0; c < 100; c++)
1864 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1865 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1872 NodeProperties nodeProperties;
1875 modifiedDocument = true;
1876 prj.topNode.modified = true;
1879 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1880 folderNode.row.tag = (int64)folderNode;
1882 folderNode.row.SetData(null, folderNode);
1883 fileList.currentRow = folderNode.row;
1887 nodeProperties = NodeProperties
1889 parent, this, mode = newFolder, node = folderNode;
1890 position = { position.x + 100, position.y + 100 };
1892 nodeProperties.Create(); // Modal?
1900 void AddFiles(bool resources)
1902 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1903 fileDialog.type = multiOpen;
1904 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
1905 fileDialog.master = parent;
1907 if(fileDialog.Modal() == ok)
1910 DataRow row = fileList.currentRow;
1911 ProjectNode parentNode = (ProjectNode)row.tag;
1912 bool addFailed = false;
1913 int numSelections = fileDialog.numSelections;
1914 char ** multiFilePaths = fileDialog.multiFilePaths;
1916 Array<String> nameConflictFiles { };
1918 for(c = 0; c < numSelections; c++)
1920 char * filePath = multiFilePaths[c];
1921 FileAttribs exists = FileExists(filePath);
1922 bool addThisFile = true;
1924 if(exists.isDirectory)
1925 addThisFile = false;
1928 if(MessageBox { master = ide, type = yesNo, text = filePath,
1929 contents = $"File doesn't exist. Create?" }.Modal() == yes)
1931 File f = FileOpen(filePath, write);
1939 MessageBox { master = ide, type = ok, text = filePath,
1940 contents = $"Couldn't create file."}.Modal();
1941 addThisFile = false;
1948 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
1950 nameConflictFiles.Add(CopyString(filePath));
1958 char * part1 = $"The following file";
1959 char * opt1 = $" was ";
1960 char * opt2 = $"s were ";
1961 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
1963 len += strlen(part1);
1964 len += strlen(part2);
1965 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1966 for(s : nameConflictFiles)
1967 len += strlen(s) + 1;
1968 message = new char[len + 1];
1969 strcpy(message, part1);
1970 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1971 strcat(message, part2);
1972 for(s : nameConflictFiles)
1975 strcat(message, "\n");
1977 MessageBox { master = ide, type = ok, text = $"Name Conflict",
1978 contents = message }.Modal();
1981 nameConflictFiles.Free();
1982 delete nameConflictFiles;
1986 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
1988 ProjectNode result = null;
1989 ProjectNode after = null;
1990 for(node : parentNode.files)
1992 if(node.type != folder && node.type != file && node.type)
1997 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
2003 modifiedDocument = true;
2004 parentNode.project.topNode.modified = true;
2005 parentNode.project.ModifiedAllConfigs(true, false, true, true);
2008 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
2009 result.row.tag = (int64)result;
2010 result.row.SetData(null, result);
2015 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
2017 CodeEditor codeEditor = null;
2018 ProjectNode projectNode;
2019 ProjectNode after = null;
2020 DataRow row = fileList.currentRow;
2021 ProjectNode parentNode;
2024 if(!row) row = project.topNode.row;
2026 parentNode = (ProjectNode)row.tag;
2028 for(node : parentNode.files)
2030 if(node.type != folder && node.type != file && node.type)
2034 for(c = 1; c < 100; c++)
2037 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
2038 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
2044 char filePath[MAX_LOCATION];
2046 modifiedDocument = true;
2047 project.topNode.modified = true;
2049 project.ModifiedAllConfigs(true, false, false, true);
2050 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2051 projectNode.row.tag =(int64)projectNode;
2053 projectNode.row.SetData(null, projectNode);
2054 fileList.currentRow = projectNode.row;
2056 strcpy(filePath, project.topNode.path);
2057 PathCat(filePath, projectNode.path);
2058 PathCat(filePath, projectNode.name);
2060 codeEditor = (CodeEditor)ide.FindWindow(filePath);
2063 Class baseClass = eSystem_FindClass(__thisModule, base);
2064 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
2067 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2068 strcpy(name, projectNode.name);
2069 sprintf(name, "%s%d", upper, c);
2071 strcpy(className, name);
2073 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2075 //codeEditor.modifiedDocument = false;
2076 //codeEditor.designer.modifiedDocument = false;
2078 //Code_EnsureUpToDate(codeEditor);
2081 else // TODO: fix no symbols generated when ommiting {} for following else
2083 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2087 codeEditor.ViewDesigner();
2088 codeEditor.codeModified = true;
2095 // Returns true if we opened something
2096 bool OpenSelectedNodes()
2098 bool result = false;
2102 fileList.GetMultiSelection(selection);
2103 for(item = selection.first; item; item = item.next)
2105 DataRow row = item.data;
2106 ProjectNode node = (ProjectNode)row.tag;
2107 if(node.type == file)
2114 selection.Free(null);
2118 void RemoveSelectedNodes()
2123 fileList.GetMultiSelection(selection);
2125 // Remove children of parents we're deleting
2126 for(item = selection.first; item; item = next)
2129 DataRow row = item.data;
2130 ProjectNode n, node = (ProjectNode)row.tag;
2131 bool remove = false;
2134 for(i = selection.first; i && !remove; i = i.next)
2136 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2137 for(n = node.parent; n; n = n.parent)
2147 selection.Delete(item);
2150 for(item = selection.first; item; item = item.next)
2152 DataRow row = item.data;
2153 ProjectNode node = (ProjectNode)row.tag;
2154 ProjectNode resNode;
2155 for(resNode = node.parent; resNode; resNode = resNode.parent)
2156 if(resNode.type == resources)
2158 if(node.type == file)
2160 Project prj = node.project;
2162 modifiedDocument = true;
2163 prj.topNode.modified = true;
2165 prj.ModifiedAllConfigs(true, false, true, true);
2167 else if(node.type == folder)
2170 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2171 "and all of its contents from the project?", node.name);
2172 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2174 Project prj = node.project;
2175 if(node.containsFile)
2176 prj.ModifiedAllConfigs(true, false, true, true);
2178 modifiedDocument = true;
2179 prj.topNode.modified = true;
2182 else if(node.type == project && node != project.topNode && !buildInProgress)
2186 for(p : workspace.projects)
2188 if(p.topNode == node)
2194 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2195 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2200 workspace.RemoveProject(prj);
2201 //modifiedDocument = true; // when project view is a workspace view
2205 selection.Free(null);