Exemplo n.º 1
0
        public void AddElement(Type dialogType)
        {
            NpcChatProject project = new NpcChatProject();

            if (project.ProjectCharacters.RegisterNewCharacter(out int id, "bill"))
            {
                DialogTree       tree   = project.ProjectDialogs.CreateNewDialogTree();
                DialogTreeBranch branch = tree.CreateNewBranch();

                DialogSegment segment = branch.CreateNewDialog(id);
                Assert.NotNull(segment);

                bool callback = false;
                segment.PropertyChanged += (sender, args) => callback = true;

                int            before  = segment.SegmentParts.Count;
                IDialogElement element = DialogTypeStore.Instance.CreateEntity(dialogType);
                segment.AddDialogElement(element);

                Assert.AreEqual(before + 1, segment.SegmentParts.Count);
                Assert.IsTrue(callback, "Failed to send callback for added type");
            }
            else
            {
                Assert.Fail("Failed to create character");
            }
        }
Exemplo n.º 2
0
        public SpellingOptions(string text, IDialogElement element, IEnumerable <string> corrections = null, Action <object, PropertyChangedEventArgs> changedCallback = null)
            : base(text, element, changedCallback)
        {
            m_element = element;

            TextDecoration decoration = new TextDecoration(TextDecorationLocation.Underline, s_underline, 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);

            TextDecorations.Add(decoration);

            m_menu           = new ContextMenu();
            m_menu.Placement = PlacementMode.MousePoint;

            if (corrections != null)
            {
                DelegateCommand <string> replaceTextCmd = new DelegateCommand <string>(ReplaceText);
                foreach (string correction in corrections)
                {
                    m_menu.Items.Add(new MenuItem
                    {
                        Header           = correction,
                        Command          = replaceTextCmd,
                        CommandParameter = correction,
                    });
                }

                m_menu.Items.Add(new Separator());
            }

            m_menu.Items.Add(new MenuItem
            {
                Header  = $"Add \"{text}\" to dictionary",
                Command = new DelegateCommand(AddToDictionary)
            });
        }
Exemplo n.º 3
0
        public EditBlock(string text, IDialogElement element, Action <object, PropertyChangedEventArgs> changedEvent = null)
            : base(text)
        {
            m_initialized  = true;
            m_text         = text;
            m_element      = element;
            m_changedEvent = changedEvent;

            m_element.PropertyChanged += OnElementPropertyChanged;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Perform spell check on the text from the element
        /// </summary>
        /// <param name="element">element to check</param>
        /// <param name="currentLanguage">language code to use spell check for</param>
        /// <param name="changedCallback">optional callback for text changes from dialog Elements</param>
        public static IEnumerable <Inline> CheckElement(IDialogElement element, string currentLanguage = "en_gb", Action <object, PropertyChangedEventArgs> changedCallback = null)
        {
            List <Inline> paragraphRuns = new List <Inline>();

            if (m_dictionary.ContainsKey(currentLanguage))
            {
                WordList dictionary = m_dictionary[currentLanguage];

                string   fullText = element.Text;
                string[] words    = fullText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   sentence = fullText.StartsWith(" ") ? " " : "";

                for (int i = 0; i < words.Length; i++)
                {
                    string        word        = words[i];
                    List <string> suggestions = dictionary.Suggest(word).ToList();
                    if (suggestions.Any() && !suggestions.Contains(word))
                    {
                        if (i > 0)
                        {
                            sentence += " ";
                        }
                        paragraphRuns.Add(new Run(sentence));
                        sentence = "";

                        paragraphRuns.Add(new Bold(new SpellingOptions(word, element, suggestions.Except(new[] { word }), changedCallback)));
                    }
                    else
                    {
                        if (i > 0)
                        {
                            sentence += " ";
                        }
                        sentence += word;
                    }
                }

                //add any remaining words
                if (fullText.EndsWith(" "))
                {
                    sentence += " ";
                }
                if (sentence.Length > 0)
                {
                    paragraphRuns.Add(new EditBlock(sentence, element, changedCallback));
                }
            }
            else
            {
                paragraphRuns.Add(new EditBlock(element.Text, element, changedCallback));
            }

            return(paragraphRuns);
        }
Exemplo n.º 5
0
 public BaseDialogFragment(Context context, Xamarin.Forms.View view,
                           DialogConfig dialogConfig, IDialogMsg dialogMsg)
 {
     _xfView       = view;
     _mContext     = context;
     _dialogConfig = dialogConfig;
     _iDialogMsg   = dialogMsg;
     if (view is IDialogElement)
     {
         _dialogElement = view as IDialogElement;
     }
 }
 public BaseDialogFragment2(Activity activity, Xamarin.Forms.View contentView,
                            DialogConfig dialogConfig, IDialogMsg dialogMsg, IDialogResult dialogResult = null)
 {
     _context      = activity;
     _dialogConfig = dialogConfig;
     _iDialogMsg   = dialogMsg;
     _contentView  = contentView;
     _dialogResult = dialogResult;
     if (contentView is IDialogElement dialogElement)
     {
         _dialogElement = contentView as IDialogElement;
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Check the given dialog element for spelling errors
 /// </summary>
 /// <param name="element">text to check</param>
 /// <param name="currentLanguage">language code too check against</param>
 /// <returns>true if sentence contains an error</returns>
 public static bool ContainsSpellingSuggestion(IDialogElement element, string currentLanguage = "en_gb")
 {
     return(ContainsSpellingSuggestion(element.Text, currentLanguage));
 }