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