-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathViewForm.cs
135 lines (115 loc) · 3.65 KB
/
ViewForm.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
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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace gta5refactor
{
public partial class ViewForm : Form
{
bool ScrollSelection = false;
int FindCharStart = 0;
public ViewForm()
{
InitializeComponent();
}
private void ViewForm_Load(object sender, EventArgs e)
{
FunctionTextBox.SetTabStopWidth(3);
}
public void LoadFunction(ScriptFunction func, int linesel, int charsel, int sellen)
{
Text = string.Format("{0}::{1}", func.File.Name, func.Name);
bool loaded = (func.File.FileLines != null);
if (!loaded)
{
func.File.Load();
}
int schar = 0;
int fchar = 0;
bool selit = false;
StringBuilder sb = new StringBuilder();
for (int i = func.StartLine; i <= func.EndLine; i++)
{
if (i == linesel)
{
schar = sb.Length;
}
sb.AppendLine(func.File.FileLines[i]);
if (i == linesel)
{
fchar = sb.Length - 1;
selit = true;
}
}
FunctionTextBox.Text = sb.ToString();
if (selit)
{
if (sellen > 0)
{
schar += charsel;
fchar = schar + sellen;
}
//FunctionTextBox.Select(schar, fchar - schar);
FunctionTextBox.SelectionStart = schar;
FunctionTextBox.SelectionLength = fchar - schar;
FunctionTextBox.ScrollToCaret();
ScrollSelection = true;
}
else
{
FunctionTextBox.SelectionStart = 0;
FunctionTextBox.SelectionLength = 0;
}
if (!loaded)
{
func.File.Unload(); //try save some memory
}
}
private void FunctionTextBox_Enter(object sender, EventArgs e)
{
if (ScrollSelection)
{
FunctionTextBox.ScrollToCaret();
ScrollSelection = false;
}
}
private void FindTextBox_TextChanged(object sender, EventArgs e)
{
FindCharStart = 0;
FindNext();
}
private void FindNextButton_Click(object sender, EventArgs e)
{
FindNext();
}
private void FindNext()
{
int schar = 0;
int fchar = 0;
string find = FindTextBox.Text;
if (find.Length > 0)
{
int found = FunctionTextBox.Text.IndexOf(find, FindCharStart, StringComparison.OrdinalIgnoreCase);
if (found < 0) //first try missed, try again from the beginning to allow wrap-around find next
{
FindCharStart = 0;
found = FunctionTextBox.Text.IndexOf(find, FindCharStart, StringComparison.OrdinalIgnoreCase);
}
if (found >= 0)
{
schar = found;
fchar = found + find.Length;
FindCharStart = fchar;
}
}
FunctionTextBox.SelectionStart = schar;
FunctionTextBox.SelectionLength = fchar - schar;
FunctionTextBox.ScrollToCaret();
}
}
}