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