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