Exemple #1
0
        private void SelectTexts()
        {
            // Create list of current items
            List <ScrText> currentItems = new List <ScrText>();

            foreach (TextCollectionItem item in m_textCollection.Items)
            {
                currentItems.Add(item.ScrText);
            }
            TextCollectionItem currentItem = null;

            if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count)
            {
                currentItem = m_textCollection.Items[m_textCollection.CurItem];
            }

            // Re-initialize, just in case.
            // We pass the directory (rather than passing no arguments, and letting the paratext dll figure
            // it out) because the figuring out goes wrong on Linux, where both programs are simulating
            // the registry.
            ScrTextCollection.Initialize(ParatextHelper.ProjectsDirectory, false);
            List <string> textNames = ScrTextCollection.ScrTextNames;

            foreach (string nameVar in textNames)
            {
                if (nameVar.Length < 1)
                {
                    continue;
                }

                string name = nameVar.ToLower();

                // Ignore P6 source language texts.
                if (name == "lxx" || name == "grk" || name == "heb")
                {
                    continue;
                }

                try
                {
                    if (ScrTextCollection.Get(nameVar) == null)
                    {
                        // REVIEW: I'm not sure how/if ScrTextCollection gets disposed
                        ScrText scrText = new ScrText(nameVar);
                        ScrTextCollection.Add(scrText);
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show(name + ": " + exception.Message);
                    // TODO What will happen if a text can't be loaded?
                }
            }

            // the two booleans indicate we want all the available texts, including resources (part of the Paratext distribution)
            // and non-scriptural materials (things like commentaries maybe?)
            using (ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
                       ScrTextCollection.ScrTexts(true, true), currentItems))
            {
                if (selForm.ShowDialog(this) == DialogResult.OK)
                {
                    // Create new list of items, keeping data from old one (to preserve zoom etc)
                    List <TextCollectionItem> newItems = new List <TextCollectionItem>();
                    foreach (ScrText scrText in selForm.Selections)
                    {
                        // Attempt to find in old list
                        bool found = false;
                        foreach (TextCollectionItem item in m_textCollection.Items)
                        {
                            if (item.ScrText == scrText)
                            {
                                newItems.Add(item);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            newItems.Add(new TextCollectionItem(scrText, 1));
                        }
                    }
                    m_textCollection.Items = newItems;
                    int curItemIndex = -1;                     // none selected
                    for (int i = 0; i < newItems.Count; i++)
                    {
                        if (newItems[i] == currentItem)
                        {
                            curItemIndex = i;
                            break;
                        }
                    }
                    // select some current item if possible; out of range does not cause problem.
                    // Currently it seems to cause a crash if the item is out of range for the OLD items;
                    // I think this is a bug in the Paratext code.
                    if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0)
                    {
                        curItemIndex = 0;
                    }
                    m_textCollection.CurItem = curItemIndex;

                    tryReloadTextCollection();
                }
            }
        }
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Method adapted from TextCollectionControl method of same name, to use our dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SelectTexts()
        {
            // Create list of current items
            List <ScrText> currentItems = new List <ScrText>();

            foreach (TextCollectionItem item in m_textCollection.Items)
            {
                currentItems.Add(item.ScrText);
            }
            TextCollectionItem currentItem = null;

            if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count)
            {
                currentItem = m_textCollection.Items[m_textCollection.CurItem];
            }

            ScrTextCollection.Initialize();             // Re-initialize, just in case
            List <string> textNames = ScrTextCollection.ScrTextNames;

            foreach (string nameVar in textNames)
            {
                if (nameVar.Length < 1)
                {
                    continue;
                }

                string name = nameVar.ToLower();

                // Ignore P6 source language texts.
                if (name == "lxx" || name == "grk" || name == "heb")
                {
                    continue;
                }

                try
                {
                    if (ScrTextCollection.Get(nameVar) == null)
                    {
                        ScrText scrText = new ScrText(nameVar);
                        ScrTextCollection.Add(scrText);
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show(name + ": " + exception.Message);
                    // TODO What will happen if a text can't be loaded?
                }
            }


            ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
                ScrTextCollection.ScrTexts, currentItems);

            if (selForm.ShowDialog(this) == DialogResult.OK)
            {
                // Create new list of items, keeping data from old one (to preserve zoom etc)
                List <TextCollectionItem> newItems = new List <TextCollectionItem>();
                foreach (ScrText scrText in selForm.Selections)
                {
                    // Attempt to find in old list
                    bool found = false;
                    foreach (TextCollectionItem item in m_textCollection.Items)
                    {
                        if (item.ScrText == scrText)
                        {
                            newItems.Add(item);
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        newItems.Add(new TextCollectionItem(scrText, 1));
                    }
                }
                m_textCollection.Items = newItems;
                int curItemIndex = -1;                 // none selected
                for (int i = 0; i < newItems.Count; i++)
                {
                    if (newItems[i] == currentItem)
                    {
                        curItemIndex = i;
                        break;
                    }
                }
                // select some current item if possible; out of range does not cause problem.
                // Currently it seems to cause a crash if the item is out of range for the OLD items;
                // I think this is a bug in the Paratext code.
                if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0)
                {
                    curItemIndex = 0;
                }
                m_textCollection.CurItem = curItemIndex;

                tryReloadTextCollection();
            }
        }
		private void SelectTexts()
		{
			// Create list of current items
			List<ScrText> currentItems = new List<ScrText>();
			foreach (TextCollectionItem item in m_textCollection.Items)
				currentItems.Add(item.ScrText);
			TextCollectionItem currentItem = null;
			if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count)
				currentItem = m_textCollection.Items[m_textCollection.CurItem];

			// Re-initialize, just in case.
			// We pass the directory (rather than passing no arguments, and letting the paratext dll figure
			// it out) because the figuring out goes wrong on Linux, where both programs are simulating
			// the registry.
			ScrTextCollection.Initialize(ParatextHelper.ProjectsDirectory, false);
			List<string> textNames = ScrTextCollection.ScrTextNames;

			foreach (string nameVar in textNames)
			{
				if (nameVar.Length < 1)
					continue;

				string name = nameVar.ToLower();

				// Ignore P6 source language texts.
				if (name == "lxx" || name == "grk" || name == "heb")
					continue;

				try
				{
					if (ScrTextCollection.Get(nameVar) == null)
					{
						// REVIEW: I'm not sure how/if ScrTextCollection gets disposed
						ScrText scrText = new ScrText(nameVar);
						ScrTextCollection.Add(scrText);
					}
				}
				catch (Exception)
				{
					//MessageBox.Show(name + ": " + exception.Message);
					// TODO What will happen if a text can't be loaded?
				}
			}

			// the two booleans indicate we want all the available texts, including resources (part of the Paratext distribution)
			// and non-scriptural materials (things like commentaries maybe?)
			using (ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
				ScrTextCollection.ScrTexts(true, true), currentItems))
			{
				if (selForm.ShowDialog(this) == DialogResult.OK)
				{
					// Create new list of items, keeping data from old one (to preserve zoom etc)
					List<TextCollectionItem> newItems = new List<TextCollectionItem>();
					foreach (ScrText scrText in selForm.Selections)
					{
						// Attempt to find in old list
						bool found = false;
						foreach (TextCollectionItem item in m_textCollection.Items)
						{
							if (item.ScrText == scrText)
							{
								newItems.Add(item);
								found = true;
								break;
							}
						}
						if (!found)
							newItems.Add(new TextCollectionItem(scrText, 1));
					}
					m_textCollection.Items = newItems;
					int curItemIndex = -1; // none selected
					for (int i = 0; i < newItems.Count; i++)
					{
						if (newItems[i] == currentItem)
						{
							curItemIndex = i;
							break;
						}
					}
					// select some current item if possible; out of range does not cause problem.
					// Currently it seems to cause a crash if the item is out of range for the OLD items;
					// I think this is a bug in the Paratext code.
					if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0)
						curItemIndex = 0;
					m_textCollection.CurItem = curItemIndex;

					tryReloadTextCollection();
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Method adapted from TextCollectionControl method of same name, to use our dialog.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void SelectTexts()
		{
			// Create list of current items
			List<ScrText> currentItems = new List<ScrText>();
			foreach (TextCollectionItem item in m_textCollection.Items)
				currentItems.Add(item.ScrText);
			TextCollectionItem currentItem = null;
			if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count)
				currentItem = m_textCollection.Items[m_textCollection.CurItem];

			ScrTextCollection.Initialize(); // Re-initialize, just in case
			List<string> textNames = ScrTextCollection.ScrTextNames;

			foreach (string nameVar in textNames)
			{
				if (nameVar.Length < 1)
					continue;

				string name = nameVar.ToLower();

				// Ignore P6 source language texts.
				if (name == "lxx" || name == "grk" || name == "heb")
					continue;

				try
				{
					if (ScrTextCollection.Get(nameVar) == null)
					{
						ScrText scrText = new ScrText(nameVar);
						ScrTextCollection.Add(scrText);
					}
				}
				catch (Exception)
				{
					//MessageBox.Show(name + ": " + exception.Message);
					// TODO What will happen if a text can't be loaded?
				}
			}


			ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
				ScrTextCollection.ScrTexts, currentItems);
			if (selForm.ShowDialog(this) == DialogResult.OK)
			{
				// Create new list of items, keeping data from old one (to preserve zoom etc)
				List<TextCollectionItem> newItems = new List<TextCollectionItem>();
				foreach (ScrText scrText in selForm.Selections)
				{
					// Attempt to find in old list
					bool found = false;
					foreach (TextCollectionItem item in m_textCollection.Items)
					{
						if (item.ScrText == scrText)
						{
							newItems.Add(item);
							found = true;
							break;
						}
					}
					if (!found)
						newItems.Add(new TextCollectionItem(scrText, 1));
				}
				m_textCollection.Items = newItems;
				int curItemIndex = -1; // none selected
				for (int i = 0; i < newItems.Count; i++)
				{
					if (newItems[i] == currentItem)
					{
						curItemIndex = i;
						break;
					}
				}
				// select some current item if possible; out of range does not cause problem.
				// Currently it seems to cause a crash if the item is out of range for the OLD items;
				// I think this is a bug in the Paratext code.
				if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0)
					curItemIndex = 0;
				m_textCollection.CurItem = curItemIndex;

				tryReloadTextCollection();
			}
		}