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", /*cFile*/
74 "<:ecere>mimeTypes/textCHeader.png", /*hFile*/
75 "<:ecere>mimeTypes/textC++Source.png", /*cppFile*/
76 "<:ecere>mimeTypes/textC++Header.png", /*hppFile*/
77 "<:ecere>mimeTypes/text.png", /*textFile*/
78 "<:ecere>mimeTypes/textHyperTextMarkup.png", /*webFile*/
79 "<:ecere>mimeTypes/image.png", /*pictureFile*/
80 "<:ecere>status/audioVolumeHigh.png", /*soundFile*/
81 "<:ecere>mimeTypes/package.png", /*archiveFile*/
82 "<:ecere>mimeTypes/packageSoftware.png", /*packageFile*/
83 "<:ecere>mimeTypes/packageOpticalDisc.png", /*opticalMediaImageFile*/
84 "<:ecere>mimeTypes/file.png" /*mFile*/ //TODO: create icon for mfile
87 enum PrepareMakefileMethod { normal, force, forceExists };
89 enum BuildType { build, rebuild, relink, run, start, restart, clean };
92 none, buildingMainProject, buildingSecondaryProject, compilingFile;
94 property bool { get { return this != none; } }
95 //property bool actualBuild { get { return this == buildingMainProject || this == buildingSecondaryProject; } }
98 class ProjectView : Window
101 //hasMinimize = true;
103 borderStyle = sizable;
104 hasHorzScroll = true;
105 hasVertScroll = true;
108 anchor = Anchor { left = 0, top = 0, bottom = 0 };
111 //hasMinimize = true;
112 saveDialog = projectFileDialog;
115 BuildState buildInProgress;
116 BitmapResource icons[NodeIcons];
119 property Workspace workspace
125 for(prj : workspace.projects)
127 DeleteNode(prj.topNode);
129 workspace.projects.Free();
130 ide.debugger.CleanUp();
135 fileDialog.currentDirectory = workspace.workspaceDir;
136 resourceFileDialog.currentDirectory = workspace.workspaceDir;
137 for(prj : workspace.projects)
138 AddNode(prj.topNode, null);
139 ide.statusBar.text = $"Generating Makefile & Dependencies...";
141 for(prj : workspace.projects)
142 prj.ModifiedAllConfigs(true, false, false, false);
143 ide.statusBar.text = $"Initializing Debugger"; app.UpdateDisplay();
144 ide.statusBar.text = null;
148 get { return workspace; }
151 bool drawingInProjectSettingsDialog;
152 bool drawingInProjectSettingsDialogHeader;
153 ProjectSettings projectSettingsDialog;
161 for(c = 0; c < NodeIcons::enumSize; c++)
163 icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
164 AddResource(icons[c]);
166 fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
172 ide.DestroyTemporaryProjectDir();
182 multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
183 borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
184 anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
186 background = projectViewBackground;
187 foreground = projectViewText;
188 selectionColor = selectionColor, selectionText = selectionText;
189 stippleColor = skyBlue;
191 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
193 if(!active) Update(null);
194 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
197 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
199 // Prevent the double click from reactivating the project view (returns false if we opened something)
200 return !OpenSelectedNodes();
203 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
205 DataRow row = listBox.currentRow;
208 ProjectNode node = (ProjectNode)row.tag;
209 if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
211 bool buildMenuUnavailable = buildInProgress;
212 Menu popupContent { };
214 if(node.type == NodeTypes::project)
216 //if(node == ((Project)workspace.projects.first).topNode)
218 MenuItem { popupContent, $"Build", b, NotifySelect = ProjectBuild }.disabled = buildMenuUnavailable;
219 MenuItem { popupContent, $"Relink", l, NotifySelect = ProjectLink }.disabled = buildMenuUnavailable;
220 MenuItem { popupContent, $"Rebuild", r, NotifySelect = ProjectRebuild }.disabled = buildMenuUnavailable;
221 MenuItem { popupContent, $"Clean", c, NotifySelect = ProjectClean }.disabled = buildMenuUnavailable;
222 MenuItem { popupContent, $"Real Clean", d, NotifySelect = ProjectRealClean }.disabled = buildMenuUnavailable;
223 MenuItem { popupContent, $"Regenerate Makefile", m, NotifySelect = ProjectRegenerate }.disabled = buildMenuUnavailable;
224 MenuDivider { popupContent };
226 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
227 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
228 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
229 MenuItem { popupContent, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
230 MenuDivider { popupContent };
231 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
232 // MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
233 MenuDivider { popupContent };
234 if(node != ((Project)workspace.projects.first).topNode)
236 MenuItem { popupContent, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = buildMenuUnavailable;
237 MenuDivider { popupContent };
239 MenuItem { popupContent, $"Active Configuration...", s, Key { f5, alt = true } , NotifySelect = MenuConfig };
240 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
241 MenuDivider { popupContent };
242 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
243 MenuDivider { popupContent };
244 MenuItem { popupContent, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
245 MenuDivider { popupContent };
246 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
248 else if(node.type == resources)
250 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
251 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
252 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
253 MenuItem { popupContent, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
254 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
255 MenuDivider { popupContent };
256 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
257 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
259 else if(node.type == file)
261 MenuItem { popupContent, $"Open", o, NotifySelect = FileOpenFile };
262 MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
263 MenuDivider { popupContent };
264 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
265 MenuDivider { popupContent };
266 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
267 MenuDivider { popupContent };
268 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
269 MenuItem { popupContent, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
271 else if(node.type == folder)
273 bool isInResources = node.isInResources;
275 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
276 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
277 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
280 MenuItem { popupContent, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
284 MenuItem { popupContent, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
288 MenuDivider { popupContent };
289 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
290 MenuItem { popupContent, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
292 MenuDivider { popupContent };
293 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
294 MenuDivider { popupContent };
295 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
296 MenuDivider { popupContent };
297 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
298 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
303 master = this, menu = popupContent;
305 x + clientStart.x + absPosition.x - app.desktop.position.x,
306 y + clientStart.y + absPosition.y - app.desktop.position.y };
308 void NotifyDestroyed(Window window, DialogResult result)
319 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
323 ProjectNode node = (ProjectNode)row.tag;
326 case altEnter: case Key { keyPadEnter, alt = true }:
328 NodeProperties { parent = parent, master = this,
329 position = { position.x + 100, position.y + 100 }, node = node }.Create();
332 case enter: case keyPadEnter:
335 for(resNode = node.parent; resNode; resNode = resNode.parent)
336 if(resNode.type == resources)
338 if(node.type == project || (node.type == folder && !resNode))
343 else if(node.type == resources || node.type == folder)
352 if(node.type == project || node.type == folder || node.type == resources)
361 if(node.type == project || node.type == folder || node.type == resources)
363 NewFolder(node, null, true);
370 if(node.type == file)
372 FileCompile(null, (Modifiers)key);
377 case Key { space, shift = true }:
380 if(node.type == NodeTypes::project)
383 for(p : workspace.projects)
385 if(p.topNode == node)
391 prj.RotateActiveConfig(!key.shift);
402 case enter: case keyPadEnter: OpenSelectedNodes(); break;
403 case del: RemoveSelectedNodes(); break;
406 Window activeClient = ide.activeClient;
408 activeClient.Activate();
410 ide.RepositionWindows(true);
417 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
419 ProjectNode node = (ProjectNode)row.tag;
420 if(node.type == folder)
421 node.icon = collapsed ? folder : openFolder;
426 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
427 FileDialog projectFileDialog
429 autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
430 types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
432 FileDialog fileDialog
434 autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
436 FileDialog resourceFileDialog
438 autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
441 Menu fileMenu { menu, $"File", f };
442 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
443 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
445 bool OnClose(bool parentClosing)
447 if(!parentClosing && visible)
457 DialogResult dialogRes;
460 strcpy(msg, $"You have modified projects.\nSave changes to ");
461 for(p : ide.workspace.projects)
463 if(p.topNode.modified)
465 if(!first) strcat(msg, ", ");
472 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
476 // TOFIX: Precomp error if brackets are taken out
477 return (DialogResult)MenuFileSave(null, 0) != cancel;
479 else if(dialogRes == cancel)
481 modifiedDocument = false;
488 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
489 // ide.findInFilesDialog.SearchStop();
491 ide.outputView.buildBox.Clear();
492 ide.outputView.debugBox.Clear();
493 //ide.outputView.findBox.Clear();
494 ide.callStackView.Clear();
495 ide.watchesView.Clear();
496 ide.threadsView.Clear();
497 ide.breakpointsView.Clear();
498 ide.outputView.ShowClearSelectTab(find); // why this?
501 bool OnSaveFile(char * fileName)
503 for(prj : ide.workspace.projects)
505 if(prj.topNode.modified)
507 prj.StopMonitoring();
508 if(prj.Save(prj.filePath))
509 prj.topNode.modified = false;
510 prj.StartMonitoring();
513 modifiedDocument = false;
518 bool IsModuleInProject(char * filePath)
520 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
521 GetLastDirectory(filePath, moduleName);
522 return project.topNode.Find(moduleName, false) != null;
525 bool GetRelativePath(char * filePath, char * relativePath)
527 return project.GetRelativePath(filePath, relativePath);
530 ProjectNode GetNodeFromWindow(Window document, Project project)
532 if(document.fileName)
534 char winFileName[MAX_LOCATION];
535 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
536 for(p : ide.workspace.projects)
538 Project prj = project ? project : p;
540 if((node = prj.topNode.FindByFullPath(documentFileName, false)))
548 // ((( UTILITY FUNCTIONS )))
550 // ************************************************************************
551 // *** These methods below are part of a sequence of events, and as ***
552 // *** such they must be passed the current compiler and project config ***
553 // ************************************************************************
554 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
556 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
560 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
561 CompilerConfig compiler, ProjectConfig config)
564 char message[MAX_F_STRING];
565 LogBox logBox = ide.outputView.buildBox;
567 ShowOutputBuildLog(cleanLog);
570 DisplayCompiler(compiler, false);
572 ProjectPrepareCompiler(project, compiler);
573 ProjectPrepareMakefile(project, method, compiler, config);
577 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler)
579 project.GenerateCrossPlatformCf();
580 project.GenerateCompilerMk(compiler);
584 // Note: Compiler is only passed in to for VisualStudio support
585 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
587 #if defined(__WIN32__) // I'm guessing we'll want to support generating VS files on Linux as well...
588 if(compiler.type.isVC)
590 ide.statusBar.text = $"Generating Visual Studio Solution...";
592 GenerateVSSolutionFile(project, compiler);
593 ide.statusBar.text = $"Generating Visual Studio Project...";
595 GenerateVCProjectFile(project, compiler);
596 ide.statusBar.text = null;
603 char makefilePath[MAX_LOCATION];
604 char makefileName[MAX_LOCATION];
606 LogBox logBox = ide.outputView.buildBox;
608 strcpy(makefilePath, project.topNode.path);
609 project.CatMakeFileName(makefileName, config);
610 PathCatSlash(makefilePath, makefileName);
612 exists = FileExists(makefilePath);
613 if(method == force ||
614 (method == forceExists && exists) ||
615 (method == normal && (!exists || config.makingModified)) )
619 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
622 if((method == normal && !exists) || (method == force && !exists))
623 action = $"Generating ";
624 else if(method == force)
625 action = $"Regenerating ";
626 else if(method == normal || method == forceExists)
627 action = $"Updating ";
631 reason = $"Makefile doesn't exist. ";
632 else if(project.topNode.modified)
633 reason = $"Project has been modified. ";
637 //logBox.Logf("%s\n", makefileName);
638 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
640 project.GenerateMakefile(null, false, null, config);
642 ide.statusBar.text = null;
650 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
652 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
654 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
655 return Build(prj, buildType, compiler, config);
660 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
663 // TOFIX: DebugStop is being abused and backfiring on us.
664 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
666 // configIsInDebugSession seems to be used for two OPPOSITE things:
667 // If we're debugging another config, we need to unload the executable!
668 // In building, we want to stop if we're debugging the 'same' executable
669 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
671 if(buildType == start || buildType == restart)
673 if(ide.debugger && ide.debugger.isPrepared)
674 result = DebugStop();
678 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
679 result = DebugStop();
685 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
691 for(document = master.firstChild; document; document = document.next)
693 if(document.modifiedDocument)
695 ProjectNode node = GetNodeFromWindow(document, prj);
696 if(node && !document.MenuFileSave(null, 0))
705 DirExpression targetDir = prj.GetTargetDir(compiler, config);
707 DebugStopForMake(prj, buildType, compiler, config);
709 // TODO: Disabled until problems fixed... is it fixed?
710 if(buildType == rebuild || (config && config.compilingModified))
711 prj.Clean(compiler, config, false);
714 if(buildType == relink || (config && config.linkingModified))
716 char target[MAX_LOCATION];
718 strcpy(target, prj.topNode.path);
719 PathCat(target, targetDir.dir);
720 prj.CatTargetFileName(target, compiler, config);
721 if(FileExists(target))
724 if(config && config.symbolGenModified)
726 DirExpression objDir = prj.GetObjDir(compiler, config);
727 char fileName[MAX_LOCATION];
728 char moduleName[MAX_FILENAME];
729 strcpy(fileName, prj.topNode.path);
730 PathCatSlash(fileName, objDir.dir);
731 strcpy(moduleName, prj.moduleName);
732 strcat(moduleName, ".main.ec");
733 PathCatSlash(fileName, moduleName);
734 if(FileExists(fileName))
735 DeleteFile(fileName);
736 ChangeExtension(fileName, "c", fileName);
737 if(FileExists(fileName))
738 DeleteFile(fileName);
739 ChangeExtension(fileName, "o", fileName);
740 if(FileExists(fileName))
741 DeleteFile(fileName);
746 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
747 ide.AdjustBuildMenus();
748 ide.AdjustDebugMenus();
750 result = prj.Build(buildType == run, null, compiler, config);
754 config.compilingModified = false;
755 if(!ide.ShouldStopBuild())
756 config.linkingModified = false;
758 config.symbolGenModified = false;
760 buildInProgress = none;
761 ide.AdjustBuildMenus();
762 ide.AdjustDebugMenus();
764 ide.workspace.modified = true;
771 // ((( USER ACTIONS )))
773 // ************************************************************************
774 // *** Methods below should atomically start a process, and as such ***
775 // *** they can query compiler and config directly from ide and project ***
776 // *** but ONLY ONCE!!! ***
777 // ************************************************************************
779 bool ProjectBuild(MenuItem selection, Modifiers mods)
781 Project prj = project;
782 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
783 ProjectConfig config;
784 if(selection || !ide.activeClient)
786 DataRow row = fileList.currentRow;
787 ProjectNode node = row ? (ProjectNode)row.tag : null;
788 if(node) prj = node.project;
792 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
797 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
799 BuildInterrim(prj, build, compiler, config);
805 bool ProjectLink(MenuItem selection, Modifiers mods)
807 Project prj = project;
808 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
809 ProjectConfig config;
810 if(selection || !ide.activeClient)
812 DataRow row = fileList.currentRow;
813 ProjectNode node = row ? (ProjectNode)row.tag : null;
814 if(node) prj = node.project;
818 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
823 if(!prj.GetConfigIsInDebugSession(config) ||
824 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
826 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
828 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
830 config.linkingModified = true;
831 Build(prj, relink, compiler, config);
838 bool ProjectRebuild(MenuItem selection, Modifiers mods)
840 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
841 Project prj = project;
842 ProjectConfig config;
843 if(selection || !ide.activeClient)
845 DataRow row = fileList.currentRow;
846 ProjectNode node = row ? (ProjectNode)row.tag : null;
847 if(node) prj = node.project;
851 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
856 if(!prj.GetConfigIsInDebugSession(config) ||
857 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
859 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
861 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
864 config.compilingModified = true;
865 config.makingModified = true;
866 }*/ // -- should this still be used depite the new solution of BuildType?
867 Build(prj, rebuild, compiler, config);
874 bool ProjectClean(MenuItem selection, Modifiers mods)
876 Project prj = project;
877 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
878 ProjectConfig config;
879 if(selection || !ide.activeClient)
881 DataRow row = fileList.currentRow;
882 ProjectNode node = row ? (ProjectNode)row.tag : null;
883 if(node) prj = node.project;
887 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
892 if(!prj.GetConfigIsInDebugSession(config) ||
893 (!ide.DontTerminateDebugSession($"Project Clean") && DebugStopForMake(prj, clean, compiler, config)))
895 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
897 ide.outputView.buildBox.Logf($"Cleaning project %s using the %s configuration...\n", prj.name, GetConfigName(config));
899 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
900 ide.AdjustBuildMenus();
901 ide.AdjustDebugMenus();
903 prj.Clean(compiler, config, false);
904 buildInProgress = none;
905 ide.AdjustBuildMenus();
906 ide.AdjustDebugMenus();
913 bool ProjectRealClean(MenuItem selection, Modifiers mods)
915 Project prj = project;
916 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
917 ProjectConfig config;
918 if(selection || !ide.activeClient)
920 DataRow row = fileList.currentRow;
921 ProjectNode node = row ? (ProjectNode)row.tag : null;
922 if(node) prj = node.project;
926 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
931 if(!prj.GetConfigIsInDebugSession(config) ||
932 (!ide.DontTerminateDebugSession($"Project Real Clean") && DebugStopForMake(prj, clean, compiler, config)))
934 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
936 ide.outputView.buildBox.Logf($"Removing intermediate objects directory for project %s using the %s configuration...\n", prj.name, GetConfigName(config));
938 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
939 ide.AdjustBuildMenus();
940 ide.AdjustDebugMenus();
942 prj.Clean(compiler, config, true);
943 buildInProgress = none;
944 ide.AdjustBuildMenus();
945 ide.AdjustDebugMenus();
952 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
954 Project prj = project;
955 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
956 ShowOutputBuildLog(true);
957 if(selection || !ide.activeClient)
959 DataRow row = fileList.currentRow;
960 ProjectNode node = row ? (ProjectNode)row.tag : null;
966 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
971 DisplayCompiler(compiler, false);
972 ProjectPrepareCompiler(project, compiler);
973 ProjectPrepareMakefile(prj, force, compiler, prj.config);
978 bool Compile(ProjectNode node)
981 char fileName[MAX_LOCATION];
983 Project prj = node.project;
984 ProjectConfig config = prj.config;
985 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
989 // Check if we have to save
990 strcpy(fileName, prj.topNode.path);
991 PathCatSlash(fileName, node.path);
992 PathCatSlash(fileName, node.name);
993 for(document = ide.firstChild; document; document = document.next)
995 if(document.modifiedDocument)
997 char documentFileName[MAX_LOCATION];
998 if(!fstrcmp(GetSlashPathBuffer(documentFileName, document.fileName), fileName))
999 if(!document.MenuFileSave(null, 0))
1004 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
1006 if(!node.GetIsExcluded(config))
1008 // Delete intermedaite files
1010 char extension[MAX_EXTENSION];
1011 DirExpression objDir = prj.GetObjDir(compiler, config);
1013 strcpy(fileName, prj.topNode.path);
1014 PathCatSlash(fileName, objDir.dir);
1015 PathCatSlash(fileName, node.name);
1016 StripExtension(fileName);
1017 strcat(fileName, ".o");
1018 if(FileExists(fileName))
1019 DeleteFile(fileName);
1021 GetExtension(node.name, extension);
1022 if(!strcmp(extension, "ec"))
1024 // Delete generated C file
1025 strcpy(fileName, prj.topNode.path);
1026 PathCat(fileName, objDir.dir);
1027 PathCat(fileName, node.name);
1028 StripExtension(fileName);
1029 strcat(fileName, ".c");
1030 if(FileExists(fileName))
1031 DeleteFile(fileName);
1033 // Delete symbol file
1034 strcpy(fileName, prj.topNode.path);
1035 PathCat(fileName, node.path);
1036 PathCat(fileName, node.name);
1037 StripExtension(fileName);
1038 strcat(fileName, ".sym");
1039 if(FileExists(fileName))
1040 DeleteFile(fileName);
1045 buildInProgress = compilingFile;
1046 ide.AdjustBuildMenus();
1048 //ide.outputView.ShowClearSelectTab(build);
1049 // this stuff doesn't even appear
1050 //ide.outputView.buildBox.Logf($"%s Compiler\n", compiler.name);
1052 ide.outputView.buildBox.Logf($"Compiling single file %s in project %s using the %s configuration...\n", node.name, prj.name, config.name);
1054 ide.outputView.buildBox.Logf($"Compiling single file %s in project %s...\n", node.name, prj.name);
1056 prj.Compile(node, compiler, config);
1057 buildInProgress = none;
1058 ide.AdjustBuildMenus();
1067 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1069 DataRow row = fileList.currentRow;
1072 char fileName[1024];
1073 char filePath[MAX_LOCATION];
1074 ProjectNode parentNode = (ProjectNode)row.tag;
1075 ProjectNode n, fileNode;
1076 parentNode.GetFileSysMatchingPath(filePath);
1077 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1078 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1079 sprintf(fileName, $"Untitled %d", documentID);
1080 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1081 fileNode.path = CopyUnixPath(filePath);
1084 NodeProperties nodeProperties
1087 position = { position.x + 100, position.y + 100 };
1091 nodeProperties.Create(); // not modal?
1097 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1099 DataRow row = fileList.currentRow;
1102 ProjectNode parentNode = (ProjectNode)row.tag;
1103 NewFolder(parentNode, null, true);
1108 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1114 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1120 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1122 DataRow row = fileList.currentRow;
1125 ProjectNode toNode = (ProjectNode)row.tag;
1126 ImportFolder(toNode);
1131 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1133 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1134 codeEditor.EnsureUpToDate();
1138 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1140 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1142 codeEditor.EnsureUpToDate();
1146 bool ProjectRemove(MenuItem selection, Modifiers mods)
1148 DataRow row = fileList.currentRow;
1151 ProjectNode node = (ProjectNode)row.tag;
1152 if(node.type == project)
1153 RemoveSelectedNodes();
1158 bool ProjectUpdateMakefileForAllConfigs(Project project)
1160 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1162 for(config : project.configurations)
1163 ProjectPrepareMakefile(project, forceExists, compiler, config);
1170 bool MenuConfig(MenuItem selection, Modifiers mods)
1172 if(ProjectActiveConfig { master = parent, project = project }.Modal() == ok)
1177 bool MenuCompiler(MenuItem selection, Modifiers mods)
1179 ActiveCompilerDialog compilerDialog
1182 ideSettings = ideSettings, workspaceActiveCompiler = ide.workspace.compiler;
1184 incref compilerDialog;
1185 if(compilerDialog.Modal() == ok && strcmp(compilerDialog.workspaceActiveCompiler, ide.workspace.compiler))
1187 CompilerConfig compiler = ideSettings.GetCompilerConfig(compilerDialog.workspaceActiveCompiler);
1188 ide.workspace.compiler = compilerDialog.workspaceActiveCompiler;
1189 ide.projectView.ShowOutputBuildLog(true);
1190 ide.projectView.DisplayCompiler(compiler, false);
1192 for(prj : ide.workspace.projects)
1193 ide.projectView.ProjectPrepareCompiler(prj, compiler);
1196 delete compilerDialog;
1200 bool MenuSettings(MenuItem selection, Modifiers mods)
1202 ProjectNode node = GetSelectedNode(true);
1203 Project prj = node ? node.project : project;
1204 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1205 projectSettingsDialog.Modal();
1212 bool FileProperties(MenuItem selection, Modifiers mods)
1214 DataRow row = fileList.currentRow;
1217 ProjectNode node = (ProjectNode)row.tag;
1218 NodeProperties { parent = parent, master = this, node = node,
1219 position = { position.x + 100, position.y + 100 } }.Create();
1224 bool FileOpenFile(MenuItem selection, Modifiers mods)
1226 OpenSelectedNodes();
1230 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1232 RemoveSelectedNodes();
1236 bool FileCompile(MenuItem selection, Modifiers mods)
1238 DataRow row = fileList.currentRow;
1241 ProjectNode node = (ProjectNode)row.tag;
1243 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1248 Project GetSelectedProject(bool useSelection)
1250 Project prj = project;
1253 DataRow row = fileList.currentRow;
1254 ProjectNode node = row ? (ProjectNode)row.tag : null;
1261 ProjectNode GetSelectedNode(bool useSelection)
1263 ProjectNode node = null;
1266 DataRow row = fileList.currentRow;
1268 node = (ProjectNode)row.tag;
1273 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1275 char folder[MAX_LOCATION];
1277 ProjectNode node = GetSelectedNode(true);
1279 node = project.topNode;
1282 strcpy(folder, prj.topNode.path);
1283 if(node != prj.topNode)
1284 PathCatSlash(folder, node.path);
1289 bool Run(MenuItem selection, Modifiers mods)
1291 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1292 ProjectConfig config = project.config;
1293 String args = new char[maxPathLen];
1295 if(ide.workspace.commandLineArgs)
1296 //ide.debugger.GetCommandLineArgs(args);
1297 strcpy(args, ide.workspace.commandLineArgs);
1298 if(ide.debugger.isActive)
1299 project.Run(args, compiler, config);
1300 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1301 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1302 else if(BuildInterrim(project, run, compiler, config))
1303 project.Run(args, compiler, config);
1311 bool result = false;
1312 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1313 ProjectConfig config = project.config;
1314 TargetTypes targetType = project.GetTargetType(config);
1315 if(targetType == sharedLibrary || targetType == staticLibrary)
1316 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1317 else if(project.GetCompress(config))
1318 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1319 else if(project.GetDebug(config) ||
1320 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1322 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config))
1324 if(compiler.type.isVC)
1326 //bool result = false;
1327 char oldwd[MAX_LOCATION];
1328 PathBackup pathBackup { };
1329 char command[MAX_LOCATION];
1331 ide.SetPath(false, compiler, config);
1333 GetWorkingDir(oldwd, sizeof(oldwd));
1334 ChangeWorkingDir(project.topNode.path);
1336 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1337 //ide.outputView.buildBox.Logf("command: %s\n", command);
1339 ChangeWorkingDir(oldwd);
1345 ide.debugger.Start(compiler, config);
1354 void GoToError(const char * line)
1358 while(isspace(*line)) line++;
1359 colon = strstr(line, ":");
1364 bool lookForLineNumber = true;
1366 // deal with linking error
1367 if(colon && colon[1] == ' ')
1369 colon = strstr(colon + 1, ":");
1370 if(colon && !colon[1])
1372 colon = strstr(line, ":");
1373 lookForLineNumber = false;
1375 else if(colon && !isdigit(colon[1]))
1378 colon = strstr(line, ":");
1381 // Don't be mistaken by the drive letter colon
1382 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1383 colon = strstr(colon + 1, ":");
1384 if(colon && lookForLineNumber)
1388 char * par = RSearchString(line, "(", colon - line, true, false);
1389 if(par && strstr(par, ")"))
1391 else if((colon+1)[0] == ' ')
1393 // NOTE: This is the same thing as saying 'colon = line'
1394 for( ; colon != line; colon--)
1398 lineNumber = atoi(colon + 1);
1400 comma = strchr(colon, ',');
1402 col = atoi(comma+1);
1404 comma = strchr(colon+1, ':');
1406 col = atoi(comma+1);
1410 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
1414 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1415 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1416 int len = (int)(colon - start);
1417 len = Min(len, MAX_LOCATION-1);
1419 strncpy(moduleName, start, len);
1420 moduleName[len] = '\0';
1423 strcpy(moduleName, line);
1425 // Remove stuff in brackets
1427 bracket = strstr(moduleName, "(");
1428 if(bracket) *bracket = '\0';
1430 MakeSlashPath(moduleName);
1434 // Check if it's one of our modules
1435 ProjectNode node = project.topNode.Find(moduleName, false);
1438 strcpy(moduleName, node.path);
1439 PathCatSlash(moduleName, node.name);
1442 moduleName[0] = '\0';
1446 CodeEditor codeEditor;
1447 strcpy(filePath, project.topNode.path);
1448 PathCatSlash(filePath, moduleName);
1450 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1453 char name[MAX_LOCATION];
1454 // TOFIX: Improve on this, don't use only filename, make a function
1455 if(ide && ide.workspace)
1457 for(prj : ide.workspace.projects)
1459 if(prj.topNode.FindWithPath(moduleName, false))
1461 strcpy(filePath, prj.topNode.path);
1462 PathCatSlash(filePath, moduleName);
1463 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1470 if(codeEditor && lineNumber)
1472 EditBox editBox = codeEditor.editBox;
1473 editBox.GoToLineNum(lineNumber - 1);
1474 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1481 bool OpenNode(ProjectNode node)
1483 char filePath[MAX_LOCATION];
1484 node.GetFullFilePath(filePath);
1485 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
1488 void AddNode(ProjectNode node, DataRow addTo)
1490 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1492 row.tag = (int)node;
1495 if(node.type == resources)
1498 row.SetData(null, node);
1500 if(node.files && node.files.first && node.parent &&
1501 !(!node.parent.parent &&
1502 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1503 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1504 row.collapsed = true;
1505 else if(node.type == folder)
1506 node.icon = openFolder;
1510 for(child : node.files)
1511 AddNode(child, row);
1515 void DeleteNode(ProjectNode projectNode)
1517 if(projectNode.files)
1520 while(child = projectNode.files.first)
1523 fileList.DeleteRow(projectNode.row);
1524 projectNode.Delete();
1527 bool ProjectSave(MenuItem selection, Modifiers mods)
1529 DataRow row = fileList.currentRow;
1530 ProjectNode node = row ? (ProjectNode)row.tag : null;
1531 Project prj = node ? node.project : null;
1534 prj.StopMonitoring();
1535 if(prj.Save(prj.filePath))
1537 Project modPrj = null;
1538 prj.topNode.modified = false;
1539 for(p : ide.workspace.projects)
1541 if(p.topNode.modified)
1548 modifiedDocument = false;
1551 prj.StartMonitoring();
1556 bool ShowOutputBuildLog(bool cleanLog)
1558 OutputView output = ide.outputView;
1560 output.ShowClearSelectTab(build);
1563 output.SelectTab(build);
1571 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1572 ProjectConfig config = project.config;
1574 bool result = false;
1575 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config))
1577 // For Restart, compiler and config will only be used if for
1578 // whatever reason (if at all possible) the Debugger is in a
1579 // 'terminated' or 'none' state
1580 ide.debugger.Restart(compiler, config);
1590 ide.debugger.Resume();
1596 ide.debugger.Break();
1602 ide.debugger.Stop();
1606 bool DebugStepInto()
1608 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1609 ProjectConfig config = project.config;
1611 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config)))
1612 ide.debugger.StepInto(compiler, config);
1617 bool DebugStepOver(bool skip)
1619 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1620 ProjectConfig config = project.config;
1622 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config)))
1623 ide.debugger.StepOver(compiler, config, skip);
1629 bool DebugStepOut(bool skip)
1631 ide.debugger.StepOut(skip);
1635 void ImportFolder(ProjectNode toNode)
1639 //bool isFolder = toNode.type == folder;
1640 //bool isRes = toNode.isInResources;
1642 FileDialog fileDialog = importFileDialog;
1643 fileDialog.master = parent;
1644 if(fileDialog.Modal() == ok)
1646 ImportFolderFSI fsi { projectView = this };
1647 fsi.stack.Add(toNode);
1648 fsi.Iterate(fileDialog.filePath);
1654 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1658 ProjectNode folderNode;
1659 Project prj = parentNode.project;
1661 ProjectNode after = null;
1662 for(node : parentNode.files)
1664 if(node.type != folder)
1670 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1673 for(c = 0; c < 100; c++)
1676 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1677 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1684 NodeProperties nodeProperties;
1687 modifiedDocument = true;
1688 prj.topNode.modified = true;
1691 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1692 folderNode.row.tag = (int)folderNode;
1694 folderNode.row.SetData(null, folderNode);
1695 fileList.currentRow = folderNode.row;
1699 nodeProperties = NodeProperties
1701 parent, this, mode = newFolder, node = folderNode;
1702 position = { position.x + 100, position.y + 100 };
1704 nodeProperties.Create(); // Modal?
1712 void AddFiles(bool resources)
1714 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1715 fileDialog.type = multiOpen;
1716 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
1717 fileDialog.master = parent;
1719 if(fileDialog.Modal() == ok)
1722 DataRow row = fileList.currentRow;
1723 ProjectNode parentNode = (ProjectNode)row.tag;
1724 bool addFailed = false;
1725 int numSelections = fileDialog.numSelections;
1726 char ** multiFilePaths = fileDialog.multiFilePaths;
1728 Array<String> nameConflictFiles { };
1730 for(c = 0; c < numSelections; c++)
1732 char * filePath = multiFilePaths[c];
1733 FileAttribs exists = FileExists(filePath);
1734 bool addThisFile = true;
1736 if(exists.isDirectory)
1737 addThisFile = false;
1740 if(MessageBox { master = ide, type = yesNo, text = filePath,
1741 contents = $"File doesn't exist. Create?" }.Modal() == yes)
1743 File f = FileOpen(filePath, write);
1751 MessageBox { master = ide, type = ok, text = filePath,
1752 contents = $"Couldn't create file."}.Modal();
1753 addThisFile = false;
1760 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
1762 nameConflictFiles.Add(CopyString(filePath));
1770 char * part1 = $"The following file";
1771 char * opt1 = $" was ";
1772 char * opt2 = $"s were ";
1773 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
1775 len += strlen(part1);
1776 len += strlen(part2);
1777 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1778 for(s : nameConflictFiles)
1779 len += strlen(s) + 1;
1780 message = new char[len + 1];
1781 strcpy(message, part1);
1782 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1783 strcat(message, part2);
1784 for(s : nameConflictFiles)
1787 strcat(message, "\n");
1789 MessageBox { master = ide, type = ok, text = $"Name Conflict",
1790 contents = message }.Modal();
1793 nameConflictFiles.Free();
1794 delete nameConflictFiles;
1798 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
1800 ProjectNode result = null;
1801 ProjectNode after = null;
1802 for(node : parentNode.files)
1804 if(node.type != folder && node.type != file && node.type)
1809 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
1815 modifiedDocument = true;
1816 parentNode.project.topNode.modified = true;
1817 parentNode.project.ModifiedAllConfigs(true, false, true, true);
1820 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
1821 result.row.tag = (int)result;
1822 result.row.SetData(null, result);
1827 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
1829 CodeEditor codeEditor = null;
1830 ProjectNode projectNode;
1831 ProjectNode after = null;
1832 DataRow row = fileList.currentRow;
1833 ProjectNode parentNode;
1836 if(!row) row = project.topNode.row;
1838 parentNode = (ProjectNode)row.tag;
1840 for(node : parentNode.files)
1842 if(node.type != folder && node.type != file && node.type)
1846 for(c = 1; c < 100; c++)
1849 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
1850 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
1856 char filePath[MAX_LOCATION];
1858 modifiedDocument = true;
1859 project.topNode.modified = true;
1861 project.ModifiedAllConfigs(true, false, false, true);
1862 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1863 projectNode.row.tag =(int)projectNode;
1865 projectNode.row.SetData(null, projectNode);
1866 fileList.currentRow = projectNode.row;
1868 strcpy(filePath, project.topNode.path);
1869 PathCat(filePath, projectNode.path);
1870 PathCat(filePath, projectNode.name);
1872 codeEditor = (CodeEditor)ide.FindWindow(filePath);
1875 Class baseClass = eSystem_FindClass(__thisModule, base);
1876 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
1879 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1880 strcpy(name, projectNode.name);
1881 sprintf(name, "%s%d", upper, c);
1883 strcpy(className, name);
1885 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
1887 //codeEditor.modifiedDocument = false;
1888 //codeEditor.designer.modifiedDocument = false;
1890 //Code_EnsureUpToDate(codeEditor);
1893 else // TODO: fix no symbols generated when ommiting {} for following else
1895 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1899 codeEditor.ViewDesigner();
1900 codeEditor.codeModified = true;
1907 // Returns true if we opened something
1908 bool OpenSelectedNodes()
1910 bool result = false;
1914 fileList.GetMultiSelection(selection);
1915 for(item = selection.first; item; item = item.next)
1917 DataRow row = item.data;
1918 ProjectNode node = (ProjectNode)row.tag;
1919 if(node.type == file)
1926 selection.Free(null);
1930 void RemoveSelectedNodes()
1935 fileList.GetMultiSelection(selection);
1937 // Remove children of parents we're deleting
1938 for(item = selection.first; item; item = next)
1941 DataRow row = item.data;
1942 ProjectNode n, node = (ProjectNode)row.tag;
1943 bool remove = false;
1946 for(i = selection.first; i && !remove; i = i.next)
1948 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
1949 for(n = node.parent; n; n = n.parent)
1959 selection.Delete(item);
1962 for(item = selection.first; item; item = item.next)
1964 DataRow row = item.data;
1965 ProjectNode node = (ProjectNode)row.tag;
1966 ProjectNode resNode;
1967 for(resNode = node.parent; resNode; resNode = resNode.parent)
1968 if(resNode.type == resources)
1970 if(node.type == file)
1972 Project prj = node.project;
1974 modifiedDocument = true;
1975 prj.topNode.modified = true;
1977 prj.ModifiedAllConfigs(true, false, true, true);
1979 else if(node.type == folder)
1982 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
1983 "and all of its contents from the project?", node.name);
1984 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
1986 Project prj = node.project;
1987 if(node.containsFile)
1988 prj.ModifiedAllConfigs(true, false, true, true);
1990 modifiedDocument = true;
1991 prj.topNode.modified = true;
1994 else if(node.type == project && node != project.topNode && !buildInProgress)
1998 for(p : workspace.projects)
2000 if(p.topNode == node)
2006 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2007 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2012 workspace.RemoveProject(prj);
2013 //modifiedDocument = true; // when project view is a workspace view
2017 selection.Free(null);