public static void LoadLanguageThemes()
        {
            sAllLanguageThemes.Clear();
            sAllLanguageThemes.Add(new LanguageTheme("Default"));

            try {
                string[] languageFiles = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\language_themes");
                int      count         = 0;

                for (int i = 0; i < languageFiles.Length; i++)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    FileStream      fs        = File.Open(languageFiles[i], FileMode.Open);

                    LanguageTheme newTheme = (LanguageTheme)formatter.Deserialize(fs);

                    sAllLanguageThemes.Add(newTheme);
                    Console.WriteLine("Loaded new theme Name: " + newTheme.Name);
                    count++;

                    fs.Close();
                }

                CustomConsole.Log("Loaded " + count + " LanguageThemes");
            }
            catch (Exception e) {
                CustomConsole.Log("Failed to load in LanguageThemes");
                CustomConsole.Log(e.Message);
                return;
            }
        }
 private static void ColourComments(LanguageTheme a_theme, ref CustomRichTextBox a_richTextBox, int a_start, int a_end)
 {
     /*
      * int currentIndex = a_start;
      * int selectionEnd = a_end;
      * int stringStartIndex = -1;
      * bool lookingForNextSlash = false;
      * bool foundDoubleSlash = false;
      * string str = a_richTextBox.Text;
      *
      * while (currentIndex < selectionEnd)
      * {
      *  // If you have found the first \
      *  if (str[currentIndex] == '/' && !lookingForNextSlash)
      *  {
      *      lookingForNextSlash = true;
      *      foundDoubleSlash = false;
      *      currentIndex++;
      *      continue;
      *  }
      *
      *  // If you have found the second \
      *  if (str[currentIndex] == '/' && lookingForNextSlash)
      *  {
      *      lookingForNextSlash = false;
      *      foundDoubleSlash = true;
      *      stringStartIndex = currentIndex - 1;
      *      currentIndex++;
      *      continue;
      *  }
      *
      *  if ((str[currentIndex] == '\n' || str[currentIndex] == '\r') && foundDoubleSlash)
      *  {
      *      if (stringStartIndex > 0)
      *      {
      *          if (allLanguageThemes[activeThemeIndex].GetColourFromKeyword("__comment", out Color col))
      *          {
      *              a_richTextBox.SelectionStart = stringStartIndex - 1;
      *              a_richTextBox.SelectionLength = (currentIndex + 1) - stringStartIndex;
      *              a_richTextBox.SelectionColor = col;
      *              a_richTextBox.SelectionLength = 0;
      *              a_richTextBox.SelectionColor = Color.Black;
      *          }
      *      }
      *
      *      foundDoubleSlash = false;
      *      stringStartIndex = -1;
      *      currentIndex++;
      *      continue;
      *  }
      *
      *  currentIndex++;
      * }*/
 }
 private static void ColourLiteralStrings(LanguageTheme a_theme, ref CustomRichTextBox a_richTextBox, int a_start, int a_end)
 {
     /*
      * int currentIndex = 0;
      * int selectionEnd = a_end;
      * string str = a_richTextBox.Text;
      *
      * // Colour literal strings
      * bool lookingForEndOfString = false;
      * int stringStartIndx = 0;
      *
      * while (currentIndex < selectionEnd)
      * {
      *  if (str[currentIndex] != '"')
      *  {
      *      currentIndex++;
      *      continue;
      *  }
      *
      *  if (str[currentIndex] == '"' && !lookingForEndOfString) // If you detect a " char and it is the first one in the string
      *  {
      *      lookingForEndOfString = true;
      *      stringStartIndx = currentIndex;
      *      currentIndex++;
      *  }
      *  else // If you detect a " char and it is the end of a literal string
      *  {
      *      if (stringStartIndx > 0)
      *      {
      *          if (allLanguageThemes[activeThemeIndex].GetColourFromKeyword("__literalstring", out Color col))
      *          {
      *              a_richTextBox.SelectionStart = stringStartIndx;
      *              a_richTextBox.SelectionLength = (currentIndex + 1) - stringStartIndx;
      *              a_richTextBox.SelectionColor = col;
      *              a_richTextBox.SelectionLength = 0;
      *              a_richTextBox.SelectionColor = Color.Black;
      *          }
      *      }
      *
      *      currentIndex++;
      *      stringStartIndx = -1;
      *      lookingForEndOfString = false;
      *  }
      * }
      */
 }
        public static void FormatCodeFragment(string a_languageName, ref CustomRichTextBox a_richTextBox, int a_start, int a_end)
        {
            LanguageTheme activeTheme = null;

            foreach (LanguageTheme theme in sAllLanguageThemes)
            {
                if (theme.Name == a_languageName)
                {
                    activeTheme = theme;
                }
            }

            if (activeTheme == null)
            {
                activeTheme = sAllLanguageThemes[0];
            }

            a_richTextBox.SelectionColor = Color.Black;

            foreach (SingleKeywordDesign keyword in activeTheme.Keywords)
            {
                ColourSingleKeyword(keyword, ref a_richTextBox, a_start, a_end);
            }

            foreach (MultiwordDesign multiword in activeTheme.MultiWordDesigns)
            {
                FormatMultiwords(multiword, ref a_richTextBox, a_start, a_end);
            }

            /*
             * LanguageTheme activeTheme = null;
             *
             * foreach (LanguageTheme theme in allLanguageThemes)
             * {
             *  if (theme.GetName() == a_languageName)
             *      activeTheme = theme;
             * }
             *
             * if (activeTheme == null)
             *  activeTheme = allLanguageThemes[0];
             *
             * string str = a_richTextBox.Text;
             * int selectionStart = a_start;
             * int selectionEnd = a_end;
             * int currentIndex = selectionStart;
             * bool nextWordIsClassName = false;
             *
             * a_richTextBox.SelectionStart = a_start;
             * a_richTextBox.SelectionLength = a_end - a_start;
             * a_richTextBox.SelectionColor = Color.Black;
             *
             * // Colour keywords
             * while (currentIndex < selectionEnd)
             * {
             *  int tempIndx = 0;
             *  string newString = "";
             *
             *  while (str[currentIndex + tempIndx] != ' ' && str[currentIndex + tempIndx] != '\n' && str[currentIndex + tempIndx] != '\t' && str[currentIndex + tempIndx] != '{' && str[currentIndex + tempIndx] != '}'
             *      && str[currentIndex + tempIndx] != '"' && str[currentIndex + tempIndx] != '(' && str[currentIndex + tempIndx] != ')' && str[currentIndex + tempIndx] != ':' && str[currentIndex + tempIndx] != '*' && str[currentIndex + tempIndx] != '&'
             *      && str[currentIndex + tempIndx] != '-' && str[currentIndex + tempIndx] != '>')
             *  {
             *      newString += str[currentIndex + tempIndx];
             *      tempIndx++;
             *
             *      if (currentIndex + tempIndx >= str.Length)
             *          break;
             *      else
             *          continue;
             *  }
             *
             *  if (nextWordIsClassName)
             *  {
             *      allLanguageThemes[activeThemeIndex].AddClass(newString);
             *      nextWordIsClassName = false;
             *  }
             *
             *  if (newString == "class")
             *      nextWordIsClassName = true;
             *
             *  Color col;
             *  if (allLanguageThemes[activeThemeIndex].GetColourFromKeyword(newString, out col))
             *  {
             *      a_richTextBox.SelectionStart = currentIndex;
             *      a_richTextBox.SelectionLength = newString.Length;
             *      a_richTextBox.SelectionColor = col;
             *      a_richTextBox.SelectionLength = 0;
             *      a_richTextBox.SelectionColor = Color.Black;
             *  }
             *
             *  currentIndex += (tempIndx + 1);
             * }
             *
             * currentIndex = selectionStart;
             *
             * ColourLiteralStrings(activeTheme, ref a_richTextBox, a_start, a_end);
             * ColourComments(activeTheme, ref a_richTextBox, a_start, a_end);
             */
        }