ide: fix unable to open generated .c files from clang build log.
authorRejean Loyer <redj@ecere.com>
Sun, 13 Jul 2014 18:53:49 +0000 (14:53 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sun, 15 Feb 2015 18:50:16 +0000 (13:50 -0500)
ide/src/debugger/Debugger.ec
ide/src/ide.ec
ide/src/project/ProjectView.ec
ide/src/project/Workspace.ec

index ffb67e7..ccdc5f4 100644 (file)
@@ -821,7 +821,7 @@ class Debugger
             if(frame.absoluteFile)
                editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, false, true, null, no, normal, false);
             if(!editor && frame.file)
-               frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+               frame.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(frame.file);
             if(!frame.absoluteFile && askForLocation && frame.file)
             {
                char * s = null;
@@ -832,7 +832,7 @@ class Debugger
                if(SourceDirDialog(title, ide.workspace.projectDir, frame.file, sourceDir))
                {
                   AddSourceDir(sourceDir);
-                  frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+                  frame.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(frame.file);
                }
             }
             if(!editor && frame.absoluteFile)
@@ -1508,7 +1508,7 @@ class Debugger
                Workspace ws = ide.workspace;
                if(ws)
                {
-                  String path = ide.workspace.GetPathWorkspaceRelativeOrAbsolute(item.value);
+                  String path = ide.workspace.CopyUnixPathWorkspaceRelativeOrAbsolute(item.value);
                   if(strcmp(frame.file, path))
                      frame.file = path;
                   delete path;
@@ -5014,7 +5014,7 @@ class CodeLocation : struct
                {
                   CodeLocation codloc { line = line };
                   codloc.file = CopyString(loc);
-                  codloc.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(loc);
+                  codloc.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(loc);
                   return codloc;
                }
             }
index 0f83e27..c9aa31d 100644 (file)
@@ -2668,6 +2668,65 @@ class IDEWorkSpace : Window
          projectView.GoToError(line, noParsing);
    }
 
+   FileAttribs GoToCodeSelectFile(const char * filePath, const char * dir, Project prj, ProjectNode * node, char * selectedPath)
+   {
+      FileAttribs result { };
+      FileAttribs fileAttribs;
+      if(filePath[0])
+      {
+         if(prj)
+            strcpy(selectedPath, prj.topNode.path);
+         else if(dir && dir[0])
+            strcpy(selectedPath, dir);
+         else
+            selectedPath[0] = '\0';
+         PathCat(selectedPath, filePath);
+
+         if((fileAttribs = FileExists(selectedPath)).isFile)
+            result = fileAttribs;
+         else if(workspace)
+         {
+            bool done = false;
+            for(p : workspace.projects)
+            {
+               strcpy(selectedPath, p.topNode.path);
+               PathCat(selectedPath, filePath);
+               if((fileAttribs = FileExists(selectedPath)).isFile)
+               {
+                  done = true;
+                  result = fileAttribs;
+                  break;
+               }
+            }
+            if(!done)
+            {
+               Project project;
+               ProjectNode n = null;
+               for(p : workspace.projects)
+               {
+                  if((n = p.topNode.Find(filePath, false)))
+                  {
+                     n.GetFullFilePath(selectedPath);
+                     if((fileAttribs = FileExists(selectedPath)).isFile)
+                     {
+                        if(node) *node = n;
+                        result = fileAttribs;
+                        break;
+                     }
+                  }
+               }
+               if(!n && (n = workspace.GetObjectFileNode(filePath, &project, selectedPath)) && project &&
+                     (fileAttribs = FileExists(selectedPath)).isFile)
+               {
+                  if(node) *node = n;
+                  result = fileAttribs;
+               }
+            }
+         }
+      }
+      return result;
+   }
+
    void CodeLocationParseAndGoTo(const char * text, Project project, const char * dir)
    {
       char *s = null;
@@ -2763,54 +2822,8 @@ class IDEWorkSpace : Window
          strcpy(filePath, path);
       }
 
-      if(filePath[0])
-      {
-         if(prj)
-            strcpy(completePath, prj.topNode.path);
-         else if(dir && dir[0])
-            strcpy(completePath, dir);
-         else
-            completePath[0] = '\0';
-         PathCat(completePath, filePath);
-
-         if((fileAttribs = FileExists(completePath)))
-            CodeLocationGoTo(completePath, fileAttribs, line, col);
-         else if(ide.workspace)
-         {
-            bool done = false;
-            for(p : ide.workspace.projects)
-            {
-               strcpy(completePath, p.topNode.path);
-               PathCat(completePath, filePath);
-               if((fileAttribs = FileExists(completePath)).isFile)
-               {
-                  CodeLocationGoTo(completePath, fileAttribs, line, col);
-                  done = true;
-                  break;
-               }
-            }
-            if(!done)
-            {
-               Project project;
-               ProjectNode node;
-               for(p : ide.workspace.projects)
-               {
-                  if((node = p.topNode.Find(filePath, false)))
-                  {
-                     node.GetFullFilePath(completePath);
-                     if((fileAttribs = FileExists(completePath)).isFile)
-                     {
-                        CodeLocationGoTo(completePath, fileAttribs, line, col);
-                        break;
-                     }
-                  }
-               }
-               if(!node && (node = workspace.GetObjectFileNode(filePath, &project, completePath)) && project &&
-                     (fileAttribs = FileExists(completePath)).isFile)
-                  CodeLocationGoTo(completePath, fileAttribs, line, col);
-            }
-         }
-      }
+      if((fileAttribs = GoToCodeSelectFile(filePath, dir, prj, null, completePath)))
+         CodeLocationGoTo(completePath, fileAttribs, line, col);
    }
 
    void CodeLocationGoTo(const char * path, const FileAttribs fileAttribs, int line, int col)
index 9fe69e8..9d758f0 100644 (file)
@@ -1796,47 +1796,40 @@ 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, false, 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, false, 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, false, 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.FindWithPath(moduleName, false)))
+                           MakePathRelative(filePath, prj.topNode.path, path);
+
+                           if((node = prj.topNode.FindWithPath(path, false)))
                            {
                               strcpy(filePath, prj.topNode.path);
                               PathCatSlash(filePath, node.path);
@@ -1846,21 +1839,37 @@ class ProjectView : Window
                                  break;
                            }
                         }
-                     }
-                     if(!codeEditor)
-                     {
-                        GetLastDirectory(moduleName, moduleName);
-                        for(prj : ide.workspace.projects)
+                        if(!codeEditor && (strchr(moduleName, '/') || strchr(moduleName, '\\')))
                         {
-                           ProjectNode node;
-                           if((node = prj.topNode.Find(moduleName, false)))
+                           for(prj : ide.workspace.projects)
                            {
-                              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;
+                              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;
+                              }
                            }
                         }
                      }
index b7f4710..41bf369 100644 (file)
@@ -358,7 +358,7 @@ public:
       }
    }
 
-   char * GetAbsolutePathFromRelative(const char * relative)
+   char * CopyAbsolutePathFromRelative(const char * relative)
    {
       char name[MAX_LOCATION];
       char absolute[MAX_LOCATION];
@@ -412,7 +412,7 @@ public:
       return null;
    }
 
-   char * GetPathWorkspaceRelativeOrAbsolute(const char * path)
+   char * CopyUnixPathWorkspaceRelativeOrAbsolute(const char * path)
    {
       if(IsPathInsideOf(path, workspaceDir))
       {
@@ -424,6 +424,31 @@ public:
          return CopyUnixPath(path);
    }
 
+   char * MakeRelativePath(char * buffer, const char * path)
+   {
+      char * result = null;
+      if(buffer && path)
+      {
+         MakePathRelative(path, workspaceDir, buffer);
+         MakeSlashPath(buffer);
+         result = buffer;
+      }
+      return result;
+   }
+
+   char * GetRelativePathForProject(char * buffer, Project project)
+   {
+      char * result = null;
+      if(buffer && project && project.topNode.path)
+      {
+         MakePathRelative(project.topNode.path, workspaceDir, buffer);
+         MakeSlashPath(buffer);
+         PathCatSlash(buffer, project.topNode.name);
+         result = buffer;
+      }
+      return result;
+   }
+
    Array<ProjectNode> GetAllProjectNodes(const char *fullPath, bool skipExcluded)
    {
       Array<ProjectNode> nodes = null;