Beispiel #1
0
        //------------------------------------------


        public void UpdateEntryList()
        {
            mbUpdatingEntries = true;

            String sSelName = "";

            if (mpTransBaseData.mpCurrentEntry != null)
            {
                sSelName = mpTransBaseData.mpCurrentEntry.msName;
            }

            cTransCategory Cat = mpTransBaseData.GetCategory((String)objTransCategories.SelectedItem);

            objTransEntries.Items.Clear();

            if (Cat == null)
            {
                objTransEntries.Text = "";
                UpdateEntryData();
                return;
            }

            if (Cat.mvEntries.Count <= 0)
            {
                objTransEntries.Text = "";
                UpdateEntryData();
                return;
            }

            for (int i = 0; i < Cat.mvEntries.Count; i++)
            {
                objTransEntries.Items.Add(((cTransEntry)Cat.mvEntries[i]).msName);
            }

            objTransEntries.SelectedIndex = 0;

            if (sSelName != "")
            {
                for (int i = 0; i < objTransEntries.Items.Count; i++)
                {
                    String sName = (String)objTransEntries.Items[i];

                    if (sName == sSelName)
                    {
                        objTransEntries.SelectedIndex = i;
                        break;
                    }
                }
            }

            UpdateEntryData();

            mbUpdatingEntries = false;
        }
Beispiel #2
0
        //------------------------------------------

        public cTransCategory GetCateogry(String asName)
        {
            for (int i = 0; i < mvCategories.Count; i++)
            {
                cTransCategory Cat = (cTransCategory)mvCategories[i];
                if (Cat.msName == asName)
                {
                    return(Cat);
                }
            }

            return(null);
        }
Beispiel #3
0
        //------------------------------------------


        public void UpdateEntryList()
        {
            String sSelName = "";

            if (mpCurrentEntry != null)
            {
                sSelName = mpCurrentEntry.msName;
            }

            cTransCategory Cat = GetCateogry((String)mpMainForm.objTransCategories.SelectedItem);

            mpMainForm.objTransEntries.Items.Clear();

            if (Cat == null)
            {
                mpMainForm.objTransEntries.Text = "";
                UpdateEntryData();
                return;
            }

            if (Cat.mvEntries.Count <= 0)
            {
                mpMainForm.objTransEntries.Text = "";
                UpdateEntryData();
                return;
            }

            for (int i = 0; i < Cat.mvEntries.Count; i++)
            {
                mpMainForm.objTransEntries.Items.Add(((cTransEntry)Cat.mvEntries[i]).msName);
            }

            mpMainForm.objTransEntries.SelectedIndex = 0;

            if (sSelName != "")
            {
                for (int i = 0; i < mpMainForm.objTransEntries.Items.Count; i++)
                {
                    String sName = (String)mpMainForm.objTransEntries.Items[i];

                    if (sName == sSelName)
                    {
                        mpMainForm.objTransEntries.SelectedIndex = i;
                        break;
                    }
                }
            }

            UpdateEntryData();
        }
        //------------------------------------------

        public void SetCurrentCat(String asName)
        {
            //The internal list
            for (int i = 0; i < mvCategories.Count; i++)
            {
                cTransCategory Cat = (cTransCategory)mvCategories[i];
                if (Cat.msName == asName)
                {
                    mpCurrentCat = Cat;
                    return;
                }
            }

            mpCurrentCat = null;
        }
Beispiel #5
0
        //------------------------------------------

        public void SetCurrentCat()
        {
            String sName = (String)mpMainForm.objTransCategories.SelectedItem;

            //The internal list
            for (int i = 0; i < mvCategories.Count; i++)
            {
                cTransCategory Cat = (cTransCategory)mvCategories[i];
                if (Cat.msName == sName)
                {
                    mpCurrentCat = Cat;
                    UpdateEntryList();
                    return;
                }
            }

            mpCurrentCat = null;

            UpdateEntryList();
        }
Beispiel #6
0
        //------------------------------------------

        public void UpdateCategroyList()
        {
            mpMainForm.objTransCategories.Items.Clear();

            if (mvCategories.Count < 0)
            {
                mpMainForm.objTransCategories.Text = "";
                return;
            }

            for (int i = 0; i < mvCategories.Count; i++)
            {
                cTransCategory Cat = (cTransCategory)mvCategories[i];

                mpMainForm.objTransCategories.Items.Add(Cat.msName);
            }

            mpMainForm.objTransCategories.SelectedIndex = 0;

            UpdateEntryList();
            UpdateEntryData();
        }
Beispiel #7
0
        //------------------------------------------

        public void AddCategory(String asName)
        {
            cTransCategory Cat = new cTransCategory(this);

            Cat.msName = asName;
            mvCategories.Add(Cat);

            mpMainForm.objTransCategories.Items.Add(asName);

            //The form list object
            for (int i = 0; i < mpMainForm.objTransCategories.Items.Count; i++)
            {
                String sName = (String)mpMainForm.objTransCategories.Items[i];
                if (sName == asName)
                {
                    mpMainForm.objTransCategories.SelectedIndex = i;
                    break;
                }
            }

            mpCurrentEntry = null;
            UpdateEntryList();
        }
Beispiel #8
0
        //------------------------------------------

        public void Save(String asFile)
        {
            XmlDocument Doc = new XmlDocument();

            XmlElement DocRoot = Doc.CreateElement("LANGUAGE");

            Doc.AppendChild(DocRoot);

            /////////////////////////////////
            // Save Directories
            XmlElement ResourceElem = Doc.CreateElement("RESOURCES");

            DocRoot.AppendChild(ResourceElem);
            for (int dir = 0; dir < mvDirectories.Count; ++dir)
            {
                String     sPath   = (String)mvDirectories[dir];
                XmlElement DirElem = Doc.CreateElement("Directory");
                ResourceElem.AppendChild(DirElem);

                DirElem.SetAttribute("Path", sPath);
            }

            /////////////////////////////////
            // Save categories
            for (int cat = 0; cat < mvCategories.Count; cat++)
            {
                cTransCategory pCat = (cTransCategory)mvCategories[cat];

                XmlElement CatElem = Doc.CreateElement("CATEGORY");
                DocRoot.AppendChild(CatElem);
                CatElem.SetAttribute("Name", pCat.msName);

                for (int entry = 0; entry < pCat.mvEntries.Count; entry++)
                {
                    cTransEntry pEntry = (cTransEntry)pCat.mvEntries[entry];

                    XmlElement EntryElem = Doc.CreateElement("Entry");
                    CatElem.AppendChild(EntryElem);

                    EntryElem.SetAttribute("Name", pEntry.msName);
                    String sText      = pEntry.msText;
                    String sNewString = "";

                    for (int i = 0; i < sText.Length; ++i)
                    {
                        if (sText[i] == '\n')
                        {
                            sNewString += "[br]";
                        }
                        else if (sText[i] == '\r')
                        {
                            //Do nothing...
                        }
                        else if (sText[i] > 255)
                        {
                            sNewString += "[u" + ((int)sText[i]).ToString() + "]";
                        }
                        else
                        {
                            sNewString += sText[i];
                        }
                    }

                    XmlText EntryTextElem = Doc.CreateTextNode(sNewString);
                    EntryElem.AppendChild(EntryTextElem);
                }
            }

            Doc.Save(asFile);
        }
Beispiel #9
0
        //------------------------------------------

        public void Load(String asFile)
        {
            mpCurrentCat   = null;
            mpCurrentEntry = null;

            mvCategories.Clear();
            mvDirectories.Clear();

            XmlDocument Doc = new XmlDocument();

            Doc.Load(asFile);

            XmlElement DocRoot = (XmlElement)Doc.FirstChild;

            /////////////////////////////////////////////////
            //Iterate all categories
            for (int child_count = 0; child_count < DocRoot.ChildNodes.Count; child_count++)
            {
                XmlElement CatElem = (XmlElement)DocRoot.ChildNodes[child_count];
                if (CatElem.Name == "RESOURCES")
                {
                    for (int dir = 0; dir < CatElem.ChildNodes.Count; dir++)
                    {
                        XmlElement DirElem = (XmlElement)CatElem.ChildNodes[dir];

                        String sPath = DirElem.GetAttribute("Path");
                        mvDirectories.Add(sPath);
                    }
                }
                else
                {
                    cTransCategory pCat = new cTransCategory(this);
                    pCat.msName = CatElem.GetAttribute("Name");
                    mvCategories.Add(pCat);

                    for (int entry = 0; entry < CatElem.ChildNodes.Count; entry++)
                    {
                        XmlElement  EntryElem = (XmlElement)CatElem.ChildNodes[entry];
                        cTransEntry pEntry    = new cTransEntry();
                        pEntry.msName = EntryElem.GetAttribute("Name");

                        String sText      = EntryElem.InnerText;
                        String sNewString = "";


                        for (int i = 0; i < sText.Length; ++i)
                        {
                            if (sText[i] == '[')
                            {
                                bool   bFoundCommand = true;
                                String sCommand      = "";
                                int    lCount        = 1;

                                while (sText[i + lCount] != ']' && i + lCount < sText.Length && lCount < 16)
                                {
                                    sCommand += sText[i + lCount];
                                    lCount++;
                                }

                                if (sCommand == "br")
                                {
                                    sNewString += "\r\n";
                                }
                                else if (sCommand[0] == 'u')
                                {
                                    int lNum = int.Parse(sCommand.Substring(1));
                                    sNewString += (char)lNum;
                                }
                                else
                                {
                                    bFoundCommand = false;
                                }

                                //Go forward or add [ to string
                                if (bFoundCommand)
                                {
                                    i += lCount;
                                }
                                else
                                {
                                    sNewString += sText[i];
                                }
                            }
                            else
                            {
                                sNewString += sText[i];
                            }
                        }

                        /*for(int i=0; i<sText.Length; ++i)
                         * {
                         *      if(sText[i]=='[' && sText.Length > i + 4)
                         *      {
                         *              String sSign = sText.Substring(i,4);
                         *              if(sSign == "[br]")
                         *              {
                         *                      sNewString += "\r\n";
                         *                      i+=3;
                         *              }
                         *              else
                         *              {
                         *                      sNewString += sText[i];
                         *              }
                         *      }
                         *      else sNewString += sText[i];
                         * }*/

                        pEntry.msText = sNewString;

                        pCat.mvEntries.Add(pEntry);
                    }
                }
            }

            UpdateCategroyList();
        }
        //------------------------------------------

        /**
         * Fills up a translation with categories and entries taken from a source one
         * If the invoking translation has stuff, it will add the ones which are not already in
         */
        public void CopyStructureFromTrans(HplTrans apSrcTrans, bool abClear)
        {
            bool bTransHasNonPresentEntries = false;

            if (abClear)
            {
                Clear();
            }

            ArrayList vAddedCategoryNames = new ArrayList();
            ArrayList vAddedCategoryCount = new ArrayList();

            ArrayList vAddedEntries    = new ArrayList();
            ArrayList vAddedEntryTexts = new ArrayList();

            for (int i = 0; i < apSrcTrans.mvDirectories.Count; ++i)
            {
                String sDir = (String)apSrcTrans.mvDirectories[i];

                if (mvDirectories.IndexOf(sDir) == -1)
                {
                    mvDirectories.Add(sDir);
                }
            }

            for (int i = 0; i < apSrcTrans.mvCategories.Count; ++i)
            {
                cTransCategory srcCat = (cTransCategory)apSrcTrans.mvCategories[i];

                cTransCategory cat = GetCategory(srcCat.msName);
                if (cat == null)
                {
                    cat = AddCategory(srcCat.msName);
                }

                for (int j = 0; j < srcCat.mvEntries.Count; ++j)
                {
                    cTransEntry srcEntry = (cTransEntry)srcCat.mvEntries[j];

                    cTransEntry entry = cat.GetEntry(srcEntry.msName);
                    if (entry == null)
                    {
                        bTransHasNonPresentEntries = true;

                        entry = cat.AddEntry(srcEntry.msName);

                        vAddedEntries.Add(entry);
                        vAddedEntryTexts.Add(srcEntry.msText);

                        int lCatIndex = vAddedCategoryNames.IndexOf(cat.msName);
                        if (lCatIndex == -1)
                        {
                            lCatIndex = vAddedCategoryNames.Add(cat.msName);
                            vAddedCategoryCount.Add(0);
                        }
                        vAddedCategoryCount[lCatIndex] = (int)vAddedCategoryCount[lCatIndex] + 1;
                    }
                }
            }

            if (abClear == false && bTransHasNonPresentEntries)
            {
                String sCategoryNames = "";
                for (int i = 0; i < vAddedCategoryNames.Count; ++i)
                {
                    sCategoryNames += (String)vAddedCategoryNames[i] + ": " + vAddedCategoryCount[i] + " entries, ";
                }

                sCategoryNames = sCategoryNames.Substring(0, sCategoryNames.Length - 2);

                DialogResult lRes = MessageBox.Show(mpMainForm, "There are entries in Base Language that are not present in loaded file, in categories:\n  " + sCategoryNames + "\nWant to add base text for them?",
                                                    "Warning!",
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (lRes == DialogResult.Yes)
                {
                    mbChanged = true;

                    for (int i = 0; i < vAddedEntries.Count; ++i)
                    {
                        cTransEntry entry = (cTransEntry)vAddedEntries[i];

                        entry.msText = (String)vAddedEntryTexts[i];
                    }
                }
            }
        }
Beispiel #11
0
		//------------------------------------------
		
		public void SetCurrentCat()
		{
			String sName = (String)mpMainForm.objTransCategories.SelectedItem;
			//The internal list
			for(int i=0; i<mvCategories.Count; i++)
			{
				cTransCategory Cat = (cTransCategory)mvCategories[i];
				if(Cat.msName == sName)
				{
					mpCurrentCat = Cat;
					UpdateEntryList();
					return;
				}
			}

			mpCurrentCat = null;

			UpdateEntryList();
		}
Beispiel #12
0
		//------------------------------------------
		
		public void Load(String asFile)
		{
			mpCurrentCat = null;
			mpCurrentEntry = null;

            mvCategories.Clear();
			mvDirectories.Clear();
			
			XmlDocument Doc = new XmlDocument();
			Doc.Load(asFile);

			XmlElement DocRoot = (XmlElement)Doc.FirstChild;

			/////////////////////////////////////////////////
			//Iterate all categories
			for(int child_count=0;child_count< DocRoot.ChildNodes.Count;child_count++)
			{
				XmlElement CatElem = (XmlElement)DocRoot.ChildNodes[child_count];
				if(CatElem.Name == "RESOURCES")
				{
					for(int dir=0;dir< CatElem.ChildNodes.Count;dir++)
					{
						XmlElement DirElem = (XmlElement)CatElem.ChildNodes[dir];
						
						String sPath = DirElem.GetAttribute("Path");
						mvDirectories.Add(sPath);
					}
				}
				else
				{
					cTransCategory pCat = new cTransCategory(this);
					pCat.msName = CatElem.GetAttribute("Name");
					mvCategories.Add(pCat);
					
					for(int entry=0; entry<CatElem.ChildNodes.Count; entry++)
					{
						XmlElement EntryElem = (XmlElement)CatElem.ChildNodes[entry];
						cTransEntry pEntry = new cTransEntry();
						pEntry.msName = EntryElem.GetAttribute("Name");
	            		
						String sText = EntryElem.InnerText;
						String sNewString = "";

						
						for(int i=0; i<sText.Length; ++i)
						{
							if(sText[i]=='[')
							{
								bool bFoundCommand = true;
								String sCommand = "";
								int lCount =1;
								
								while(sText[i+lCount] != ']' && i+lCount<sText.Length && lCount < 16)
								{
									sCommand += sText[i+lCount];
									lCount++;
								}

								if(sCommand=="br")
								{
									sNewString += "\r\n";
								}
								else if(sCommand[0]=='u')
								{
									int lNum = int.Parse(sCommand.Substring(1));	
									sNewString += (char)lNum;
								}
								else
								{
									bFoundCommand = false;
								}
								
								//Go forward or add [ to string
								if(bFoundCommand)
								{
									i += lCount;
								}
								else
								{
									sNewString += sText[i];
								}
							}
							else
							{
								sNewString += sText[i];
							}
						}
						
						/*for(int i=0; i<sText.Length; ++i)
						{
							if(sText[i]=='[' && sText.Length > i + 4)
							{
								String sSign = sText.Substring(i,4);
								if(sSign == "[br]")
								{
									sNewString += "\r\n";
									i+=3;
								}
								else
								{
									sNewString += sText[i];
								}
							}
							else sNewString += sText[i];
						}*/

						pEntry.msText = sNewString;

						pCat.mvEntries.Add(pEntry);
					}
				}
			}

			UpdateCategroyList();
		}
Beispiel #13
0
		//------------------------------------------
		
		public void AddCategory(String asName)
		{
			cTransCategory Cat = new cTransCategory(this);
			Cat.msName = asName;
			mvCategories.Add(Cat);

			mpMainForm.objTransCategories.Items.Add(asName);

			//The form list object
			for(int i=0; i<mpMainForm.objTransCategories.Items.Count; i++)
			{
				String sName = (String)mpMainForm.objTransCategories.Items[i];
				if(sName == asName)
				{
					mpMainForm.objTransCategories.SelectedIndex = i;
					break;
				}
			}
			
			mpCurrentEntry = null;
			UpdateEntryList();
		}