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