From: konekoneko Date: Tue, 15 Nov 2016 15:58:32 +0000 (+0530) Subject: CompleteItemでドキュメントから補完候補を作成できるようにした X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=496c365e73627ef8628ca03d7a99539f51bacb0c;p=fooeditengine%2FFooEditEngine.git CompleteItemでドキュメントから補完候補を作成できるようにした --- diff --git a/Core/AutoCompleteBoxBase.cs b/Core/AutoCompleteBoxBase.cs index 22e64c7..c62460b 100644 --- a/Core/AutoCompleteBoxBase.cs +++ b/Core/AutoCompleteBoxBase.cs @@ -76,6 +76,34 @@ namespace FooEditEngine } /// + /// イベントパラメーターイベントパラメーター + /// + public sealed class CollectCompleteItemEventArgs : EventArgs + { + /// + /// 入力された行 + /// + public int InputedRow; + /// + /// 補完対象のテキストボックス + /// + public Document textbox; + /// + /// コンストラクター + /// + /// + /// + /// + public CollectCompleteItemEventArgs(Document textbox) + { + this.textbox = textbox; + this.InputedRow = textbox.CaretPostion.row - 1; + if (this.InputedRow < 0) + this.InputedRow = 0; + } + } + + /// /// イベントパンドラーの定義 /// /// @@ -147,6 +175,11 @@ namespace FooEditEngine } } }; + 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; } @@ -154,15 +187,19 @@ namespace FooEditEngine internal void ParseInput(string input_text) { if (this.Operators == null || - input_text == "\r" || - input_text == "\n" || this.ShowingCompleteBox == null || (this.IsCloseCompleteBox == false && input_text == "\b")) return; + if (input_text == "\r" || input_text == "\n") + { + this.CollectItems(this, new CollectCompleteItemEventArgs(this.Document)); + return; + } + this.OpenCompleteBox(input_text); } - + public EventHandler CollectItems; /// /// 補完すべき単語が選択されたときに発生するイベント /// diff --git a/Core/Document.cs b/Core/Document.cs index 794909c..4ed7083 100644 --- a/Core/Document.cs +++ b/Core/Document.cs @@ -1036,8 +1036,12 @@ namespace FooEditEngine if (this.FireUpdateEvent && UserInput) { - if(this.AutoComplete != null) - this.AutoComplete.ParseInput(string.Empty); //入力は終わっているので空文字を渡す + var input_str = string.Empty; + if (s == Document.NewLine.ToString()) + input_str = s; + //入力は終わっているので空文字を渡すが処理の都合で一部文字だけはそのまま渡す + if (this.AutoComplete != null) + this.AutoComplete.ParseInput(input_str); if (s == Document.NewLine.ToString()) this.AutoIndentHook(this, null); } diff --git a/UWP/Test/MainViewModel.cs b/UWP/Test/MainViewModel.cs index 00c4a0e..4bb19f3 100644 --- a/UWP/Test/MainViewModel.cs +++ b/UWP/Test/MainViewModel.cs @@ -28,6 +28,7 @@ namespace Test var doc = new Document() { Title = "test1" }; doc.AutoComplete = new AutoCompleteBox(doc); doc.AutoComplete.Items = complete_collection; + doc.AutoComplete.Enabled = true; this._list.Add(doc); doc = new Document() { Title = "test2" };