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