public static void EditSymbol(string symbolName, string newName, string newDescription)
        {
            InitializeIfNeeded();
            ScriptDefineSymbolManagerSettings settings = GetSettings();

            Symbol symbol = settings.Symbols.Find((s) => s.Name == symbolName);

            if (symbol == null)
            {
                Log.Error($"No user-created symbol named {symbolName} exists.");
                return;
            }

            symbol.Name        = newName;
            symbol.Description = newDescription;

            foreach (var item in settings.Profiles)
            {
                int indexToReplace = item.Symbols.IndexOf(symbolName);
                if (indexToReplace != -1)
                {
                    item.Symbols[indexToReplace] = newName;
                }
            }

            EditorUtility.SetDirty(settings);
        }
        private static ScriptDefineSymbolManagerSettings GetSettings()
        {
            if (s_settings == null)
            {
                s_settings = ScriptDefineSymbolManagerSettings.GetOrCreateSettings();
            }

            return(s_settings);
        }
        public static void CreateSymbol(string symbolName, string symbolDescription)
        {
            InitializeIfNeeded();
            ScriptDefineSymbolManagerSettings settings = GetSettings();

            settings.Symbols.AddUnique(new Symbol()
            {
                Name = symbolName, Description = symbolDescription
            });
            EditorUtility.SetDirty(settings);
        }
        public static bool DeleteProfile(IProfile profile)
        {
            InitializeIfNeeded();
            ScriptDefineSymbolManagerSettings settings = GetSettings();

            if (settings.Profiles.Remove(profile as Profile))
            {
                EditorUtility.SetDirty(settings);
                return(true);
            }

            return(false);
        }
        public static ISymbol[] GetSymbols()
        {
            InitializeIfNeeded();

            ScriptDefineSymbolManagerSettings settings = GetSettings();

            List <ISymbol> combinedSymbols = new List <ISymbol>(settings.Symbols.Count + s_codeProvidedSymbols.Count);

            combinedSymbols.AddRange(settings.Symbols);
            combinedSymbols.AddRange(s_codeProvidedSymbols);

            return(combinedSymbols.ToArray());
        }
        public static void DeleteSymbol(string symbol)
        {
            InitializeIfNeeded();

            ScriptDefineSymbolManagerSettings settings = GetSettings();

            foreach (var p in settings.Profiles)
            {
                RemoveSymbolFromProfile(symbol, p);
            }

            settings.Symbols.RemoveFirst((s) => s.Name == symbol);

            EditorUtility.SetDirty(settings);
        }
        private static bool IsProfileNameValid(string name)
        {
            InitializeIfNeeded();
            if (string.IsNullOrEmpty(name))
            {
                Debug.LogError($"Invalid profile name.");
                return(false);
            }

            ScriptDefineSymbolManagerSettings settings = GetSettings();

            if (settings.Profiles.Any((p => p.Name == name)))
            {
                Debug.LogError($"A profile with the name {name} already exists.");
                return(false);
            }

            return(true);
        }
        public static void AddSymbolInProfile(string symbol, IProfile profile)
        {
            InitializeIfNeeded();
            ScriptDefineSymbolManagerSettings settings = GetSettings();

            if (settings.Symbols.Any((s) => s.Name == symbol) || s_codeProvidedSymbols.Any((s) => s.Name == symbol))
            {
                if (profile is Profile p)
                {
                    p.Symbols.AddUnique(symbol);
                }
            }
            else
            {
                Debug.LogError($"Symbol {symbol} doesn't exist.");
            }

            EditorUtility.SetDirty(settings);
        }
        public static IProfile CreateProfile(string name)
        {
            InitializeIfNeeded();
            ScriptDefineSymbolManagerSettings settings = GetSettings();

            if (!IsProfileNameValid(name))
            {
                return(null);
            }

            var newProfile = new Profile();

            newProfile.Name = name;

            settings.Profiles.Add(newProfile);
            settings.Profiles.Sort((a, b) => a.Name.CompareTo(b.Name));

            EditorUtility.SetDirty(settings);

            return(newProfile);
        }