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, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = buildMenuUnavailable;
227 MenuDivider { popupContent };
228 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
229 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
230 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
231 MenuItem { popupContent, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
232 MenuDivider { popupContent };
233 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
234 // MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
235 MenuDivider { popupContent };
236 if(node != ((Project)workspace.projects.first).topNode)
238 MenuItem { popupContent, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = buildMenuUnavailable;
239 MenuDivider { popupContent };
241 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
242 MenuDivider { popupContent };
243 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
244 MenuDivider { popupContent };
245 MenuItem { popupContent, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
246 MenuDivider { popupContent };
247 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
249 else if(node.type == resources)
251 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
252 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
253 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
254 MenuItem { popupContent, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
255 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
256 MenuDivider { popupContent };
257 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
258 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
260 else if(node.type == file)
262 MenuItem { popupContent, $"Open", o, NotifySelect = FileOpenFile };
263 MenuDivider { popupContent };
264 MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
265 MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
266 MenuDivider { popupContent };
267 MenuItem { popupContent, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = buildMenuUnavailable;
268 MenuItem { popupContent, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = buildMenuUnavailable;
269 MenuDivider { popupContent };
270 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
271 MenuDivider { popupContent };
272 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
273 MenuDivider { popupContent };
274 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
275 MenuItem { popupContent, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
277 else if(node.type == folder)
279 bool isInResources = node.isInResources;
281 MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
282 MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
283 MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
286 MenuItem { popupContent, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
290 MenuItem { popupContent, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
294 MenuDivider { popupContent };
295 MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
296 MenuItem { popupContent, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
298 MenuDivider { popupContent };
299 MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
300 MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
301 MenuDivider { popupContent };
302 MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
303 MenuDivider { popupContent };
304 MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
305 MenuDivider { popupContent };
306 MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
307 MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
312 master = this, menu = popupContent;
314 x + clientStart.x + absPosition.x - app.desktop.position.x,
315 y + clientStart.y + absPosition.y - app.desktop.position.y };
317 void NotifyDestroyed(Window window, DialogResult result)
328 bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
330 if(key == altUp || key == altDown)
332 SelectNextProject(key == altUp);
338 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
342 ProjectNode node = (ProjectNode)row.tag;
345 case altEnter: case Key { keyPadEnter, alt = true }:
347 NodeProperties { parent = parent, master = this,
348 position = { position.x + 100, position.y + 100 }, node = node }.Create();
351 case enter: case keyPadEnter:
354 for(resNode = node.parent; resNode; resNode = resNode.parent)
355 if(resNode.type == resources)
357 if(node.type == project || (node.type == folder && !resNode))
362 else if(node.type == resources || node.type == folder)
371 if(node.type == project || node.type == folder || node.type == resources)
380 if(node.type == project || node.type == folder || node.type == resources)
382 NewFolder(node, null, true);
389 if(node.type == file)
391 FileCompile(null, (Modifiers)key);
396 case Key { space, shift = true }:
399 if(node.type == NodeTypes::project)
402 for(p : workspace.projects)
404 if(p.topNode == node)
410 prj.RotateActiveConfig(!key.shift);
421 case enter: case keyPadEnter: OpenSelectedNodes(); break;
422 case del: RemoveSelectedNodes(); break;
425 Window activeClient = ide.activeClient;
427 activeClient.Activate();
429 ide.RepositionWindows(true);
436 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
438 ProjectNode node = (ProjectNode)row.tag;
439 if(node.type == folder)
440 node.icon = collapsed ? folder : openFolder;
445 FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
446 FileDialog projectFileDialog
448 autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
449 types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
451 FileDialog fileDialog
453 autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
455 FileDialog resourceFileDialog
457 autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
460 Menu fileMenu { menu, $"File", f };
461 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
462 // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
464 bool OnClose(bool parentClosing)
466 if(!parentClosing && visible)
476 DialogResult dialogRes;
479 strcpy(msg, $"You have modified projects.\nSave changes to ");
480 for(p : ide.workspace.projects)
482 if(p.topNode.modified)
484 if(!first) strcat(msg, ", ");
491 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
495 // TOFIX: Precomp error if brackets are taken out
496 return (DialogResult)MenuFileSave(null, 0) != cancel;
498 else if(dialogRes == cancel)
500 modifiedDocument = false;
507 //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
508 // ide.findInFilesDialog.SearchStop();
510 ide.outputView.buildBox.Clear();
511 ide.outputView.debugBox.Clear();
512 //ide.outputView.findBox.Clear();
513 ide.callStackView.Clear();
514 ide.watchesView.Clear();
515 ide.threadsView.Clear();
516 ide.breakpointsView.Clear();
517 ide.outputView.ShowClearSelectTab(find); // why this?
520 bool OnSaveFile(char * fileName)
522 for(prj : ide.workspace.projects)
524 if(prj.topNode.modified)
526 prj.StopMonitoring();
527 if(prj.Save(prj.filePath))
528 prj.topNode.modified = false;
529 prj.StartMonitoring();
532 modifiedDocument = false;
537 bool IsModuleInProject(char * filePath)
539 char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
540 GetLastDirectory(filePath, moduleName);
541 return project.topNode.Find(moduleName, false) != null;
544 bool GetRelativePath(char * filePath, char * relativePath)
546 return project.GetRelativePath(filePath, relativePath);
549 ProjectNode GetNodeFromWindow(Window document, Project project)
551 if(document.fileName)
553 char winFileName[MAX_LOCATION];
554 char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
555 for(p : ide.workspace.projects)
557 Project prj = project ? project : p;
559 if((node = prj.topNode.FindByFullPath(documentFileName, false)))
567 // ((( UTILITY FUNCTIONS )))
569 // ************************************************************************
570 // *** These methods below are part of a sequence of events, and as ***
571 // *** such they must be passed the current compiler and project config ***
572 // ************************************************************************
573 bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
575 ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
579 bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
580 CompilerConfig compiler, ProjectConfig config)
583 char message[MAX_F_STRING];
584 LogBox logBox = ide.outputView.buildBox;
586 ShowOutputBuildLog(cleanLog);
589 DisplayCompiler(compiler, false);
591 ProjectPrepareCompiler(project, compiler);
592 ProjectPrepareMakefile(project, method, compiler, config);
596 bool ProjectPrepareCompiler(Project project, CompilerConfig compiler)
598 if(!project.GenerateCrossPlatformMk() || !project.GenerateCompilerCf(compiler))
599 ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
603 // Note: Compiler is only passed in to for VisualStudio support
604 bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
606 if(compiler.type.isVC)
608 // I'm guessing we'll want to support generating VS files on Linux as well...
609 ide.statusBar.text = $"Generating Visual Studio Solution...";
611 //GenerateVSSolutionFile(project, compiler);
612 ide.statusBar.text = $"Generating Visual Studio Project...";
614 //GenerateVCProjectFile(project, compiler);
615 ide.statusBar.text = null;
621 char makefilePath[MAX_LOCATION];
622 char makefileName[MAX_LOCATION];
624 LogBox logBox = ide.outputView.buildBox;
626 strcpy(makefilePath, project.topNode.path);
627 project.CatMakeFileName(makefileName, config);
628 PathCatSlash(makefilePath, makefileName);
630 exists = FileExists(makefilePath);
631 if(method == force ||
632 (method == forceExists && exists) ||
633 (method == normal && (!exists || (config && config.makingModified))))
637 ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
640 if((method == normal && !exists) || (method == force && !exists))
641 action = $"Generating ";
642 else if(method == force)
643 action = $"Regenerating ";
644 else if(method == normal || method == forceExists)
645 action = $"Updating ";
649 reason = $"Makefile doesn't exist. ";
650 else if(project.topNode.modified)
651 reason = $"Project has been modified. ";
655 //logBox.Logf("%s\n", makefileName);
656 logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
658 if(!project.GenerateMakefile(null, false, null, config))
659 ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
661 ide.statusBar.text = null;
669 bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, bool justPrint)
671 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
673 ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
674 return Build(prj, buildType, compiler, config, justPrint);
679 bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
682 // TOFIX: DebugStop is being abused and backfiring on us.
683 // It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
685 // configIsInDebugSession seems to be used for two OPPOSITE things:
686 // If we're debugging another config, we need to unload the executable!
687 // In building, we want to stop if we're debugging the 'same' executable
688 if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
690 if(buildType == start || buildType == restart)
692 if(ide.debugger && ide.debugger.isPrepared)
693 result = DebugStop();
697 if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
698 result = DebugStop();
704 bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, bool justPrint)
710 for(document = master.firstChild; document; document = document.next)
712 if(document.modifiedDocument)
714 ProjectNode node = GetNodeFromWindow(document, prj);
715 if(node && !document.MenuFileSave(null, 0))
724 DirExpression targetDir = prj.GetTargetDir(compiler, config);
726 DebugStopForMake(prj, buildType, compiler, config);
728 // TODO: Disabled until problems fixed... is it fixed?
729 if(buildType == rebuild || (config && config.compilingModified))
730 prj.Clean(compiler, config, false, justPrint);
733 if(buildType == relink || (config && config.linkingModified))
735 char target[MAX_LOCATION];
737 strcpy(target, prj.topNode.path);
738 PathCat(target, targetDir.dir);
739 prj.CatTargetFileName(target, compiler, config);
740 if(FileExists(target))
743 if(config && config.symbolGenModified)
745 DirExpression objDir = prj.GetObjDir(compiler, config);
746 char fileName[MAX_LOCATION];
747 char moduleName[MAX_FILENAME];
748 strcpy(fileName, prj.topNode.path);
749 PathCatSlash(fileName, objDir.dir);
750 strcpy(moduleName, prj.moduleName);
751 strcat(moduleName, ".main.ec");
752 PathCatSlash(fileName, moduleName);
753 if(FileExists(fileName))
754 DeleteFile(fileName);
755 ChangeExtension(fileName, "c", fileName);
756 if(FileExists(fileName))
757 DeleteFile(fileName);
758 ChangeExtension(fileName, "o", fileName);
759 if(FileExists(fileName))
760 DeleteFile(fileName);
765 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
766 ide.AdjustBuildMenus();
767 ide.AdjustDebugMenus();
769 result = prj.Build(buildType == run, null, compiler, config, justPrint, normal);
773 config.compilingModified = false;
774 if(!ide.ShouldStopBuild())
775 config.linkingModified = false;
777 config.symbolGenModified = false;
779 buildInProgress = none;
780 ide.AdjustBuildMenus();
781 ide.AdjustDebugMenus();
783 ide.workspace.modified = true;
790 // ((( USER ACTIONS )))
792 // ************************************************************************
793 // *** Methods below should atomically start a process, and as such ***
794 // *** they can query compiler and config directly from ide and project ***
795 // *** but ONLY ONCE!!! ***
796 // ************************************************************************
798 bool ProjectBuild(MenuItem selection, Modifiers mods)
800 Project prj = project;
801 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
802 ProjectConfig config;
803 if(selection || !ide.activeClient)
805 DataRow row = fileList.currentRow;
806 ProjectNode node = row ? (ProjectNode)row.tag : null;
807 if(node) prj = node.project;
811 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
816 if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
818 BuildInterrim(prj, build, compiler, config, mods.ctrl && mods.shift);
824 bool ProjectLink(MenuItem selection, Modifiers mods)
826 Project prj = project;
827 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
828 ProjectConfig config;
829 if(selection || !ide.activeClient)
831 DataRow row = fileList.currentRow;
832 ProjectNode node = row ? (ProjectNode)row.tag : null;
833 if(node) prj = node.project;
837 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
842 if(!prj.GetConfigIsInDebugSession(config) ||
843 (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
845 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
847 ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
849 config.linkingModified = true;
850 Build(prj, relink, compiler, config, mods.ctrl && mods.shift);
857 bool ProjectRebuild(MenuItem selection, Modifiers mods)
859 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
860 Project prj = project;
861 ProjectConfig config;
862 if(selection || !ide.activeClient)
864 DataRow row = fileList.currentRow;
865 ProjectNode node = row ? (ProjectNode)row.tag : null;
866 if(node) prj = node.project;
870 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
875 if(!prj.GetConfigIsInDebugSession(config) ||
876 (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
878 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
880 ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
883 config.compilingModified = true;
884 config.makingModified = true;
885 }*/ // -- should this still be used depite the new solution of BuildType?
886 Build(prj, rebuild, compiler, config, mods.ctrl && mods.shift);
893 bool ProjectClean(MenuItem selection, Modifiers mods)
895 Project prj = project;
896 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
897 ProjectConfig config;
898 if(selection || !ide.activeClient)
900 DataRow row = fileList.currentRow;
901 ProjectNode node = row ? (ProjectNode)row.tag : null;
902 if(node) prj = node.project;
906 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
911 if(!prj.GetConfigIsInDebugSession(config) ||
912 (!ide.DontTerminateDebugSession($"Project Clean") && DebugStopForMake(prj, clean, compiler, config)))
914 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
916 ide.outputView.buildBox.Logf($"Cleaning project %s using the %s configuration...\n", prj.name, GetConfigName(config));
918 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
919 ide.AdjustBuildMenus();
920 ide.AdjustDebugMenus();
922 prj.Clean(compiler, config, false, mods.ctrl && mods.shift);
923 buildInProgress = none;
924 ide.AdjustBuildMenus();
925 ide.AdjustDebugMenus();
932 bool ProjectRealClean(MenuItem selection, Modifiers mods)
934 Project prj = project;
935 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
936 ProjectConfig config;
937 if(selection || !ide.activeClient)
939 DataRow row = fileList.currentRow;
940 ProjectNode node = row ? (ProjectNode)row.tag : null;
941 if(node) prj = node.project;
945 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
950 if(!prj.GetConfigIsInDebugSession(config) ||
951 (!ide.DontTerminateDebugSession($"Project Real Clean") && DebugStopForMake(prj, clean, compiler, config)))
953 if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
955 ide.outputView.buildBox.Logf($"Removing intermediate objects directory for project %s using the %s configuration...\n", prj.name, GetConfigName(config));
957 buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
958 ide.AdjustBuildMenus();
959 ide.AdjustDebugMenus();
961 prj.Clean(compiler, config, true, mods.ctrl && mods.shift);
962 buildInProgress = none;
963 ide.AdjustBuildMenus();
964 ide.AdjustDebugMenus();
971 bool ProjectRegenerate(MenuItem selection, Modifiers mods)
973 Project prj = project;
974 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
975 ShowOutputBuildLog(true);
976 if(selection || !ide.activeClient)
978 DataRow row = fileList.currentRow;
979 ProjectNode node = row ? (ProjectNode)row.tag : null;
985 ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
990 DisplayCompiler(compiler, false);
991 ProjectPrepareCompiler(project, compiler);
992 ProjectPrepareMakefile(prj, force, compiler, prj.config);
997 bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
1000 char fileName[MAX_LOCATION];
1002 ProjectConfig config = project.config;
1006 for(document = ide.firstChild; document; document = document.next)
1008 if(document.modifiedDocument)
1010 ProjectNode n = GetNodeFromWindow(document, project);
1013 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1015 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1025 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1027 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1030 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1031 mode == normal ? $"Compiling" : $"Debug compiling", project.name, config.name);
1033 ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1034 mode == normal ? $"Compiling" : $"Debug compiling", project.name);
1036 buildInProgress = compilingFile;
1037 ide.AdjustBuildMenus();
1038 project.Compile(nodes, compiler, config, justPrint, mode);
1039 buildInProgress = none;
1040 ide.AdjustBuildMenus();
1049 bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1052 char fileName[MAX_LOCATION];
1054 ProjectConfig config = project.config;
1058 for(document = ide.firstChild; document; document = document.next)
1060 if(document.modifiedDocument)
1062 ProjectNode n = GetNodeFromWindow(document, project);
1065 if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1067 ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1077 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1079 if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1083 if(node.GetIsExcluded(config))
1084 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1088 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s using the %s configuration...\n",
1089 node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1091 ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s...\n",
1092 node.type == file ? $"single file" : $"folder", node.name, project.name);
1094 node.DeleteIntermediateFiles(compiler, config);
1104 bool ProjectNewFile(MenuItem selection, Modifiers mods)
1106 DataRow row = fileList.currentRow;
1109 char fileName[1024];
1110 char filePath[MAX_LOCATION];
1111 ProjectNode parentNode = (ProjectNode)row.tag;
1112 ProjectNode n, fileNode;
1113 parentNode.GetFileSysMatchingPath(filePath);
1114 MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1115 for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1116 sprintf(fileName, $"Untitled %d", documentID);
1117 fileNode = AddFile(parentNode, fileName, (bool)n, true);
1118 fileNode.path = CopyUnixPath(filePath);
1121 NodeProperties nodeProperties
1124 position = { position.x + 100, position.y + 100 };
1128 nodeProperties.Create(); // not modal?
1134 bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1136 DataRow row = fileList.currentRow;
1139 ProjectNode parentNode = (ProjectNode)row.tag;
1140 NewFolder(parentNode, null, true);
1145 bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1151 bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1157 bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1159 DataRow row = fileList.currentRow;
1162 ProjectNode toNode = (ProjectNode)row.tag;
1163 ImportFolder(toNode);
1168 bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1170 CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1171 codeEditor.EnsureUpToDate();
1175 bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1177 CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1179 codeEditor.EnsureUpToDate();
1183 bool ProjectRemove(MenuItem selection, Modifiers mods)
1185 DataRow row = fileList.currentRow;
1188 ProjectNode node = (ProjectNode)row.tag;
1189 if(node.type == project)
1190 RemoveSelectedNodes();
1195 bool ProjectUpdateMakefileForAllConfigs(Project project)
1197 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1199 // This call really does not belong here:
1200 ide.UpdateToolBarActiveConfigs(false);
1201 for(config : project.configurations)
1202 ProjectPrepareMakefile(project, forceExists, compiler, config);
1209 bool MenuSettings(MenuItem selection, Modifiers mods)
1211 ProjectNode node = GetSelectedNode(true);
1212 Project prj = node ? node.project : project;
1213 projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1214 projectSettingsDialog.Modal();
1221 bool FileProperties(MenuItem selection, Modifiers mods)
1223 DataRow row = fileList.currentRow;
1226 ProjectNode node = (ProjectNode)row.tag;
1227 NodeProperties { parent = parent, master = this, node = node,
1228 position = { position.x + 100, position.y + 100 } }.Create();
1233 bool FileOpenFile(MenuItem selection, Modifiers mods)
1235 OpenSelectedNodes();
1239 bool FileRemoveFile(MenuItem selection, Modifiers mods)
1241 RemoveSelectedNodes();
1245 bool FileCompile(MenuItem selection, Modifiers mods)
1248 OldList selectedRows;
1249 Project project = null;
1250 List<ProjectNode> nodes { };
1251 fileList.GetMultiSelection(selectedRows);
1252 for(item = selectedRows.first; item; item = item.next)
1255 DataRow row = item.data;
1256 ProjectNode node = (ProjectNode)row.tag;
1258 project = node.project;
1259 else if(node.project != project)
1266 selectedRows.Free(null);
1268 Compile(project, nodes, mods.ctrl && mods.shift, normal);
1270 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1275 bool FileClean(MenuItem selection, Modifiers mods)
1278 OldList selectedRows;
1279 Project project = null;
1280 List<ProjectNode> nodes { };
1281 fileList.GetMultiSelection(selectedRows);
1282 for(item = selectedRows.first; item; item = item.next)
1285 DataRow row = item.data;
1286 ProjectNode node = (ProjectNode)row.tag;
1288 project = node.project;
1289 else if(node.project != project)
1296 selectedRows.Free(null);
1298 Clean(project, nodes, mods.ctrl && mods.shift);
1300 ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1305 bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1307 DataRow row = fileList.currentRow;
1308 ProjectNode node = row ? (ProjectNode)row.tag : null;
1311 List<ProjectNode> nodes { };
1313 Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1318 bool FileDebugCompile(MenuItem selection, Modifiers mods)
1320 DataRow row = fileList.currentRow;
1321 ProjectNode node = row ? (ProjectNode)row.tag : null;
1324 List<ProjectNode> nodes { };
1326 Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1331 bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1333 DataRow row = fileList.currentRow;
1334 ProjectNode node = row ? (ProjectNode)row.tag : null;
1337 List<ProjectNode> nodes { };
1339 Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1344 Project GetSelectedProject(bool useSelection)
1346 Project prj = project;
1349 DataRow row = fileList.currentRow;
1350 ProjectNode node = row ? (ProjectNode)row.tag : null;
1357 void SelectNextProject(bool backwards)
1359 DataRow row = fileList.currentRow;
1360 DataRow currentRow = row;
1361 ProjectNode node = (ProjectNode)row.tag;
1362 if(node.type != project)
1363 row = node.project.topNode.row;
1365 row = row.previous ? row.previous : fileList.lastRow;
1367 row = row.next ? row.next : fileList.firstRow;
1368 if(row && row != currentRow)
1370 fileList.SelectRow(row);
1371 fileList.currentRow = row;
1375 ProjectNode GetSelectedNode(bool useSelection)
1377 ProjectNode node = null;
1380 DataRow row = fileList.currentRow;
1382 node = (ProjectNode)row.tag;
1387 bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1389 char folder[MAX_LOCATION];
1391 ProjectNode node = GetSelectedNode(true);
1393 node = project.topNode;
1396 strcpy(folder, prj.topNode.path);
1397 if(node != prj.topNode)
1398 PathCatSlash(folder, node.path);
1403 bool Run(MenuItem selection, Modifiers mods)
1405 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1406 ProjectConfig config = project.config;
1407 String args = new char[maxPathLen];
1409 if(ide.workspace.commandLineArgs)
1410 //ide.debugger.GetCommandLineArgs(args);
1411 strcpy(args, ide.workspace.commandLineArgs);
1412 if(ide.debugger.isActive)
1413 project.Run(args, compiler, config);
1414 /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1415 MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1416 else if(BuildInterrim(project, run, compiler, config, false))
1417 project.Run(args, compiler, config);
1425 bool result = false;
1426 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1427 ProjectConfig config = project.config;
1428 TargetTypes targetType = project.GetTargetType(config);
1429 if(targetType == sharedLibrary || targetType == staticLibrary)
1430 MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1431 else if(project.GetCompress(config))
1432 MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1433 else if(project.GetDebug(config) ||
1434 MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1436 if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, false))
1438 if(compiler.type.isVC)
1440 //bool result = false;
1441 char oldwd[MAX_LOCATION];
1442 PathBackup pathBackup { };
1443 char command[MAX_LOCATION];
1445 ide.SetPath(false, compiler, config);
1447 GetWorkingDir(oldwd, sizeof(oldwd));
1448 ChangeWorkingDir(project.topNode.path);
1450 sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1452 ChangeWorkingDir(oldwd);
1458 ide.debugger.Start(compiler, config);
1467 void GoToError(const char * line)
1471 while(isspace(*line)) line++;
1472 colon = strstr(line, ":");
1477 bool lookForLineNumber = true;
1479 // deal with linking error
1480 if(colon && colon[1] == ' ')
1482 colon = strstr(colon + 1, ":");
1483 if(colon && !colon[1])
1485 colon = strstr(line, ":");
1486 lookForLineNumber = false;
1488 else if(colon && !isdigit(colon[1]))
1491 colon = strstr(line, ":");
1494 // Don't be mistaken by the drive letter colon
1495 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1496 colon = strstr(colon + 1, ":");
1497 if(colon && lookForLineNumber)
1501 char * par = RSearchString(line, "(", colon - line, true, false);
1502 if(par && strstr(par, ")"))
1504 else if((colon+1)[0] == ' ')
1506 // NOTE: This is the same thing as saying 'colon = line'
1507 for( ; colon != line; colon--)
1511 lineNumber = atoi(colon + 1);
1513 comma = strchr(colon, ',');
1515 col = atoi(comma+1);
1517 comma = strchr(colon+1, ':');
1519 col = atoi(comma+1);
1523 char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
1527 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1528 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1529 int len = (int)(colon - start);
1530 len = Min(len, MAX_LOCATION-1);
1532 strncpy(moduleName, start, len);
1533 moduleName[len] = '\0';
1536 strcpy(moduleName, line);
1538 // Remove stuff in brackets
1540 bracket = strstr(moduleName, "(");
1541 if(bracket) *bracket = '\0';
1543 MakeSlashPath(moduleName);
1547 // Check if it's one of our modules
1548 ProjectNode node = project.topNode.Find(moduleName, false);
1551 strcpy(moduleName, node.path);
1552 PathCatSlash(moduleName, node.name);
1555 moduleName[0] = '\0';
1559 CodeEditor codeEditor;
1560 strcpy(filePath, project.topNode.path);
1561 PathCatSlash(filePath, moduleName);
1563 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1566 char name[MAX_LOCATION];
1567 // TOFIX: Improve on this, don't use only filename, make a function
1568 if(ide && ide.workspace)
1570 for(prj : ide.workspace.projects)
1572 if(prj.topNode.FindWithPath(moduleName, false))
1574 strcpy(filePath, prj.topNode.path);
1575 PathCatSlash(filePath, moduleName);
1576 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1583 if(codeEditor && lineNumber)
1585 EditBox editBox = codeEditor.editBox;
1586 editBox.GoToLineNum(lineNumber - 1);
1587 editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1594 bool OpenNode(ProjectNode node)
1596 char filePath[MAX_LOCATION];
1597 node.GetFullFilePath(filePath);
1598 return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
1601 void AddNode(ProjectNode node, DataRow addTo)
1603 DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1605 row.tag = (int64)node;
1608 if(node.type == resources)
1611 row.SetData(null, node);
1613 if(node.files && node.files.first && node.parent &&
1614 !(!node.parent.parent &&
1615 (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") ||
1616 !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1617 row.collapsed = true;
1618 else if(node.type == folder)
1619 node.icon = openFolder;
1623 for(child : node.files)
1624 AddNode(child, row);
1628 void DeleteNode(ProjectNode projectNode)
1630 if(projectNode.files)
1633 while(child = projectNode.files.first)
1636 fileList.DeleteRow(projectNode.row);
1637 projectNode.Delete();
1640 bool ProjectSave(MenuItem selection, Modifiers mods)
1642 DataRow row = fileList.currentRow;
1643 ProjectNode node = row ? (ProjectNode)row.tag : null;
1644 Project prj = node ? node.project : null;
1647 prj.StopMonitoring();
1648 if(prj.Save(prj.filePath))
1650 Project modPrj = null;
1651 prj.topNode.modified = false;
1652 for(p : ide.workspace.projects)
1654 if(p.topNode.modified)
1661 modifiedDocument = false;
1664 prj.StartMonitoring();
1669 bool ShowOutputBuildLog(bool cleanLog)
1671 OutputView output = ide.outputView;
1673 output.ShowClearSelectTab(build);
1676 output.SelectTab(build);
1684 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1685 ProjectConfig config = project.config;
1687 bool result = false;
1688 if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, false))
1690 // For Restart, compiler and config will only be used if for
1691 // whatever reason (if at all possible) the Debugger is in a
1692 // 'terminated' or 'none' state
1693 ide.debugger.Restart(compiler, config);
1703 ide.debugger.Resume();
1709 ide.debugger.Break();
1715 ide.debugger.Stop();
1719 bool DebugStepInto()
1721 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1722 ProjectConfig config = project.config;
1724 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, false)))
1725 ide.debugger.StepInto(compiler, config);
1730 bool DebugStepOver(bool skip)
1732 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1733 ProjectConfig config = project.config;
1735 if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, false)))
1736 ide.debugger.StepOver(compiler, config, skip);
1742 bool DebugStepOut(bool skip)
1744 ide.debugger.StepOut(skip);
1748 void ImportFolder(ProjectNode toNode)
1752 //bool isFolder = toNode.type == folder;
1753 //bool isRes = toNode.isInResources;
1755 FileDialog fileDialog = importFileDialog;
1756 fileDialog.master = parent;
1757 if(fileDialog.Modal() == ok)
1759 ImportFolderFSI fsi { projectView = this };
1760 fsi.stack.Add(toNode);
1761 fsi.Iterate(fileDialog.filePath);
1767 ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1771 ProjectNode folderNode;
1772 Project prj = parentNode.project;
1774 ProjectNode after = null;
1775 for(node : parentNode.files)
1777 if(node.type != folder)
1783 folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1786 for(c = 0; c < 100; c++)
1789 sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1790 if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1797 NodeProperties nodeProperties;
1800 modifiedDocument = true;
1801 prj.topNode.modified = true;
1804 folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1805 folderNode.row.tag = (int64)folderNode;
1807 folderNode.row.SetData(null, folderNode);
1808 fileList.currentRow = folderNode.row;
1812 nodeProperties = NodeProperties
1814 parent, this, mode = newFolder, node = folderNode;
1815 position = { position.x + 100, position.y + 100 };
1817 nodeProperties.Create(); // Modal?
1825 void AddFiles(bool resources)
1827 FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1828 fileDialog.type = multiOpen;
1829 fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
1830 fileDialog.master = parent;
1832 if(fileDialog.Modal() == ok)
1835 DataRow row = fileList.currentRow;
1836 ProjectNode parentNode = (ProjectNode)row.tag;
1837 bool addFailed = false;
1838 int numSelections = fileDialog.numSelections;
1839 char ** multiFilePaths = fileDialog.multiFilePaths;
1841 Array<String> nameConflictFiles { };
1843 for(c = 0; c < numSelections; c++)
1845 char * filePath = multiFilePaths[c];
1846 FileAttribs exists = FileExists(filePath);
1847 bool addThisFile = true;
1849 if(exists.isDirectory)
1850 addThisFile = false;
1853 if(MessageBox { master = ide, type = yesNo, text = filePath,
1854 contents = $"File doesn't exist. Create?" }.Modal() == yes)
1856 File f = FileOpen(filePath, write);
1864 MessageBox { master = ide, type = ok, text = filePath,
1865 contents = $"Couldn't create file."}.Modal();
1866 addThisFile = false;
1873 /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
1875 nameConflictFiles.Add(CopyString(filePath));
1883 char * part1 = $"The following file";
1884 char * opt1 = $" was ";
1885 char * opt2 = $"s were ";
1886 char * part2 = $"not added because of identical file name conflict within the project.\n\n";
1888 len += strlen(part1);
1889 len += strlen(part2);
1890 len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1891 for(s : nameConflictFiles)
1892 len += strlen(s) + 1;
1893 message = new char[len + 1];
1894 strcpy(message, part1);
1895 strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1896 strcat(message, part2);
1897 for(s : nameConflictFiles)
1900 strcat(message, "\n");
1902 MessageBox { master = ide, type = ok, text = $"Name Conflict",
1903 contents = message }.Modal();
1906 nameConflictFiles.Free();
1907 delete nameConflictFiles;
1911 ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
1913 ProjectNode result = null;
1914 ProjectNode after = null;
1915 for(node : parentNode.files)
1917 if(node.type != folder && node.type != file && node.type)
1922 result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
1928 modifiedDocument = true;
1929 parentNode.project.topNode.modified = true;
1930 parentNode.project.ModifiedAllConfigs(true, false, true, true);
1933 result.row = parentNode.row.AddRowAfter(after ? after.row : null);
1934 result.row.tag = (int64)result;
1935 result.row.SetData(null, result);
1940 CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
1942 CodeEditor codeEditor = null;
1943 ProjectNode projectNode;
1944 ProjectNode after = null;
1945 DataRow row = fileList.currentRow;
1946 ProjectNode parentNode;
1949 if(!row) row = project.topNode.row;
1951 parentNode = (ProjectNode)row.tag;
1953 for(node : parentNode.files)
1955 if(node.type != folder && node.type != file && node.type)
1959 for(c = 1; c < 100; c++)
1962 sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
1963 if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
1969 char filePath[MAX_LOCATION];
1971 modifiedDocument = true;
1972 project.topNode.modified = true;
1974 project.ModifiedAllConfigs(true, false, false, true);
1975 projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1976 projectNode.row.tag =(int64)projectNode;
1978 projectNode.row.SetData(null, projectNode);
1979 fileList.currentRow = projectNode.row;
1981 strcpy(filePath, project.topNode.path);
1982 PathCat(filePath, projectNode.path);
1983 PathCat(filePath, projectNode.name);
1985 codeEditor = (CodeEditor)ide.FindWindow(filePath);
1988 Class baseClass = eSystem_FindClass(__thisModule, base);
1989 subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
1992 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1993 strcpy(name, projectNode.name);
1994 sprintf(name, "%s%d", upper, c);
1996 strcpy(className, name);
1998 designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2000 //codeEditor.modifiedDocument = false;
2001 //codeEditor.designer.modifiedDocument = false;
2003 //Code_EnsureUpToDate(codeEditor);
2006 else // TODO: fix no symbols generated when ommiting {} for following else
2008 codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2012 codeEditor.ViewDesigner();
2013 codeEditor.codeModified = true;
2020 // Returns true if we opened something
2021 bool OpenSelectedNodes()
2023 bool result = false;
2027 fileList.GetMultiSelection(selection);
2028 for(item = selection.first; item; item = item.next)
2030 DataRow row = item.data;
2031 ProjectNode node = (ProjectNode)row.tag;
2032 if(node.type == file)
2039 selection.Free(null);
2043 void RemoveSelectedNodes()
2048 fileList.GetMultiSelection(selection);
2050 // Remove children of parents we're deleting
2051 for(item = selection.first; item; item = next)
2054 DataRow row = item.data;
2055 ProjectNode n, node = (ProjectNode)row.tag;
2056 bool remove = false;
2059 for(i = selection.first; i && !remove; i = i.next)
2061 ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2062 for(n = node.parent; n; n = n.parent)
2072 selection.Delete(item);
2075 for(item = selection.first; item; item = item.next)
2077 DataRow row = item.data;
2078 ProjectNode node = (ProjectNode)row.tag;
2079 ProjectNode resNode;
2080 for(resNode = node.parent; resNode; resNode = resNode.parent)
2081 if(resNode.type == resources)
2083 if(node.type == file)
2085 Project prj = node.project;
2087 modifiedDocument = true;
2088 prj.topNode.modified = true;
2090 prj.ModifiedAllConfigs(true, false, true, true);
2092 else if(node.type == folder)
2095 sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2096 "and all of its contents from the project?", node.name);
2097 if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2099 Project prj = node.project;
2100 if(node.containsFile)
2101 prj.ModifiedAllConfigs(true, false, true, true);
2103 modifiedDocument = true;
2104 prj.topNode.modified = true;
2107 else if(node.type == project && node != project.topNode && !buildInProgress)
2111 for(p : workspace.projects)
2113 if(p.topNode == node)
2119 sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2120 if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2125 workspace.RemoveProject(prj);
2126 //modifiedDocument = true; // when project view is a workspace view
2130 selection.Free(null);