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 mfile
88 enum PrepareMakefileMethod { normal, force, forceExists };
90 enum CleanType { clean, realClean, cleanTarget };
91 enum BuildType { build, rebuild, relink, run, start, restart, clean };
94 none, buildingMainProject, buildingSecondaryProject, compilingFile;
96 property bool { get { return this != none; } }
97 //property bool actualBuild { get { return this == buildingMainProject || this == buildingSecondaryProject; } }
100 class ProjectView : Window
103 //hasMinimize = true;
105 borderStyle = sizable;
106 hasHorzScroll = true;
107 hasVertScroll = true;
110 anchor = Anchor { left = 0, top = 0, bottom = 0 };
113 //hasMinimize = true;
114 saveDialog = projectFileDialog;
117 BuildState buildInProgress;
118 BitmapResource icons[NodeIcons];
121 property Workspace workspace
127 for(prj : workspace.projects)
129 DeleteNode(prj.topNode);
131 workspace.projects.Free();
132 ide.debugger.CleanUp();
137 fileDialog.currentDirectory = workspace.workspaceDir;
138 resourceFileDialog.currentDirectory = workspace.workspaceDir;
139 for(prj : workspace.projects)
140 AddNode(prj.topNode, null);
141 ide.statusBar.text = $"Generating Makefile & Dependencies...";
143 for(prj : workspace.projects)
144 prj.ModifiedAllConfigs(true, false, false, false);
145 ide.statusBar.text = $"Initializing Debugger"; app.UpdateDisplay();
146 ide.statusBar.text = null;
150 get { return workspace; }
153 bool drawingInProjectSettingsDialog;
154 bool drawingInProjectSettingsDialogHeader;
155 ProjectSettings projectSettingsDialog;
163 for(c = 0; c < NodeIcons::enumSize; c++)
165 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
166 AddResource(icons[c]);
168 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
174 ide.DestroyTemporaryProjectDir();
184 multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
185 borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
186 anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
188 background = projectViewBackground;
189 foreground = projectViewText;
190 selectionColor = selectionColor, selectionText = selectionText;
191 stippleColor = skyBlue;
193 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
195 if(!active) Update(null);
196 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
199 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
201 // Prevent the double click from reactivating the project view (returns false if we opened something)
202 return !OpenSelectedNodes();
205 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
207 DataRow row = listBox.currentRow;
210 ProjectNode node = (ProjectNode)row.tag;
211 if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
213 bool buildMenuUnavailable = buildInProgress;
214 Menu popupContent { };
216 if(node.type == NodeTypes::project)
218 //if(node == ((Project)workspace.projects.first).topNode)
220 MenuItem { popupContent, $"Build", b, f7, NotifySelect = ProjectBuild }.disabled = buildMenuUnavailable;
221 MenuItem { popupContent, $"Relink", l, NotifySelect = ProjectLink }.disabled = buildMenuUnavailable;
222 MenuItem { popupContent, $"Rebuild", r, shiftF7, NotifySelect = ProjectRebuild }.disabled = buildMenuUnavailable;
223 MenuItem { popupContent, $"Clean", c, NotifySelect = ProjectClean }.disabled = buildMenuUnavailable;
224 MenuItem { popupContent, $"Real Clean", d, NotifySelect = ProjectRealClean }.disabled = buildMenuUnavailable;
225 MenuItem { popupContent, $"Regenerate Makefile", m, NotifySelect = ProjectRegenerate }.disabled = buildMenuUnavailable;
226 MenuDivider { popupContent };
228 MenuItem { popupContent, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = buildMenuUnavailable;
229 MenuDivider { popupContent };
230 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
231 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
232 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
233 MenuItem { popupContent, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
234 MenuDivider { popupContent };
235 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
236 // MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
237 MenuDivider { popupContent };
238 if(node != ((Project)workspace.projects.first).topNode)
240 MenuItem { popupContent, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = buildMenuUnavailable;
241 MenuDivider { popupContent };
243 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
244 MenuDivider { popupContent };
245 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
246 MenuDivider { popupContent };
247 MenuItem { popupContent, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
248 MenuDivider { popupContent };
249 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
251 else if(node.type == resources)
253 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
254 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
255 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
256 MenuItem { popupContent, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
257 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
258 MenuDivider { popupContent };
259 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
260 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
262 else if(node.type == file)
264 MenuItem { popupContent, $"Open", o, NotifySelect = FileOpenFile };
265 MenuDivider { popupContent };
266 MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
267 MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
268 MenuDivider { popupContent };
269 MenuItem { popupContent, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = buildMenuUnavailable;
270 MenuItem { popupContent, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = buildMenuUnavailable;
271 MenuDivider { popupContent };
272 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
273 MenuDivider { popupContent };
274 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
275 MenuDivider { popupContent };
276 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
277 MenuItem { popupContent, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
279 else if(node.type == folder)
281 bool isInResources = node.isInResources;
283 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
284 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
285 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
288 MenuItem { popupContent, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
292 MenuItem { popupContent, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
296 MenuDivider { popupContent };
297 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
298 MenuItem { popupContent, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
300 MenuDivider { popupContent };
301 MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
302 MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
303 MenuDivider { popupContent };
304 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
305 MenuDivider { popupContent };
306 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
307 MenuDivider { popupContent };
308 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
309 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
314 master = this, menu = popupContent;
316 x + clientStart.x + absPosition.x - app.desktop.position.x,
317 y + clientStart.y + absPosition.y - app.desktop.position.y };
319 void NotifyDestroyed(Window window, DialogResult result)
325 ide.AdjustPopupBuildMenus();
331 bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
333 if(key == altUp || key == altDown)
335 SelectNextProject(key == altUp);
341 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
345 ProjectNode node = (ProjectNode)row.tag;
348 case altEnter: case Key { keyPadEnter, alt = true }:
350 NodeProperties { parent = parent, master = this,
351 position = { position.x + 100, position.y + 100 }, node = node }.Create();
354 case enter: case keyPadEnter:
357 for(resNode = node.parent; resNode; resNode = resNode.parent)
358 if(resNode.type == resources)
360 if(node.type == project || (node.type == folder && !resNode))
365 else if(node.type == resources || node.type == folder)
374 if(node.type == project || node.type == folder || node.type == resources)
383 if(node.type == project || node.type == folder || node.type == resources)
385 NewFolder(node, null, true);
392 if(node.type == file)
394 FileCompile(null, (Modifiers)key);
399 case Key { space, shift = true }:
402 if(node.type == NodeTypes::project)
405 for(p : workspace.projects)
407 if(p.topNode == node)
413 prj.RotateActiveConfig(!key.shift);
424 case enter: case keyPadEnter: OpenSelectedNodes(); break;
425 case del: RemoveSelectedNodes(); break;
428 Window activeClient = ide.activeClient;
430 activeClient.Activate();
432 ide.RepositionWindows(true);
439 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
441 ProjectNode node = (ProjectNode)row.tag;
442 if(node.type == folder)
443 node.icon = collapsed ? folder : openFolder;
448 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
449 FileDialog projectFileDialog
451 autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
452 types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
454 FileDialog fileDialog
456 autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
458 FileDialog resourceFileDialog
460 autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
463 Menu fileMenu { menu, $"File", f };
464 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
465 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
467 bool OnClose(bool parentClosing)
469 if(!parentClosing && visible)
479 DialogResult dialogRes;
482 strcpy(msg, $"You have modified projects.\nSave changes to ");
483 for(p : ide.workspace.projects)
485 if(p.topNode.modified)
487 if(!first) strcat(msg, ", ");
494 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
498 // TOFIX: Precomp error if brackets are taken out
499 return (DialogResult)MenuFileSave(null, 0) != cancel;
501 else if(dialogRes == cancel)
503 modifiedDocument = false;
510 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
511 // ide.findInFilesDialog.SearchStop();
513 ide.outputView.buildBox.Clear();
514 ide.outputView.debugBox.Clear();
515 //ide.outputView.findBox.Clear();
516 ide.callStackView.Clear();
517 ide.watchesView.Clear();
518 ide.threadsView.Clear();
519 ide.breakpointsView.Clear();
520 ide.outputView.ShowClearSelectTab(find); // why this?
523 bool OnSaveFile(char * fileName)
525 for(prj : ide.workspace.projects)
527 if(prj.topNode.modified)
529 prj.StopMonitoring();
530 if(prj.Save(prj.filePath))
531 prj.topNode.modified = false;
532 prj.StartMonitoring();
535 modifiedDocument = false;
540 bool IsModuleInProject(char * filePath)
542 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
543 GetLastDirectory(filePath, moduleName);
544 return project.topNode.Find(moduleName, false) != null;
547 bool GetRelativePath(char * filePath, char * relativePath)
549 return project.GetRelativePath(filePath, relativePath);
552 ProjectNode GetNodeFromWindow(Window document, Project project, bool isCObject)
554 if(document.fileName)
556 char winFileName[MAX_LOCATION];
557 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
562 char name[MAX_FILENAME];
563 GetLastDirectory(documentFileName, name);
564 ChangeExtension(name, "ec", name);
565 for(p : ide.workspace.projects)
567 prj = project ? project : p;
568 if((node = prj.topNode.Find(name, false)))
575 for(p : ide.workspace.projects)
577 prj = project ? project : p;
578 if((node = prj.topNode.FindByFullPath(documentFileName, false)))
587 // ((( UTILITY FUNCTIONS )))
589 // ************************************************************************
590 // *** These methods below are part of a sequence of events, and as ***
591 // *** such they must be passed the current compiler and project config ***
592 // ************************************************************************
593 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
595 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
599 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
600 CompilerConfig compiler, ProjectConfig config)
603 char message[MAX_F_STRING];
604 LogBox logBox = ide.outputView.buildBox;
606 ShowOutputBuildLog(cleanLog);
609 DisplayCompiler(compiler, false);
611 ProjectPrepareCompiler(project, compiler, false);
612 ProjectPrepareMakefile(project, method, compiler, config);
616 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
618 if((!project.GenerateCrossPlatformMk(app.includeFile) || !project.GenerateCompilerCf(compiler)) && !silent)
619 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
623 // Note: Compiler is only passed in to for VisualStudio support
624 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
626 if(compiler.type.isVC)
628 // I'm guessing we'll want to support generating VS files on Linux as well...
629 ide.statusBar.text = $"Generating Visual Studio Solution...";
631 //GenerateVSSolutionFile(project, compiler);
632 ide.statusBar.text = $"Generating Visual Studio Project...";
634 //GenerateVCProjectFile(project, compiler, bitDepth);
635 ide.statusBar.text = null;
641 char makefilePath[MAX_LOCATION];
642 char makefileName[MAX_LOCATION];
644 LogBox logBox = ide.outputView.buildBox;
646 strcpy(makefilePath, project.topNode.path);
647 project.CatMakeFileName(makefileName, config);
648 PathCatSlash(makefilePath, makefileName);
650 exists = FileExists(makefilePath);
651 if(method == force ||
652 (method == forceExists && exists) ||
653 (method == normal && (!exists || (config && config.makingModified))))
657 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
660 if((method == normal && !exists) || (method == force && !exists))
661 action = $"Generating ";
662 else if(method == force)
663 action = $"Regenerating ";
664 else if(method == normal || method == forceExists)
665 action = $"Updating ";
669 reason = $"Makefile doesn't exist. ";
670 else if(project.topNode.modified)
671 reason = $"Project has been modified. ";
675 //logBox.Logf("%s\n", makefileName);
676 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
678 if(!project.GenerateMakefile(null, false, null, config))
679 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
681 ide.statusBar.text = null;
689 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
691 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
693 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
694 return Build(prj, buildType, compiler, config, bitDepth, justPrint);
699 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
702 // TOFIX: DebugStop is being abused and backfiring on us.
703 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
705 // configIsInDebugSession seems to be used for two OPPOSITE things:
706 // If we're debugging another config, we need to unload the executable!
707 // In building, we want to stop if we're debugging the 'same' executable
708 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
710 if(buildType == start || buildType == restart)
712 if(ide.debugger && ide.debugger.isPrepared)
713 result = DebugStop();
717 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
718 result = DebugStop();
724 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint)
730 for(document = master.firstChild; document; document = document.next)
732 if(document.modifiedDocument)
734 ProjectNode node = GetNodeFromWindow(document, prj, false);
735 if(node && !document.MenuFileSave(null, 0))
744 DirExpression targetDir = prj.GetTargetDir(compiler, config, bitDepth);
746 DebugStopForMake(prj, buildType, compiler, config);
748 // TODO: Disabled until problems fixed... is it fixed?
749 if(buildType == rebuild || (config && config.compilingModified))
750 prj.Clean(compiler, config, bitDepth, clean, justPrint);
753 if(buildType == relink || (config && config.linkingModified))
754 prj.Clean(compiler, config, bitDepth, cleanTarget, false);
755 if(config && config.symbolGenModified)
757 DirExpression objDir = prj.GetObjDir(compiler, config, bitDepth);
758 char fileName[MAX_LOCATION];
759 char moduleName[MAX_FILENAME];
760 strcpy(fileName, prj.topNode.path);
761 PathCatSlash(fileName, objDir.dir);
762 strcpy(moduleName, prj.moduleName);
763 strcat(moduleName, ".main.ec");
764 PathCatSlash(fileName, moduleName);
765 if(FileExists(fileName))
766 DeleteFile(fileName);
767 ChangeExtension(fileName, "c", fileName);
768 if(FileExists(fileName))
769 DeleteFile(fileName);
770 ChangeExtension(fileName, "o", fileName);
771 if(FileExists(fileName))
772 DeleteFile(fileName);
777 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
778 ide.AdjustBuildMenus();
779 ide.AdjustDebugMenus();
781 result = prj.Build(buildType == run, null, compiler, config, bitDepth, justPrint, normal);
785 config.compilingModified = false;
786 if(!ide.ShouldStopBuild())
787 config.linkingModified = false;
789 config.symbolGenModified = false;
791 buildInProgress = none;
792 ide.AdjustBuildMenus();
793 ide.AdjustDebugMenus();
795 ide.workspace.modified = true;
802 // ((( USER ACTIONS )))
804 // ************************************************************************
805 // *** Methods below should atomically start a process, and as such ***
806 // *** they can query compiler and config directly from ide and project ***
807 // *** but ONLY ONCE!!! ***
808 // ************************************************************************
810 bool ProjectBuild(MenuItem selection, Modifiers mods)
812 if(buildInProgress == none)
814 Project prj = project;
815 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
816 int bitDepth = ide.workspace.bitDepth;
817 ProjectConfig config;
818 if(selection || !ide.activeClient)
820 DataRow row = fileList.currentRow;
821 ProjectNode node = row ? (ProjectNode)row.tag : null;
822 if(node) prj = node.project;
826 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
831 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
833 BuildInterrim(prj, build, compiler, config, bitDepth, mods.ctrl && mods.shift);
842 bool ProjectLink(MenuItem selection, Modifiers mods)
844 Project prj = project;
845 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
846 int bitDepth = ide.workspace.bitDepth;
847 ProjectConfig config;
848 if(selection || !ide.activeClient)
850 DataRow row = fileList.currentRow;
851 ProjectNode node = row ? (ProjectNode)row.tag : null;
852 if(node) prj = node.project;
856 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
861 if(!prj.GetConfigIsInDebugSession(config) ||
862 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
864 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
866 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
868 config.linkingModified = true;
869 Build(prj, relink, compiler, config, bitDepth, mods.ctrl && mods.shift);
876 bool ProjectRebuild(MenuItem selection, Modifiers mods)
878 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
879 int bitDepth = ide.workspace.bitDepth;
880 Project prj = project;
881 ProjectConfig config;
882 if(selection || !ide.activeClient)
884 DataRow row = fileList.currentRow;
885 ProjectNode node = row ? (ProjectNode)row.tag : null;
886 if(node) prj = node.project;
890 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
895 if(!prj.GetConfigIsInDebugSession(config) ||
896 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
898 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
900 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
903 config.compilingModified = true;
904 config.makingModified = true;
905 }*/ // -- should this still be used depite the new solution of BuildType?
906 Build(prj, rebuild, compiler, config, bitDepth, mods.ctrl && mods.shift);
914 bool ProjectCleanTarget(MenuItem selection, Modifiers mods)
916 Project prj = project;
917 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
918 ProjectConfig config;
919 if(selection || !ide.activeClient)
921 DataRow row = fileList.currentRow;
922 ProjectNode node = row ? (ProjectNode)row.tag : null;
923 if(node) prj = node.project;
927 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
932 if(!prj.GetConfigIsInDebugSession(config) ||
933 (!ide.DontTerminateDebugSession($"Project Clean Target") && DebugStopForMake(prj, clean, compiler, config)))
935 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
937 ide.outputView.buildBox.Logf($"Cleaning target for project %s using the %s configuration...\n", prj.name, GetConfigName(config));
939 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
940 ide.AdjustBuildMenus();
941 ide.AdjustDebugMenus();
943 prj.Clean(compiler, config, cleanTarget, mods.ctrl && mods.shift);
944 buildInProgress = none;
945 ide.AdjustBuildMenus();
946 ide.AdjustDebugMenus();
954 bool ProjectClean(MenuItem selection, Modifiers mods)
956 Project prj = project;
957 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
958 ProjectConfig config;
959 int bitDepth = ide.workspace.bitDepth;
960 if(selection || !ide.activeClient)
962 DataRow row = fileList.currentRow;
963 ProjectNode node = row ? (ProjectNode)row.tag : null;
964 if(node) prj = node.project;
968 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
973 if(!prj.GetConfigIsInDebugSession(config) ||
974 (!ide.DontTerminateDebugSession($"Project Clean") && DebugStopForMake(prj, clean, compiler, config)))
976 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
978 ide.outputView.buildBox.Logf($"Cleaning project %s using the %s configuration...\n", prj.name, GetConfigName(config));
980 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
981 ide.AdjustBuildMenus();
982 ide.AdjustDebugMenus();
984 prj.Clean(compiler, config, bitDepth, clean, mods.ctrl && mods.shift);
985 buildInProgress = none;
986 ide.AdjustBuildMenus();
987 ide.AdjustDebugMenus();
994 bool ProjectRealClean(MenuItem selection, Modifiers mods)
996 Project prj = project;
997 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
998 ProjectConfig config;
999 int bitDepth = ide.workspace.bitDepth;
1000 if(selection || !ide.activeClient)
1002 DataRow row = fileList.currentRow;
1003 ProjectNode node = row ? (ProjectNode)row.tag : null;
1004 if(node) prj = node.project;
1008 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
1012 config = prj.config;
1013 if(!prj.GetConfigIsInDebugSession(config) ||
1014 (!ide.DontTerminateDebugSession($"Project Real Clean") && DebugStopForMake(prj, clean, compiler, config)))
1016 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1018 ide.outputView.buildBox.Logf($"Removing intermediate objects directory for project %s using the %s configuration...\n", prj.name, GetConfigName(config));
1020 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
1021 ide.AdjustBuildMenus();
1022 ide.AdjustDebugMenus();
1024 prj.Clean(compiler, config, bitDepth, realClean, mods.ctrl && mods.shift);
1025 buildInProgress = none;
1026 ide.AdjustBuildMenus();
1027 ide.AdjustDebugMenus();
1034 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
1036 Project prj = project;
1037 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1038 ShowOutputBuildLog(true);
1039 if(selection || !ide.activeClient)
1041 DataRow row = fileList.currentRow;
1042 ProjectNode node = row ? (ProjectNode)row.tag : null;
1048 ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false);
1053 DisplayCompiler(compiler, false);
1054 ProjectPrepareCompiler(project, compiler, false);
1055 ProjectPrepareMakefile(prj, force, compiler, prj.config);
1060 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1063 char fileName[MAX_LOCATION];
1065 ProjectConfig config = project.config;
1069 for(document = ide.firstChild; document; document = document.next)
1071 if(document.modifiedDocument)
1073 ProjectNode n = GetNodeFromWindow(document, project, mode == cObject ? true : false);
1076 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1078 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1088 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1089 int bitDepth = ide.workspace.bitDepth;
1091 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1094 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1095 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name, config.name);
1097 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1098 (mode == normal || mode == cObject) ? $"Compiling" : $"Debug compiling", project.name);
1100 buildInProgress = compilingFile;
1101 ide.AdjustBuildMenus();
1102 project.Compile(nodes, compiler, config, bitDepth, justPrint, mode);
1103 buildInProgress = none;
1104 ide.AdjustBuildMenus();
1113 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1116 char fileName[MAX_LOCATION];
1118 ProjectConfig config = project.config;
1122 for(document = ide.firstChild; document; document = document.next)
1124 if(document.modifiedDocument)
1126 ProjectNode n = GetNodeFromWindow(document, project, false);
1129 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1131 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1141 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1142 int bitDepth = ide.workspace.bitDepth;
1144 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1146 Map<String, NameCollisionInfo> namesInfo { };
1147 project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1150 if(node.GetIsExcluded(config))
1151 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1155 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s using the %s configuration...\n",
1156 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1158 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s...\n",
1159 node.type == file ? $"single file" : $"folder", node.name, project.name);
1161 node.DeleteIntermediateFiles(compiler, config, bitDepth, namesInfo, false);
1173 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1175 DataRow row = fileList.currentRow;
1178 char fileName[1024];
1179 char filePath[MAX_LOCATION];
1180 ProjectNode parentNode = (ProjectNode)row.tag;
1181 ProjectNode n, fileNode;
1182 parentNode.GetFileSysMatchingPath(filePath);
1183 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1184 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1185 sprintf(fileName, $"Untitled %d", documentID);
1186 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1187 fileNode.path = CopyUnixPath(filePath);
1190 NodeProperties nodeProperties
1193 position = { position.x + 100, position.y + 100 };
1197 nodeProperties.Create(); // not modal?
1203 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1205 DataRow row = fileList.currentRow;
1208 ProjectNode parentNode = (ProjectNode)row.tag;
1209 NewFolder(parentNode, null, true);
1214 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1220 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1226 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1228 DataRow row = fileList.currentRow;
1231 ProjectNode toNode = (ProjectNode)row.tag;
1232 ImportFolder(toNode);
1237 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1239 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1240 codeEditor.EnsureUpToDate();
1244 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1246 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1248 codeEditor.EnsureUpToDate();
1252 bool ProjectRemove(MenuItem selection, Modifiers mods)
1254 DataRow row = fileList.currentRow;
1257 ProjectNode node = (ProjectNode)row.tag;
1258 if(node.type == project)
1259 RemoveSelectedNodes();
1264 bool ProjectUpdateMakefileForAllConfigs(Project project)
1266 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1268 // This call really does not belong here:
1269 ide.UpdateToolBarActiveConfigs(false);
1270 for(config : project.configurations)
1271 ProjectPrepareMakefile(project, forceExists, compiler, config);
1278 bool MenuSettings(MenuItem selection, Modifiers mods)
1280 ProjectNode node = GetSelectedNode(true);
1281 Project prj = node ? node.project : project;
1282 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1283 incref projectSettingsDialog;
1284 projectSettingsDialog.Modal();
1285 delete projectSettingsDialog;
1286 ide.UpdateToolBarActiveConfigs(false);
1292 bool FileProperties(MenuItem selection, Modifiers mods)
1294 DataRow row = fileList.currentRow;
1297 ProjectNode node = (ProjectNode)row.tag;
1298 NodeProperties { parent = parent, master = this, node = node,
1299 position = { position.x + 100, position.y + 100 } }.Create();
1304 bool FileOpenFile(MenuItem selection, Modifiers mods)
1306 OpenSelectedNodes();
1310 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1312 RemoveSelectedNodes();
1316 bool FileCompile(MenuItem selection, Modifiers mods)
1319 OldList selectedRows;
1320 Project project = null;
1321 List<ProjectNode> nodes { };
1322 fileList.GetMultiSelection(selectedRows);
1323 for(item = selectedRows.first; item; item = item.next)
1326 DataRow row = item.data;
1327 ProjectNode node = (ProjectNode)row.tag;
1329 project = node.project;
1330 else if(node.project != project)
1337 selectedRows.Free(null);
1339 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1341 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1346 bool FileClean(MenuItem selection, Modifiers mods)
1349 OldList selectedRows;
1350 Project project = null;
1351 List<ProjectNode> nodes { };
1352 fileList.GetMultiSelection(selectedRows);
1353 for(item = selectedRows.first; item; item = item.next)
1356 DataRow row = item.data;
1357 ProjectNode node = (ProjectNode)row.tag;
1359 project = node.project;
1360 else if(node.project != project)
1367 selectedRows.Free(null);
1369 Clean(project, nodes, mods.ctrl && mods.shift);
1371 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1376 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1378 DataRow row = fileList.currentRow;
1379 ProjectNode node = row ? (ProjectNode)row.tag : null;
1382 List<ProjectNode> nodes { };
1384 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1389 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1391 DataRow row = fileList.currentRow;
1392 ProjectNode node = row ? (ProjectNode)row.tag : null;
1395 List<ProjectNode> nodes { };
1397 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1402 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1404 DataRow row = fileList.currentRow;
1405 ProjectNode node = row ? (ProjectNode)row.tag : null;
1408 List<ProjectNode> nodes { };
1410 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1415 Project GetSelectedProject(bool useSelection)
1417 Project prj = project;
1420 DataRow row = fileList.currentRow;
1421 ProjectNode node = row ? (ProjectNode)row.tag : null;
1428 void SelectNextProject(bool backwards)
1430 DataRow row = fileList.currentRow;
1431 DataRow currentRow = row;
1432 ProjectNode node = (ProjectNode)row.tag;
1433 if(node.type != project)
1434 row = node.project.topNode.row;
1436 row = row.previous ? row.previous : fileList.lastRow;
1438 row = row.next ? row.next : fileList.firstRow;
1439 if(row && row != currentRow)
1441 fileList.SelectRow(row);
1442 fileList.currentRow = row;
1446 ProjectNode GetSelectedNode(bool useSelection)
1448 ProjectNode node = null;
1451 DataRow row = fileList.currentRow;
1453 node = (ProjectNode)row.tag;
1458 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1460 char folder[MAX_LOCATION];
1462 ProjectNode node = GetSelectedNode(true);
1464 node = project.topNode;
1467 strcpy(folder, prj.topNode.path);
1468 if(node != prj.topNode)
1469 PathCatSlash(folder, node.path);
1474 bool Run(MenuItem selection, Modifiers mods)
1476 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1477 ProjectConfig config = project.config;
1478 int bitDepth = ide.workspace.bitDepth;
1479 String args = new char[maxPathLen];
1481 if(ide.workspace.commandLineArgs)
1482 //ide.debugger.GetCommandLineArgs(args);
1483 strcpy(args, ide.workspace.commandLineArgs);
1484 if(ide.debugger.isActive)
1485 project.Run(args, compiler, config, bitDepth);
1486 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1487 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1488 else if(BuildInterrim(project, run, compiler, config, bitDepth, false))
1489 project.Run(args, compiler, config, bitDepth);
1497 bool result = false;
1498 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1499 ProjectConfig config = project.config;
1500 int bitDepth = ide.workspace.bitDepth;
1501 TargetTypes targetType = project.GetTargetType(config);
1502 if(targetType == sharedLibrary || targetType == staticLibrary)
1503 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1504 else if(project.GetCompress(config))
1505 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1506 else if(project.GetDebug(config) ||
1507 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1509 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, bitDepth, false))
1511 if(compiler.type.isVC)
1513 //bool result = false;
1514 char oldwd[MAX_LOCATION];
1515 PathBackup pathBackup { };
1516 char command[MAX_LOCATION];
1518 ide.SetPath(false, compiler, config, bitDepth);
1520 GetWorkingDir(oldwd, sizeof(oldwd));
1521 ChangeWorkingDir(project.topNode.path);
1523 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1525 ChangeWorkingDir(oldwd);
1531 ide.debugger.Start(compiler, config, bitDepth);
1540 void GoToError(const char * line)
1544 while(isspace(*line)) line++;
1545 colon = strstr(line, ":");
1550 bool lookForLineNumber = true;
1552 // deal with linking error
1553 if(colon && colon[1] == ' ')
1555 colon = strstr(colon + 1, ":");
1556 if(colon && !colon[1])
1558 colon = strstr(line, ":");
1559 lookForLineNumber = false;
1561 else if(colon && !isdigit(colon[1]))
1564 colon = strstr(line, ":");
1567 // Don't be mistaken by the drive letter colon
1568 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1569 colon = strstr(colon + 1, ":");
1570 if(colon && lookForLineNumber)
1574 char * par = RSearchString(line, "(", colon - line, true, false);
1575 if(par && strstr(par, ")"))
1577 else if((colon+1)[0] == ' ')
1579 // NOTE: This is the same thing as saying 'colon = line'
1580 for( ; colon != line; colon--)
1584 lineNumber = atoi(colon + 1);
1586 comma = strchr(colon, ',');
1588 col = atoi(comma+1);
1590 comma = strchr(colon+1, ':');
1592 col = atoi(comma+1);
1596 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
1600 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1601 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1602 int len = (int)(colon - start);
1603 len = Min(len, MAX_LOCATION-1);
1605 strncpy(moduleName, start, len);
1606 moduleName[len] = '\0';
1609 strcpy(moduleName, line);
1611 // Remove stuff in brackets
1613 bracket = strstr(moduleName, "(");
1614 if(bracket) *bracket = '\0';
1616 MakeSlashPath(moduleName);
1620 // Check if it's one of our modules
1621 ProjectNode node = project.topNode.Find(moduleName, false);
1624 strcpy(moduleName, node.path);
1625 PathCatSlash(moduleName, node.name);
1628 moduleName[0] = '\0';
1632 CodeEditor codeEditor;
1633 strcpy(filePath, project.topNode.path);
1634 PathCatSlash(filePath, moduleName);
1636 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1639 char name[MAX_LOCATION];
1640 // TOFIX: Improve on this, don't use only filename, make a function
1641 if(ide && ide.workspace)
1643 for(prj : ide.workspace.projects)
1645 if(prj.topNode.FindWithPath(moduleName, false))
1647 strcpy(filePath, prj.topNode.path);
1648 PathCatSlash(filePath, moduleName);
1649 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1656 if(codeEditor && lineNumber)
1658 EditBox editBox = codeEditor.editBox;
1659 editBox.GoToLineNum(lineNumber - 1);
1660 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1667 bool OpenNode(ProjectNode node)
1669 char filePath[MAX_LOCATION];
1670 node.GetFullFilePath(filePath);
1671 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
1674 void AddNode(ProjectNode node, DataRow addTo)
1676 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1678 row.tag = (int64)node;
1681 if(node.type == resources)
1684 row.SetData(null, node);
1686 if(node.files && node.files.first && node.parent &&
1687 !(!node.parent.parent &&
1688 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1689 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1690 row.collapsed = true;
1691 else if(node.type == folder)
1692 node.icon = openFolder;
1696 for(child : node.files)
1697 AddNode(child, row);
1701 void DeleteNode(ProjectNode projectNode)
1703 if(projectNode.files)
1706 while(child = projectNode.files.first)
1709 fileList.DeleteRow(projectNode.row);
1710 projectNode.Delete();
1713 bool ProjectSave(MenuItem selection, Modifiers mods)
1715 DataRow row = fileList.currentRow;
1716 ProjectNode node = row ? (ProjectNode)row.tag : null;
1717 Project prj = node ? node.project : null;
1720 prj.StopMonitoring();
1721 if(prj.Save(prj.filePath))
1723 Project modPrj = null;
1724 prj.topNode.modified = false;
1725 for(p : ide.workspace.projects)
1727 if(p.topNode.modified)
1734 modifiedDocument = false;
1737 prj.StartMonitoring();
1742 bool ShowOutputBuildLog(bool cleanLog)
1744 OutputView output = ide.outputView;
1746 output.ShowClearSelectTab(build);
1749 output.SelectTab(build);
1757 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1758 ProjectConfig config = project.config;
1759 int bitDepth = ide.workspace.bitDepth;
1761 bool result = false;
1762 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, bitDepth, false))
1764 // For Restart, compiler and config will only be used if for
1765 // whatever reason (if at all possible) the Debugger is in a
1766 // 'terminated' or 'none' state
1767 ide.debugger.Restart(compiler, config, bitDepth);
1777 ide.debugger.Resume();
1783 ide.debugger.Break();
1789 ide.debugger.Stop();
1793 bool DebugStepInto()
1795 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1796 ProjectConfig config = project.config;
1797 int bitDepth = ide.workspace.bitDepth;
1799 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1800 ide.debugger.StepInto(compiler, config, bitDepth);
1805 bool DebugStepOver(bool skip)
1807 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1808 ProjectConfig config = project.config;
1809 int bitDepth = ide.workspace.bitDepth;
1811 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, bitDepth, false)))
1812 ide.debugger.StepOver(compiler, config, bitDepth, skip);
1818 bool DebugStepOut(bool skip)
1820 ide.debugger.StepOut(skip);
1824 void ImportFolder(ProjectNode toNode)
1828 //bool isFolder = toNode.type == folder;
1829 //bool isRes = toNode.isInResources;
1831 FileDialog fileDialog = importFileDialog;
1832 fileDialog.master = parent;
1833 if(fileDialog.Modal() == ok)
1835 ImportFolderFSI fsi { projectView = this };
1836 fsi.stack.Add(toNode);
1837 fsi.Iterate(fileDialog.filePath);
1843 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1847 ProjectNode folderNode;
1848 Project prj = parentNode.project;
1850 ProjectNode after = null;
1851 for(node : parentNode.files)
1853 if(node.type != folder)
1859 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1862 for(c = 0; c < 100; c++)
1865 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1866 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1873 NodeProperties nodeProperties;
1876 modifiedDocument = true;
1877 prj.topNode.modified = true;
1880 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1881 folderNode.row.tag = (int64)folderNode;
1883 folderNode.row.SetData(null, folderNode);
1884 fileList.currentRow = folderNode.row;
1888 nodeProperties = NodeProperties
1890 parent, this, mode = newFolder, node = folderNode;
1891 position = { position.x + 100, position.y + 100 };
1893 nodeProperties.Create(); // Modal?
1901 void AddFiles(bool resources)
1903 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1904 fileDialog.type = multiOpen;
1905 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
1906 fileDialog.master = parent;
1908 if(fileDialog.Modal() == ok)
1911 DataRow row = fileList.currentRow;
1912 ProjectNode parentNode = (ProjectNode)row.tag;
1913 bool addFailed = false;
1914 int numSelections = fileDialog.numSelections;
1915 char ** multiFilePaths = fileDialog.multiFilePaths;
1917 Array<String> nameConflictFiles { };
1919 for(c = 0; c < numSelections; c++)
1921 char * filePath = multiFilePaths[c];
1922 FileAttribs exists = FileExists(filePath);
1923 bool addThisFile = true;
1925 if(exists.isDirectory)
1926 addThisFile = false;
1929 if(MessageBox { master = ide, type = yesNo, text = filePath,
1930 contents = $"File doesn't exist. Create?" }.Modal() == yes)
1932 File f = FileOpen(filePath, write);
1940 MessageBox { master = ide, type = ok, text = filePath,
1941 contents = $"Couldn't create file."}.Modal();
1942 addThisFile = false;
1949 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
1951 nameConflictFiles.Add(CopyString(filePath));
1959 char * part1 = $"The following file";
1960 char * opt1 = $" was ";
1961 char * opt2 = $"s were ";
1962 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
1964 len += strlen(part1);
1965 len += strlen(part2);
1966 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1967 for(s : nameConflictFiles)
1968 len += strlen(s) + 1;
1969 message = new char[len + 1];
1970 strcpy(message, part1);
1971 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1972 strcat(message, part2);
1973 for(s : nameConflictFiles)
1976 strcat(message, "\n");
1978 MessageBox { master = ide, type = ok, text = $"Name Conflict",
1979 contents = message }.Modal();
1982 nameConflictFiles.Free();
1983 delete nameConflictFiles;
1987 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
1989 ProjectNode result = null;
1990 ProjectNode after = null;
1991 for(node : parentNode.files)
1993 if(node.type != folder && node.type != file && node.type)
1998 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
2004 modifiedDocument = true;
2005 parentNode.project.topNode.modified = true;
2006 parentNode.project.ModifiedAllConfigs(true, false, true, true);
2009 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
2010 result.row.tag = (int64)result;
2011 result.row.SetData(null, result);
2016 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
2018 CodeEditor codeEditor = null;
2019 ProjectNode projectNode;
2020 ProjectNode after = null;
2021 DataRow row = fileList.currentRow;
2022 ProjectNode parentNode;
2025 if(!row) row = project.topNode.row;
2027 parentNode = (ProjectNode)row.tag;
2029 for(node : parentNode.files)
2031 if(node.type != folder && node.type != file && node.type)
2035 for(c = 1; c < 100; c++)
2038 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
2039 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
2045 char filePath[MAX_LOCATION];
2047 modifiedDocument = true;
2048 project.topNode.modified = true;
2050 project.ModifiedAllConfigs(true, false, false, true);
2051 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
2052 projectNode.row.tag =(int64)projectNode;
2054 projectNode.row.SetData(null, projectNode);
2055 fileList.currentRow = projectNode.row;
2057 strcpy(filePath, project.topNode.path);
2058 PathCat(filePath, projectNode.path);
2059 PathCat(filePath, projectNode.name);
2061 codeEditor = (CodeEditor)ide.FindWindow(filePath);
2064 Class baseClass = eSystem_FindClass(__thisModule, base);
2065 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
2068 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2069 strcpy(name, projectNode.name);
2070 sprintf(name, "%s%d", upper, c);
2072 strcpy(className, name);
2074 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2076 //codeEditor.modifiedDocument = false;
2077 //codeEditor.designer.modifiedDocument = false;
2079 //Code_EnsureUpToDate(codeEditor);
2082 else // TODO: fix no symbols generated when ommiting {} for following else
2084 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2088 codeEditor.ViewDesigner();
2089 codeEditor.codeModified = true;
2096 // Returns true if we opened something
2097 bool OpenSelectedNodes()
2099 bool result = false;
2103 fileList.GetMultiSelection(selection);
2104 for(item = selection.first; item; item = item.next)
2106 DataRow row = item.data;
2107 ProjectNode node = (ProjectNode)row.tag;
2108 if(node.type == file)
2115 selection.Free(null);
2119 void RemoveSelectedNodes()
2124 fileList.GetMultiSelection(selection);
2126 // Remove children of parents we're deleting
2127 for(item = selection.first; item; item = next)
2130 DataRow row = item.data;
2131 ProjectNode n, node = (ProjectNode)row.tag;
2132 bool remove = false;
2135 for(i = selection.first; i && !remove; i = i.next)
2137 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2138 for(n = node.parent; n; n = n.parent)
2148 selection.Delete(item);
2151 for(item = selection.first; item; item = item.next)
2153 DataRow row = item.data;
2154 ProjectNode node = (ProjectNode)row.tag;
2155 ProjectNode resNode;
2156 for(resNode = node.parent; resNode; resNode = resNode.parent)
2157 if(resNode.type == resources)
2159 if(node.type == file)
2161 Project prj = node.project;
2163 modifiedDocument = true;
2164 prj.topNode.modified = true;
2166 prj.ModifiedAllConfigs(true, false, true, true);
2168 else if(node.type == folder)
2171 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2172 "and all of its contents from the project?", node.name);
2173 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2175 Project prj = node.project;
2176 if(node.containsFile)
2177 prj.ModifiedAllConfigs(true, false, true, true);
2179 modifiedDocument = true;
2180 prj.topNode.modified = true;
2183 else if(node.type == project && node != project.topNode && !buildInProgress)
2187 for(p : workspace.projects)
2189 if(p.topNode == node)
2195 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2196 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2201 workspace.RemoveProject(prj);
2202 //modifiedDocument = true; // when project view is a workspace view
2206 selection.Free(null);