HelpPanel.cs
2.9 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
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Help
{
internal class HelpPanel
{
internal Vector2 TextScroll;
internal bool Visible { get; private set; }
internal PlasticGui.Help.HelpImage Image
{
get { return mHelpImage; }
}
internal HelpData Data
{
get { return mHelpData; }
}
internal GUIContent GUIContent
{
get { return mHelpGUIContent; }
}
internal HelpPanel(EditorWindow window)
{
mWindow = window;
}
internal void Show(PlasticGui.Help.HelpImage helpImage, HelpData helpData)
{
ClearData();
UpdateData(helpImage, helpData);
Visible = true;
mWindow.Repaint();
}
internal void Hide()
{
ClearData();
Visible = false;
mWindow.Repaint();
}
internal bool TryGetLinkAtChar(
int charIndex,
out HelpLink link)
{
link = null;
FormattedHelpLink formattedLink = GetFormattedLinkAtChar(
mFormattedLinks, charIndex);
if (formattedLink == null)
return false;
link = formattedLink.Source;
return !BuildFormattedHelp.IsLinkMetaChar(formattedLink, charIndex);
}
void ClearData()
{
mHelpImage = PlasticGui.Help.HelpImage.GenericBuho;
mHelpData = null;
mHelpGUIContent = null;
mFormattedLinks = null;
}
void UpdateData(PlasticGui.Help.HelpImage helpImage, HelpData helpData)
{
mHelpImage = helpImage;
mHelpData = helpData;
string formattedHelpText;
BuildFormattedHelp.ForData(
mHelpData.CleanText,
mHelpData.FormattedBlocks.ToArray(),
mHelpData.Links.ToArray(),
out formattedHelpText,
out mFormattedLinks);
mHelpGUIContent = new GUIContent(formattedHelpText);
}
static FormattedHelpLink GetFormattedLinkAtChar(
List<FormattedHelpLink> formattedLinks, int charIndex)
{
for(int i = 0; i < formattedLinks.Count; i++)
{
FormattedHelpLink link = formattedLinks[i];
if (link.Position <= charIndex &&
charIndex < link.Position + link.Length)
return link;
if (charIndex <= link.Position + link.Length)
return null;
}
return null;
}
PlasticGui.Help.HelpImage mHelpImage;
HelpData mHelpData;
GUIContent mHelpGUIContent;
List<FormattedHelpLink> mFormattedLinks;
EditorWindow mWindow;
}
}