Esempio n. 1
0
        // Menu -> PhraseList_LanguageSelection -> PhraseList -> PhraseList_EditingPhrase
        private IUserInterface BuildEditingPhraseSection(PhraseAndTranslation phrase)
        {
            string sectionName = "phrase_list-editing_phrase";

            TextInputtingInterface.VariableInfoPair[] variableInfoPairs =
            {
                new TextInputtingInterface.VariableInfoPair {
                    Info = $"{localization[$"{sectionName}:input_empty_to_exit"]}\n" +
                           $"{localization[$"{sectionName}:input_new_phrase"]} ({localization[$"{sectionName}:current_phrase"]} {phrase.Phrase})"
                }
            };
            TextInputtingInterface phraseEditingInterface = new TextInputtingInterface(
                variableInfoPairs: variableInfoPairs,
                successfulInputtingMsg: localization[$"{sectionName}:phrase_was_edited"],
                getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}"
                );

            phraseEditingInterface.OnGettingData += (newPhrases) =>
            {
                phrase.Edit(newPhrases.ElementAt(0));
                SerializeDataContainer();
                phraseEditingInterface.Stop();
            };
            return(phraseEditingInterface);
        }
Esempio n. 2
0
 private void AddTranslation(PhraseAndTranslation translation)
 {
     // Здесь нет проверки на activeValue, потому что этот метод используется только в конструкторе
     if (!translation.activeValue)
     {
         throw new ArgumentException("Passed translation parameter has been deleted");
     }
     if (!ContainsTranslation(translation))
     {
         Translations.AddLast(translation);
     }
 }
Esempio n. 3
0
        public T GetPhrase <T>(string phrase) where T : PhraseAndTranslation
        {
            PhraseAndTranslation phraseObj = null;

            if (typeof(T) == typeof(RuPhraseAndTranslation))
            {
                phraseObj = RuPhrasesDb.FirstOrDefault(p => p.Phrase.Equals(phrase));
            }
            else
            {
                phraseObj = EnPhrasesDb.FirstOrDefault(p => p.Phrase.Equals(phrase));
            }
            return(phraseObj as T);
        }
Esempio n. 4
0
 public virtual void DeleteTranslation(PhraseAndTranslation translation)
 {
     if (!activeValue)
     {
         throw new InvalidOperationException("This object has been deleted");
     }
     translation.Translations.Remove(this);
     Translations.Remove(translation);
     if (translation.Translations.Count() == 0)
     {
         translation.Delete();
     }
     if (Translations.Count() == 0)
     {
         Delete();
     }
 }
Esempio n. 5
0
        // Menu -> PhraseList_LanguageSelection -> PhraseList -> PhraseList-PhraseInfo
        private IUserInterface BuildPhraseInfoSection(PhraseAndTranslation phrase)
        {
            string          sectionName         = "phrase_list-phrase_info";
            Buttons         buttons             = new Buttons();
            ButtonInterface phraseInfoInterface = new ButtonInterface(
                buttons: buttons,
                controlKeyContainer: controlKeyContainer,
                getTitle: () => $"{programName} - {localization[$"{sectionName}:section_name"]}",
                withSoundEffect: () => withSoundEffect,
                getHeaderText: () => $"{localization[$"{sectionName}:phrase"]}: {phrase.Phrase}\n{localization[$"{sectionName}:translations"]}:"
                );
            // Добавляем кнопки для удаления перевода
            int verticalLineId = 1;

            foreach (var translation in phrase.Translations)
            {
                Button translationButton = new Button(translation.Phrase, false);
                buttons.AddButton(verticalLineId, 1, translationButton);
                Button deleteTranslationButton = new Button($"{localization["common:delete_button"]}");
                deleteTranslationButton.OnPressed += (o, args) =>
                {
                    phrase.DeleteTranslation(translation);
                    SerializeDataContainer();
                    buttons.RemoveVerticalLine(phraseInfoInterface.Position.Item1);
                    if (phraseInfoInterface.Position.Item1 != 1 && phraseInfoInterface.Position.Item1 == buttons.VerticalLineCount)
                    {
                        phraseInfoInterface.Position = (phraseInfoInterface.Position.Item1 - 1, phraseInfoInterface.Position.Item2);
                    }
                    if (phrase.Deleted)
                    {
                        phraseInfoInterface.Stop();
                    }
                };
                buttons.AddButton(verticalLineId++, 2, deleteTranslationButton);
            }
            // Добавляем кнопку "Назад"
            Button backButton = new Button($"{localization["common:back_button"]}");

            backButton.OnPressed += (o, args) => phraseInfoInterface.Stop();
            buttons.AddButton(buttons.VerticalLineCount + 1, 1, backButton);
            return(phraseInfoInterface);
        }
 public PhraseAndTranslation(string phrase, PhraseAndTranslation translation,
                             IEnumerable <PhraseAndTranslation> phraseDb, IEnumerable <PhraseAndTranslation> translationDb)
     : this(phrase, phraseDb, translationDb)
 {
     AddTranslation(translation);
 }
Esempio n. 7
0
 public bool ContainsTranslation(PhraseAndTranslation translation)
 {
     return(Translations.Contains(translation));
 }
Esempio n. 8
0
 public PhraseExistsException(PhraseAndTranslation phrase,
                              string errMsg = "Phrase has already existed in Database")
     : base(errMsg)
 {
     Phrase = phrase;
 }