forked from PavelTorgashov/FastColoredTextBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutocompleteSample4.cs
116 lines (96 loc) · 3.21 KB
/
AutocompleteSample4.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System.Reflection;
using System.Windows.Forms;
using FastColoredTextBoxNS;
using System.Drawing;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Tester
{
public partial class AutocompleteSample4 : Form
{
AutocompleteMenu popupMenu;
static readonly string[] sources = new string[]{
"com",
"com.company",
"com.company.Class1",
"com.company.Class1.Method1",
"com.company.Class1.Method2",
"com.company.Class2",
"com.company.Class3",
"com.example",
"com.example.ClassX",
"com.example.ClassX.Method1",
"com.example.ClassY",
"com.example.ClassY.Method1"
};
public AutocompleteSample4()
{
InitializeComponent();
//create autocomplete popup menu
popupMenu = new AutocompleteMenu(fctb);
popupMenu.SearchPattern = @"[\w\.]";
//
var items = new List<AutocompleteItem>();
foreach (var item in sources)
items.Add(new MethodAutocompleteItem2(item));
popupMenu.Items.SetAutocompleteItems(items);
}
}
/// <summary>
/// This autocomplete item appears after dot
/// </summary>
public class MethodAutocompleteItem2 : MethodAutocompleteItem
{
string firstPart;
string lastPart;
public MethodAutocompleteItem2(string text)
: base(text)
{
var i = text.LastIndexOf('.');
if (i < 0)
firstPart = text;
else
{
firstPart = text.Substring(0, i);
lastPart = text.Substring(i + 1);
}
}
public override CompareResult Compare(string fragmentText)
{
int i = fragmentText.LastIndexOf('.');
if (i < 0)
{
if (firstPart.StartsWith(fragmentText) && string.IsNullOrEmpty(lastPart))
return CompareResult.VisibleAndSelected;
//if (firstPart.ToLower().Contains(fragmentText.ToLower()))
// return CompareResult.Visible;
}
else
{
var fragmentFirstPart = fragmentText.Substring(0, i);
var fragmentLastPart = fragmentText.Substring(i + 1);
if (firstPart != fragmentFirstPart)
return CompareResult.Hidden;
if (lastPart != null && lastPart.StartsWith(fragmentLastPart))
return CompareResult.VisibleAndSelected;
if (lastPart != null && lastPart.ToLower().Contains(fragmentLastPart.ToLower()))
return CompareResult.Visible;
}
return CompareResult.Hidden;
}
public override string GetTextForReplace()
{
if (lastPart == null)
return firstPart;
return firstPart + "." + lastPart;
}
public override string ToString()
{
if (lastPart == null)
return firstPart;
return lastPart;
}
}
}