131
132
list.CompletionString = PartialWord;
133
if (list.filteredItems.Count == 0 && !list.PreviewCompletionString) {
136
if (IsRealized && !Visible)
134
if (IsRealized && !Visible)
140
137
int width = list.WidthRequest;
141
138
int height = list.HeightRequest + (footer != null ? footer.Allocation.Height : 0);
242
/// Gets or sets a value indicating that shift was pressed during enter.
245
/// <c>true</c> if was shift pressed; otherwise, <c>false</c>.
247
public bool WasShiftPressed {
244
252
public KeyActions ProcessKey (Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
247
255
case Gdk.Key.Home:
256
if ((modifier & ModifierType.ShiftMask) == ModifierType.ShiftMask)
257
return KeyActions.Process;
248
258
List.Selection = 0;
249
259
return KeyActions.Ignore;
250
260
case Gdk.Key.End:
261
if ((modifier & ModifierType.ShiftMask) == ModifierType.ShiftMask)
262
return KeyActions.Process;
251
263
List.Selection = List.filteredItems.Count - 1;
252
264
return KeyActions.Ignore;
293
305
return KeyActions.Ignore;
295
307
case Gdk.Key.Page_Up:
308
if ((modifier & ModifierType.ShiftMask) == ModifierType.ShiftMask)
309
return KeyActions.Process;
296
310
if (list.filteredItems.Count < 2)
297
311
return KeyActions.CloseWindow | KeyActions.Process;
298
312
list.MoveCursor (-(list.VisibleRows - 1));
299
313
return KeyActions.Ignore;
301
315
case Gdk.Key.Page_Down:
316
if ((modifier & ModifierType.ShiftMask) == ModifierType.ShiftMask)
317
return KeyActions.Process;
302
318
if (list.filteredItems.Count < 2)
303
319
return KeyActions.CloseWindow | KeyActions.Process;
304
320
list.MoveCursor (list.VisibleRows - 1);
367
384
& modifier) != 0;
368
385
if (nonShiftModifierActive)
369
386
return KeyActions.Ignore;
370
const string commitChars = " <>()[]{}=";
387
const string commitChars = " <>()[]{}=+-*/%~&|!";
371
388
if (System.Char.IsLetterOrDigit (keyChar) || keyChar == '_') {
372
389
word.Insert (curPos, keyChar);
381
398
bool hasMismatches;
382
399
int match = FindMatchedEntry (CurrentPartialWord, out hasMismatches);
400
if (match >= 0 && System.Char.IsPunctuation (keyChar)) {
401
string text = DataProvider.GetCompletionText (FilteredItems [match]);
402
if (!text.ToUpper ().StartsWith (word.ToString ().ToUpper ()))
384
405
if (match >= 0 && !hasMismatches && keyChar != '<') {
386
407
UpdateWordSelection ();
409
434
class WordComparer : IComparer <KeyValuePair<int, string>>
411
436
string filterWord;
437
StringMatcher matcher;
413
439
public WordComparer (string filterWord)
415
441
this.filterWord = filterWord ?? "";
442
matcher = CompletionMatcher.CreateCompletionMatcher (filterWord);
418
445
public int Compare (KeyValuePair<int, string> xpair, KeyValuePair<int, string> ypair)
420
447
string x = xpair.Value;
421
448
string y = ypair.Value;
422
int[] xMatches = ListWidget.Match (filterWord, x) ?? new int[0];
423
int[] yMatches = ListWidget.Match (filterWord, y) ?? new int[0];
449
int[] xMatches = matcher.GetMatch (x) ?? new int[0];
450
int[] yMatches = matcher.GetMatch (y) ?? new int[0];
424
451
if (xMatches.Length < yMatches.Length)
426
453
if (xMatches.Length > yMatches.Length)
459
486
// default - word with highest match rating in the list.
460
487
hasMismatches = true;
488
if (partialWord == null)
463
List<KeyValuePair<int, string>> words = new List<KeyValuePair<int, string>> ();
492
var matcher = CompletionMatcher.CreateCompletionMatcher (partialWord);
494
string bestWord = null;
495
int bestRank = int.MinValue;
464
498
if (!string.IsNullOrEmpty (partialWord)) {
465
499
for (int i = 0; i < list.filteredItems.Count; i++) {
466
500
int index = list.filteredItems[i];
467
501
string text = DataProvider.GetCompletionText (index);
468
if (!ListWidget.Matches (partialWord, text))
503
if (!matcher.CalcMatchRank (text, out rank))
470
words.Add (new KeyValuePair <int,string> (i, text));
505
if (rank > bestRank) {
474
ListWindow.WordComparer comparer = new WordComparer (partialWord);
475
if (words.Count > 0) {
476
words.Sort (comparer);
513
if (bestWord != null) {
478
515
hasMismatches = false;
479
516
// exact match found.
480
if (words[0].Value.ToUpper () == (partialWord ?? "").ToUpper ())
517
if (string.Compare (bestWord, partialWord ?? "", true) == 0)
484
521
if (string.IsNullOrEmpty (partialWord) || partialWord.Length <= 2) {
485
522
// Search for history matches.
486
for (int i = 0; i < wordHistory.Count; i++) {
487
string historyWord = wordHistory[i];
488
if (ListWidget.Matches (partialWord, historyWord)) {
489
for (int xIndex = 0; xIndex < list.filteredItems.Count; xIndex++) {
490
string currentWord = DataProvider.GetCompletionText (list.filteredItems[xIndex]);
491
if (currentWord == historyWord) {
524
if (wordHistory.TryGetValue (partialWord, out historyWord)) {
525
for (int xIndex = 0; xIndex < list.filteredItems.Count; xIndex++) {
526
string currentWord = DataProvider.GetCompletionText (list.filteredItems[xIndex]);
527
if (currentWord == historyWord) {
502
static List<string> wordHistory = new List<string> ();
537
static Dictionary<string,string> wordHistory = new Dictionary<string,string> ();
538
static List<string> partalWordHistory = new List<string> ();
503
539
const int maxHistoryLength = 500;
504
protected void AddWordToHistory (string word)
540
protected void AddWordToHistory (string partialWord, string word)
506
if (!wordHistory.Contains (word)) {
507
wordHistory.Add (word);
508
while (wordHistory.Count > maxHistoryLength)
509
wordHistory.RemoveAt (0);
542
if (!wordHistory.ContainsKey (partialWord)) {
543
wordHistory.Add (partialWord, word);
544
partalWordHistory.Add (partialWord);
545
while (partalWordHistory.Count > maxHistoryLength) {
546
string first = partalWordHistory [0];
547
partalWordHistory.RemoveAt (0);
548
wordHistory.Remove (first);
511
wordHistory.Remove (word);
512
wordHistory.Add (word);
551
partalWordHistory.Remove (partialWord);
552
partalWordHistory.Add (partialWord);
553
wordHistory [partialWord] = word;
515
556
public static void ClearHistory ()
517
558
wordHistory.Clear ();
559
partalWordHistory.Clear ();
520
562
void SelectEntry (int n)