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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
|
//
// ListWidget.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Gdk;
using Gtk;
using Pango;
using MonoDevelop.Components;
using MonoDevelop.Ide.Fonts;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.Ide.Editor;
using System.ComponentModel.Design;
using MonoDevelop.Ide.Editor.Highlighting;
using MonoDevelop.Ide.Editor.Extension;
using MonoDevelop.Core;
using Xwt.Drawing;
using MonoDevelop.Ide.Gui;
using System.Threading.Tasks;
namespace MonoDevelop.Ide.CodeCompletion
{
[Obsolete ("Use the Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion APIs")]
public class CategorizedCompletionItems
{
public CompletionCategory CompletionCategory {
get;
set;
}
System.Collections.Generic.List<int> items = new System.Collections.Generic.List<int> ();
public List<int> Items {
get { return items; }
set { items = value; }
}
internal IListDataProvider DataProvider { get; set; }
}
[Obsolete ("Use the Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion APIs")]
public class CompletionListFilterInput
{
public ICompletionDataList DataList { get; }
public IReadOnlyList<int> FilteredItems { get; }
public string OldCompletionString { get; }
public string CompletionString { get; }
public CompletionListFilterInput (ICompletionDataList dataList, IReadOnlyList<int> filteredItems, string oldCompletionString, string completionString)
{
DataList = dataList;
FilteredItems = filteredItems;
OldCompletionString = oldCompletionString;
CompletionString = completionString;
}
}
[Obsolete ("Use the Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion APIs")]
public class CompletionListFilterResult
{
public readonly List<CategorizedCompletionItems> CategorizedItems;
public readonly List<int> FilteredItems;
public CompletionListFilterResult (List<int> filteredItems)
{
FilteredItems = filteredItems;
}
public CompletionListFilterResult (List<int> filteredItems, List<CategorizedCompletionItems> categorizedItems)
{
CategorizedItems = categorizedItems;
FilteredItems = filteredItems;
}
}
[Obsolete]
class ListWidget : Gtk.DrawingArea
{
const int minSize = 400;
const int maxListWidth = 800;
const int rows = 13;
const int marginIconSpacing = 4;
const int iconTextSpacing = 6;
const int itemSeparatorHeight = 2;
int listWidth = minSize;
int rowHeight;
Pango.Layout layout, categoryLayout, noMatchLayout;
CompletionListWindowGtk win;
FontDescription itemFont, noMatchFont, categoryFont;
Adjustment vadj;
int selection = 0;
bool buttonPressed;
List<CategorizedCompletionItems> categories = new List<CategorizedCompletionItems> ();
List<int> filteredItems = new List<int> ();
public event EventHandler SelectionChanged;
protected virtual void OnSelectionChanged (EventArgs e)
{
var handler = SelectionChanged;
if (handler != null)
handler (this, e);
}
public IListDataProvider DataProvider {
get;
set;
}
bool inCategoryMode;
public bool InCategoryMode {
get { return inCategoryMode; }
set {
inCategoryMode = value;
CalcVisibleRows ();
}
}
public Adjustment VAdjustment => vadj;
void SetFont ()
{
// TODO: Add font property to ICompletionWidget;
if (itemFont != null)
itemFont.Dispose ();
if (categoryFont != null)
categoryFont.Dispose ();
if (noMatchFont != null)
noMatchFont.Dispose ();
itemFont = FontService.MonospaceFont.Copy ();
categoryFont = FontService.SansFont.CopyModified (Styles.FontScale11);
noMatchFont = FontService.SansFont.CopyModified (Styles.FontScale11);
var newItemFontSize = itemFont.Size;
var newCategoryFontSize = categoryFont.Size;
var newNoMatchFontSize = noMatchFont.Size;
if (newItemFontSize > 0) {
itemFont.Size = (int)newItemFontSize;
layout.FontDescription = itemFont;
}
if (newCategoryFontSize > 0) {
categoryFont.Size = (int)newCategoryFontSize;
categoryLayout.FontDescription = categoryFont;
}
if (newNoMatchFontSize > 0) {
noMatchFont.Size = (int)newNoMatchFontSize;
noMatchLayout.FontDescription = noMatchFont;
}
}
public ListWidget (CompletionListWindowGtk win)
{
this.win = win;
this.Events = EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask;
categoryLayout = new Pango.Layout (this.PangoContext);
noMatchLayout = new Pango.Layout (this.PangoContext);
layout = new Pango.Layout (this.PangoContext);
layout.Wrap = Pango.WrapMode.Char;
SetFont ();
this.Show ();
}
protected override void OnDestroyed ()
{
base.OnDestroyed ();
if (layout != null) {
layout.Dispose ();
categoryLayout.Dispose ();
noMatchLayout.Dispose ();
layout = categoryLayout = noMatchLayout = null;
}
if (itemFont != null) {
itemFont.Dispose ();
itemFont = null;
}
}
protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
{
if (this.vadj != null)
this.vadj.ValueChanged -= HandleValueChanged;
this.vadj = vadj;
base.OnSetScrollAdjustments (hadj, vadj);
if (this.vadj != null) {
this.vadj.ValueChanged += HandleValueChanged;
SetAdjustments ();
}
}
void HandleValueChanged (object sender, EventArgs e)
{
QueueDraw ();
OnListScrolled (EventArgs.Empty);
}
public event EventHandler ListScrolled;
protected virtual void OnListScrolled (EventArgs e)
{
EventHandler handler = this.ListScrolled;
if (handler != null)
handler (this, e);
}
public void ResetState ()
{
categories.Clear ();
filteredItems.Clear ();
selection = 0;
listWidth = minSize;
}
public int SelectedItemIndex {
get {
if (selection < 0 || filteredItems.Count == 0)
return -1;
return selection;
}
set {
if (value != selection) {
selection = value;
ScrollToSelectedItem ();
OnSelectionChanged (EventArgs.Empty);
QueueDraw ();
}
}
}
int GetIndex (bool countCategories, int item)
{
int result = -1;
int yPos = 0;
int curItem = 0;
Iterate (false, ref yPos, delegate (CategorizedCompletionItems category, int ypos) {
if (countCategories)
curItem++;
}, delegate (CategorizedCompletionItems curCategory, int item2, int itemIndex, int ypos) {
if (item == item2) {
result = curItem;
return false;
}
curItem++;
return true;
});
return result;
}
int GetItem (bool countCategories, int index)
{
int result = -1;
int curItem = 0;
int yPos = 0;
Iterate (false, ref yPos, delegate (CategorizedCompletionItems category, int ypos) {
if (countCategories) {
if (curItem == index)
result = category.Items [0];
curItem++;
}
}, delegate (CategorizedCompletionItems curCategory, int item, int itemIndex, int ypos) {
if (curItem == index) {
result = item;
return false;
}
curItem++;
return true;
});
return result;
}
public void MoveCursor (int relative)
{
int newIndex = GetIndex (false, SelectedItemIndex) + relative;
newIndex = Math.Min (filteredItems.Count - 1, Math.Max (0, newIndex));
int newSelection = GetItem (false, newIndex);
if (newSelection < 0)
return;
if (SelectedItemIndex == newSelection && relative < 0) {
SelectedItemIndex = GetItem (false, 0);
} else {
SelectedItemIndex = newSelection;
}
}
public void ScrollToSelectedItem ()
{
ScrollToItem (SelectedItemIndex);
}
public void ScrollToItem (int item)
{
var area = GetRowArea (item);
double newValue;
if (vadj.PageSize == 1.0) {
newValue = Math.Min (vadj.Upper - vadj.PageSize, area.Y);
} else if (area.Y < vadj.Value) {
newValue = Math.Min (vadj.Upper - vadj.PageSize, area.Y);
} else if (vadj.Value + vadj.PageSize < area.Bottom) {
newValue = Math.Min (vadj.Upper - vadj.PageSize, area.Bottom - vadj.PageSize + 1);
} else {
return;
}
if (vadj.Upper <= vadj.PageSize) {
vadj.Value = 0;
} else {
vadj.Value = Math.Min (vadj.Upper, Math.Max (vadj.Lower, newValue));
}
}
bool selectionEnabled;
public bool SelectionEnabled {
get {
return selectionEnabled;
}
set {
selectionEnabled = value;
QueueDraw ();
}
}
protected override bool OnButtonPressEvent (EventButton e)
{
SelectedItemIndex = GetRowByPosition ((int)e.Y);
buttonPressed = true;
return base.OnButtonPressEvent (e);
}
protected override bool OnButtonReleaseEvent (EventButton e)
{
buttonPressed = false;
return base.OnButtonReleaseEvent (e);
}
protected override void OnRealized ()
{
base.OnRealized ();
this.GdkWindow.Background = this.Style.Base (StateType.Normal);
}
protected override bool OnMotionNotifyEvent (EventMotion e)
{
if (!buttonPressed)
return base.OnMotionNotifyEvent (e);
int winWidth, winHeight;
this.GdkWindow.GetSize (out winWidth, out winHeight);
SelectedItemIndex = GetRowByPosition ((int)e.Y);
return true;
}
string NoMatchesMsg {
get { return MonoDevelop.Core.GettextCatalog.GetString ("No completions found"); }
}
string NoSuggestionsMsg {
get { return MonoDevelop.Core.GettextCatalog.GetString ("No suggestions"); }
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
using (var context = Gdk.CairoHelper.Create (args.Window)) {
var scalef = GtkWorkarounds.GetScaleFactor (this);
context.LineWidth = 1;
var alloc = Allocation;
int width = alloc.Width;
int height = alloc.Height;
context.Rectangle (args.Area.X, args.Area.Y, args.Area.Width, args.Area.Height);
var backgroundColor = Styles.CodeCompletion.BackgroundColor.ToCairoColor ();
var textColor = Styles.CodeCompletion.TextColor.ToCairoColor ();
var categoryColor = Styles.CodeCompletion.CategoryColor.ToCairoColor ();
context.SetSourceColor (backgroundColor);
context.Fill ();
int xpos = iconTextSpacing;
int yPos = (int)-vadj.Value;
//when there are no matches, display a message to indicate that the completion list is still handling input
if (filteredItems.Count == 0) {
context.Rectangle (0, yPos, width, height - yPos);
context.SetSourceColor (backgroundColor);
context.Stroke ();
noMatchLayout.SetText (DataProvider.ItemCount == 0 ? NoSuggestionsMsg : NoMatchesMsg);
int lWidth, lHeight;
noMatchLayout.GetPixelSize (out lWidth, out lHeight);
context.SetSourceColor (textColor);
context.MoveTo ((width - lWidth) / 2, yPos + (height - lHeight - yPos) / 2 - lHeight / 2);
Pango.CairoHelper.ShowLayout (context, noMatchLayout);
return false;
}
Iterate (true, ref yPos, delegate (CategorizedCompletionItems category, int ypos) {
if (ypos >= height)
return;
if (ypos < -rowHeight)
return;
// window.DrawRectangle (this.Style.BackgroundGC (StateType.Insensitive), true, 0, yPos, width, rowHeight);
int x = 2;
if (category.CompletionCategory != null && !string.IsNullOrEmpty (category.CompletionCategory.Icon)) {
var icon = ImageService.GetIcon (category.CompletionCategory.Icon, IconSize.Menu);
context.DrawImage (this, icon, 0, ypos);
x = (int)icon.Width + 4;
}
context.Rectangle (0, ypos, Allocation.Width, rowHeight);
context.SetSourceColor (backgroundColor);
context.Fill ();
// layout.SetMarkup ("<span weight='bold' foreground='#AAAAAA'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
// window.DrawLayout (textGCInsensitive, x - 1, ypos + 1 + (rowHeight - py) / 2, layout);
// layout.SetMarkup ("<span weight='bold'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
categoryLayout.SetMarkup ((category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized"));
int px, py;
categoryLayout.GetPixelSize (out px, out py);
context.MoveTo (x, ypos + (rowHeight - py) / 2);
context.SetSourceColor (categoryColor);
Pango.CairoHelper.ShowLayout (context, categoryLayout);
}, delegate (CategorizedCompletionItems curCategory, int item, int itemidx, int ypos) {
if (ypos >= height)
return false;
if (ypos < -rowHeight)
return true;
const int categoryModeItemIndenting = 0;
if (InCategoryMode && curCategory != null && curCategory.CompletionCategory != null) {
xpos = iconTextSpacing + categoryModeItemIndenting;
} else {
xpos = iconTextSpacing;
}
bool drawIconAsSelected = SelectionEnabled && item == SelectedItemIndex;
string markup = DataProvider.HasMarkup (item) ? (DataProvider.GetMarkup (item) ?? "<null>") : GLib.Markup.EscapeText (DataProvider.GetText (item) ?? "<null>");
string description = DataProvider.GetDescription (item, drawIconAsSelected);
if (string.IsNullOrEmpty (description)) {
layout.SetMarkup (markup);
} else {
layout.SetMarkup (markup + " " + description);
}
string text = DataProvider.GetText (item);
if (!string.IsNullOrEmpty (text)) {
int [] matchIndices = DataProvider.GetHighlightedTextIndices(item);
if (matchIndices != null) {
Pango.AttrList attrList = layout.Attributes ?? new Pango.AttrList ();
for (int newSelection = 0; newSelection < matchIndices.Length; newSelection++) {
int idx = matchIndices [newSelection];
var bold = new AttrWeight (Weight.Bold);
bold.StartIndex = (uint)idx;
bold.EndIndex = (uint)(idx + 1);
attrList.Insert (bold);
if (item != SelectedItemIndex) {
var highlightColor = (item == SelectedItemIndex) ? Styles.CodeCompletion.SelectionHighlightColor : Styles.CodeCompletion.HighlightColor;
var fg = new AttrForeground ((ushort)(highlightColor.Red * ushort.MaxValue), (ushort)(highlightColor.Green * ushort.MaxValue), (ushort)(highlightColor.Blue * ushort.MaxValue));
fg.StartIndex = (uint)idx;
fg.EndIndex = (uint)(idx + 1);
attrList.Insert (fg);
}
}
layout.Attributes = attrList;
}
}
Xwt.Drawing.Image icon = DataProvider.GetIcon (item);
int iconHeight, iconWidth;
if (icon != null) {
if (drawIconAsSelected)
icon = icon.WithStyles ("sel");
iconWidth = (int)icon.Width;
iconHeight = (int)icon.Height;
} else if (!Gtk.Icon.SizeLookup (IconSize.Menu, out iconWidth, out iconHeight)) {
iconHeight = iconWidth = 24;
}
int wi, he, typos, iypos;
layout.GetPixelSize (out wi, out he);
typos = he < rowHeight ? ypos + (int)Math.Ceiling ((rowHeight - he) / 2.0) : ypos;
if (scalef <= 1.0)
typos -= 1; // 1px up on non HiDPI
iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
if (item == SelectedItemIndex) {
var barStyle = SelectionEnabled ? Styles.CodeCompletion.SelectionBackgroundColor : Styles.CodeCompletion.SelectionBackgroundInactiveColor;
context.SetSourceColor (barStyle.ToCairoColor ());
if (SelectionEnabled) {
context.Rectangle (0, ypos, Allocation.Width, rowHeight);
context.Fill ();
} else {
context.LineWidth++;
context.Rectangle (0.5, ypos + 0.5, Allocation.Width - 1, rowHeight - 1);
context.Stroke ();
context.LineWidth--;
}
}
if (icon != null) {
context.DrawImage (this, icon, xpos, iypos);
xpos += iconTextSpacing;
}
context.SetSourceColor ((drawIconAsSelected ? Styles.CodeCompletion.SelectionTextColor : Styles.CodeCompletion.TextColor).ToCairoColor ());
var textXPos = xpos + iconWidth + 2;
context.MoveTo (textXPos, typos);
layout.Width = (int)((Allocation.Width - textXPos) * Pango.Scale.PangoScale);
layout.Ellipsize = EllipsizeMode.End;
Pango.CairoHelper.ShowLayout (context, layout);
int textW, textH;
layout.GetPixelSize (out textW, out textH);
layout.Width = -1;
layout.Ellipsize = EllipsizeMode.None;
layout.SetMarkup ("");
if (layout.Attributes != null) {
layout.Attributes.Dispose ();
layout.Attributes = null;
}
string rightText = DataProvider.GetRightSideDescription (item, drawIconAsSelected);
if (!string.IsNullOrEmpty (rightText)) {
layout.SetMarkup (rightText);
int w, h;
layout.GetPixelSize (out w, out h);
const int leftpadding = 8;
const int rightpadding = 3;
w += rightpadding;
w = Math.Min (w, Allocation.Width - textXPos - textW - leftpadding);
wi += w;
typos = h < rowHeight ? ypos + (rowHeight - h) / 2 : ypos;
if (scalef <= 1.0)
typos -= 1; // 1px up on non HiDPI
context.MoveTo (Allocation.Width - w, typos);
layout.Width = (int)(w * Pango.Scale.PangoScale);
layout.Ellipsize = EllipsizeMode.End;
Pango.CairoHelper.ShowLayout (context, layout);
layout.Width = -1;
layout.Ellipsize = EllipsizeMode.None;
}
if (Math.Min (maxListWidth, wi + xpos + iconWidth + 2) > listWidth) {
WidthRequest = listWidth = Math.Min (maxListWidth, wi + xpos + iconWidth + 2 + iconTextSpacing);
win.ResetSizes ();
} else {
//workaround for the vscrollbar display - the calculated width needs to be the width ofthe render region.
if (Allocation.Width < listWidth) {
if (listWidth - Allocation.Width < 30) {
WidthRequest = listWidth + listWidth - Allocation.Width;
win.ResetSizes ();
}
}
}
return true;
});
return false;
}
}
public int TextOffset {
get {
int iconWidth, iconHeight;
if (!Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out iconWidth, out iconHeight))
iconHeight = iconWidth = 16;
var xSpacing = marginIconSpacing + iconTextSpacing;
return iconWidth + xSpacing + 5;
}
}
public void ShowFilteredItems (CompletionListFilterResult filterResult)
{
filteredItems = filterResult.FilteredItems;
if (filterResult.CategorizedItems == null) {
categories.Clear ();
} else {
categories = filterResult.CategorizedItems;
}
CalcVisibleRows ();
SetAdjustments ();
QueueDraw ();
}
void SetAdjustments (bool scrollToSelectedItem = true)
{
if (vadj == null)
return;
int viewableCats = InCategoryMode ? categories.Count + 1 : 0;
if (InCategoryMode && categories.Any (cat => cat.CompletionCategory == null))
viewableCats--;
var upper = Math.Max (Allocation.Height, (filteredItems.Count + viewableCats) * rowHeight);
if (upper != vadj.Upper || Allocation.Height != vadj.PageSize) {
vadj.SetBounds (0, upper, rowHeight, Allocation.Height, Allocation.Height);
if (vadj.Upper <= Allocation.Height)
vadj.Value = 0;
}
if (scrollToSelectedItem)
ScrollToSelectedItem ();
}
int GetRowByPosition (int ypos)
{
return GetItem (true, ((int)vadj.Value + ypos) / rowHeight);
}
public Gdk.Rectangle GetRowArea (int row)
{
int outpos = 0;
int yPos = 0;
Iterate (false, ref yPos, delegate (CategorizedCompletionItems category, int ypos) {
}, delegate (CategorizedCompletionItems curCategory, int item, int itemIndex, int ypos) {
if (item == row) {
outpos = ypos;
return false;
}
return true;
});
return new Gdk.Rectangle (0, outpos, Allocation.Width, rowHeight);
}
protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
base.OnSizeAllocated (allocation);
SetAdjustments (false);
}
protected override void OnSizeRequested (ref Requisition requisition)
{
base.OnSizeRequested (ref requisition);
requisition.Width = listWidth;
if (rowHeight > 0)
requisition.Height += requisition.Height % rowHeight;
}
void CalcVisibleRows ()
{
var icon = ImageService.GetIcon (TypeSystem.Stock.Namespace, IconSize.Menu);
rowHeight = Math.Max (1, (int)icon.Height + 2);
int newHeight = rowHeight * rows;
if (Allocation.Width != listWidth || Allocation.Height != newHeight)
this.SetSizeRequest (listWidth, newHeight);
SetAdjustments ();
}
const int spacing = 2;
EditorTheme EditorTheme => SyntaxHighlightingService.GetEditorTheme (IdeApp.Preferences.ColorScheme);
delegate void CategoryAction (CategorizedCompletionItems category, int yPos);
delegate bool ItemAction (CategorizedCompletionItems curCategory, int item, int itemIndex, int yPos);
void Iterate (bool startAtPage, ref int ypos, CategoryAction catAction, ItemAction action)
{
int curItem = 0;
if (InCategoryMode) {
foreach (CategorizedCompletionItems category in this.categories) {
var nextYPos = ypos + rowHeight;
// if (!startAtPage || nextYPos >= vadj.Value) {
if (catAction != null)
catAction (category, ypos);
// }
ypos = nextYPos;
curItem++;
bool result = IterateItems (category, startAtPage,ref ypos, ref curItem, action);
if (!result)
break;
}
} else {
int startItem = 0;
if (startAtPage)
startItem = curItem = Math.Max (0, (int)(ypos / rowHeight));
if (action != null) {
for (int item = startItem; item < filteredItems.Count; item++) {
bool result = action (null, filteredItems[item], curItem, ypos);
if (!result)
break;
ypos += rowHeight;
curItem++;
}
} else {
int itemCount = (filteredItems.Count - startItem);
ypos += rowHeight * itemCount;
curItem += itemCount;
}
}
}
bool IterateItems (CategorizedCompletionItems category, bool startAtPage, ref int ypos, ref int curItem, ItemAction action)
{
foreach (int item in category.Items) {
var nextYpos = ypos + rowHeight;
// if (!startAtPage || nextYpos >= vadj.Value) {
if (action != null) {
bool result = action (category, item, curItem, ypos);
if (!result)
return false;
}
// }
ypos = nextYpos;
curItem++;
}
return true;
}
}
}
|