1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.PluginInfrastructure;
|
---|
10 | using System.IO;
|
---|
11 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
14 | internal partial class PluginView : InstallationManagerControl {
|
---|
15 | private const string IMAGE_KEY_ASSEMBLY = "Assembly";
|
---|
16 | private const string IMAGE_KEY_FILE = "File";
|
---|
17 | private const string IMAGE_KEY_DOCUMENT = "Document";
|
---|
18 |
|
---|
19 | private PluginDescription plugin;
|
---|
20 |
|
---|
21 | public PluginView() {
|
---|
22 | InitializeComponent();
|
---|
23 | PopulateImageList();
|
---|
24 | }
|
---|
25 |
|
---|
26 | public PluginView(PluginDescription plugin) {
|
---|
27 | InitializeComponent();
|
---|
28 | PopulateImageList();
|
---|
29 |
|
---|
30 | this.plugin = plugin;
|
---|
31 | this.Name = "Plugin Details: " + plugin.ToString();
|
---|
32 | UpdateControls();
|
---|
33 | }
|
---|
34 |
|
---|
35 | private void PopulateImageList() {
|
---|
36 | imageList.Images.Add(IMAGE_KEY_ASSEMBLY, HeuristicLab.PluginInfrastructure.Resources.Resources.Assembly);
|
---|
37 | imageList.Images.Add(IMAGE_KEY_FILE, HeuristicLab.PluginInfrastructure.Resources.Resources.File);
|
---|
38 | imageList.Images.Add(IMAGE_KEY_DOCUMENT, HeuristicLab.PluginInfrastructure.Resources.Resources.Document);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void UpdateControls() {
|
---|
42 | string appDir = Path.GetDirectoryName(Application.ExecutablePath);
|
---|
43 | nameTextBox.Text = plugin.Name;
|
---|
44 | versionTextBox.Text = plugin.Version.ToString();
|
---|
45 | contactTextBox.Text = CombineStrings(plugin.ContactName, plugin.ContactEmail);
|
---|
46 | descriptionTextBox.Text = plugin.Description;
|
---|
47 | stateTextBox.Text = plugin.PluginState.ToString();
|
---|
48 | errorTextBox.Text = plugin.LoadingErrorInformation;
|
---|
49 | foreach (PluginDescription dependency in plugin.Dependencies) {
|
---|
50 | var depItem = new ListViewItem(new string[] { dependency.Name, dependency.Version.ToString() });
|
---|
51 | depItem.Tag = dependency;
|
---|
52 | depItem.ImageKey = IMAGE_KEY_ASSEMBLY;
|
---|
53 | dependenciesListView.Items.Add(depItem);
|
---|
54 | }
|
---|
55 | foreach (var file in plugin.Files) {
|
---|
56 | string displayedFileName = file.Name.Replace(appDir, string.Empty);
|
---|
57 | displayedFileName = displayedFileName.TrimStart(Path.DirectorySeparatorChar);
|
---|
58 | var fileItem = new ListViewItem(new string[] { displayedFileName, file.Type.ToString() });
|
---|
59 | if (file.Type == PluginFileType.Assembly) {
|
---|
60 | fileItem.ImageKey = IMAGE_KEY_ASSEMBLY;
|
---|
61 | } else if (file.Type == PluginFileType.License) {
|
---|
62 | fileItem.ImageKey = IMAGE_KEY_DOCUMENT;
|
---|
63 | } else fileItem.ImageKey = IMAGE_KEY_FILE;
|
---|
64 | filesListView.Items.Add(fileItem);
|
---|
65 | }
|
---|
66 | licenseButton.Enabled = !string.IsNullOrEmpty(plugin.LicenseText);
|
---|
67 | }
|
---|
68 |
|
---|
69 | private string CombineStrings(string a, string b) {
|
---|
70 | if (string.IsNullOrEmpty(a))
|
---|
71 | // a is empty
|
---|
72 | if (!string.IsNullOrEmpty(b)) return CombineStrings(b, string.Empty);
|
---|
73 | else return string.Empty;
|
---|
74 | // a is not empty
|
---|
75 | else if (string.IsNullOrEmpty(b)) return a;
|
---|
76 | // and b are not empty
|
---|
77 | else return a + ", " + b;
|
---|
78 | }
|
---|
79 |
|
---|
80 | private void licenseButton_Click(object sender, EventArgs e) {
|
---|
81 | LicenseView view = new LicenseView(plugin);
|
---|
82 | view.ShowInForm();
|
---|
83 | }
|
---|
84 |
|
---|
85 | private void dependenciesListView_ItemActivate(object sender, EventArgs e) {
|
---|
86 | if (dependenciesListView.SelectedItems.Count > 0) {
|
---|
87 | var dep = (PluginDescription)dependenciesListView.SelectedItems[0].Tag;
|
---|
88 | PluginView view = new PluginView(dep);
|
---|
89 | view.ShowInForm();
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|