7eff355633536182efe2822bbf1fb494c35e0d58
[sdk] / ide / src / project / ProjectView.ec
1 import "ide"
2
3 import "FileSystemIterator"
4
5 class ImportFolderFSI : NormalFileSystemIterator
6 {
7    ProjectView projectView;
8    Array<ProjectNode> stack { };
9
10    bool OnFolder(char * folderPath)
11    {
12       char name[MAX_LOCATION];
13       ProjectNode parentNode = stack.lastIterator.data;
14       ProjectNode folder;
15       GetLastDirectory(folderPath, name);
16       folder = parentNode.FindSpecial(name, false, true, true);
17       if(!folder)
18          folder = projectView.NewFolder(parentNode, name, false);
19       stack.Add(folder);
20       return true;
21    }
22
23    void OutFolder(char * folderPath, bool isRoot)
24    {
25       stack.lastIterator.Remove(); //stack.Remove();
26    }
27
28    bool OnFile(char * filePath)
29    {
30       ProjectNode parentNode = stack.lastIterator.data;
31       projectView.AddFile(parentNode, filePath, parentNode.isInResources, false);
32       return true;
33    }
34 }
35
36 static Array<FileFilter> fileFilters
37 { [
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 }
42 ] };
43
44 static Array<FileFilter> resourceFilters
45 { [
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 }
50 ] };
51
52 static Array<FileFilter> projectFilters
53 { [
54    { $"Project Files (*.epj)", ProjectExtension },
55    { $"Workspace Files (*.ews)", WorkspaceExtension }
56 ] };
57
58 static Array<FileType> projectTypes
59 { [
60    { $"Ecere IDE Project", ProjectExtension },
61    { $"Ecere IDE Workspace", WorkspaceExtension }
62 ] };
63
64 static char * iconNames[] = 
65 {
66    "<:ecere>mimeTypes/file.png",                   /*genFile*/
67    "<:ecere>mimeTypes/textEcereWorkspace.png",     /*ewsFile*/
68    "<:ecere>mimeTypes/textEcereProject.png",       /*epjFile*/
69    "<:ecere>places/folder.png",                    /*folder*/
70    "<:ecere>status/folderOpen.png",                /*openFolder*/
71    "<:ecere>mimeTypes/textEcereSource.png",        /*ecFile*/
72    "<:ecere>mimeTypes/textEcereHeader.png",        /*ehFile*/
73    "<:ecere>mimeTypes/textCSource.png",            /*sFile*/ // TODO: change sFile icon to differentiate from cFile icon
74    "<:ecere>mimeTypes/textCSource.png",            /*cFile*/
75    "<:ecere>mimeTypes/textCHeader.png",            /*hFile*/
76    "<:ecere>mimeTypes/textC++Source.png",          /*cppFile*/
77    "<:ecere>mimeTypes/textC++Header.png",          /*hppFile*/
78    "<:ecere>mimeTypes/text.png",                   /*textFile*/
79    "<:ecere>mimeTypes/textHyperTextMarkup.png",    /*webFile*/
80    "<:ecere>mimeTypes/image.png",                  /*pictureFile*/
81    "<:ecere>status/audioVolumeHigh.png",           /*soundFile*/
82    "<:ecere>mimeTypes/package.png",                /*archiveFile*/
83    "<:ecere>mimeTypes/packageSoftware.png",        /*packageFile*/
84    "<:ecere>mimeTypes/packageOpticalDisc.png",     /*opticalMediaImageFile*/
85    "<:ecere>mimeTypes/file.png"                    /*mFile*/ //TODO: create icon for mfile
86 };
87
88 enum PrepareMakefileMethod { normal, force, forceExists };
89
90 enum BuildType { build, rebuild, relink, run, start, restart, clean };
91 enum BuildState
92 {
93    none, buildingMainProject, buildingSecondaryProject, compilingFile;
94
95    property bool { get { return this != none; } }
96    //property bool actualBuild { get { return this == buildingMainProject || this == buildingSecondaryProject;  } }
97 };
98
99 class ProjectView : Window
100 {
101    isDocument = true;
102    //hasMinimize = true;
103    hasClose = true;
104    borderStyle = sizable;
105    hasHorzScroll = true;
106    hasVertScroll = true;
107    background = white;
108    size = { 300 };
109    anchor = Anchor { left = 0, top = 0, bottom = 0 };
110    menu = Menu { };
111    
112    //hasMinimize = true;
113    saveDialog = projectFileDialog;
114    
115    DataRow resourceRow;
116    BuildState buildInProgress;
117    BitmapResource icons[NodeIcons];
118    Project project;
119    Workspace workspace;
120    property Workspace workspace
121    {
122       set
123       {
124          if(workspace)
125          {
126             for(prj : workspace.projects)
127             {
128                DeleteNode(prj.topNode);
129             }
130             workspace.projects.Free();
131             ide.debugger.CleanUp();
132          }
133          workspace = value;
134          if(workspace)
135          {
136             fileDialog.currentDirectory = workspace.workspaceDir;
137             resourceFileDialog.currentDirectory = workspace.workspaceDir;
138             for(prj : workspace.projects)
139                AddNode(prj.topNode, null);
140             ide.statusBar.text = $"Generating Makefile & Dependencies...";
141             app.UpdateDisplay();
142             for(prj : workspace.projects)
143                prj.ModifiedAllConfigs(true, false, false, false);
144             ide.statusBar.text = $"Initializing Debugger"; app.UpdateDisplay();
145             ide.statusBar.text = null;
146             app.UpdateDisplay();
147          }
148       }
149       get { return workspace; }
150    }
151    
152    bool drawingInProjectSettingsDialog;
153    bool drawingInProjectSettingsDialogHeader;
154    ProjectSettings projectSettingsDialog;
155
156    bool stopBuild;
157    PopupMenu popupMenu;
158
159    ProjectView()
160    {
161       NodeIcons c;
162       for(c = 0; c < NodeIcons::enumSize; c++)
163       {
164          icons[c] = BitmapResource { iconNames[c], alphaBlend = true };
165          AddResource(icons[c]);
166       }
167       fileList.AddField(DataField { dataType = class(ProjectNode), freeData = false, userData = this });
168    }
169
170    ~ProjectView()
171    {
172       DebugStop();
173       ide.DestroyTemporaryProjectDir();
174       if(project)
175       {
176          workspace.Free();
177          delete workspace;
178       }
179    }
180
181    ListBox fileList
182    {
183       multiSelect = true, fullRowSelect = false, hasVertScroll = true, hasHorzScroll = true;
184       borderStyle = deep, parent = this, collapseControl = true, treeBranches = true;
185       anchor = Anchor { left = 0, right = 0, top = 0 , bottom = 0 };
186
187       background = projectViewBackground;
188       foreground = projectViewText;
189       selectionColor = selectionColor, selectionText = selectionText;
190       stippleColor = skyBlue;
191
192       bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
193       {
194          if(!active) Update(null);
195          return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
196       }
197       
198       bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
199       {
200          // Prevent the double click from reactivating the project view (returns false if we opened something)
201          return !OpenSelectedNodes();
202       }
203
204       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
205       {
206          DataRow row = listBox.currentRow;
207          if(row)
208          {
209             ProjectNode node = (ProjectNode)row.tag;
210             if(node.type == NodeTypes::project || node.type == resources || node.type == file || node.type == folder)
211             {
212                bool buildMenuUnavailable = buildInProgress;
213                Menu popupContent { };
214                
215                if(node.type == NodeTypes::project)
216                {
217                   //if(node == ((Project)workspace.projects.first).topNode)
218                   {
219                      MenuItem { popupContent, $"Build", b, NotifySelect = ProjectBuild }.disabled = buildMenuUnavailable;
220                      MenuItem { popupContent, $"Relink", l, NotifySelect = ProjectLink }.disabled = buildMenuUnavailable;
221                      MenuItem { popupContent, $"Rebuild", r, NotifySelect = ProjectRebuild }.disabled = buildMenuUnavailable;
222                      MenuItem { popupContent, $"Clean", c, NotifySelect = ProjectClean }.disabled = buildMenuUnavailable;
223                      MenuItem { popupContent, $"Real Clean", d, NotifySelect = ProjectRealClean }.disabled = buildMenuUnavailable;
224                      MenuItem { popupContent, $"Regenerate Makefile", m, NotifySelect = ProjectRegenerate }.disabled = buildMenuUnavailable;
225                      MenuDivider { popupContent };
226                   }
227                   MenuItem { popupContent, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = buildMenuUnavailable;
228                   MenuDivider { popupContent };
229                   MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
230                   MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
231                   MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
232                   MenuItem { popupContent, $"Add Files to Project...", f, NotifySelect = ProjectAddFiles };
233                   MenuDivider { popupContent };
234                   MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
235                   // MenuItem { popupContent, "Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
236                   MenuDivider { popupContent };
237                   if(node != ((Project)workspace.projects.first).topNode)
238                   {
239                      MenuItem { popupContent, $"Remove project from workspace", r, NotifySelect = ProjectRemove }.disabled = buildMenuUnavailable;
240                      MenuDivider { popupContent };
241                   }
242                   MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
243                   MenuDivider { popupContent };
244                   MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
245                   MenuDivider { popupContent };
246                   MenuItem { popupContent, $"Save", v, Key { s, ctrl = true }, NotifySelect = ProjectSave }.disabled = !node.modified;
247                   MenuDivider { popupContent };
248                   MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
249                }
250                else if(node.type == resources)
251                {
252                   MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
253                   MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
254                   MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
255                   MenuItem { popupContent, $"Add Resources to Project...", f, NotifySelect = ResourcesAddFiles };
256                   MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
257                   MenuDivider { popupContent };
258                   MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
259                   MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
260                }
261                else if(node.type == file)
262                {
263                   MenuItem { popupContent, $"Open", o, NotifySelect = FileOpenFile };
264                   MenuDivider { popupContent };
265                   MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
266                   MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
267                   MenuDivider { popupContent };
268                   MenuItem { popupContent, $"Debug Precompile", l, NotifySelect = FileDebugPrecompile }.disabled = buildMenuUnavailable;
269                   MenuItem { popupContent, $"Debug Compile", l, NotifySelect = FileDebugCompile }.disabled = buildMenuUnavailable;
270                   MenuDivider { popupContent };
271                   MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
272                   MenuDivider { popupContent };
273                   MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
274                   MenuDivider { popupContent };
275                   MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
276                   MenuItem { popupContent, $"Properties..", p, Key { enter, alt = true }, NotifySelect = FileProperties };
277                }
278                else if(node.type == folder)
279                {
280                   bool isInResources = node.isInResources;
281
282                   MenuItem { popupContent, $"New File...", l, Key { l, ctrl = true }, NotifySelect = ProjectNewFile };
283                   MenuItem { popupContent, $"New Folder...", n, Key { f, ctrl = true }, NotifySelect = ProjectNewFolder };
284                   MenuItem { popupContent, $"Import Folder...", i, NotifySelect = ProjectImportFolder };
285                   if(isInResources)
286                   {
287                      MenuItem { popupContent, $"Add Resources to Folder...", f, NotifySelect = ResourcesAddFiles };
288                   }
289                   else
290                   {
291                      MenuItem { popupContent, $"Add Files to Folder...", f, NotifySelect = ProjectAddFiles };
292                   }
293                   if(!isInResources)
294                   {
295                      MenuDivider { popupContent };
296                      MenuItem { popupContent, $"Add New Form...", o, NotifySelect = ProjectAddNewForm };
297                      MenuItem { popupContent, $"Add New Behavior Graph...", g, NotifySelect = ProjectAddNewGraph };
298                   }
299                   MenuDivider { popupContent };
300                   MenuItem { popupContent, $"Clean", l, NotifySelect = FileClean }.disabled = buildMenuUnavailable;
301                   MenuItem { popupContent, $"Compile", c, Key { f7, ctrl = true}, NotifySelect = FileCompile }.disabled = buildMenuUnavailable;
302                   MenuDivider { popupContent };
303                   MenuItem { popupContent, $"Remove", r, NotifySelect = FileRemoveFile };
304                   MenuDivider { popupContent };
305                   MenuItem { popupContent, $"Browse Folder", w, NotifySelect = MenuBrowseFolder };
306                   MenuDivider { popupContent };
307                   MenuItem { popupContent, $"Settings...", s, Key { f7, alt = true } , NotifySelect = MenuSettings };
308                   MenuItem { popupContent, $"Properties...", p, Key { enter, alt = true }, NotifySelect = FileProperties };
309                }
310
311                popupMenu = 
312                {
313                   master = this, menu = popupContent;
314                   position = {
315                      x + clientStart.x + absPosition.x - app.desktop.position.x, 
316                      y + clientStart.y + absPosition.y - app.desktop.position.y };
317
318                   void NotifyDestroyed(Window window, DialogResult result)
319                   {
320                      popupMenu = null;
321                   }
322                };
323                popupMenu.Create();
324             }
325          }
326          return true;
327       }
328
329       bool NotifyKeyHit(ListBox listBox, DataRow row, Key key, unichar ch)
330       {
331          if(key == altUp || key == altDown)
332          {
333             SelectNextProject(key == altUp);
334             return false;
335          }
336          return true;
337       }
338
339       bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
340       {
341          if(row)
342          {
343             ProjectNode node = (ProjectNode)row.tag;
344             switch(key)
345             {
346                case altEnter: case Key { keyPadEnter, alt = true }:
347                {
348                   NodeProperties { parent = parent, master = this, 
349                      position = { position.x + 100, position.y + 100 }, node = node }.Create();
350                   return false;
351                }
352                case enter: case keyPadEnter:
353                {
354                   ProjectNode resNode;
355                   for(resNode = node.parent; resNode; resNode = resNode.parent)
356                      if(resNode.type == resources)
357                         break;
358                   if(node.type == project || (node.type == folder && !resNode))
359                   {
360                      AddFiles(false);
361                      return false;
362                   }
363                   else if(node.type == resources || node.type == folder)
364                   {
365                      AddFiles(true);
366                      return false;
367                   }
368                   break;
369                }
370                case ctrlI:
371                {
372                   if(node.type == project || node.type == folder || node.type == resources)
373                   {
374                      ImportFolder(node);
375                      return false;
376                   }
377                   break;
378                }
379                case ctrlF:
380                {
381                   if(node.type == project || node.type == folder || node.type == resources)
382                   {
383                      NewFolder(node, null, true);
384                      return false;
385                   }
386                   break;
387                }
388                case ctrlF7:
389                {
390                   if(node.type == file)
391                   {
392                      FileCompile(null, (Modifiers)key);
393                      return false;
394                   }
395                   break;
396                }
397                case Key { space, shift = true }:
398                case space:
399                {
400                   if(node.type == NodeTypes::project)
401                   {
402                      Project prj = null;
403                      for(p : workspace.projects)
404                      {
405                         if(p.topNode == node)
406                         {
407                            prj = p;
408                            break;
409                         }
410                      }
411                      prj.RotateActiveConfig(!key.shift);
412                      if(prj == project)
413                         ide.AdjustMenus();
414                      return false;
415                   }
416                   break;
417                }
418             }
419          }
420          switch(key)
421          {
422             case enter: case keyPadEnter:  OpenSelectedNodes();   break;
423             case del:                      RemoveSelectedNodes(); break;
424             case escape:                      
425             {
426                Window activeClient = ide.activeClient;
427                if(activeClient)
428                   activeClient.Activate();
429                else
430                   ide.RepositionWindows(true);
431                break;
432             }
433          }
434          return true;
435       }
436
437       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
438       {
439          ProjectNode node = (ProjectNode)row.tag;
440          if(node.type == folder)
441             node.icon = collapsed ? folder : openFolder;
442          return true;
443       }
444    };
445
446    FileDialog importFileDialog { autoCreate = false, type = selectDir, text = $"Import Folder" };
447    FileDialog projectFileDialog
448    {
449       autoCreate = false, filters = projectFilters.array, sizeFilters = projectFilters.count * sizeof(FileFilter);
450       types = projectTypes.array, sizeTypes = projectTypes.count * sizeof(FileType);
451    };
452    FileDialog fileDialog
453    {
454       autoCreate = false, mayNotExist = true, filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter);
455    };
456    FileDialog resourceFileDialog
457    {
458       autoCreate = false, mayNotExist = true, filters = resourceFilters.array, sizeFilters = resourceFilters.count * sizeof(FileFilter);
459    };
460
461    Menu fileMenu { menu, $"File", f };
462    MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
463    // MenuItem { fileMenu, "Save As...", a, NotifySelect = MenuFileSaveAs };
464
465    bool OnClose(bool parentClosing)
466    {
467       if(!parentClosing && visible)
468       {
469          visible = false;
470          return false;
471       }
472       if(buildInProgress)
473          return false;
474
475       if(modifiedDocument)
476       {
477          DialogResult dialogRes;
478          char msg[2048];
479          bool first = true;
480          strcpy(msg, $"You have modified projects.\nSave changes to ");
481          for(p : ide.workspace.projects)
482          {
483             if(p.topNode.modified)
484             {
485                if(!first) strcat(msg, ", ");
486                strcat(msg, p.name);
487                first = false;
488             }
489          }
490          strcat(msg, "?");
491
492          dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = msg }.Modal();
493
494          if(dialogRes == yes)
495          {
496             // TOFIX: Precomp error if brackets are taken out
497             return (DialogResult)MenuFileSave(null, 0) != cancel;
498          }
499          else if(dialogRes == cancel)
500             return false;
501          modifiedDocument = false;
502       }
503       return true;
504    }
505
506    void OnDestroy(void)
507    {
508       //if(ide.findInFilesDialog && ide.findInFilesDialog.created && ide.findInFilesDialog.mode != directory)
509       //   ide.findInFilesDialog.SearchStop();
510
511       ide.outputView.buildBox.Clear();
512       ide.outputView.debugBox.Clear();
513       //ide.outputView.findBox.Clear();
514       ide.callStackView.Clear();
515       ide.watchesView.Clear();
516       ide.threadsView.Clear();
517       ide.breakpointsView.Clear();
518       ide.outputView.ShowClearSelectTab(find); // why this? 
519    }
520
521    bool OnSaveFile(char * fileName)
522    {
523       for(prj : ide.workspace.projects)
524       {
525          if(prj.topNode.modified)
526          {
527             prj.StopMonitoring();
528             if(prj.Save(prj.filePath))
529                prj.topNode.modified = false;
530             prj.StartMonitoring();
531          }
532       }
533       modifiedDocument = false;
534       Update(null);
535       return true;
536    }
537
538    bool IsModuleInProject(char * filePath)
539    {
540       char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
541       GetLastDirectory(filePath, moduleName);
542       return project.topNode.Find(moduleName, false) != null;
543    }
544
545    bool GetRelativePath(char * filePath, char * relativePath)
546    {
547       return project.GetRelativePath(filePath, relativePath);
548    }
549
550    ProjectNode GetNodeFromWindow(Window document, Project project)
551    {
552       if(document.fileName)
553       {
554          char winFileName[MAX_LOCATION];
555          char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
556          for(p : ide.workspace.projects)
557          {
558             Project prj = project ? project : p;
559             ProjectNode node;
560             if((node = prj.topNode.FindByFullPath(documentFileName, false)))
561                return node;
562             if(project) break;
563          }
564       }
565       return null;
566    }
567
568    //                          ((( UTILITY FUNCTIONS )))
569    //
570    //  ************************************************************************
571    //  *** These methods below are part of a sequence of events, and as     ***
572    //  *** such they must be passed the current compiler and project config ***
573    //  ************************************************************************
574    bool DisplayCompiler(CompilerConfig compiler, bool cleanLog)
575    {
576       ide.outputView.buildBox.Logf($"%s Compiler\n", compiler ? compiler.name : $"{problem with compiler selection}");
577       return true;
578    }
579
580    bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
581       CompilerConfig compiler, ProjectConfig config)
582    {
583       bool isReady = true;
584       char message[MAX_F_STRING];
585       LogBox logBox = ide.outputView.buildBox;
586
587       ShowOutputBuildLog(cleanLog);
588
589       if(displayCompiler)
590          DisplayCompiler(compiler, false);
591
592       ProjectPrepareCompiler(project, compiler);
593       ProjectPrepareMakefile(project, method, compiler, config);
594       return true;
595    }
596
597    bool ProjectPrepareCompiler(Project project, CompilerConfig compiler)
598    {
599       if(!project.GenerateCrossPlatformMk() || !project.GenerateCompilerCf(compiler))
600          ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
601       return true;
602    }
603
604    // Note: Compiler is only passed in to for VisualStudio support
605    bool ProjectPrepareMakefile(Project project, PrepareMakefileMethod method, CompilerConfig compiler, ProjectConfig config)
606    {
607       if(compiler.type.isVC)
608       {
609          // I'm guessing we'll want to support generating VS files on Linux as well...
610          ide.statusBar.text = $"Generating Visual Studio Solution...";
611          app.UpdateDisplay();
612          //GenerateVSSolutionFile(project, compiler);
613          ide.statusBar.text = $"Generating Visual Studio Project...";
614          app.UpdateDisplay();
615          //GenerateVCProjectFile(project, compiler);
616          ide.statusBar.text = null;
617          app.UpdateDisplay();
618          return true;
619       }
620       else
621       {
622          char makefilePath[MAX_LOCATION];
623          char makefileName[MAX_LOCATION];
624          bool exists;
625          LogBox logBox = ide.outputView.buildBox;
626          
627          strcpy(makefilePath, project.topNode.path);
628          project.CatMakeFileName(makefileName, config);
629          PathCatSlash(makefilePath, makefileName);
630
631          exists = FileExists(makefilePath);
632          if(method == force ||
633            (method == forceExists && exists) ||
634            (method == normal && (!exists || (config && config.makingModified))))
635          {
636             char * reason;
637             char * action;
638             ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
639             app.UpdateDisplay();
640
641             if((method == normal && !exists) || (method == force && !exists))
642                action = $"Generating ";
643             else if(method == force)
644                action = $"Regenerating ";
645             else if(method == normal || method == forceExists)
646                action = $"Updating ";
647             else
648                action = "";
649             if(!exists)
650                reason = $"Makefile doesn't exist. ";
651             else if(project.topNode.modified)
652                reason = $"Project has been modified. ";
653             else
654                reason = "";
655
656             //logBox.Logf("%s\n", makefileName);
657             logBox.Logf($"%s - %s%smakefile for %s config...\n", makefileName, reason, action, GetConfigName(config));
658
659             if(!project.GenerateMakefile(null, false, null, config))
660                ide.outputView.buildBox.Logf($"Error generating makefile (Is the project directory writable?)\n");
661
662             ide.statusBar.text = null;
663             app.UpdateDisplay();
664             return true;
665          }
666       }
667       return false;
668    }
669    
670    bool BuildInterrim(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, bool justPrint)
671    {
672       if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
673       {
674          ide.outputView.buildBox.Logf($"Building project %s using the %s configuration...\n", prj.name, GetConfigName(config));
675          return Build(prj, buildType, compiler, config, justPrint);
676       }
677       return false;
678    }
679
680    bool DebugStopForMake(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config)
681    {
682       bool result = false;
683       // TOFIX: DebugStop is being abused and backfiring on us.
684       //        It's supposed to be the 'Debug/Stop' item, not unloading executable or anything else
685
686       //        configIsInDebugSession seems to be used for two OPPOSITE things:
687       //        If we're debugging another config, we need to unload the executable!
688       //        In building, we want to stop if we're debugging the 'same' executable
689       if(buildType != run) ///* && prj == project*/ && prj.configIsInDebugSession)
690       {
691          if(buildType == start || buildType == restart)
692          {
693             if(ide.debugger && ide.debugger.isPrepared)
694                result = DebugStop();
695          }
696          else
697          {
698             if(ide.project == prj && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared)
699                result = DebugStop();
700          }
701       }
702       return result;
703    }
704
705    bool Build(Project prj, BuildType buildType, CompilerConfig compiler, ProjectConfig config, bool justPrint)
706    {
707       bool result = true;
708       Window document;
709
710       stopBuild = false;
711       for(document = master.firstChild; document; document = document.next)
712       {
713          if(document.modifiedDocument)
714          {
715             ProjectNode node = GetNodeFromWindow(document, prj);
716             if(node && !document.MenuFileSave(null, 0))
717             {
718                result = false;
719                break;
720             }
721          }
722       }
723       if(result)
724       {
725          DirExpression targetDir = prj.GetTargetDir(compiler, config);
726
727          DebugStopForMake(prj, buildType, compiler, config);
728
729          // TODO: Disabled until problems fixed... is it fixed?
730          if(buildType == rebuild || (config && config.compilingModified))
731             prj.Clean(compiler, config, false, justPrint);
732          else
733          {
734             if(buildType == relink || (config && config.linkingModified))
735             {
736                char target[MAX_LOCATION];
737
738                strcpy(target, prj.topNode.path);
739                PathCat(target, targetDir.dir);
740                prj.CatTargetFileName(target, compiler, config);
741                if(FileExists(target))
742                   DeleteFile(target);
743             }
744             if(config && config.symbolGenModified)
745             {
746                DirExpression objDir = prj.GetObjDir(compiler, config);
747                char fileName[MAX_LOCATION];
748                char moduleName[MAX_FILENAME];
749                strcpy(fileName, prj.topNode.path);
750                PathCatSlash(fileName, objDir.dir);
751                strcpy(moduleName, prj.moduleName);
752                strcat(moduleName, ".main.ec");
753                PathCatSlash(fileName, moduleName);
754                if(FileExists(fileName))
755                   DeleteFile(fileName);
756                ChangeExtension(fileName, "c", fileName);
757                if(FileExists(fileName))
758                   DeleteFile(fileName);
759                ChangeExtension(fileName, "o", fileName);
760                if(FileExists(fileName))
761                   DeleteFile(fileName);
762
763                delete objDir;
764             }
765          }
766          buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
767          ide.AdjustBuildMenus();
768          ide.AdjustDebugMenus();
769
770          result = prj.Build(buildType == run, null, compiler, config, justPrint, normal);
771
772          if(config)
773          {
774             config.compilingModified = false;
775             if(!ide.ShouldStopBuild())
776                config.linkingModified = false;
777
778             config.symbolGenModified = false;
779          }
780          buildInProgress = none;
781          ide.AdjustBuildMenus();
782          ide.AdjustDebugMenus();
783
784          ide.workspace.modified = true;
785
786          delete targetDir;
787       }
788       return result;
789    }
790
791    //                          ((( USER ACTIONS )))
792    //
793    //  ************************************************************************
794    //  *** Methods below should atomically start a process, and as such     ***
795    //  *** they can query compiler and config directly from ide and project ***
796    //  *** but ONLY ONCE!!!                                                 ***
797    //  ************************************************************************
798
799    bool ProjectBuild(MenuItem selection, Modifiers mods)
800    {
801       Project prj = project;
802       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
803       ProjectConfig config;
804       if(selection || !ide.activeClient)
805       {
806          DataRow row = fileList.currentRow;
807          ProjectNode node = row ? (ProjectNode)row.tag : null;
808          if(node) prj = node.project;
809       }
810       else
811       {
812          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
813          if(node)
814             prj = node.project;
815       }
816       config = prj.config;
817       if(/*prj != project || */!prj.GetConfigIsInDebugSession(config) || !ide.DontTerminateDebugSession($"Project Build"))
818       {
819          BuildInterrim(prj, build, compiler, config, mods.ctrl && mods.shift);
820       }
821       delete compiler;
822       return true;
823    }
824
825    bool ProjectLink(MenuItem selection, Modifiers mods)
826    {
827       Project prj = project;
828       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
829       ProjectConfig config;
830       if(selection || !ide.activeClient)
831       {
832          DataRow row = fileList.currentRow;
833          ProjectNode node = row ? (ProjectNode)row.tag : null;
834          if(node) prj = node.project;
835       }
836       else
837       {
838          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
839          if(node)
840             prj = node.project;
841       }
842       config = prj.config;
843       if(!prj.GetConfigIsInDebugSession(config) ||
844             (!ide.DontTerminateDebugSession($"Project Link") && DebugStopForMake(prj, relink, compiler, config)))
845       {
846          if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
847          {
848             ide.outputView.buildBox.Logf($"Relinking project %s using the %s configuration...\n", prj.name, GetConfigName(config));
849             if(config)
850                config.linkingModified = true;
851             Build(prj, relink, compiler, config, mods.ctrl && mods.shift);
852          }
853       }
854       delete compiler;
855       return true;
856    }
857
858    bool ProjectRebuild(MenuItem selection, Modifiers mods)
859    {
860       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
861       Project prj = project;
862       ProjectConfig config;
863       if(selection || !ide.activeClient)
864       {
865          DataRow row = fileList.currentRow;
866          ProjectNode node = row ? (ProjectNode)row.tag : null;
867          if(node) prj = node.project;
868       }
869       else
870       {
871          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
872          if(node)
873             prj = node.project;
874       }
875       config = prj.config;
876       if(!prj.GetConfigIsInDebugSession(config) ||
877             (!ide.DontTerminateDebugSession($"Project Rebuild") && DebugStopForMake(prj, rebuild, compiler, config)))
878       {
879          if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
880          {
881             ide.outputView.buildBox.Logf($"Rebuilding project %s using the %s configuration...\n", prj.name, GetConfigName(config));
882             /*if(config)
883             {
884                config.compilingModified = true;
885                config.makingModified = true;
886             }*/ // -- should this still be used depite the new solution of BuildType?
887             Build(prj, rebuild, compiler, config, mods.ctrl && mods.shift);
888          }
889       }
890       delete compiler;
891       return true;
892    }
893
894    bool ProjectClean(MenuItem selection, Modifiers mods)
895    {
896       Project prj = project;
897       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
898       ProjectConfig config;
899       if(selection || !ide.activeClient)
900       {
901          DataRow row = fileList.currentRow;
902          ProjectNode node = row ? (ProjectNode)row.tag : null;
903          if(node) prj = node.project;
904       }
905       else
906       {
907          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
908          if(node)
909             prj = node.project;
910       }
911       config = prj.config;
912       if(!prj.GetConfigIsInDebugSession(config) ||
913             (!ide.DontTerminateDebugSession($"Project Clean") && DebugStopForMake(prj, clean, compiler, config)))
914       {
915          if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
916          {
917             ide.outputView.buildBox.Logf($"Cleaning project %s using the %s configuration...\n", prj.name, GetConfigName(config));
918
919             buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
920             ide.AdjustBuildMenus();
921             ide.AdjustDebugMenus();
922
923             prj.Clean(compiler, config, false, mods.ctrl && mods.shift);
924             buildInProgress = none;
925             ide.AdjustBuildMenus();
926             ide.AdjustDebugMenus();
927          }
928       }
929       delete compiler;
930       return true;
931    }
932
933    bool ProjectRealClean(MenuItem selection, Modifiers mods)
934    {
935       Project prj = project;
936       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
937       ProjectConfig config;
938       if(selection || !ide.activeClient)
939       {
940          DataRow row = fileList.currentRow;
941          ProjectNode node = row ? (ProjectNode)row.tag : null;
942          if(node) prj = node.project;
943       }
944       else
945       {
946          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
947          if(node)
948             prj = node.project;
949       }
950       config = prj.config;
951       if(!prj.GetConfigIsInDebugSession(config) ||
952             (!ide.DontTerminateDebugSession($"Project Real Clean") && DebugStopForMake(prj, clean, compiler, config)))
953       {
954          if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
955          {
956             ide.outputView.buildBox.Logf($"Removing intermediate objects directory for project %s using the %s configuration...\n", prj.name, GetConfigName(config));
957
958             buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
959             ide.AdjustBuildMenus();
960             ide.AdjustDebugMenus();
961
962             prj.Clean(compiler, config, true, mods.ctrl && mods.shift);
963             buildInProgress = none;
964             ide.AdjustBuildMenus();
965             ide.AdjustDebugMenus();
966          }
967       }
968       delete compiler;
969       return true;
970    }
971
972    bool ProjectRegenerate(MenuItem selection, Modifiers mods)
973    {
974       Project prj = project;
975       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
976       ShowOutputBuildLog(true);
977       if(selection || !ide.activeClient)
978       {
979          DataRow row = fileList.currentRow;
980          ProjectNode node = row ? (ProjectNode)row.tag : null;
981          if(node)
982             prj = node.project;
983       }
984       else
985       {
986          ProjectNode node = GetNodeFromWindow(ide.activeClient, null);
987          if(node)
988             prj = node.project;
989       }
990
991       DisplayCompiler(compiler, false);
992       ProjectPrepareCompiler(project, compiler);
993       ProjectPrepareMakefile(prj, force, compiler, prj.config);
994       delete compiler;
995       return true;
996    }
997
998    bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
999    {
1000       bool result = true;
1001       char fileName[MAX_LOCATION];
1002       Window document;
1003       ProjectConfig config = project.config;
1004
1005       stopBuild = false;
1006
1007       for(document = ide.firstChild; document; document = document.next)
1008       {
1009          if(document.modifiedDocument)
1010          {
1011             ProjectNode n = GetNodeFromWindow(document, project);
1012             for(node : nodes)
1013             {
1014                if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1015                {
1016                   ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1017                   result = false;
1018                   break;
1019                }
1020             }
1021          }
1022       }
1023
1024       if(result)
1025       {
1026          CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1027          result = false;
1028          if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1029          {
1030             if(config)
1031                ide.outputView.buildBox.Logf($"%s specific file(s) in project %s using the %s configuration...\n",
1032                      mode == normal ? $"Compiling" : $"Debug compiling", project.name, config.name);
1033             else
1034                ide.outputView.buildBox.Logf($"%s specific file(s) in project %s...\n",
1035                      mode == normal ? $"Compiling" : $"Debug compiling", project.name);
1036
1037             buildInProgress = compilingFile;
1038             ide.AdjustBuildMenus();
1039             project.Compile(nodes, compiler, config, justPrint, mode);
1040             buildInProgress = none;
1041             ide.AdjustBuildMenus();
1042
1043             result = true;
1044          }
1045          delete compiler;
1046       }
1047       return result;
1048    }
1049
1050    bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
1051    {
1052       bool result = true;
1053       char fileName[MAX_LOCATION];
1054       Window document;
1055       ProjectConfig config = project.config;
1056
1057       stopBuild = false;
1058
1059       for(document = ide.firstChild; document; document = document.next)
1060       {
1061          if(document.modifiedDocument)
1062          {
1063             ProjectNode n = GetNodeFromWindow(document, project);
1064             for(node : nodes)
1065             {
1066                if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
1067                {
1068                   ide.outputView.buildBox.Logf($"Unable to save %s file.\n", node.name);
1069                   result = false;
1070                   break;
1071                }
1072             }
1073          }
1074       }
1075
1076       if(result)
1077       {
1078          CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1079          result = false;
1080          if(ProjectPrepareForToolchain(project, normal, true, true, compiler, config))
1081          {
1082             Map<String, NameCollisionInfo> namesInfo { };
1083             project.topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1084             for(node : nodes)
1085             {
1086                if(node.GetIsExcluded(config))
1087                   ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
1088                else
1089                {
1090                   if(config)
1091                      ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s using the %s configuration...\n",
1092                            node.type == file ? $"single file" : $"folder", node.name, project.name, config.name);
1093                   else
1094                      ide.outputView.buildBox.Logf($"Deleteing intermediate objects for %s %s in project %s...\n",
1095                            node.type == file ? $"single file" : $"folder", node.name, project.name);
1096
1097                   node.DeleteIntermediateFiles(compiler, config, namesInfo);
1098                   result = true;
1099                }
1100             }
1101             namesInfo.Free();
1102             delete namesInfo;
1103          }
1104          delete compiler;
1105       }
1106       return result;
1107    }
1108
1109    bool ProjectNewFile(MenuItem selection, Modifiers mods)
1110    {
1111       DataRow row = fileList.currentRow;
1112       if(row)
1113       {
1114          char fileName[1024];
1115          char filePath[MAX_LOCATION];
1116          ProjectNode parentNode = (ProjectNode)row.tag;
1117          ProjectNode n, fileNode;
1118          parentNode.GetFileSysMatchingPath(filePath);
1119          MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
1120          for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
1121          sprintf(fileName, $"Untitled %d", documentID);
1122          fileNode = AddFile(parentNode, fileName, (bool)n, true);
1123          fileNode.path = CopyUnixPath(filePath);
1124          if(fileNode)
1125          {
1126             NodeProperties nodeProperties
1127             {
1128                parent, this;
1129                position = { position.x + 100, position.y + 100 };
1130                mode = newFile;
1131                node = fileNode;
1132             };
1133             nodeProperties.Create(); // not modal?
1134          }
1135       }
1136       return true;
1137    }
1138
1139    bool ProjectNewFolder(MenuItem selection, Modifiers mods)
1140    {
1141       DataRow row = fileList.currentRow;
1142       if(row)
1143       {
1144          ProjectNode parentNode = (ProjectNode)row.tag;
1145          NewFolder(parentNode, null, true);
1146       }
1147       return true;
1148    }
1149
1150    bool ResourcesAddFiles(MenuItem selection, Modifiers mods)
1151    {
1152       AddFiles(true);
1153       return true;
1154    }
1155
1156    bool ProjectAddFiles(MenuItem selection, Modifiers mods)
1157    {
1158       AddFiles(false);
1159       return true;
1160    }
1161
1162    bool ProjectImportFolder(MenuItem selection, Modifiers mods)
1163    {
1164       DataRow row = fileList.currentRow;
1165       if(row)
1166       {
1167          ProjectNode toNode = (ProjectNode)row.tag;
1168          ImportFolder(toNode);
1169       }
1170       return true;
1171    }
1172
1173    bool ProjectAddNewForm(MenuItem selection, Modifiers mods)
1174    {
1175       CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
1176       codeEditor.EnsureUpToDate();
1177       return true;
1178    }
1179
1180    bool ProjectAddNewGraph(MenuItem selection, Modifiers mods)
1181    {
1182       CodeEditor codeEditor = CreateNew("Graph", "graph", "Block", null);
1183       if(codeEditor)
1184          codeEditor.EnsureUpToDate();
1185       return true;
1186    }
1187
1188    bool ProjectRemove(MenuItem selection, Modifiers mods)
1189    {
1190       DataRow row = fileList.currentRow;
1191       if(row)
1192       {
1193          ProjectNode node = (ProjectNode)row.tag;
1194          if(node.type == project)
1195             RemoveSelectedNodes();
1196       }
1197       return true;
1198    }
1199
1200    bool ProjectUpdateMakefileForAllConfigs(Project project)
1201    {
1202       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1203
1204       // This call really does not belong here:
1205       ide.UpdateToolBarActiveConfigs(false);
1206       for(config : project.configurations)
1207          ProjectPrepareMakefile(project, forceExists, compiler, config);
1208
1209       ide.Update(null);
1210       delete compiler;
1211       return true;
1212    }
1213
1214    bool MenuSettings(MenuItem selection, Modifiers mods)
1215    {
1216       ProjectNode node = GetSelectedNode(true);
1217       Project prj = node ? node.project : project;
1218       projectSettingsDialog = ProjectSettings { master = parent, project = prj, projectNode = node };
1219       projectSettingsDialog.Modal();
1220
1221       Update(null);
1222       ide.AdjustMenus();
1223       return true;
1224    }
1225
1226    bool FileProperties(MenuItem selection, Modifiers mods)
1227    {
1228       DataRow row = fileList.currentRow;
1229       if(row)
1230       {
1231          ProjectNode node = (ProjectNode)row.tag;
1232          NodeProperties { parent = parent, master = this, node = node, 
1233                position = { position.x + 100, position.y + 100 } }.Create();
1234       }
1235       return true;
1236    }
1237
1238    bool FileOpenFile(MenuItem selection, Modifiers mods)
1239    {
1240       OpenSelectedNodes();
1241       return true;
1242    }
1243
1244    bool FileRemoveFile(MenuItem selection, Modifiers mods)
1245    {
1246       RemoveSelectedNodes();
1247       return true;
1248    }
1249
1250    bool FileCompile(MenuItem selection, Modifiers mods)
1251    {
1252       OldLink item;
1253       OldList selectedRows;
1254       Project project = null;
1255       List<ProjectNode> nodes { };
1256       fileList.GetMultiSelection(selectedRows);
1257       for(item = selectedRows.first; item; item = item.next)
1258       {
1259          OldLink i;
1260          DataRow row = item.data;
1261          ProjectNode node = (ProjectNode)row.tag;
1262          if(!project)
1263             project = node.project;
1264          else if(node.project != project)
1265          {
1266             project = null;
1267             break;
1268          }
1269          nodes.Add(node);
1270       }
1271       selectedRows.Free(null);
1272       if(project)
1273          Compile(project, nodes, mods.ctrl && mods.shift, normal);
1274       else
1275          ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1276       delete nodes;
1277       return true;
1278    }
1279
1280    bool FileClean(MenuItem selection, Modifiers mods)
1281    {
1282       OldLink item;
1283       OldList selectedRows;
1284       Project project = null;
1285       List<ProjectNode> nodes { };
1286       fileList.GetMultiSelection(selectedRows);
1287       for(item = selectedRows.first; item; item = item.next)
1288       {
1289          OldLink i;
1290          DataRow row = item.data;
1291          ProjectNode node = (ProjectNode)row.tag;
1292          if(!project)
1293             project = node.project;
1294          else if(node.project != project)
1295          {
1296             project = null;
1297             break;
1298          }
1299          nodes.Add(node);
1300       }
1301       selectedRows.Free(null);
1302       if(project)
1303          Clean(project, nodes, mods.ctrl && mods.shift);
1304       else
1305          ide.outputView.buildBox.Logf($"Please select files from a single project.\n");
1306       delete nodes;
1307       return true;
1308    }
1309
1310    bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
1311    {
1312       DataRow row = fileList.currentRow;
1313       ProjectNode node = row ? (ProjectNode)row.tag : null;
1314       if(node)
1315       {
1316          List<ProjectNode> nodes { };
1317          nodes.Add(node);
1318          Compile(node.project, nodes, mods.ctrl && mods.shift, debugPrecompile);
1319          delete nodes;
1320       }
1321    }
1322
1323    bool FileDebugCompile(MenuItem selection, Modifiers mods)
1324    {
1325       DataRow row = fileList.currentRow;
1326       ProjectNode node = row ? (ProjectNode)row.tag : null;
1327       if(node)
1328       {
1329          List<ProjectNode> nodes { };
1330          nodes.Add(node);
1331          Compile(node.project, nodes, mods.ctrl && mods.shift, debugCompile);
1332          delete nodes;
1333       }
1334    }
1335
1336    bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
1337    {
1338       DataRow row = fileList.currentRow;
1339       ProjectNode node = row ? (ProjectNode)row.tag : null;
1340       if(node)
1341       {
1342          List<ProjectNode> nodes { };
1343          nodes.Add(node);
1344          Compile(node.project, nodes, mods.ctrl && mods.shift, debugGenerateSymbols);
1345          delete nodes;
1346       }
1347    }
1348
1349    Project GetSelectedProject(bool useSelection)
1350    {
1351       Project prj = project;
1352       if(useSelection)
1353       {
1354          DataRow row = fileList.currentRow;
1355          ProjectNode node = row ? (ProjectNode)row.tag : null;
1356          if(node)
1357             prj = node.project;
1358       }
1359       return prj;
1360    }
1361    
1362    void SelectNextProject(bool backwards)
1363    {
1364       DataRow row = fileList.currentRow;
1365       DataRow currentRow = row;
1366       ProjectNode node = (ProjectNode)row.tag;
1367       if(node.type != project)
1368          row = node.project.topNode.row;
1369       else if(backwards)
1370          row = row.previous ? row.previous : fileList.lastRow;
1371       if(!backwards)
1372          row = row.next ? row.next : fileList.firstRow;
1373       if(row && row != currentRow)
1374       {
1375          fileList.SelectRow(row);
1376          fileList.currentRow = row;
1377       }
1378    }
1379
1380    ProjectNode GetSelectedNode(bool useSelection)
1381    {
1382       ProjectNode node = null;
1383       if(useSelection)
1384       {
1385          DataRow row = fileList.currentRow;
1386          if(row)
1387             node = (ProjectNode)row.tag;
1388       }
1389       return node;
1390    }
1391
1392    bool MenuBrowseFolder(MenuItem selection, Modifiers mods)
1393    {
1394       char folder[MAX_LOCATION];
1395       Project prj;
1396       ProjectNode node = GetSelectedNode(true);
1397       if(!node)
1398          node = project.topNode;
1399       prj = node.project;
1400
1401       strcpy(folder, prj.topNode.path);
1402       if(node != prj.topNode)
1403          PathCatSlash(folder, node.path);
1404       ShellOpen(folder);
1405       return true;
1406    }
1407
1408    bool Run(MenuItem selection, Modifiers mods)
1409    {
1410       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1411       ProjectConfig config = project.config;
1412       String args = new char[maxPathLen];
1413       args[0] = '\0';
1414       if(ide.workspace.commandLineArgs)
1415          //ide.debugger.GetCommandLineArgs(args);
1416          strcpy(args, ide.workspace.commandLineArgs);
1417       if(ide.debugger.isActive)
1418          project.Run(args, compiler, config);
1419       /*else if(config.targetType == sharedLibrary || config.targetType == staticLibrary)
1420          MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
1421       else if(BuildInterrim(project, run, compiler, config, false))
1422          project.Run(args, compiler, config);
1423       delete args;
1424       delete compiler;
1425       return true;
1426    }
1427
1428    bool DebugStart()
1429    {
1430       bool result = false;
1431       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1432       ProjectConfig config = project.config;
1433       TargetTypes targetType = project.GetTargetType(config);
1434       if(targetType == sharedLibrary || targetType == staticLibrary)
1435          MessageBox { master = ide, type = ok, text = $"Run", contents = $"Shared and static libraries cannot be run like executables." }.Modal();
1436       else if(project.GetCompress(config))
1437          MessageBox { master = ide, text = $"Starting Debug", contents = $"Debugging compressed applications is not supported\n" }.Modal();
1438       else if(project.GetDebug(config) ||
1439          MessageBox { master = ide, type = okCancel, text = $"Starting Debug", contents = $"Attempting to debug non-debug configuration\nProceed anyways?" }.Modal() == ok)
1440       {
1441          if(/*!IsProjectModified() ||*/ BuildInterrim(project, start, compiler, config, false))
1442          {
1443             if(compiler.type.isVC)
1444             {
1445                //bool result = false;
1446                char oldwd[MAX_LOCATION];
1447                PathBackup pathBackup { };
1448                char command[MAX_LOCATION];
1449
1450                ide.SetPath(false, compiler, config);
1451                
1452                GetWorkingDir(oldwd, sizeof(oldwd));
1453                ChangeWorkingDir(project.topNode.path);
1454
1455                sprintf(command, "%s /useenv %s.sln /projectconfig \"%s|Win32\" /command \"%s\"" , "devenv", project.name, config.name, "Debug.Start");
1456                Execute(command);
1457                ChangeWorkingDir(oldwd);
1458
1459                delete pathBackup;
1460             }
1461             else
1462             {
1463                ide.debugger.Start(compiler, config);
1464                result = true;
1465             }
1466          }
1467       }
1468       delete compiler;
1469       return result;      
1470    }
1471
1472    void GoToError(const char * line)
1473    {
1474       char * colon;
1475       
1476       while(isspace(*line)) line++;
1477       colon = strstr(line, ":");
1478
1479       {
1480          int lineNumber = 0;
1481          int col = 1;
1482          bool lookForLineNumber = true;
1483
1484          // deal with linking error
1485          if(colon && colon[1] == ' ')
1486          {
1487             colon = strstr(colon + 1, ":");
1488             if(colon && !colon[1])
1489             {
1490                colon = strstr(line, ":");
1491                lookForLineNumber = false;
1492             }
1493             else if(colon && !isdigit(colon[1]))
1494             {
1495                line = colon + 1;
1496                colon = strstr(line, ":");
1497             }
1498          }
1499          // Don't be mistaken by the drive letter colon
1500          if(colon && (colon[1] == '/' || colon[1] == '\\'))
1501             colon = strstr(colon + 1, ":");
1502          if(colon && lookForLineNumber)
1503          {
1504             char * comma;
1505             // MSVS Errors
1506             char * par = RSearchString(line, "(", colon - line, true, false);
1507             if(par && strstr(par, ")"))
1508                colon = par;
1509             else if((colon+1)[0] == ' ')
1510             {
1511                // NOTE: This is the same thing as saying 'colon = line'
1512                for( ; colon != line; colon--)
1513                   /*if(*colon == '(')
1514                      break*/;
1515             }
1516             lineNumber = atoi(colon + 1);
1517             /*
1518             comma = strchr(colon, ',');
1519             if(comma)
1520                col = atoi(comma+1);
1521             */
1522             comma = strchr(colon+1, ':');
1523             if(comma)
1524                col = atoi(comma+1);
1525          }
1526          
1527          {
1528             char moduleName[MAX_LOCATION], filePath[MAX_LOCATION];
1529             char * bracket;
1530             if(colon)
1531             {
1532                char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1533                char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1534                int len = (int)(colon - start);
1535                len = Min(len, MAX_LOCATION-1);
1536                // Cut module name
1537                strncpy(moduleName, start, len);
1538                moduleName[len] = '\0';
1539             }
1540             else
1541                strcpy(moduleName, line);
1542
1543             // Remove stuff in brackets
1544             /*
1545             bracket = strstr(moduleName, "(");
1546             if(bracket) *bracket = '\0';
1547             */
1548             MakeSlashPath(moduleName);
1549
1550             if(!colon)
1551             {
1552                // Check if it's one of our modules
1553                ProjectNode node = project.topNode.Find(moduleName, false);
1554                if(node)
1555                {
1556                   strcpy(moduleName, node.path);
1557                   PathCatSlash(moduleName, node.name);
1558                }
1559                else
1560                   moduleName[0] = '\0';
1561             }
1562             if(moduleName[0])
1563             {
1564                CodeEditor codeEditor;
1565                strcpy(filePath, project.topNode.path);
1566                PathCatSlash(filePath, moduleName);
1567       
1568                codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1569                if(!codeEditor)
1570                {
1571                   char name[MAX_LOCATION];
1572                   // TOFIX: Improve on this, don't use only filename, make a function
1573                   if(ide && ide.workspace)
1574                   {
1575                      for(prj : ide.workspace.projects)
1576                      {
1577                         if(prj.topNode.FindWithPath(moduleName, false))
1578                         {
1579                            strcpy(filePath, prj.topNode.path);
1580                            PathCatSlash(filePath, moduleName);
1581                            codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal);
1582                            if(codeEditor)
1583                               break;
1584                         }
1585                      }
1586                   }
1587                }
1588                if(codeEditor && lineNumber)
1589                {
1590                   EditBox editBox = codeEditor.editBox;
1591                   editBox.GoToLineNum(lineNumber - 1);
1592                   editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
1593                }
1594             }
1595          }
1596       }
1597    }
1598
1599    bool OpenNode(ProjectNode node)
1600    {
1601       char filePath[MAX_LOCATION];
1602       node.GetFullFilePath(filePath);
1603       return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal) ? true : false;
1604    }
1605
1606    void AddNode(ProjectNode node, DataRow addTo)
1607    {
1608       DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
1609
1610       row.tag = (int64)node;
1611       node.row = row;
1612
1613       if(node.type == resources)
1614          resourceRow = row;
1615
1616       row.SetData(null, node);
1617
1618       if(node.files && node.files.first && node.parent && 
1619             !(!node.parent.parent && 
1620                (!strcmpi(node.name, "notes") || !strcmpi(node.name, "sources") || 
1621                   !strcmpi(node.name, "src") || !strcmpi(node.name, "tools"))))
1622          row.collapsed = true;
1623       else if(node.type == folder)
1624          node.icon = openFolder;
1625
1626       if(node.files)
1627       {
1628          for(child : node.files)
1629             AddNode(child, row);
1630       }
1631    }
1632
1633    void DeleteNode(ProjectNode projectNode)
1634    {
1635       if(projectNode.files)
1636       {
1637          ProjectNode child;
1638          while(child = projectNode.files.first)
1639             DeleteNode(child);
1640       }
1641       fileList.DeleteRow(projectNode.row);
1642       projectNode.Delete();
1643    }
1644
1645    bool ProjectSave(MenuItem selection, Modifiers mods)
1646    {
1647       DataRow row = fileList.currentRow;
1648       ProjectNode node = row ? (ProjectNode)row.tag : null;
1649       Project prj = node ? node.project : null;
1650       if(prj)
1651       {
1652          prj.StopMonitoring();
1653          if(prj.Save(prj.filePath))
1654          {
1655             Project modPrj = null;
1656             prj.topNode.modified = false;
1657             for(p : ide.workspace.projects)
1658             {
1659                if(p.topNode.modified)
1660                { 
1661                   modPrj = p;
1662                   break;
1663                }
1664             }
1665             if(!modPrj)
1666                modifiedDocument = false;
1667             Update(null);
1668          }
1669          prj.StartMonitoring();
1670       }
1671       return true;
1672    }
1673
1674    bool ShowOutputBuildLog(bool cleanLog)
1675    {
1676       OutputView output = ide.outputView;
1677       if(cleanLog)
1678          output.ShowClearSelectTab(build);
1679       else
1680       {
1681          output.SelectTab(build);
1682          output.Show();
1683       }
1684       return true;
1685    }
1686
1687    bool DebugRestart()
1688    {
1689       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1690       ProjectConfig config = project.config;
1691
1692       bool result = false;
1693       if(/*!IsProjectModified() ||*/ BuildInterrim(project, restart, compiler, config, false))
1694       {
1695          // For Restart, compiler and config will only be used if for
1696          // whatever reason (if at all possible) the Debugger is in a
1697          // 'terminated' or 'none' state
1698          ide.debugger.Restart(compiler, config);
1699          result = true;
1700       }
1701
1702       delete compiler;
1703       return result;
1704    }
1705
1706    bool DebugResume()
1707    {
1708       ide.debugger.Resume();
1709       return true;
1710    }
1711
1712    bool DebugBreak()
1713    {
1714       ide.debugger.Break();
1715       return true;
1716    }
1717
1718    bool DebugStop()
1719    {
1720       ide.debugger.Stop();
1721       return true;
1722    }
1723
1724    bool DebugStepInto()
1725    {
1726       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1727       ProjectConfig config = project.config;
1728
1729       if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, false)))
1730          ide.debugger.StepInto(compiler, config);
1731       delete compiler;
1732       return true;
1733    }
1734
1735    bool DebugStepOver(bool skip)
1736    {
1737       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1738       ProjectConfig config = project.config;
1739
1740       if((ide.debugger.isActive) || (!buildInProgress && BuildInterrim(project, start, compiler, config, false)))
1741          ide.debugger.StepOver(compiler, config, skip);
1742
1743       delete compiler;
1744       return true;
1745    }
1746
1747    bool DebugStepOut(bool skip)
1748    {
1749       ide.debugger.StepOut(skip);
1750       return true;
1751    }
1752
1753    void ImportFolder(ProjectNode toNode)
1754    {
1755       if(toNode)
1756       {
1757          //bool isFolder = toNode.type == folder;
1758          //bool isRes = toNode.isInResources;
1759          
1760          FileDialog fileDialog = importFileDialog;
1761          fileDialog.master = parent;
1762          if(fileDialog.Modal() == ok)
1763          {
1764             ImportFolderFSI fsi { projectView = this };
1765             fsi.stack.Add(toNode);
1766             fsi.Iterate(fileDialog.filePath);
1767             delete fsi;
1768          }
1769       }
1770    }
1771
1772    ProjectNode NewFolder(ProjectNode parentNode, char * name, bool showProperties)
1773    {
1774       if(parentNode)
1775       {
1776          ProjectNode folderNode;
1777          Project prj = parentNode.project;
1778          int c;
1779          ProjectNode after = null;
1780          for(node : parentNode.files)
1781          {
1782             if(node.type != folder)
1783                break;
1784             after = node;
1785          }
1786          
1787          if(name && name[0])
1788             folderNode = parentNode.Add(prj, name, after, folder, folder, true);
1789          else
1790          {
1791             for(c = 0; c < 100; c++)
1792             {
1793                char string[16];
1794                sprintf(string, c ? "New Folder (%d)" : "New Folder", c);
1795                if((folderNode = parentNode.Add(prj, string, after, folder, folder, true)))
1796                   break;
1797             }
1798          }
1799
1800          if(folderNode)
1801          {
1802             NodeProperties nodeProperties;
1803             if(!showProperties)
1804             {
1805                modifiedDocument = true;
1806                prj.topNode.modified = true;
1807             }
1808             Update(null);
1809             folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1810             folderNode.row.tag = (int64)folderNode;
1811                
1812             folderNode.row.SetData(null, folderNode);
1813             fileList.currentRow = folderNode.row;
1814             
1815             if(showProperties)
1816             {
1817                nodeProperties = NodeProperties
1818                {
1819                   parent, this, mode = newFolder, node = folderNode;
1820                   position = { position.x + 100, position.y + 100 };
1821                };
1822                nodeProperties.Create();   // Modal?
1823             }
1824             return folderNode;
1825          }
1826       }
1827       return null;
1828    }
1829
1830    void AddFiles(bool resources)
1831    {
1832       FileDialog fileDialog = (!resources) ? this.fileDialog : resourceFileDialog;
1833       fileDialog.type = multiOpen;
1834       fileDialog.text = !resources ? $"Add Files to Project" : $"Add Resources to Project";
1835       fileDialog.master = parent;
1836
1837       if(fileDialog.Modal() == ok)
1838       {
1839          int c;
1840          DataRow row = fileList.currentRow;
1841          ProjectNode parentNode = (ProjectNode)row.tag;
1842          bool addFailed = false;
1843          int numSelections = fileDialog.numSelections;
1844          char ** multiFilePaths = fileDialog.multiFilePaths;
1845
1846          Array<String> nameConflictFiles { };
1847
1848          for(c = 0; c < numSelections; c++)
1849          {
1850             char * filePath = multiFilePaths[c];
1851             FileAttribs exists = FileExists(filePath);
1852             bool addThisFile = true;
1853
1854             if(exists.isDirectory)
1855                addThisFile = false;
1856             else if(!exists)
1857             {
1858                if(MessageBox { master = ide, type = yesNo, text = filePath, 
1859                      contents = $"File doesn't exist. Create?" }.Modal() == yes)
1860                {
1861                   File f = FileOpen(filePath, write);
1862                   if(f)
1863                   {
1864                      addThisFile = true;
1865                      delete f;
1866                   }
1867                   else
1868                   {
1869                      MessageBox { master = ide, type = ok, text = filePath, 
1870                            contents = $"Couldn't create file."}.Modal();
1871                      addThisFile = false;
1872                   }
1873                }
1874             }
1875
1876             if(addThisFile)
1877             {
1878                /*addFailed = */if(!AddFile(parentNode, filePath, resources, false))//;
1879                {
1880                   nameConflictFiles.Add(CopyString(filePath));
1881                   addFailed = true;
1882                }
1883             }
1884          }
1885          if(addFailed)
1886          {
1887             int len = 0;
1888             char * part1 = $"The following file";
1889             char * opt1 = $" was ";
1890             char * opt2 = $"s were ";
1891             char * part2 = $"not added because of identical file name conflict within the project.\n\n";
1892             char * message;
1893             len += strlen(part1);
1894             len += strlen(part2);
1895             len += nameConflictFiles.count > 1 ? strlen(opt2) : strlen(opt1);
1896             for(s : nameConflictFiles)
1897                len += strlen(s) + 1;
1898             message = new char[len + 1];
1899             strcpy(message, part1);
1900             strcat(message, nameConflictFiles.count > 1 ? opt2 : opt1);
1901             strcat(message, part2);
1902             for(s : nameConflictFiles)
1903             {
1904                strcat(message, s);
1905                strcat(message, "\n");
1906             }
1907             MessageBox { master = ide, type = ok, text = $"Name Conflict", 
1908                   contents = message }.Modal();
1909             delete message;
1910          }
1911          nameConflictFiles.Free();
1912          delete nameConflictFiles;
1913       }
1914    }
1915
1916    ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
1917    {
1918       ProjectNode result = null;
1919       ProjectNode after = null;
1920       for(node : parentNode.files)
1921       {
1922          if(node.type != folder && node.type != file && node.type)
1923             break;
1924          after = node;
1925       }
1926
1927       result = parentNode.Add(parentNode.project, filePath, after, file, NodeIcons::SelectFileIcon(filePath), !resources);
1928
1929       if(result)
1930       {
1931          if(!isTemporary)
1932          {
1933             modifiedDocument = true;
1934             parentNode.project.topNode.modified = true;
1935             parentNode.project.ModifiedAllConfigs(true, false, true, true);
1936          }
1937          Update(null);
1938          result.row = parentNode.row.AddRowAfter(after ? after.row : null);
1939          result.row.tag = (int64)result;
1940          result.row.SetData(null, result);
1941       }
1942       return result;
1943    }
1944
1945    CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
1946    {
1947       CodeEditor codeEditor = null;
1948       ProjectNode projectNode;
1949       ProjectNode after = null;
1950       DataRow row = fileList.currentRow;
1951       ProjectNode parentNode;
1952       int c;
1953
1954       if(!row) row = project.topNode.row;
1955
1956       parentNode = (ProjectNode)row.tag;
1957
1958       for(node : parentNode.files)
1959       {
1960          if(node.type != folder && node.type != file && node.type)
1961             break;
1962          after = node;
1963       }
1964       for(c = 1; c < 100; c++)
1965       {
1966          char string[16];
1967          sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
1968          if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
1969             break;
1970       }
1971       if(projectNode)
1972       {
1973          char name[256];
1974          char filePath[MAX_LOCATION];
1975
1976          modifiedDocument = true;
1977          project.topNode.modified = true;
1978          Update(null);
1979          project.ModifiedAllConfigs(true, false, false, true);
1980          projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
1981          projectNode.row.tag =(int64)projectNode;
1982             
1983          projectNode.row.SetData(null, projectNode);
1984          fileList.currentRow = projectNode.row;
1985
1986          strcpy(filePath, project.topNode.path);
1987          PathCat(filePath, projectNode.path);
1988          PathCat(filePath, projectNode.name);
1989
1990          codeEditor = (CodeEditor)ide.FindWindow(filePath);
1991          if(!codeEditor)
1992          {
1993             Class baseClass = eSystem_FindClass(__thisModule, base);
1994             subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
1995             if(designerClass)
1996             {
1997                codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
1998                strcpy(name, projectNode.name);
1999                sprintf(name, "%s%d", upper, c);
2000                if(className)
2001                   strcpy(className, name);
2002
2003                designerClass.CreateNew(codeEditor.editBox, codeEditor.clientSize, name, base);
2004
2005                //codeEditor.modifiedDocument = false;
2006                //codeEditor.designer.modifiedDocument = false;
2007
2008                //Code_EnsureUpToDate(codeEditor);
2009             }
2010          }
2011          else // TODO: fix no symbols generated when ommiting {} for following else
2012          {
2013             codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal);
2014          }
2015          if(codeEditor)
2016          {
2017             codeEditor.ViewDesigner();
2018             codeEditor.codeModified = true;
2019          }
2020       }
2021       visible = false;
2022       return codeEditor;   
2023    }
2024
2025    // Returns true if we opened something
2026    bool OpenSelectedNodes()
2027    {
2028       bool result = false;
2029       OldList selection;
2030       OldLink item;
2031
2032       fileList.GetMultiSelection(selection);
2033       for(item = selection.first; item; item = item.next)
2034       {
2035          DataRow row = item.data;
2036          ProjectNode node = (ProjectNode)row.tag;
2037          if(node.type == file)
2038          {
2039             OpenNode(node);
2040             result = true;
2041             break;
2042          }
2043       }
2044       selection.Free(null);
2045       return result;
2046    }
2047
2048    void RemoveSelectedNodes()
2049    {
2050       OldList selection;
2051       OldLink item, next;
2052       
2053       fileList.GetMultiSelection(selection);
2054
2055       // Remove children of parents we're deleting
2056       for(item = selection.first; item; item = next)
2057       {
2058          OldLink i;
2059          DataRow row = item.data;
2060          ProjectNode n, node = (ProjectNode)row.tag;
2061          bool remove = false;
2062
2063          next = item.next;
2064          for(i = selection.first; i && !remove; i = i.next)
2065          {
2066             ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
2067             for(n = node.parent; n; n = n.parent)
2068             {
2069                if(iNode == n)
2070                {
2071                   remove = true;
2072                   break;
2073                }
2074             }
2075          }
2076          if(remove)
2077             selection.Delete(item);
2078       }
2079
2080       for(item = selection.first; item; item = item.next)
2081       {
2082          DataRow row = item.data;
2083          ProjectNode node = (ProjectNode)row.tag;
2084          ProjectNode resNode;
2085          for(resNode = node.parent; resNode; resNode = resNode.parent)
2086             if(resNode.type == resources)
2087                break;
2088          if(node.type == file)
2089          {
2090             Project prj = node.project;
2091             DeleteNode(node);
2092             modifiedDocument = true;
2093             prj.topNode.modified = true;
2094             Update(null);
2095             prj.ModifiedAllConfigs(true, false, true, true);
2096          }
2097          else if(node.type == folder)
2098          {
2099             char message[1024];
2100             sprintf(message, $"Are you sure you want to remove the folder \"%s\"\n"
2101                   "and all of its contents from the project?", node.name);
2102             if(MessageBox { master = ide, type = yesNo, text = $"Delete Folder", contents = message }.Modal() == yes)
2103             {
2104                Project prj = node.project;
2105                if(node.containsFile)
2106                   prj.ModifiedAllConfigs(true, false, true, true);
2107                DeleteNode(node);
2108                modifiedDocument = true;
2109                prj.topNode.modified = true;
2110             }
2111          }
2112          else if(node.type == project && node != project.topNode && !buildInProgress)
2113          {
2114             char message[1024];
2115             Project prj = null;
2116             for(p : workspace.projects)
2117             {
2118                if(p.topNode == node)
2119                {
2120                   prj = p;
2121                   break;
2122                }
2123             }
2124             sprintf(message, $"Are you sure you want to remove the \"%s\" project\n" "from this workspace?", node.name);
2125             if(MessageBox { master = ide, type = yesNo, text = $"Remove Project", contents = message }.Modal() == yes)
2126             {
2127                // THIS GOES FIRST!
2128                DeleteNode(node);
2129                if(prj)
2130                   workspace.RemoveProject(prj);
2131                //modifiedDocument = true; // when project view is a workspace view
2132             }
2133          }
2134       }
2135       selection.Free(null);
2136    }
2137 }