ide; fixed project settings additional include dirs cant add current (./) dir. also...
[sdk] / ide / src / ProjectSettings.ec
index a16cbfc..1c4a517 100644 (file)
@@ -227,6 +227,10 @@ class ProjectSettings : Window
    {
       UpdateDialogTitle();
       prjTabControl.curTab = buildTab;
+
+      ((DirectoriesBox)buildTab.compilerTab.includeDirs.editor).baseBrowsePath = project.topNode.path;
+      ((DirectoriesBox)buildTab.linkerTab.libraryDirs.editor).baseBrowsePath = project.topNode.path;
+
       return true;
    }
 }
@@ -751,21 +755,7 @@ class PathOptionBox : OptionBox<String>
 
       bool NotifyModified(PathBox pathBox)
       {
-         char path[MAX_LOCATION];
-         strcpy(path, pathBox.path);
-         TrimLSpaces(path, path);
-         TrimRSpaces(path, path);
-         {
-            char * chars = "*|:\",<>?";
-            char ch, * s = path, * o = path;
-            for(; (ch = *s); s++) { if(!strchr(chars, ch)) *o++ = ch; }
-            *o = '\0';
-         }
-         if(!fstrcmp(path, project.topNode.path))
-            strcpy(path, ".");
-         else if(fstrcmp(path, ".") && !(strlen(path) > 1 && path[0] == '.' && path[1] == '.'))
-            MakePathRelative(path, project.topNode.path, path);
-         pathBox.path = path;
+         FixPathOnPathBoxNotifyModified(pathBox);
          ((OptionBox)pathBox.id).Retrieve();
          return true;
       }
@@ -943,68 +933,92 @@ class StringsArrayOptionBox : MultiStringOptionBox
    void SetStrings(Array<String> value) { ((StringsBox)editor).strings = value; }
 }
 
-class DirsArrayOptionBox : MultiStringOptionBox
+bool eString_IsPathRelatedTo(char * path, char * to)
 {
-   editor = DirectoriesBox
+   if(path[0] && to[0])
    {
-      bool NotifyModified(DirectoriesBox dirsBox)
+      char rest[MAX_FILENAME];
+      char pathPart[MAX_FILENAME], pathRest[MAX_LOCATION] = "";
+      char toPart[MAX_FILENAME], toRest[MAX_LOCATION] = "";
+      SplitDirectory(path, pathPart, pathRest);
+      SplitDirectory(to, toPart, toRest);
+      if(!fstrcmp(pathPart, toPart))
       {
-         ((OptionBox)dirsBox.id).Retrieve();
-         return true;
-      }
-
-      bool OnChangedDir(char * * directory)
-      {
-         char fixedDirectory[MAX_LOCATION] = "";
-         if(PathCat(fixedDirectory, *directory))
+         if(pathRest[0] && toRest[0])
          {
-            char cwdBackup[MAX_LOCATION];
-            if(project)
-            {
-               GetWorkingDir(cwdBackup, sizeof(cwdBackup));
-               ChangeWorkingDir(project.topNode.path);
-            }
-            FileFixCase(fixedDirectory);
-            if(project)
-               ChangeWorkingDir(cwdBackup);
-            delete *directory;
-            *directory = CopyString(fixedDirectory);
-            return true;
+            SplitDirectory(pathRest, pathPart, pathRest);
+            SplitDirectory(toRest, toPart, toRest);
+            if(!fstrcmp(pathPart, toPart))
+               return true;
          }
-         return false;
       }
+   }
+   return false;
+}
 
-      bool OnPrepareBrowseDir(char * * directory)
-      {
-         char dir[MAX_LOCATION];
-         if(project)
-         {
-            GetSystemPathBuffer(dir, project.topNode.path);
-            if(*directory)
-               PathCat(dir, *directory);
-         }
-         else if(*directory)
-            strcpy(dir, *directory);
-         else
-            dir[0] = '\0';
-         
-         delete *directory;
-         *directory = CopyString(dir);
+static void FixPathOnPathBoxNotifyModified(PathBox pathBox)
+{
+   int len;
+   char path[MAX_LOCATION];
+#ifdef __WIN32__
+   bool volumePath = false;
+#endif
+   strcpy(path, pathBox.path);
+   TrimLSpaces(path, path);
+   TrimRSpaces(path, path);
+   MakeSystemPath(path);
+#ifdef __WIN32__
+   if(path[0] && path[1] == ':')
+   {
+      path[1] = '_';
+      volumePath = true;
+   }
+#endif
+   {
+      char * chars = "*|:\",<>?";
+      char ch, * s = path, * o = path;
+      while((ch = *s++)) { if(!strchr(chars, ch)) *o++ = ch; }
+      *o = '\0';
+   }
+   len = strlen(path);
+   if(len>1 && path[len-1] == DIR_SEP)
+      path[--len] = '\0';
+#ifdef __WIN32__
+   if(volumePath && path[0])
+      path[1] = ':';
+#endif
+   if(len && !(path[0] == '.' && (len == 1 || (len == 2 && path[1] == DIR_SEP) || (len > 1 && path[1] == '.'))))
+   {
+      char cwdBackup[MAX_LOCATION];
+      if(project)
+      {
+         GetWorkingDir(cwdBackup, sizeof(cwdBackup));
+         ChangeWorkingDir(project.topNode.path);
+      }
+      FileFixCase(path);
+      if(project)
+         ChangeWorkingDir(cwdBackup);
+      if(eString_IsPathRelatedTo(path, project.topNode.path))
+         MakePathRelative(path, project.topNode.path, path);
+      if(!path[0])
+         strcpy(path, ".");
+   }
+   pathBox.path = path;
+}
 
-            // GCC 4.4 bug:  -----  path becomes *directory
-            //strcpy(dir, path ? path : "");
+class DirsArrayOptionBox : MultiStringOptionBox
+{
+   editor = DirectoriesBox
+   {
+      bool NotifyModified(DirectoriesBox dirsBox)
+      {
+         ((OptionBox)dirsBox.id).Retrieve();
          return true;
       }
 
-      bool OnBrowsedDir(char * * directory)
+      bool NotifyPathBoxModified(DirectoriesBox dirsBox, PathBox pathBox)
       {
-         if(project)
-         {
-            char path[MAX_LOCATION];
-            MakePathRelative(*directory, project.topNode.path, path);
-            delete *directory;
-            *directory = CopyString(path);
-         }
+         FixPathOnPathBoxNotifyModified(pathBox);
          return true;
       }
    };