Beispiel #1
0
        static TermData AddTerm(string Term, bool AutoSelect = true, eTermType termType = eTermType.Text)
        {
            if (Term == "-" || string.IsNullOrEmpty(Term))
            {
                return(null);
            }

            Term = I2Utils.GetValidTermName(Term, true);

            TermData data = mLanguageSource.AddTerm(Term, termType);

            GetParsedTerm(Term);
            string sCategory = LanguageSourceData.GetCategoryFromFullTerm(Term);

            mParsedCategories.Add(sCategory);

            if (AutoSelect)
            {
                if (!mSelectedKeys.Contains(Term))
                {
                    mSelectedKeys.Add(Term);
                }

                if (!mSelectedCategories.Contains(sCategory))
                {
                    mSelectedCategories.Add(sCategory);
                }
            }
            ScheduleUpdateTermsToShowInList();
            mLanguageSource.Editor_SetDirty();
            return(data);
        }
Beispiel #2
0
        List <string> ScriptTool_GetSelectedTermsInCategory(string Category)
        {
            List <string> list = new List <string>();

            foreach (string FullKey in mSelectedKeys)
            {
                string categ = LanguageSourceData.GetCategoryFromFullTerm(FullKey);
                if (categ == Category && ShouldShowTerm(FullKey))
                {
                    list.Add(LanguageSourceData.GetKeyFromFullTerm(FullKey));
                }
            }

            return(list);
        }
        void ReplaceSelectedTerms()
        {
            EditorApplication.update -= ReplaceSelectedTerms;
            if (string.IsNullOrEmpty(mKeyToExplore))
            {
                return;
            }

            mIsParsing = true;
            string sNewKey = mKeyToExplore;

            //--[ Create new Term ]-----------------------
            if (mLanguageSource.GetTermData(sNewKey) == null)
            {
                TermData termData = AddLocalTerm(sNewKey);

                //--[ Copy the values from any existing term if the target is a new term
                TermData oldTerm = null;
                for (int i = 0, imax = mSelectedKeys.Count; i < imax; ++i)
                {
                    oldTerm = mLanguageSource.GetTermData(mSelectedKeys[i]);
                    if (oldTerm != null)
                    {
                        break;
                    }
                }

                if (oldTerm != null)
                {
                    termData.TermType    = oldTerm.TermType;
                    termData.Description = oldTerm.Description;
                    System.Array.Copy(oldTerm.Languages, termData.Languages, oldTerm.Languages.Length);
                }
            }

            //--[ Delete the selected Terms from the source ]-----------------
            TermReplacements = new Dictionary <string, string>(System.StringComparer.Ordinal);
            for (int i = mSelectedKeys.Count - 1; i >= 0; --i)
            {
                string OldTerm = mSelectedKeys[i];
                if (OldTerm == sNewKey)
                {
                    continue;
                }

                TermReplacements[OldTerm] = mKeyToExplore;
                DeleteTerm(OldTerm);
            }
            ExecuteActionOnSelectedScenes(ReplaceTermsInCurrentScene);
            DoParseTermsInCurrentScene();

            //--[ Update Selected Categories ]-------------
            string mNewCategory = LanguageSourceData.GetCategoryFromFullTerm(sNewKey);

            if (mNewCategory == string.Empty)
            {
                mNewCategory = LanguageSourceData.EmptyCategory;
            }
            if (!mSelectedCategories.Contains(mNewCategory))
            {
                mSelectedCategories.Add(mNewCategory);
            }
            //RemoveUnusedCategoriesFromSelected();
            ScheduleUpdateTermsToShowInList();
            TermReplacements = null;
            mIsParsing       = false;
        }