示例#1
0
        private void PromptToAddCandidatesToDictionary(List <string> candidates, IKeyboard originalKeyboard)
        {
            if (candidates.Any())
            {
                var candidate = candidates.First();

                var prompt = candidate.Contains(' ')
                    ? string.Format(Resources.ADD_PHRASE_TO_DICTIONARY_CONFIRMATION_MESSAGE,
                                    candidate, candidate.NormaliseAndRemoveRepeatingCharactersAndHandlePhrases(log: true))
                    : string.Format(Resources.ADD_WORD_TO_DICTIONARY_CONFIRMATION_MESSAGE, candidate);

                if (candidate.Any(char.IsUpper))
                {
                    prompt = string.Concat(prompt, Resources.NEW_DICTIONARY_ENTRY_WILL_CONTAIN_CAPITALS);
                }

                var similarEntries = dictionaryService.GetAllEntries()
                                     .Where(de => string.Equals(de.Entry, candidate, StringComparison.InvariantCultureIgnoreCase))
                                     .Select(de => de.Entry)
                                     .ToList();

                if (similarEntries.Any())
                {
                    string similarEntriesPrompt = string.Format(Resources.SIMILAR_DICTIONARY_ENTRIES_EXIST,
                                                                string.Join(", ", similarEntries.Select(se => string.Format("'{0}'", se))));

                    prompt = string.Concat(prompt, "\n\n", similarEntriesPrompt);
                }

                Action nextAction = candidates.Count > 1
                        ? (Action)(() => PromptToAddCandidatesToDictionary(candidates.Skip(1).ToList(), originalKeyboard))
                        : (Action)(() => Keyboard = originalKeyboard);

                Keyboard = new YesNoQuestion(
                    prompt,
                    () =>
                {
                    dictionaryService.AddNewEntryToDictionary(candidate);
                    inputService.RequestSuspend();

                    RaiseToastNotification(Resources.ADDED, string.Format(Resources.ENTRY_ADDED_TO_DICTIONARY, candidate),
                                           NotificationTypes.Normal, () => { inputService.RequestResume(); });

                    nextAction();
                },
                    () => nextAction());
            }
        }
示例#2
0
        private void PromptToAddCandidatesToDictionary(List <string> candidates, IKeyboard originalKeyboard)
        {
            if (candidates.Any())
            {
                var candidate = candidates.First();

                var prompt = candidate.Contains(' ')
                    ? string.Format("Would you like to add the phrase '{0}' to the dictionary with shortcut '{1}'?",
                                    candidate, candidate.CreateDictionaryEntryHash(log: true))
                    : string.Format("Would you like to add the word '{0}' to the dictionary?", candidate);

                if (candidate.Any(Char.IsUpper))
                {
                    prompt = string.Concat(prompt, "\n(The new dictionary entry will contain capital letters)");
                }

                var similarEntries = dictionaryService.GetAllEntries()
                                     .Where(de => string.Equals(de.Entry, candidate, StringComparison.InvariantCultureIgnoreCase))
                                     .Select(de => de.Entry)
                                     .ToList();

                if (similarEntries.Any())
                {
                    string similarEntriesPrompt = string.Format("(FYI some similar entries are already in the dictionary: {0})",
                                                                string.Join(", ", similarEntries.Select(se => string.Format("'{0}'", se))));

                    prompt = string.Concat(prompt, "\n\n", similarEntriesPrompt);
                }

                Action nextAction = candidates.Count > 1
                        ? (Action)(() => PromptToAddCandidatesToDictionary(candidates.Skip(1).ToList(), originalKeyboard))
                        : (Action)(() => Keyboard = originalKeyboard);

                Keyboard = new YesNoQuestion(
                    prompt,
                    () =>
                {
                    dictionaryService.AddNewEntryToDictionary(candidate);
                    inputService.RequestSuspend();
                    nextAction();

                    RaiseToastNotification("Added", string.Format("Great stuff. '{0}' has been added to the dictionary.", candidate),
                                           NotificationTypes.Normal, () => { inputService.RequestResume(); });
                },
                    () => nextAction());
            }
        }
示例#3
0
        public void ApplyChanges()
        {
            if (Entries != null)
            {
                //Add new entries
                foreach (var addedEntry in Entries.Where(e => e.Added).Select(e => e.Entry))
                {
                    dictionaryService.AddNewEntryToDictionary(addedEntry);
                }

                //Remove deleted entries
                foreach (var deletedEntry in Entries.Where(e => e.Deleted).Select(e => e.Entry))
                {
                    dictionaryService.RemoveEntryFromDictionary(deletedEntry);
                }
            }
        }