コード例 #1
0
        // Устанавливает состояние для панели редактирования translation unit для выделенного слова/фразы
        public void SetTranslationUnitAreaState(bool enabled, Logic.TranslationUnit translationUnit = null)
        {
            textBoxOriginalInfinitive.IsEnabled = textBoxTranslatedInfinitive.IsEnabled = textBoxOriginal.IsEnabled = textBoxTranslated.IsEnabled = enabled;

            if (enabled)
            {
                if (translationUnit != null)
                {
                    textBoxOriginalInfinitive.Text   = translationUnit.infinitiveTranslation.originalPhrase;
                    textBoxTranslatedInfinitive.Text = translationUnit.infinitiveTranslation.translatedPhrase;
                    textBoxTranslated.Text           = translationUnit.translatedPhrase;
                }
                else
                {
                    textBoxOriginalInfinitive.Text = textBoxTranslatedInfinitive.Text = textBoxTranslated.Text = string.Empty;
                }

                StringBuilder selectedWordsAsString = new StringBuilder();
                foreach (var wordInSelection in m_selectedWords)
                {
                    selectedWordsAsString.Append(wordInSelection.ToString());
                    selectedWordsAsString.Append(ReferenceEquals(wordInSelection, m_selectedWords[m_selectedWords.Count - 1]) ? string.Empty : " ");
                }

                textBoxOriginal.Text = selectedWordsAsString.ToString();
            }
            else
            {
                textBoxOriginalInfinitive.Text = textBoxTranslatedInfinitive.Text = textBoxOriginal.Text = textBoxTranslated.Text = string.Empty;
            }
        }
コード例 #2
0
        private void test_Click(object sender, RoutedEventArgs e)
        {
            Logic.TranslationUnit translationUnit = new Logic.TranslationUnit(m_selectedWords.ToArray());

            translationUnit.translatedPhrase = textBoxTranslated.Text == string.Empty ? null : textBoxTranslated.Text;

            if (textBoxOriginalInfinitive.Text == string.Empty || textBoxTranslatedInfinitive.Text == string.Empty)
            {
                translationUnit.infinitiveTranslation.originalPhrase   = null;
                translationUnit.infinitiveTranslation.translatedPhrase = null;
            }
            else
            {
                translationUnit.infinitiveTranslation.originalPhrase   = textBoxOriginalInfinitive.Text;
                translationUnit.infinitiveTranslation.translatedPhrase = textBoxTranslatedInfinitive.Text;
            }

            Global.CurrentWorkspace.CurrentArticle.ModifyTranslationUnit(translationUnit, Global.CurrentWorkspace.TranslationLanguages[0].Code);

            // Test_OpenStarDict();
        }
コード例 #3
0
        private void OnSelectedWordsChange()
        {
            // ToDo: тест. временно берем тупо первый язык в списке. надо брать из выпадающего списка (если языков вообще нет то эта функция не должна была вызываться)
            string selectedTranslationLanguageCode = Global.CurrentWorkspace.TranslationLanguages[0].Code;

            if (m_selectedWords.Count == 0)
            {
                SetTranslationUnitAreaState(false);
                SetUnselectedPhraseWords(null);
                m_wrongWords.Clear();

            }
            else if (m_selectedWords.Count == 1)
            {
                SetTranslationUnitAreaState(true, Global.CurrentWorkspace.CurrentArticle.GetWordTranslation(selectedTranslationLanguageCode, m_selectedWords[0]));
                m_wrongWords.Clear();

                var phraseTranslationUnit = Global.CurrentWorkspace.CurrentArticle.GetPhraseTranslation(selectedTranslationLanguageCode, m_selectedWords[0]);
                SetUnselectedPhraseWords(phraseTranslationUnit == null ? null : phraseTranslationUnit.OriginalPhrase);
            }
            else
            {
                bool selectionHasSinglePhrase = true;

                // Получаем фразу-перевод для каждого из выделенных слов
                Logic.TranslationUnit[] phrasesForEachWordInSelection = new Logic.TranslationUnit[m_selectedWords.Count];
                for (int i = 0; i < m_selectedWords.Count; i++)
                {
                    phrasesForEachWordInSelection[i] = Global.CurrentWorkspace.CurrentArticle.GetPhraseTranslation(selectedTranslationLanguageCode, m_selectedWords[i]);

                    if (selectionHasSinglePhrase && i != 0 && phrasesForEachWordInSelection[i] != phrasesForEachWordInSelection[i - 1])
                        selectionHasSinglePhrase = false;
                }

                m_wrongWords.Clear();

                if (selectionHasSinglePhrase)
                {
                    var phraseTranslationUnit = phrasesForEachWordInSelection[0];

                    if (phraseTranslationUnit == null || phraseTranslationUnit.OriginalPhrase.Length == m_selectedWords.Count)
                    {
                        SetTranslationUnitAreaState(true, phraseTranslationUnit);
                        SetUnselectedPhraseWords(null);
                    }
                    else
                    {
                        SetTranslationUnitAreaState(false);
                        SetUnselectedPhraseWords(phraseTranslationUnit.OriginalPhrase);
                    }
                }
                else
                {
                    SetTranslationUnitAreaState(false);
                    SetUnselectedPhraseWords(null);

                    for (int i = 0; i < m_selectedWords.Count; i++)
                    {
                        if (phrasesForEachWordInSelection[i] != null)
                            m_wrongWords.Add(m_selectedWords[i]);
                    }
                }
            }
        }
コード例 #4
0
        private void test_Click(object sender, RoutedEventArgs e)
        {
            Logic.TranslationUnit translationUnit = new Logic.TranslationUnit(m_selectedWords.ToArray());

            translationUnit.translatedPhrase = textBoxTranslated.Text == string.Empty ? null : textBoxTranslated.Text;

            if (textBoxOriginalInfinitive.Text == string.Empty || textBoxTranslatedInfinitive.Text == string.Empty)
            {
                translationUnit.infinitiveTranslation.originalPhrase = null;
                translationUnit.infinitiveTranslation.translatedPhrase = null;
            }
            else
            {
                translationUnit.infinitiveTranslation.originalPhrase = textBoxOriginalInfinitive.Text;
                translationUnit.infinitiveTranslation.translatedPhrase = textBoxTranslatedInfinitive.Text;
            }

            Global.CurrentWorkspace.CurrentArticle.ModifyTranslationUnit(translationUnit, Global.CurrentWorkspace.TranslationLanguages[0].Code);

            // Test_OpenStarDict();
        }
コード例 #5
0
        private void OnSelectedWordsChange()
        {
            // ToDo: тест. временно берем тупо первый язык в списке. надо брать из выпадающего списка (если языков вообще нет то эта функция не должна была вызываться)
            string selectedTranslationLanguageCode = Global.CurrentWorkspace.TranslationLanguages[0].Code;

            if (m_selectedWords.Count == 0)
            {
                SetTranslationUnitAreaState(false);
                SetUnselectedPhraseWords(null);
                m_wrongWords.Clear();
            }
            else if (m_selectedWords.Count == 1)
            {
                SetTranslationUnitAreaState(true, Global.CurrentWorkspace.CurrentArticle.GetWordTranslation(selectedTranslationLanguageCode, m_selectedWords[0]));
                m_wrongWords.Clear();

                var phraseTranslationUnit = Global.CurrentWorkspace.CurrentArticle.GetPhraseTranslation(selectedTranslationLanguageCode, m_selectedWords[0]);
                SetUnselectedPhraseWords(phraseTranslationUnit == null ? null : phraseTranslationUnit.OriginalPhrase);
            }
            else
            {
                bool selectionHasSinglePhrase = true;

                // Получаем фразу-перевод для каждого из выделенных слов
                Logic.TranslationUnit[] phrasesForEachWordInSelection = new Logic.TranslationUnit[m_selectedWords.Count];
                for (int i = 0; i < m_selectedWords.Count; i++)
                {
                    phrasesForEachWordInSelection[i] = Global.CurrentWorkspace.CurrentArticle.GetPhraseTranslation(selectedTranslationLanguageCode, m_selectedWords[i]);

                    if (selectionHasSinglePhrase && i != 0 && phrasesForEachWordInSelection[i] != phrasesForEachWordInSelection[i - 1])
                    {
                        selectionHasSinglePhrase = false;
                    }
                }

                m_wrongWords.Clear();

                if (selectionHasSinglePhrase)
                {
                    var phraseTranslationUnit = phrasesForEachWordInSelection[0];

                    if (phraseTranslationUnit == null || phraseTranslationUnit.OriginalPhrase.Length == m_selectedWords.Count)
                    {
                        SetTranslationUnitAreaState(true, phraseTranslationUnit);
                        SetUnselectedPhraseWords(null);
                    }
                    else
                    {
                        SetTranslationUnitAreaState(false);
                        SetUnselectedPhraseWords(phraseTranslationUnit.OriginalPhrase);
                    }
                }
                else
                {
                    SetTranslationUnitAreaState(false);
                    SetUnselectedPhraseWords(null);

                    for (int i = 0; i < m_selectedWords.Count; i++)
                    {
                        if (phrasesForEachWordInSelection[i] != null)
                        {
                            m_wrongWords.Add(m_selectedWords[i]);
                        }
                    }
                }
            }
        }