- Timestamp:
- 09/26/08 16:33:42 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.1/sources/HeuristicLab.PluginInfrastructure.GUI/ManagerForm.cs
r140 r604 34 34 namespace HeuristicLab.PluginInfrastructure.GUI { 35 35 public partial class ManagerForm : Form { 36 private TreeNode installedPlugins;37 private TreeNode availablePlugins;38 private TreeNode disabledPlugins;39 36 private List<PluginTag> allTags = new List<PluginTag>(); 40 37 private Dictionary<PluginTag, PluginAction> actions = new Dictionary<PluginTag, PluginAction>(); … … 44 41 private string backupDir = Application.StartupPath + "/" + HeuristicLab.PluginInfrastructure.GUI.Properties.Settings.Default.BackupDir; 45 42 private string tempDir = Application.StartupPath + "/" + HeuristicLab.PluginInfrastructure.GUI.Properties.Settings.Default.TempDir; 43 private const string AVAILABLE_PLUGINS = "Available plugins"; 44 private const string DISABLED_PLUGINS = "Disabled plugins"; 45 private const string INSTALLED_PLUGINS = "Installed plugins"; 46 46 47 47 public ManagerForm() { … … 51 51 52 52 private void InitializePlugins() { 53 pluginTreeView.Nodes.Clear(); 53 listView.View = View.Details; 54 listView.FullRowSelect = true; 55 listView.Items.Clear(); 54 56 allTags.Clear(); 55 57 actions.Clear(); … … 66 68 deleteMenuItem.Checked = false; 67 69 68 installedPlugins = new TreeNode("Installed plugins");69 installedPlugins.ImageIndex = 1;70 installedPlugins.SelectedImageIndex = 1;71 availablePlugins = new TreeNode("Available plugins");72 availablePlugins.ImageIndex = 1;73 availablePlugins.SelectedImageIndex = 1;74 disabledPlugins = new TreeNode("Disabled plugins");75 disabledPlugins.ImageIndex = 1;76 disabledPlugins.SelectedImageIndex = 1;77 78 pluginTreeView.Nodes.Add(installedPlugins);79 pluginTreeView.Nodes.Add(availablePlugins);80 pluginTreeView.Nodes.Add(disabledPlugins);81 82 70 foreach(PluginInfo pluginInfo in PluginManager.Manager.ActivePlugins) { 83 71 // create a new PluginAction tag for the plugin 84 72 PluginTag tag = new PluginTag(allTags, pluginInfo, PluginState.Installed); 85 73 allTags.Add(tag); 86 // add to "installed plugins" node 87 TreeNode installedPluginsNode = new TreeNode(pluginInfo.Name); 88 installedPluginsNode.ContextMenuStrip = pluginContextMenuStrip; 89 installedPluginsNode.Tag = tag; 90 installedPluginsNode.ImageIndex = 0; 91 installedPlugins.Nodes.Add(installedPluginsNode); 74 // add to "installed plugins" item 75 ListViewItem installedPluginsItem = new ListViewItem(pluginInfo.Name); 76 installedPluginsItem.Tag = tag; 77 installedPluginsItem.ImageIndex = 0; 78 installedPluginsItem.Group = listView.Groups[INSTALLED_PLUGINS]; 79 installedPluginsItem.SubItems.Add(pluginInfo.Version.ToString()); 80 listView.Items.Add(installedPluginsItem); 92 81 } 93 82 foreach(PluginInfo pluginInfo in PluginManager.Manager.DisabledPlugins) { 94 83 PluginTag tag = new PluginTag(allTags, pluginInfo, PluginState.Disabled); 95 84 allTags.Add(tag); 96 TreeNode disabledPluginsNode = new TreeNode(pluginInfo.Name); 97 disabledPluginsNode.ContextMenuStrip = pluginContextMenuStrip; 98 disabledPluginsNode.Tag = tag; 99 disabledPluginsNode.ImageIndex = 0; 100 disabledPlugins.Nodes.Add(disabledPluginsNode); 85 ListViewItem disabledPluginsItem = new ListViewItem(pluginInfo.Name); 86 disabledPluginsItem.Tag = tag; 87 disabledPluginsItem.ImageIndex = 0; 88 disabledPluginsItem.Group = listView.Groups[DISABLED_PLUGINS]; 89 disabledPluginsItem.SubItems.Add(pluginInfo.Version.ToString()); 90 listView.Items.Add(disabledPluginsItem); 101 91 } 102 92 … … 111 101 PluginTag tag = new PluginTag(allTags, plugin, PluginState.Available); 112 102 allTags.Add(tag); 113 TreeNode availableNode = new TreeNode(plugin.Name); 114 availableNode.ContextMenuStrip = pluginContextMenuStrip; 115 availableNode.Tag = tag; 116 availableNode.ImageIndex = 0; 117 availablePlugins.Nodes.Add(availableNode); 103 ListViewItem availableItem = new ListViewItem(plugin.Name); 104 availableItem.Tag = tag; 105 availableItem.ImageIndex = 0; 106 availableItem.Group = listView.Groups[AVAILABLE_PLUGINS]; 107 availableItem.SubItems.Add(plugin.Version.ToString()); 108 listView.Items.Add(availableItem); 118 109 }); 119 110 upgrades.ForEach(delegate(PluginDescription upgrade) { … … 135 126 currentPlugin.PluginDescription = overridingPlugin; 136 127 }); 137 toolStripStatusLabel.Text = "Installed: " + installedPlugins.Nodes.Count + " Updates: " + upgrades.Count + " Available: " + availablePlugins.Nodes.Count; 128 toolStripStatusLabel.Text = "Installed: " + listView.Groups[INSTALLED_PLUGINS].Items.Count + 129 " Updates: " + upgrades.Count + " Available: " + listView.Groups[AVAILABLE_PLUGINS].Items.Count; 138 130 RebuildActionHulls(); 139 pluginTreeView.Sort(); 131 132 listView.Sort(); 140 133 } 141 134 … … 146 139 147 140 private void publishButton_Click(object sender, EventArgs args) { 148 PluginInfo plugin = ((PluginTag)pluginTreeView.SelectedNode.Tag).Plugin; 149 publishPlugin(plugin); 150 } 151 152 private void publishPlugin(PluginInfo plugin) { 141 if(listView.SelectedItems.Count == 0) return; 142 List<PluginInfo> plugins = new List<PluginInfo>(); 143 foreach(ListViewItem item in listView.SelectedItems) { 144 plugins.Add(((PluginTag)item.Tag).Plugin); 145 } 146 PublishPlugin(plugins); 147 } 148 149 private void PublishPlugin(List<PluginInfo> plugins) { 150 StringBuilder xmlEntries = new StringBuilder(); 153 151 try { 154 string packageFileName = plugin.Name + "-" + plugin.Version + ".zip"; 155 ZipFile zipFile = ZipFile.Create(packageFileName); 156 zipFile.NameTransform = new PluginNameTransform(); 157 zipFile.BeginUpdate(); 158 159 infoTextBox.Text = "Publishing plugin:\nCreating " + packageFileName + "...\n"; 160 foreach(string filename in plugin.Files) { 161 infoTextBox.Text += "Adding " + filename + "\n"; 162 zipFile.Add(filename); 163 } 164 165 zipFile.CommitUpdate(); 166 zipFile.Close(); 167 FileInfo fileInfo = new FileInfo(packageFileName); 168 infoTextBox.Text += "\nCreated " + packageFileName + " (" + fileInfo.Length + " bytes)\n"; 169 infoTextBox.Text += "Upload this file to your plugin source and add the following entry to" + 152 infoTextBox.Text = "Publishing plugin:\n"; 153 foreach(PluginInfo plugin in plugins) { 154 string packageFileName = plugin.Name + "-" + plugin.Version + ".zip"; 155 ZipFile zipFile = ZipFile.Create(packageFileName); 156 zipFile.NameTransform = new PluginNameTransform(); 157 zipFile.BeginUpdate(); 158 159 infoTextBox.Text+="Creating " + packageFileName + "...\n"; 160 foreach(string filename in plugin.Files) { 161 infoTextBox.Text += "Adding " + filename + "\n"; 162 zipFile.Add(filename); 163 } 164 165 zipFile.CommitUpdate(); 166 zipFile.Close(); 167 FileInfo fileInfo = new FileInfo(packageFileName); 168 infoTextBox.Text += "Created " + packageFileName + " (" + fileInfo.Length + " bytes)\n"; 169 xmlEntries.Append(" <Plugin Name=\"").Append(plugin.Name).Append("\" Version=\"").Append(plugin.Version) 170 .Append("\" Build=\"").Append(plugin.BuildDate.ToUniversalTime().ToString(System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat)) 171 .Append("\">").AppendLine(); 172 foreach(PluginInfo dependency in plugin.Dependencies) { 173 xmlEntries.Append(" <Dependency Name=\"").Append(dependency.Name).Append("\" />").AppendLine(); 174 } 175 xmlEntries.Append(" </Plugin>").AppendLine(); 176 } 177 178 infoTextBox.Text += "Upload the zip files to your plugin source and add the following to" + 170 179 " the file plugins.xml residing in the base directory of your plugin source.\n\n"; 171 infoTextBox.Text += " <Plugin Name=\"" + plugin.Name + "\" Version=\"" 172 + plugin.Version + "\" Build=\"" + plugin.BuildDate.ToUniversalTime().ToString(System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat) + "\">\n"; 173 foreach(PluginInfo dependency in plugin.Dependencies) { 174 infoTextBox.Text += " <Dependency Name=\"" + dependency.Name + "\" />\n"; 175 } 176 infoTextBox.Text += " </Plugin>"; 180 infoTextBox.Text += xmlEntries.ToString(); 177 181 } catch(Exception exception) { 178 182 infoTextBox.Text += "\nThere was an error!\n" + exception; … … 337 341 338 342 // update the GUI to represent new state of the selected plugin 339 if(pluginTreeView.SelectedNode != null && pluginTreeView.SelectedNode.Tag is PluginTag) { 340 UpdateActionButtons((PluginTag)pluginTreeView.SelectedNode.Tag); 341 DisplayPluginInfo(((PluginTag)pluginTreeView.SelectedNode.Tag).GetPluginDetails()); 342 } 343 } 344 345 343 if(listView.SelectedItems.Count>0 && listView.SelectedItems[0].Tag is PluginTag) { 344 UpdateActionButtons((PluginTag)listView.SelectedItems[0].Tag); 345 DisplayPluginInfo(((PluginTag)listView.SelectedItems[0].Tag).GetPluginDetails()); 346 } 347 } 346 348 347 349 private void MarkInstall(PluginTag actionTag) { … … 421 423 newAction.Hull = hull; 422 424 newAction.Hull.Add(actionTag); 423 424 425 425 actions[actionTag] = newAction; 426 426 UpdateTreeNodes(newAction.Hull); … … 542 542 private void UpdateTreeNodes(List<PluginTag> hull) { 543 543 hull.ForEach(delegate(PluginTag tag) { 544 FindPlugin Nodes(tag).ForEach(delegate(TreeNode node) {544 FindPluginItems(tag).ForEach(delegate(ListViewItem item) { 545 545 ManagerAction action = GetAction(tag); 546 546 if(action != ManagerAction.None) { 547 node.Text = tag.PluginName + " - Action: " + action;547 item.Text = tag.PluginName + " - Action: " + action; 548 548 if(action == ManagerAction.Remove) { 549 node.ImageIndex = 3; 550 node.SelectedImageIndex = 3; 549 item.ImageIndex = 3; 551 550 } else if(action == ManagerAction.Install) { 552 node.ImageIndex = 2; 553 node.SelectedImageIndex = 2; 551 item.ImageIndex = 2; 554 552 } 555 553 } else if(tag.State == PluginState.Upgradeable) { 556 node.Text = tag.PluginName + " - Upgrade: " + tag.PluginVersion + " -> " + tag.UpgradePluginDescription.Version; 557 node.ImageIndex = 2; 558 node.SelectedImageIndex = 2; 554 item.Text = tag.PluginName + " - Upgrade: " + tag.PluginVersion + " -> " + tag.UpgradePluginDescription.Version; 555 item.ImageIndex = 2; 559 556 } else { 560 node.Text = tag.PluginName; 561 node.ImageIndex = 0; 562 node.SelectedImageIndex = 0; 557 item.Text = tag.PluginName; 558 item.ImageIndex = 0; 563 559 } 564 560 }); … … 604 600 } 605 601 606 private List< TreeNode> FindPluginNodes(PluginTag pluginTag) {607 List< TreeNode> nodes = new List<TreeNode>();608 foreach( TreeNode rootNode in new TreeNode[] { installedPlugins, availablePlugins, disabledPlugins }) {609 foreach( TreeNode node in rootNode.Nodes) {610 if(pluginTag.Equals( node.Tag)) {611 nodes.Add(node);612 } 613 } 614 } 615 return nodes;602 private List<ListViewItem> FindPluginItems(PluginTag pluginTag) { 603 List<ListViewItem> items = new List<ListViewItem>(); 604 foreach(ListViewGroup group in listView.Groups) { 605 foreach(ListViewItem item in group.Items) { 606 if(pluginTag.Equals(item.Tag)) { 607 items.Add(item); 608 } 609 } 610 } 611 return items; 616 612 } 617 613 private void DisplayPluginInfo(string pluginInformation) { … … 889 885 890 886 private void removeButton_Clicked(object sender, EventArgs e) { 891 // get the tag of the selected treeNode892 PluginTag actionTag = (PluginTag) pluginTreeView.SelectedNode.Tag;887 // get the tag of the selected listViewItem 888 PluginTag actionTag = (PluginTag)listView.SelectedItems[0].Tag; 893 889 List<PluginAction> rootActions = GetActionsInvolving(actionTag); 894 890 if(rootActions.Count > 0) { … … 905 901 906 902 private void installButton_Clicked(object sender, EventArgs e) { 907 // get the tag of the selected treeNode908 PluginTag actionTag = (PluginTag) pluginTreeView.SelectedNode.Tag;903 // get the tag of the selected listViewItem 904 PluginTag actionTag = (PluginTag)listView.SelectedItems[0].Tag; 909 905 List<PluginAction> rootActions = GetActionsInvolving(actionTag); 910 906 … … 936 932 937 933 InitializePlugins(); 938 }939 940 private void pluginTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e) {941 if(e.Node.Tag != null) {942 943 UpdateActionButtons((PluginTag)e.Node.Tag);944 // display the plugin details in the lower pane945 DisplayPluginInfo(((PluginTag)e.Node.Tag).GetPluginDetails());946 947 } else {948 // when a node was selected that doesn't represent a plugin (root node) then install and remove are not possible949 publishButton.Enabled = false;950 installButton.Enabled = false;951 deleteButton.Enabled = false;952 }953 }954 955 private void pluginTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {956 // dumb solution to automatically select the node on right clicks which opens the context menu because957 // per default the treeview doesn't select nodes on right click958 if(e.Button == MouseButtons.Right) {959 pluginTreeView.SelectedNode = e.Node;960 }961 934 } 962 935 … … 1002 975 } 1003 976 1004 private void pluginTreeView_KeyPress(object sender, KeyPressEventArgs e) { 1005 e.Handled = true; 1006 if(e.KeyChar == 'i' && installButton.Enabled) { 977 private void pluginTreeView_KeyDown(object sender, KeyEventArgs e) { 978 if(e.KeyData == Keys.I && installButton.Enabled) { 979 e.Handled = true; 980 e.SuppressKeyPress = true; 1007 981 installButton_Clicked(sender, e); 1008 } else if(e.KeyChar == 'd' && deleteButton.Enabled) { 982 } else if((e.KeyData == Keys.D || e.KeyData == Keys.Delete) && deleteButton.Enabled) { 983 e.Handled = true; 984 e.SuppressKeyPress = true; 1009 985 removeButton_Clicked(sender, e); 986 } 987 } 988 989 private void listView_MouseDown(object sender, MouseEventArgs e) { 990 // dumb solution to automatically select the node on right clicks which opens the context menu because 991 // per default the treeview doesn't select nodes on right click 992 if(e.Button == MouseButtons.Right) { 993 listView.GetItemAt(e.X, e.Y).Selected = true; 994 } 995 } 996 997 private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { 998 if(e.Item.Tag != null && e.IsSelected) { 999 UpdateActionButtons((PluginTag)e.Item.Tag); 1000 // display the plugin details in the lower pane 1001 DisplayPluginInfo(((PluginTag)e.Item.Tag).GetPluginDetails()); 1002 } else { 1003 // when an item was 'unselected' or was selected but doesn't represent a plugin then install and remove are not possible 1004 publishButton.Enabled = false; 1005 installButton.Enabled = false; 1006 deleteButton.Enabled = false; 1010 1007 } 1011 1008 }
Note: See TracChangeset
for help on using the changeset viewer.