예제 #1
0
        /// <summary>
        /// 補完候補を追加する
        /// </summary>
        /// <param name="items"></param>
        /// <param name="word"></param>
        public static void AddComleteWord(CompleteCollection <ICompleteItem> items, string word)
        {
            CompleteWord newItem = new CompleteWord(word);

            if (items.Contains(newItem) == false && CompleteHelper.IsVaildWord(word))
            {
                items.Add(newItem);
            }
        }
        /// <summary>
        /// コンストラクター
        /// </summary>
        /// <param name="document">対象となるDocumentWindow</param>
        public AutoCompleteBoxBase(Document document)
        {
            this.SelectItem = (s, e) => {
                string inputing_word = e.inputing_word;
                string word          = e.item.word;

                var doc = e.textbox;
                //キャレットは入力された文字の後ろにあるので、一致する分だけ選択して置き換える
                int caretIndex = doc.LayoutLines.GetIndexFromTextPoint(e.textbox.CaretPostion);
                int start      = caretIndex - inputing_word.Length;
                if (start < 0)
                {
                    start = 0;
                }
                doc.Replace(start, inputing_word.Length, word);
                doc.RequestRedraw();
            };
            this.ShowingCompleteBox = (s, e) => {
                AutoCompleteBoxBase box = (AutoCompleteBoxBase)s;

                var doc           = e.textbox;
                int caretIndex    = doc.LayoutLines.GetIndexFromTextPoint(e.textbox.CaretPostion);
                int inputingIndex = caretIndex - 1;
                if (inputingIndex < 0)
                {
                    inputingIndex = 0;
                }

                e.inputedWord = CompleteHelper.GetWord(doc, inputingIndex, box.Operators) + e.KeyChar;

                if (e.inputedWord == null)
                {
                    return;
                }

                for (int i = 0; i < box.Items.Count; i++)
                {
                    CompleteWord item = (CompleteWord)box.Items[i];
                    if (item.word.StartsWith(e.inputedWord))
                    {
                        e.foundIndex = i;
                        break;
                    }
                }
            };
            this.CollectItems = (s, e) =>
            {
                AutoCompleteBoxBase box = (AutoCompleteBoxBase)s;
                CompleteHelper.AddCompleteWords(box.Items, box.Operators, e.textbox.LayoutLines[e.InputedRow]);
            };
            this.Operators = new char[] { ' ', '\t', Document.NewLine };
            this.Document  = document;
        }
예제 #3
0
        /// <summary>
        /// KeywordManager.Operatorsで区切られた単語を補完候補に追加する
        /// </summary>
        /// <param name="items"></param>
        /// <param name="Operators"></param>
        /// <param name="s"></param>
        public static void AddCompleteWords(CompleteCollection <ICompleteItem> items, IList <char> Operators, string s)
        {
            if (items == null || Operators == null)
            {
                return;
            }

            char[] seps = new char[Operators.Count];
            Operators.CopyTo(seps, 0);

            string[] words = s.Split(seps, StringSplitOptions.RemoveEmptyEntries);

            foreach (string word in words)
            {
                CompleteHelper.AddComleteWord(items, word);
            }
        }