ide: fix unable to open generated .c files from clang build log.
[sdk] / ide / src / project / ProjectView.ec
index 48c5355..9d758f0 100644 (file)
@@ -7,7 +7,7 @@ class ImportFolderFSI : NormalFileSystemIterator
    ProjectView projectView;
    Array<ProjectNode> stack { };
 
-   bool OnFolder(char * folderPath)
+   bool OnFolder(const char * folderPath)
    {
       char name[MAX_LOCATION];
       ProjectNode parentNode = stack.lastIterator.data;
@@ -20,12 +20,12 @@ class ImportFolderFSI : NormalFileSystemIterator
       return true;
    }
 
-   void OutFolder(char * folderPath, bool isRoot)
+   void OutFolder(const char * folderPath, bool isRoot)
    {
       stack.lastIterator.Remove(); //stack.Remove();
    }
 
-   bool OnFile(char * filePath)
+   bool OnFile(const char * filePath)
    {
       ProjectNode parentNode = stack.lastIterator.data;
       if(!projectView.AddFile(parentNode, filePath, parentNode.isInResources, false))
@@ -49,7 +49,7 @@ static Array<FileFilter> fileFilters
 
 static Array<FileFilter> resourceFilters
 { [
-   { $"Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png,*.gif)", "jpg, jpeg, bmp, pcx, png, gif" },
+   { $"Image Files (*.jpg, *.jpeg, *.bmp, *.pcx, *.png, *.gif)", "jpg, jpeg, bmp, pcx, png, gif" },
    { $"3D Studio Model Files (*.3ds)", "3ds" },
    { $"Translations (*.mo)", "mo" },
    { $"All files", null }
@@ -67,7 +67,7 @@ static Array<FileType> projectTypes
    { $"Ecere IDE Workspace", WorkspaceExtension }
 ] };
 
-static char * iconNames[] =
+static const char * iconNames[] =
 {
    "<:ecere>mimeTypes/file.png",                   /*genFile*/
    "<:ecere>mimeTypes/textEcereWorkspace.png",     /*ewsFile*/
@@ -216,7 +216,7 @@ class ProjectView : Window
          {
             bool showDebuggingMenuItems = mods.ctrl && mods.shift;
             bool showInstallMenuItem = mods.ctrl && mods.shift;
-            ProjectNode node = (ProjectNode)row.tag;
+            ProjectNode node = (ProjectNode)(intptr)row.tag;
 #ifdef IDE_SHOW_INSTALL_MENU_BUTTON
             showInstallMenuItem = true;
 #endif
@@ -241,7 +241,7 @@ class ProjectView : Window
                      mi = ide.projectInstallItem;
                      MenuItem { pop, $"Install"            , t         , NotifySelect = ProjectInstall    , bitmap = mi.bitmap }.disabled = na;
                   }
-                  if(showDebuggingMenuItems && node.ContainsFilesWithExtension("ec"))
+                  if(showDebuggingMenuItems && node.ContainsFilesWithExtension("ec", node.project.config))
                   {
                      MenuDivider { pop };
                      MenuItem { pop, $"Debug Generate Symbols", l, NotifySelect = FileDebugGenerateSymbols }.disabled = na;
@@ -372,7 +372,7 @@ class ProjectView : Window
       {
          if(row)
          {
-            ProjectNode node = (ProjectNode)row.tag;
+            ProjectNode node = (ProjectNode)(intptr)row.tag;
             switch(key)
             {
                case altEnter: case Key { keyPadEnter, alt = true }:
@@ -472,7 +472,7 @@ class ProjectView : Window
 
       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
       {
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          if(node.type == folder)
             node.icon = collapsed ? folder : openFolder;
          return true;
@@ -554,7 +554,7 @@ class ProjectView : Window
       ide.outputView.ShowClearSelectTab(find); // why this?
    }
 
-   bool OnSaveFile(char * fileName)
+   bool OnSaveFile(const char * fileName)
    {
       for(prj : ide.workspace.projects)
       {
@@ -571,21 +571,43 @@ class ProjectView : Window
       return true;
    }
 
-   bool IsModuleInProject(char * filePath)
+   bool IsModuleInProject(const char * filePath)
    {
       char moduleName[MAX_FILENAME]; //, modulePath[MAX_LOCATION];
       GetLastDirectory(filePath, moduleName);
       return project.topNode.Find(moduleName, false) != null;
    }
 
-   ProjectNode GetNodeFromWindow(Window document, Project project, bool skipExcluded, bool isCObject)
+   ProjectNode GetNodeForCompilationFromWindow(Window document, bool nonExcludedFirst, bool * isExcluded, bool * isCObject)
    {
+      ProjectNode node = null;
+      if(nonExcludedFirst)
+         node = GetNodeFromWindow(document, null, false, false, isExcluded);
+      if(!node)
+         node = GetNodeFromWindow(document, null, true, false, isExcluded);
+      if(!node && nonExcludedFirst)
+      {
+         node = GetNodeFromWindow(document, null, false, true, isExcluded);
+         if(isCObject && node) *isCObject = true;
+      }
+      if(!node)
+      {
+         node = GetNodeFromWindow(document, null, true, true, isExcluded);
+         if(isCObject && node) *isCObject = true;
+      }
+      return node;
+   }
+
+   ProjectNode GetNodeFromWindow(Window document, Project project, bool allNodes, bool isCObject, bool * isNodeExcluded)
+   {
+      ProjectNode node = null;
       if(document.fileName)
       {
+         bool excluded = false;
          char winFileName[MAX_LOCATION];
          char * documentFileName = GetSlashPathBuffer(winFileName, document.fileName);
-         ProjectNode node;
          Project prj;
+         ProjectNode n;
          if(isCObject)
          {
             char name[MAX_FILENAME];
@@ -594,10 +616,13 @@ class ProjectView : Window
             for(p : ide.workspace.projects)
             {
                prj = project ? project : p;
-               if((node = prj.topNode.Find(name, false)))
+               if((n = prj.topNode.Find(name, false)))
                {
-                  if(!skipExcluded || !node.GetIsExcluded(prj.config))
-                     return node;
+                  if(allNodes || !(excluded = n.GetIsExcluded(prj.config)))
+                  {
+                     node = n;
+                     break;
+                  }
                }
                if(project) break;
             }
@@ -607,16 +632,21 @@ class ProjectView : Window
             for(p : ide.workspace.projects)
             {
                prj = project ? project : p;
-               if((node = prj.topNode.FindByFullPath(documentFileName, false)))
+               if((n = prj.topNode.FindByFullPath(documentFileName, false)))
                {
-                  if(!skipExcluded || !node.GetIsExcluded(prj.config))
-                     return node;
+                  if(allNodes || !(excluded = n.GetIsExcluded(prj.config)))
+                  {
+                     node = n;
+                     break;
+                  }
                }
                if(project) break;
             }
          }
+         if(node && isNodeExcluded)
+            *isNodeExcluded = excluded;
       }
-      return null;
+      return node;
    }
 
    //                          ((( UTILITY FUNCTIONS )))
@@ -634,10 +664,6 @@ class ProjectView : Window
    bool ProjectPrepareForToolchain(Project project, PrepareMakefileMethod method, bool cleanLog, bool displayCompiler,
       CompilerConfig compiler, ProjectConfig config)
    {
-      bool isReady = true;
-      char message[MAX_F_STRING];
-      LogBox logBox = ide.outputView.buildBox;
-
       ShowOutputBuildLog(cleanLog);
 
       if(displayCompiler)
@@ -650,7 +676,8 @@ class ProjectView : Window
 
    bool ProjectPrepareCompiler(Project project, CompilerConfig compiler, bool silent)
    {
-      if((!project.GenerateCrossPlatformMk(app.includeFile) || !project.GenerateCompilerCf(compiler)) && !silent)
+      if((!project.GenerateCrossPlatformMk(app.includeFile) ||
+            !project.GenerateCompilerCf(compiler, project.topNode.ContainsFilesWithExtension("ec", project.config))) && !silent)
          ide.outputView.buildBox.Logf($"Error generating compiler configuration (Is the project/config directory writable?)\n");
       return true;
    }
@@ -687,8 +714,8 @@ class ProjectView : Window
            (method == forceExists && exists) ||
            (method == normal && (!exists || (config && config.makingModified))))
          {
-            char * reason;
-            char * action;
+            const char * reason;
+            const char * action;
             ide.statusBar.text = $"Generating Makefile & Dependencies..."; // Dependencies?
             app.UpdateDisplay();
 
@@ -753,6 +780,8 @@ class ProjectView : Window
                result = DebugStop();
          }
       }
+      app.ProcessInput(true);
+      ShowOutputBuildLog(false);
       return result;
    }
 
@@ -766,7 +795,7 @@ class ProjectView : Window
       {
          if(document.modifiedDocument)
          {
-            ProjectNode node = GetNodeFromWindow(document, prj, false, false);
+            ProjectNode node = GetNodeFromWindow(document, prj, true, false, null);
             if(node && !document.MenuFileSave(null, 0))
             {
                result = false;
@@ -853,12 +882,12 @@ class ProjectView : Window
          if(selection || !ide.activeClient)
          {
             DataRow row = fileList.currentRow;
-            ProjectNode node = row ? (ProjectNode)row.tag : null;
+            ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
             if(node) prj = node.project;
          }
          else
          {
-            ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+            ProjectNode node = GetNodeForCompilationFromWindow(ide.activeClient, true, null, null);
             if(node)
                prj = node.project;
          }
@@ -883,12 +912,12 @@ class ProjectView : Window
       if(selection || !ide.activeClient)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node) prj = node.project;
       }
       else
       {
-         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
          if(node)
             prj = node.project;
       }
@@ -916,12 +945,12 @@ class ProjectView : Window
       if(selection || !ide.activeClient)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node) prj = node.project;
       }
       else
       {
-         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
          if(node)
             prj = node.project;
       }
@@ -950,12 +979,12 @@ class ProjectView : Window
       if(selection || !ide.activeClient)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node) prj = node.project;
       }
       else
       {
-         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
          if(node)
             prj = node.project;
       }
@@ -996,42 +1025,65 @@ class ProjectView : Window
       return true;
    }
 
-   void CleanProject(char * terminateDebugSessionMessage, char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
+   void CleanProject(const char * terminateDebugSessionMessage, const char * cleaningMessageLogFormat, MenuItem selection, CleanType cleanType, bool justPrint)
    {
       Project prj = project;
+      Array<Project> projects { };
       CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
-      ProjectConfig config;
       int bitDepth = ide.workspace.bitDepth;
+      if(selection)
+      {
+         OldLink item;
+         OldList selectedRows;
+         fileList.GetMultiSelection(selectedRows);
+         for(item = selectedRows.first; item; item = item.next)
+         {
+            DataRow row = item.data;
+            ProjectNode node = (ProjectNode)(intptr)row.tag;
+            if(node.type == project)
+               projects.Add(node.project);
+         }
+         selectedRows.Free(null);
+      }
       if(selection || !ide.activeClient)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node) prj = node.project;
+         if(projects.count == 0)
+            projects.Add(prj);
       }
       else
       {
-         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+         // TODO: a file can belong to more than one project, ask which one to clean
+         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
          if(node) prj = node.project;
+         if(projects.count == 0)
+            projects.Add(prj);
       }
-      config = prj.config;
-      if(!prj.GetConfigIsInDebugSession(config) ||
-            (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
+      for(prj : projects)
       {
-         if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
+         ProjectConfig config = prj.config;
+         if(!prj.GetConfigIsInDebugSession(config) ||
+               (!ide.DontTerminateDebugSession(terminateDebugSessionMessage) && DebugStopForMake(prj, clean, compiler, config)))
          {
-            ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
+            if(ProjectPrepareForToolchain(prj, normal, true, true, compiler, config))
+            {
+               ide.outputView.buildBox.Logf(cleaningMessageLogFormat, prj.name, GetConfigName(config));
 
-            buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
-            ide.AdjustBuildMenus();
-            ide.AdjustDebugMenus();
+               buildInProgress = prj == project ? buildingMainProject : buildingSecondaryProject;
+               ide.AdjustBuildMenus();
+               ide.AdjustDebugMenus();
 
-            prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
-            buildInProgress = none;
-            ide.AdjustBuildMenus();
-            ide.AdjustDebugMenus();
+               prj.Clean(compiler, config, bitDepth, cleanType, justPrint);
+               buildInProgress = none;
+               ide.AdjustBuildMenus();
+               ide.AdjustDebugMenus();
+            }
          }
       }
       delete compiler;
+      delete projects;
    }
 
    bool ProjectRegenerate(MenuItem selection, Modifiers mods)
@@ -1042,13 +1094,13 @@ class ProjectView : Window
       if(selection || !ide.activeClient)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node)
             prj = node.project;
       }
       else
       {
-         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, false, false);
+         ProjectNode node = GetNodeFromWindow(ide.activeClient, null, true, false, null);
          if(node)
             prj = node.project;
       }
@@ -1063,7 +1115,6 @@ class ProjectView : Window
    bool Compile(Project project, List<ProjectNode> nodes, bool justPrint, SingleFileCompileMode mode)
    {
       bool result = true;
-      char fileName[MAX_LOCATION];
       Window document;
       ProjectConfig config = project.config;
 
@@ -1073,7 +1124,7 @@ class ProjectView : Window
       {
          if(document.modifiedDocument)
          {
-            ProjectNode n = GetNodeFromWindow(document, project, false, mode == cObject ? true : false);
+            ProjectNode n = GetNodeFromWindow(document, project, true, mode == cObject ? true : false, null);
             for(node : nodes)
             {
                if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
@@ -1114,7 +1165,6 @@ class ProjectView : Window
    bool Clean(Project project, List<ProjectNode> nodes, bool justPrint)
    {
       bool result = true;
-      char fileName[MAX_LOCATION];
       Window document;
       ProjectConfig config = project.config;
 
@@ -1124,7 +1174,7 @@ class ProjectView : Window
       {
          if(document.modifiedDocument)
          {
-            ProjectNode n = GetNodeFromWindow(document, project, false, false);
+            ProjectNode n = GetNodeFromWindow(document, project, true, false, null);
             for(node : nodes)
             {
                if(n && n.IsInNode(node) && !document.MenuFileSave(null, 0))
@@ -1178,13 +1228,13 @@ class ProjectView : Window
       {
          char fileName[1024];
          char filePath[MAX_LOCATION];
-         ProjectNode parentNode = (ProjectNode)row.tag;
+         ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
          ProjectNode n, fileNode;
          parentNode.GetFileSysMatchingPath(filePath);
          MakePathRelative(filePath, parentNode.project.topNode.path, filePath);
          for(n = parentNode; n && n != parentNode.project.resNode; n = n.parent);
          sprintf(fileName, $"Untitled %d", documentID);
-         fileNode = AddFile(parentNode, fileName, (bool)n, true);
+         fileNode = AddFile(parentNode, fileName, n != null, true);
          fileNode.path = CopyUnixPath(filePath);
          if(fileNode)
          {
@@ -1206,7 +1256,7 @@ class ProjectView : Window
       DataRow row = fileList.currentRow;
       if(row)
       {
-         ProjectNode parentNode = (ProjectNode)row.tag;
+         ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
          NewFolder(parentNode, null, true);
       }
       return true;
@@ -1229,7 +1279,7 @@ class ProjectView : Window
       DataRow row = fileList.currentRow;
       if(row)
       {
-         ProjectNode toNode = (ProjectNode)row.tag;
+         ProjectNode toNode = (ProjectNode)(intptr)row.tag;
          ImportFolder(toNode);
       }
       return true;
@@ -1239,6 +1289,7 @@ class ProjectView : Window
    {
       CodeEditor codeEditor = CreateNew("Form", "form", "Window", null);
       codeEditor.EnsureUpToDate();
+      ide.RepositionWindows(false);
       return true;
    }
 
@@ -1255,7 +1306,7 @@ class ProjectView : Window
       DataRow row = fileList.currentRow;
       if(row)
       {
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          if(node.type == project)
             RemoveSelectedNodes();
       }
@@ -1295,7 +1346,7 @@ class ProjectView : Window
       DataRow row = fileList.currentRow;
       if(row)
       {
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          NodeProperties { parent = parent, master = this, node = node,
                position = { position.x + 100, position.y + 100 } }.Create();
       }
@@ -1323,9 +1374,8 @@ class ProjectView : Window
       fileList.GetMultiSelection(selectedRows);
       for(item = selectedRows.first; item; item = item.next)
       {
-         OldLink i;
          DataRow row = item.data;
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          if(!project)
             project = node.project;
          else if(node.project != project)
@@ -1353,9 +1403,8 @@ class ProjectView : Window
       fileList.GetMultiSelection(selectedRows);
       for(item = selectedRows.first; item; item = item.next)
       {
-         OldLink i;
          DataRow row = item.data;
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          if(!project)
             project = node.project;
          else if(node.project != project)
@@ -1377,7 +1426,7 @@ class ProjectView : Window
    bool FileDebugPrecompile(MenuItem selection, Modifiers mods)
    {
       DataRow row = fileList.currentRow;
-      ProjectNode node = row ? (ProjectNode)row.tag : null;
+      ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
       if(node)
       {
          List<ProjectNode> nodes { };
@@ -1395,7 +1444,7 @@ class ProjectView : Window
    bool FileDebugCompile(MenuItem selection, Modifiers mods)
    {
       DataRow row = fileList.currentRow;
-      ProjectNode node = row ? (ProjectNode)row.tag : null;
+      ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
       if(node)
       {
          List<ProjectNode> nodes { };
@@ -1414,7 +1463,7 @@ class ProjectView : Window
    bool FileDebugGenerateSymbols(MenuItem selection, Modifiers mods)
    {
       DataRow row = fileList.currentRow;
-      ProjectNode node = row ? (ProjectNode)row.tag : null;
+      ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
       if(node)
       {
          List<ProjectNode> nodes { };
@@ -1436,7 +1485,7 @@ class ProjectView : Window
       if(useSelection)
       {
          DataRow row = fileList.currentRow;
-         ProjectNode node = row ? (ProjectNode)row.tag : null;
+         ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
          if(node)
             prj = node.project;
       }
@@ -1446,18 +1495,24 @@ class ProjectView : Window
    void SelectNextProject(bool backwards)
    {
       DataRow row = fileList.currentRow;
-      DataRow currentRow = row;
-      ProjectNode node = (ProjectNode)row.tag;
-      if(node.type != project)
-         row = node.project.topNode.row;
-      else if(backwards)
-         row = row.previous ? row.previous : fileList.lastRow;
-      if(!backwards)
-         row = row.next ? row.next : fileList.firstRow;
-      if(row && row != currentRow)
+      if(!row)
+         row = backwards ? fileList.lastRow : fileList.firstRow;
+
+      if(row)
       {
-         fileList.SelectRow(row);
-         fileList.currentRow = row;
+         DataRow currentRow = row;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
+         if(node.type != project)
+            row = node.project.topNode.row;
+         else if(backwards)
+            row = row.previous ? row.previous : fileList.lastRow;
+         if(!backwards)
+            row = row.next ? row.next : fileList.firstRow;
+         if(row && row != currentRow)
+         {
+            fileList.SelectRow(row);
+            fileList.currentRow = row;
+         }
       }
    }
 
@@ -1468,7 +1523,7 @@ class ProjectView : Window
       {
          DataRow row = fileList.currentRow;
          if(row)
-            node = (ProjectNode)row.tag;
+            node = (ProjectNode)(intptr)row.tag;
       }
       return node;
    }
@@ -1615,13 +1670,12 @@ class ProjectView : Window
          {
             char moduleName[MAX_LOCATION], filePath[MAX_LOCATION] = "";
             char ext[MAX_EXTENSION] = "";
-            char * bracket;
             ProjectNode node = null;
             if(colon)
             {
-               char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
-               char * from = strstr(line, "from ");
-               char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
+               const char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
+               const char * from = strstr(line, "from ");
+               const char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen("from ") : line;
                int len;
                if(colon < start)
                   start = line;
@@ -1700,7 +1754,7 @@ class ProjectView : Window
                else
                {
                   char ext[MAX_EXTENSION];
-                  GetExtension(fileName, ext);
+                  GetExtension(moduleName, ext);
                   {
                      DotMain dotMain = DotMain::FromFileName(moduleName);
                      IntermediateFileType type = IntermediateFileType::FromExtension(ext);
@@ -1742,64 +1796,90 @@ class ProjectView : Window
                moduleName[0] = 0;    // Avoid opening binary files
             if(moduleName[0])
             {
-               CodeEditor codeEditor;
-               if(!filePath[0])
-               {
-                  strcpy(filePath, project.topNode.path);
-                  PathCatSlash(filePath, moduleName);
-               }
+               CodeEditor codeEditor = null;
 
-               codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
-               if(!codeEditor && !strcmp(ext, "c"))
+               if(ide.GoToCodeSelectFile(moduleName, null, project, null, filePath))
                {
-                  char ecName[MAX_LOCATION];
-                  ChangeExtension(filePath, "ec", ecName);
-                  codeEditor = (CodeEditor)ide.OpenFile(ecName, normal, true, null, no, normal, noParsing);
+                  codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
                }
+
                if(!codeEditor)
                {
-                  char path[MAX_LOCATION];
-                  // TOFIX: Improve on this, don't use only filename, make a function
-                  if(ide && ide.workspace)
+                  if(!filePath[0])
                   {
-                     for(prj : ide.workspace.projects)
-                     {
-                        ProjectNode node;
-                        MakePathRelative(filePath, prj.topNode.path, path);
+                     strcpy(filePath, project.topNode.path);
+                     PathCatSlash(filePath, moduleName);
+                  }
 
-                        if((node = prj.topNode.FindWithPath(path, false)))
-                        {
-                           strcpy(filePath, prj.topNode.path);
-                           PathCatSlash(filePath, node.path);
-                           PathCatSlash(filePath, node.name);
-                           codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
-                           if(codeEditor)
-                              break;
-                        }
-                     }
-                     if(!codeEditor && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
+                  codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
+                  if(!codeEditor && !strcmp(ext, "c"))
+                  {
+                     char ecName[MAX_LOCATION];
+                     ChangeExtension(filePath, "ec", ecName);
+                     codeEditor = (CodeEditor)ide.OpenFile(ecName, false, true, null, no, normal, noParsing);
+                  }
+                  if(!codeEditor)
+                  {
+                     char path[MAX_LOCATION];
+                     // TOFIX: Improve on this, don't use only filename, make a function
+                     if(ide && ide.workspace)
                      {
                         for(prj : ide.workspace.projects)
                         {
                            ProjectNode node;
-                           if((node = prj.topNode.Find(moduleName, false)))
+                           MakePathRelative(filePath, prj.topNode.path, path);
+
+                           if((node = prj.topNode.FindWithPath(path, false)))
                            {
                               strcpy(filePath, prj.topNode.path);
                               PathCatSlash(filePath, node.path);
                               PathCatSlash(filePath, node.name);
-                              codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, true, null, no, normal, noParsing);
+                              codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
                               if(codeEditor)
                                  break;
                            }
                         }
+                        if(!codeEditor && (strchr(moduleName, '/') || strchr(moduleName, '\\')))
+                        {
+                           for(prj : ide.workspace.projects)
+                           {
+                              ProjectNode node;
+                              if((node = prj.topNode.FindWithPath(moduleName, false)))
+                              {
+                                 strcpy(filePath, prj.topNode.path);
+                                 PathCatSlash(filePath, node.path);
+                                 PathCatSlash(filePath, node.name);
+                                 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
+                                 if(codeEditor)
+                                    break;
+                              }
+                           }
+                        }
+                        if(!codeEditor)
+                        {
+                           GetLastDirectory(moduleName, moduleName);
+                           for(prj : ide.workspace.projects)
+                           {
+                              ProjectNode node;
+                              if((node = prj.topNode.Find(moduleName, false)))
+                              {
+                                 strcpy(filePath, prj.topNode.path);
+                                 PathCatSlash(filePath, node.path);
+                                 PathCatSlash(filePath, node.name);
+                                 codeEditor = (CodeEditor)ide.OpenFile(filePath, false, true, null, no, normal, noParsing);
+                                 if(codeEditor)
+                                    break;
+                              }
+                           }
+                        }
                      }
                   }
                }
                if(codeEditor && lineNumber)
                {
                   EditBox editBox = codeEditor.editBox;
-                  editBox.GoToLineNum(lineNumber - 1);
-                  editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
+                  if(editBox.GoToLineNum(lineNumber - 1))
+                     editBox.GoToPosition(editBox.line, lineNumber - 1, col ? (col - 1) : 0);
                }
             }
          }
@@ -1809,15 +1889,23 @@ class ProjectView : Window
    bool OpenNode(ProjectNode node, bool noParsing)
    {
       char filePath[MAX_LOCATION];
+      char ext[MAX_EXTENSION];
       node.GetFullFilePath(filePath);
-      return ide.OpenFile(filePath, normal, true/*false Why was it opening hidden?*/, null, something, normal, noParsing) ? true : false;
+      GetExtension(filePath, ext);
+      if(binaryDocExt.Find(ext))
+      {
+         ShellOpen(filePath);
+         return true;
+      }
+      else
+         return ide.OpenFile(filePath, false, true/*false Why was it opening hidden?*/, null, something, normal, noParsing) ? true : false;
    }
 
    void AddNode(ProjectNode node, DataRow addTo)
    {
       DataRow row = addTo ? addTo.AddRow() : fileList.AddRow();
 
-      row.tag = (int64)node;
+      row.tag = (int64)(intptr)node;
       node.row = row;
 
       if(node.type == resources)
@@ -1845,7 +1933,7 @@ class ProjectView : Window
       if(projectNode.files)
       {
          ProjectNode child;
-         while(child = projectNode.files.first)
+         while((child = projectNode.files.first))
             DeleteNode(child);
       }
       fileList.DeleteRow(projectNode.row);
@@ -1855,7 +1943,7 @@ class ProjectView : Window
    bool ProjectSave(MenuItem selection, Modifiers mods)
    {
       DataRow row = fileList.currentRow;
-      ProjectNode node = row ? (ProjectNode)row.tag : null;
+      ProjectNode node = row ? (ProjectNode)(intptr)row.tag : null;
       Project prj = node ? node.project : null;
       if(prj)
       {
@@ -1984,11 +2072,28 @@ class ProjectView : Window
    {
       if(toNode)
       {
-         //bool isFolder = toNode.type == folder;
-         //bool isRes = toNode.isInResources;
-
+         char path[MAX_LOCATION];
+         char currentDir[MAX_LOCATION];
+         ProjectNode node = toNode;
          FileDialog fileDialog = importFileDialog;
          fileDialog.master = parent;
+         while(node)
+         {
+            node.GetFullFilePath(path);
+            while(path[0])
+            {
+               StripLastDirectory(path, path);
+               if(FileExists(path).isDirectory) break;
+            }
+            if(path[0] || node == toNode.project.topNode)
+               node = null;
+            else
+               node = toNode.project.topNode;
+         }
+         MakeSystemPath(path);
+         StripLastDirectory(path, currentDir);
+         fileDialog.currentDirectory = currentDir[0] ? currentDir : path;
+         fileDialog.filePath = path;
          if(fileDialog.Modal() == ok)
          {
             ImportFolderFSI fsi { projectView = this };
@@ -2037,7 +2142,7 @@ class ProjectView : Window
             }
             Update(null);
             folderNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
-            folderNode.row.tag = (int64)folderNode;
+            folderNode.row.tag = (int64)(intptr)folderNode;
 
             folderNode.row.SetData(null, folderNode);
             fileList.currentRow = folderNode.row;
@@ -2068,16 +2173,16 @@ class ProjectView : Window
       {
          int c;
          DataRow row = fileList.currentRow;
-         ProjectNode parentNode = (ProjectNode)row.tag;
+         ProjectNode parentNode = (ProjectNode)(intptr)row.tag;
          bool addFailed = false;
          int numSelections = fileDialog.numSelections;
-         char ** multiFilePaths = fileDialog.multiFilePaths;
+         const char * const * multiFilePaths = fileDialog.multiFilePaths;
 
          Array<String> nameConflictFiles { };
 
          for(c = 0; c < numSelections; c++)
          {
-            char * filePath = multiFilePaths[c];
+            const char * filePath = multiFilePaths[c];
             FileAttribs exists = FileExists(filePath);
             bool addThisFile = true;
 
@@ -2115,10 +2220,10 @@ class ProjectView : Window
          if(addFailed)
          {
             int len = 0;
-            char * part1 = $"The following file";
-            char * opt1 = $" was ";
-            char * opt2 = $"s were ";
-            char * part2 = $"not added because of identical file name conflict within the project.\n\n";
+            const char * part1 = $"The following file";
+            const char * opt1 = $" was ";
+            const char * opt2 = $"s were ";
+            const char * part2 = $"not added because of identical file name conflict within the project.\n\n";
             char * message;
             len += strlen(part1);
             len += strlen(part2);
@@ -2143,7 +2248,7 @@ class ProjectView : Window
       }
    }
 
-   ProjectNode AddFile(ProjectNode parentNode, char * filePath, bool resources, bool isTemporary)
+   ProjectNode AddFile(ProjectNode parentNode, const char * filePath, bool resources, bool isTemporary)
    {
       ProjectNode result = null;
       ProjectNode after = null;
@@ -2166,13 +2271,13 @@ class ProjectView : Window
          }
          Update(null);
          result.row = parentNode.row.AddRowAfter(after ? after.row : null);
-         result.row.tag = (int64)result;
+         result.row.tag = (int64)(intptr)result;
          result.row.SetData(null, result);
       }
       return result;
    }
 
-   CodeEditor CreateNew(char * upper, char * lower, char * base, char * className)
+   CodeEditor CreateNew(const char * upper, const char * lower, const char * base, char * className)
    {
       CodeEditor codeEditor = null;
       ProjectNode projectNode;
@@ -2183,7 +2288,7 @@ class ProjectView : Window
 
       if(!row) row = project.topNode.row;
 
-      parentNode = (ProjectNode)row.tag;
+      parentNode = (ProjectNode)(intptr)row.tag;
 
       for(node : parentNode.files)
       {
@@ -2194,7 +2299,7 @@ class ProjectView : Window
       for(c = 1; c < 100; c++)
       {
          char string[16];
-         sprintf(string, c ? "%s%d.ec" : "%s.ec", lower, c);
+         sprintf(string, "%s%d.ec", lower, c);
          if((projectNode = parentNode.Add(project, string, after, file, genFile, true)))
             break;
       }
@@ -2208,7 +2313,7 @@ class ProjectView : Window
          Update(null);
          project.ModifiedAllConfigs(true, false, false, true);
          projectNode.row = parentNode.row.AddRowAfter(after ? after.row : null);
-         projectNode.row.tag =(int64)projectNode;
+         projectNode.row.tag = (int64)(intptr)projectNode;
 
          projectNode.row.SetData(null, projectNode);
          fileList.currentRow = projectNode.row;
@@ -2224,7 +2329,7 @@ class ProjectView : Window
             subclass(ClassDesignerBase) designerClass = eClass_GetDesigner(baseClass);
             if(designerClass)
             {
-               codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
+               codeEditor = (CodeEditor)ide.OpenFile(filePath, false, false, null, whatever, normal, false);
                strcpy(name, projectNode.name);
                sprintf(name, "%s%d", upper, c);
                if(className)
@@ -2240,7 +2345,7 @@ class ProjectView : Window
          }
          else // TODO: fix no symbols generated when ommiting {} for following else
          {
-            codeEditor = (CodeEditor)ide.OpenFile(filePath, normal, false, null, whatever, normal, false);
+            codeEditor = (CodeEditor)ide.OpenFile(filePath, false, false, null, whatever, normal, false);
          }
          ide.sheet.visible = true;
          ide.sheet.Activate();
@@ -2265,7 +2370,7 @@ class ProjectView : Window
       for(item = selection.first; item; item = item.next)
       {
          DataRow row = item.data;
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          if(node.type == file)
          {
             OpenNode(node, noParsing);
@@ -2289,13 +2394,13 @@ class ProjectView : Window
       {
          OldLink i;
          DataRow row = item.data;
-         ProjectNode n, node = (ProjectNode)row.tag;
+         ProjectNode n, node = (ProjectNode)(intptr)row.tag;
          bool remove = false;
 
          next = item.next;
          for(i = selection.first; i && !remove; i = i.next)
          {
-            ProjectNode iNode = (ProjectNode)((DataRow)i.data).tag;
+            ProjectNode iNode = (ProjectNode)(intptr)((DataRow)i.data).tag;
             for(n = node.parent; n; n = n.parent)
             {
                if(iNode == n)
@@ -2312,7 +2417,7 @@ class ProjectView : Window
       for(item = selection.first; item; item = item.next)
       {
          DataRow row = item.data;
-         ProjectNode node = (ProjectNode)row.tag;
+         ProjectNode node = (ProjectNode)(intptr)row.tag;
          ProjectNode resNode;
          for(resNode = node.parent; resNode; resNode = resNode.parent)
             if(resNode.type == resources)