-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPluginsTabPage.cs
138 lines (120 loc) · 4.39 KB
/
PluginsTabPage.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
136
137
138
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using Lucene.Net.LukeNet.Plugins;
using Lucene.Net.Index;
namespace Lucene.Net.LukeNet
{
[System.ComponentModel.ToolboxItem(true)]
//[Designer(typeof(System.Windows.Forms.Design.ScrollableControlDesigner))]
public partial class PluginsTabPage : TabPage
{
private List<LukePlugin> plugins = new List<LukePlugin>();
private Luke _luke;
public PluginsTabPage(Luke luke)
{
_luke = luke;
InitializeComponent();
}
private void lstPlugins_SelectedIndexChanged(object sender, System.EventArgs e)
{
LoadPluginTab((LukePlugin)plugins[lstPlugins.SelectedIndex]);
}
private void linkPluginURL_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
linkPluginURL.Links[linkPluginURL.Links.IndexOf(e.Link)].Visited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
public void LoadPlugins()
{
List<Type> pluginTypes = new List<Type>();
// try to find all plugins
try
{
Type[] types =
Lucene.Net.LukeNet.ClassFinder.ClassFinder.GetInstantiableSubtypes(typeof(LukePlugin));
foreach (Type type in types)
{
pluginTypes.Add(type);
}
}
catch (Exception) { }
// load plugins declared in the ".plugins" file
try
{
StreamReader reader = new StreamReader(".plugins");
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("#")) continue;
if (line.Trim().Equals("")) continue;
Type t = Type.GetType(line, false);
if (t.IsSubclassOf(typeof(LukePlugin)) && !pluginTypes.Contains(t))
{
pluginTypes.Add(t);
}
}
}
catch (IOException)
{ }
foreach (Type pluginType in pluginTypes)
{
try
{
LukePlugin plugin = (LukePlugin)pluginType.GetConstructor(new Type[] { }).Invoke(new Object[] { });
plugins.Add(plugin);
}
catch (Exception)
{ }
}
if (plugins.Count == 0) return;
InitPlugins();
}
private void InitPlugins()
{
ClearPluginsUI();
foreach (LukePlugin plugin in plugins)
{
plugin.SetDirectory(_luke.Directory);
plugin.SetIndexReader(_luke.IndexReader);
try
{
plugin.Init();
plugin.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
}
catch (Exception e)
{
plugins.Remove(plugin);
_luke.ShowStatus("PLUGIN ERROR: " + e.Message);
MessageBox.Show("PLUGIN ERROR: " + e.Message);
}
lstPlugins.Items.Add(plugin.GetPluginName());
}
if (lstPlugins.Items.Count > 0)
{
lstPlugins.SelectedIndex = 0;
}
}
private void ClearPluginsUI()
{
lstPlugins.Items.Clear();
panelPlugin.Controls.Clear();
lblPluginInfo.Text = "";
linkPluginURL.Text = "";
linkPluginURL.Links.Clear();
}
private void LoadPluginTab(LukePlugin plugin)
{
lblPluginInfo.Text = plugin.GetPluginInfo();
linkPluginURL.Text = plugin.GetPluginHome();
linkPluginURL.Links.Clear();
linkPluginURL.Links.Add(0, linkPluginURL.Text.Length, linkPluginURL.Text);
plugin.Size = panelPlugin.Size;
panelPlugin.Controls.Clear();
panelPlugin.Controls.Add(plugin);
}
}
}