buildsystem, ide; added install feature. aka install library or executable from ide...
[sdk] / ide / src / ProjectSettings.ec
index 93bf4f0..223f53f 100644 (file)
@@ -9,16 +9,32 @@ static Platform platform;
 static ProjectNode currentNode;
 static Project project;
 
-static String MakeString(char * s, int len)
+static String MakeString(char * s, int len, char * switchToKeep, int lenSwitchToKeep)
 {
    String string = new char[len+1];
-   memcpy(string, s, len);
-   string[len] = 0;
+   if(s[0] == '-' && switchToKeep && switchToKeep[0])
+   {
+      if(strstr(s+1, switchToKeep) == s+1)
+      {
+         memcpy(string, s+lenSwitchToKeep+1, len-lenSwitchToKeep-1);
+         string[len-lenSwitchToKeep-1] = '\0';
+      }
+      else
+         delete string;
+   }
+   else
+   {
+      memcpy(string, s, len);
+      string[len] = '\0';
+   }
    return string;
 }
 
 class StringListBox : EditBox
 {
+   char * switchToKeep;
+   int lenSwitchToKeep;
+
    textHorzScroll = true;
 
    property Array<String> strings
@@ -31,10 +47,13 @@ class StringListBox : EditBox
             bool first = true;
             for(item : value)
             {
-               if(!first)
-                  AddS(" ");
-               AddS(item);
-               first = false;
+               if(item)
+               {
+                  if(!first)
+                     AddS(" ");
+                  AddS(item);
+                  first = false;
+               }
             }
          }
       }
@@ -43,6 +62,7 @@ class StringListBox : EditBox
          Array<String> array { };
          int c, start = 0;
          char * contents = property::contents;
+         char * s;
          char ch;
          bool quoted = false;
 
@@ -51,7 +71,10 @@ class StringListBox : EditBox
             if(ch == ' ' && !quoted)
             {
                if(c - start)
-                  array.Add(MakeString(contents + start, c - start));
+               {
+                  if((s = MakeString(contents + start, c - start, switchToKeep, lenSwitchToKeep)))
+                     array.Add(s);
+               }
                start = c + 1;
             }
             else if(ch == '\"')
@@ -63,7 +86,10 @@ class StringListBox : EditBox
             }
          }
          if(c - start)
-            array.Add(MakeString(contents + start, c - start));
+         {
+            if((s = MakeString(contents + start, c - start, switchToKeep, lenSwitchToKeep)))
+               array.Add(s);
+         }
          return array;
       }
    }
@@ -818,7 +844,7 @@ class MultiStringOptionBox : OptionBox<Array<String>>
             {
                String s = it.data;
                bool found = false;
-               for(i : tempStrings; !(caseSensitive ? strcmp : strcmpi)(i, s)) { found = true; break; }
+               for(i : tempStrings; i && s && !(caseSensitive ? strcmp : strcmpi)(i, s)) { found = true; break; }
                if(found && (!configReplaces || platform))   // ADDED || platform here...
                {
                   delete s;
@@ -852,7 +878,7 @@ class MultiStringOptionBox : OptionBox<Array<String>>
             for(s : strings)
             {
                bool found = false;
-               for(i : tempStrings; !(caseSensitive ? strcmp : strcmpi)(i, s)) { found = true; break; }
+               for(i : tempStrings; i && s && !(caseSensitive ? strcmp : strcmpi)(i, s)) { found = true; break; }
                if(!found) tempStrings.Add(s);
             }
          }
@@ -910,6 +936,8 @@ class StringArrayOptionBox : MultiStringOptionBox
    // NO VIRTUAL PROPERTIES YET...
    Array<String> GetStrings() { return ((StringListBox)editor).strings; }
    void SetStrings(Array<String> value) { ((StringListBox)editor).strings = value; }
+
+   property char * switchToKeep { set { ((StringListBox)editor).switchToKeep = value; ((StringListBox)editor).lenSwitchToKeep = strlen(value); } };
 }
 
 class StringsArrayOptionBox : MultiStringOptionBox
@@ -960,30 +988,7 @@ 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';
-   }
-#ifdef __WIN32__
-   if(volumePath && path[0])
-      path[1] = ':';
-#endif
+   ValidPathBufCopy(path, pathBox.path);
    len = strlen(path);
    if(len && !(path[0] == '.' && (len == 1 || (len == 2 && path[1] == DIR_SEP) || (len > 1 && path[1] == '.'))))
    {
@@ -1009,10 +1014,53 @@ static void FixPathOnPathBoxNotifyModified(PathBox pathBox)
 
 class DirsArrayOptionBox : MultiStringOptionBox
 {
+public:
+   property char * switchToKeep { set { switchToKeep = value; lenSwitchToKeep = strlen(value); } };
+private:
+   char * switchToKeep;
+   int lenSwitchToKeep;
+
    editor = DirectoriesBox
    {
+      browseDialog = { };
       bool NotifyModified(DirectoriesBox dirsBox)
       {
+         char * switchToKeep = ((DirsArrayOptionBox)dirsBox.id).switchToKeep;
+         if(switchToKeep && switchToKeep[0])
+         {
+            bool change = false;
+            int lenSwitchToKeep = ((DirsArrayOptionBox)dirsBox.id).lenSwitchToKeep;
+            Array<String> dirs { };
+            Array<String> previousDirs = dirsBox.strings;
+            for(d : previousDirs)
+            {
+               int c;
+               char * buffer = new char[strlen(d)+64];
+               char * tokens[1024];
+               uint count;
+               strcpy(buffer, d);
+               count = Tokenize(buffer, sizeof(tokens)/sizeof(tokens[0]), tokens, (BackSlashEscaping)false);
+               for(c=0; c<count; c++)
+               {
+                  if(tokens[c][0] == '-')
+                  {
+                     if(strstr(tokens[c]+1, switchToKeep) == tokens[c]+1)
+                        tokens[c] += lenSwitchToKeep+1;
+                     else
+                        tokens[c][0] = '\0';
+                     change = true;
+                  }
+                  dirs.Add(CopyString(tokens[c]));
+               }
+               delete buffer;
+            }
+            if(change)
+               dirsBox.strings = dirs;
+            dirs.Free();
+            delete dirs;
+            previousDirs.Free();
+            delete previousDirs;
+         }
          ((OptionBox)dirsBox.id).Retrieve();
          return true;
       }
@@ -2026,7 +2074,7 @@ class CompilerTab : Tab
    DirsArrayOptionBox includeDirs
    {
       rightPane, this, size = { 290, 22 }, anchor = { left = 8, top = 250, right = 8, bottom = 8 };
-      text = $"Additional Include Directories", hotKey = altI, option = OPTION(includeDirs);
+      text = $"Additional Include Directories", hotKey = altI, option = OPTION(includeDirs), switchToKeep = "I";
    };
 
    CompilerTab()
@@ -2117,7 +2165,7 @@ class LinkerTab : Tab
    StringArrayOptionBox libraries
    {
       this, size = { 290, 22 }, anchor = { left = 8, top = 66, right = 8 };
-      text = $"Additional Libraries", hotKey = altL, option = OPTION(libraries);
+      text = $"Additional Libraries", hotKey = altL, option = OPTION(libraries), switchToKeep = "l";
       configReplaces = true;
    };
 
@@ -2145,7 +2193,7 @@ class LinkerTab : Tab
    DirsArrayOptionBox libraryDirs
    {
       this, size = { 290, 22 }, anchor = { left = 8, top = 182, right = 8, bottom = 8 };
-      text = $"Additional Library Directories", hotKey = altY, option = OPTION(libraryDirs);
+      text = $"Additional Library Directories", hotKey = altY, option = OPTION(libraryDirs), switchToKeep = "L";
    };
 
    bool OnCreate()
@@ -2179,17 +2227,24 @@ class BuilderTab : Tab
    Label labelPrebuildCommands { prebuildCommands.editor, labeledWindow = prebuildCommands, position = { 0, 6 }; };
    StringsArrayOptionBox prebuildCommands
    {
-      this, size = { 290, 100 }, anchor = { left = 8, top = 8, right = 8, bottom = 0.5 };
+      this, size = { 290, 100 }, anchor = { left = 8, top = 8, right = 8, bottom = 0.66 };
       text = $"Pre-build Commands", hotKey = altE, option = OPTION(prebuildCommands);
    };
 
    Label labelPostbuildCommands { postbuildCommands.editor, labeledWindow = postbuildCommands, position = { 0, 6 }; };
    StringsArrayOptionBox postbuildCommands
    {
-      this, size = { 290 }, anchor = { left = 8, top = 0.5, right = 8, bottom = 8 };
+      this, size = { 290 }, anchor = { left = 8, top = 0.33, right = 8, bottom = 0.33 };
       text = $"Post-build Commands", hotKey = altT, option = OPTION(postbuildCommands);
    };
 
+   Label labelInstallCommands { installCommands.editor, labeledWindow = installCommands, position = { 0, 6 }; };
+   StringsArrayOptionBox installCommands
+   {
+      this, size = { 290 }, anchor = { left = 8, top = 0.66, right = 8, bottom = 8 };
+      text = $"Install Commands", hotKey = altT, option = OPTION(installCommands);
+   };
+
    void LoadSettings()
    {
       bool disabled = strlen(((BuildTab)master).selectedPlatformName) > 0;