forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFRDialogGenerics.cs
More file actions
135 lines (126 loc) · 4.59 KB
/
FRDialogGenerics.cs
File metadata and controls
135 lines (126 loc) · 4.59 KB
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PluginCore.FRService;
using ScintillaNet;
namespace FlashDevelop.Utilities
{
class FRDialogGenerics
{
/// <summary>
/// Gets the dialog icon
/// </summary>
public static Image GetImage(Int32 img)
{
Image image;
if (img == 1) image = Globals.MainForm.FindImage("196");
else if (img == 2) image = Globals.MainForm.FindImage("197");
else image = Globals.MainForm.FindImage("229");
return image;
}
/// <summary>
/// Adds the value to ComboBox items
/// </summary>
public static void UpdateComboBoxItems(ComboBox comboBox)
{
if (!comboBox.Items.Contains(comboBox.Text))
{
comboBox.Items.Insert(0, comboBox.Text);
comboBox.SelectedIndex = 0;
}
}
/// <summary>
/// Gets an index of the search match
/// </summary>
public static Int32 GetMatchIndex(SearchMatch match, List<SearchMatch> matches)
{
for (Int32 i = 0; i < matches.Count; i++)
{
if (match == matches[i]) return i + 1;
}
return -1;
}
/// <summary>
/// Selects a search match
/// </summary>
public static void SelectMatch(ScintillaControl sci, SearchMatch match)
{
Int32 start = sci.MBSafePosition(match.Index); // wchar to byte position
Int32 end = start + sci.MBSafeTextLength(match.Value); // wchar to byte text length
Int32 line = sci.LineFromPosition(start);
sci.EnsureVisible(line);
sci.SetSel(start, end);
}
/// <summary>
/// Bookmarks a search match
/// </summary>
public static void BookmarkMatches(ScintillaControl sci, List<SearchMatch> matches)
{
for (Int32 i = 0; i < matches.Count; i++)
{
Int32 line = matches[i].Line - 1;
sci.EnsureVisible(line);
sci.MarkerAdd(line, 0);
}
}
/// <summary>
/// Filters the matches based on the start and end positions
/// </summary>
public static List<SearchMatch> FilterMatches(List<SearchMatch> matches, Int32 start, Int32 end)
{
List<SearchMatch> filtered = new List<SearchMatch>();
foreach (SearchMatch match in matches)
{
if (match.Index >= start && (match.Index + match.Length) <= end)
{
filtered.Add(match);
}
}
return filtered;
}
/// <summary>
/// Gets the next valid match but fixes position with selected text's length
/// </summary>
public static SearchMatch GetNextDocumentMatch(ScintillaControl sci, List<SearchMatch> matches, Boolean forward, Boolean fixedPosition)
{
SearchMatch nearestMatch = matches[0];
Int32 currentPosition = sci.MBSafeCharPosition(sci.CurrentPos);
if (fixedPosition) currentPosition -= sci.MBSafeTextLength(sci.SelText);
for (Int32 i = 0; i < matches.Count; i++)
{
if (forward)
{
if (currentPosition > matches[matches.Count - 1].Index)
{
return matches[0];
}
if (matches[i].Index >= currentPosition)
{
return matches[i];
}
}
else
{
if (sci.SelText.Length > 0 && currentPosition <= matches[0].Index + matches[0].Value.Length)
{
return matches[matches.Count - 1];
}
if (currentPosition < matches[0].Index + matches[0].Value.Length)
{
return matches[matches.Count - 1];
}
if (sci.SelText.Length == 0 && currentPosition == matches[i].Index + matches[i].Value.Length)
{
return matches[i];
}
if (matches[i].Index > nearestMatch.Index && matches[i].Index + matches[i].Value.Length < currentPosition)
{
nearestMatch = matches[i];
}
}
}
return nearestMatch;
}
}
}