⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 managerform.cs

📁 SharpDevelop2.0.0 c#开发免费工具
💻 CS
📖 第 1 页 / 共 3 页
字号:
			
			// add new addins
			if (mode != ShowDependencyMode.Disable) {
				foreach (AddIn addIn in addIns) {
					if (mode == ShowDependencyMode.CancelUpdate && !addIn.Enabled) {
						continue;
					}
					foreach (KeyValuePair<string, Version> pair in addIn.Manifest.Identities) {
						addInDict[pair.Key] = pair.Value;
					}
					foreach (AddInReference dep in addIn.Manifest.Dependencies) {
						if (!dependencies.Contains(dep))
							dependencies.Add(dep);
					}
				}
			}
			
			// add dependencies to the to-be-changed addins
			foreach (AddIn addIn in AddInTree.AddIns) {
				if (addIn.Action != AddInAction.Enable && addIn.Action != AddInAction.Install)
					continue;
				if (addIns.Contains(addIn))
					continue;
				foreach (AddInReference dep in addIn.Manifest.Dependencies) {
					if (modifiedAddIns.ContainsKey(dep.Name)) {
						dependenciesToSel.Add(new KeyValuePair<AddIn, AddInReference>(addIn, dep));
					}
				}
			}
			
			foreach (Control ctl in dependencyTable.Controls) {
				ctl.Dispose();
			}
			dependencyTable.Controls.Clear();
			bool allDepenciesOK = true;
			if (dependencies.Count > 0 || dependenciesToSel.Count > 0) {
				if (dependencies.Count == 0) {
					dependencyTable.RowCount = 1 + dependenciesToSel.Count;
				} else if (dependenciesToSel.Count == 0) {
					dependencyTable.RowCount = 1 + dependencies.Count;
				} else {
					dependencyTable.RowCount = 2 + dependencies.Count + dependenciesToSel.Count;
				}
				while (dependencyTable.RowStyles.Count < dependencyTable.RowCount) {
					dependencyTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));
				}
				int rowIndex = 0;
				if (dependencies.Count > 0) {
					AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredDependencies"));
					foreach (AddInReference dep in dependencies) {
						if (!AddDependencyRow(addInDict, dep, rowIndex++, null))
							allDepenciesOK = false;
					}
				}
				if (dependenciesToSel.Count > 0) {
					AddLabelRow(rowIndex++, ResourceService.GetString("AddInManager.RequiredBy"));
					foreach (KeyValuePair<AddIn, AddInReference> pair in dependenciesToSel) {
						if (!AddDependencyRow(addInDict, pair.Value, rowIndex++, pair.Key.Name))
							allDepenciesOK = false;
					}
				}
				dependencyTable.Visible = true;
			}
			return allDepenciesOK;
		}
		
		bool AddDependencyRow(Dictionary<string, Version> addInDict, AddInReference dep, int rowIndex, string requiredByName)
		{
			string text = requiredByName ?? GetDisplayName(dep.Name);
			Version versionFound;
			Label label = new Label();
			label.AutoSize = true;
			label.Text = text;
			PictureBox box = new PictureBox();
			box.BorderStyle = BorderStyle.None;
			box.Size = new Size(16, 16);
			bool isOK = dep.Check(addInDict, out versionFound);
			box.SizeMode = PictureBoxSizeMode.CenterImage;
			box.Image = isOK ? ResourceService.GetBitmap("Icons.16x16.OK") : ResourceService.GetBitmap("Icons.16x16.DeleteIcon");
			dependencyTable.Controls.Add(label, 1, rowIndex);
			dependencyTable.Controls.Add(box,   0, rowIndex);
			return isOK;
		}
		
		void AddLabelRow(int rowIndex, string text)
		{
			Label label = new Label();
			label.AutoSize = true;
			label.Text = text;
			dependencyTable.Controls.Add(label, 0, rowIndex);
			dependencyTable.SetColumnSpan(label, 2);
		}
		
		string GetDisplayName(string identity)
		{
			foreach (AddIn addIn in AddInTree.AddIns) {
				if (addIn.Manifest.Identities.ContainsKey(identity))
					return addIn.Name;
			}
			return identity;
		}
		#endregion
		
		#region Install new AddIns
		void InstallButtonClick(object sender, EventArgs e)
		{
			using (OpenFileDialog dlg = new OpenFileDialog()) {
				dlg.Filter = ResourceService.GetString("AddInManager.FileFilter");
				dlg.Multiselect = true;
				if (dlg.ShowDialog() == DialogResult.OK) {
					if (ShowInstallableAddIns(dlg.FileNames)) {
						if (runActionButton.Visible && runActionButton.Enabled)
							runActionButton.PerformClick();
					}
				}
			}
		}
		
		public bool ShowInstallableAddIns(IEnumerable<string> fileNames)
		{
			foreach (AddInControl ctl in splitContainer.Panel1.Controls) {
				ctl.Selected = false;
			}
			UpdateActionBox();
			List<InstallableAddIn> list = new List<InstallableAddIn>();
			foreach (string file in fileNames) {
				try {
					// Same file-extension check is in Panel1DragEnter
					switch (Path.GetExtension(file).ToLowerInvariant()) {
						case ".addin":
							if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, file)) {
								MessageService.ShowMessage("You cannot install AddIns inside the SharpDevelop directory, " +
								                           "they will be picked up as pre-installed AddIns automatically.");
								return false;
							}
							list.Add(new InstallableAddIn(file, false));
							break;
						case ".sdaddin":
						case ".zip":
							list.Add(new InstallableAddIn(file, true));
							break;
						default:
							MessageService.ShowMessage("Unknown file format: " + Path.GetExtension(file));
							return false;
					}
				} catch (AddInLoadException ex) {
					MessageService.ShowMessage("Error loading " + file + ":\n" + ex.Message);
					return false;
				}
			}
			ShowInstallableAddIns(list);
			return true;
		}
		
		IList<InstallableAddIn> shownAddInPackages;
		
		void ShowInstallableAddIns(IList<InstallableAddIn> addInPackages)
		{
			shownAddInPackages = addInPackages;
			ignoreFocusChange = true;
			splitContainer.Panel2Collapsed = false;
			dependencyTable.Visible = false;
			runActionButton.Visible = true;
			uninstallButton.Visible = false;
			
			selectedAction = AddInAction.Install;
			List<string> installAddIns = new List<string>();
			List<string> updateAddIns = new List<string>();
			foreach (InstallableAddIn addInPackage in addInPackages) {
				string identity = addInPackage.AddIn.Manifest.PrimaryIdentity;
				AddIn foundAddIn = null;
				foreach (AddIn addIn in AddInTree.AddIns) {
					if (addIn.Action != AddInAction.Install
					    && addIn.Manifest.Identities.ContainsKey(identity))
					{
						foundAddIn = addIn;
						break;
					}
				}
				if (foundAddIn != null) {
					updateAddIns.Add(addInPackage.AddIn.Name);
				} else {
					installAddIns.Add(addInPackage.AddIn.Name);
				}
			}
			
			if (updateAddIns.Count == 0) {
				actionGroupBox.Text = runActionButton.Text = ResourceService.GetString("AddInManager.ActionInstall");
			} else if (installAddIns.Count == 0) {
				actionGroupBox.Text = runActionButton.Text = ResourceService.GetString("AddInManager.ActionUpdate");
			} else {
				actionGroupBox.Text = runActionButton.Text =
					ResourceService.GetString("AddInManager.ActionInstall")
					+ " + " +
					ResourceService.GetString("AddInManager.ActionUpdate");
			}
			List<AddIn> addInList = new List<AddIn>();
			StringBuilder b = new StringBuilder();
			if (installAddIns.Count == 1) {
				b.Append("Installs the AddIn " + installAddIns[0]);
			} else if (installAddIns.Count > 1) {
				b.Append("Installs the AddIns " + string.Join(",", installAddIns.ToArray()));
			}
			if (updateAddIns.Count > 0 && installAddIns.Count > 0)
				b.Append("; ");
			if (updateAddIns.Count == 1) {
				b.Append("Updates the AddIn " + updateAddIns[0]);
			} else if (updateAddIns.Count > 1) {
				b.Append("Updates the AddIns " + string.Join(",", updateAddIns.ToArray()));
			}
			actionDescription.Text = b.ToString();
			runActionButton.Enabled = ShowDependencies(addInList, ShowDependencyMode.Enable);
		}
		
		void RunInstallation()
		{
			// install new AddIns
			foreach (InstallableAddIn addInPackage in shownAddInPackages) {
				string identity = addInPackage.AddIn.Manifest.PrimaryIdentity;
				AddIn foundAddIn = null;
				foreach (AddIn addIn in AddInTree.AddIns) {
					if (addIn.Manifest.Identities.ContainsKey(identity)) {
						foundAddIn = addIn;
						break;
					}
				}
				if (foundAddIn != null) {
					addInPackage.Install(true);
					if (foundAddIn.Action != AddInAction.Enable) {
						ICSharpCode.Core.AddInManager.Enable(new AddIn[] { foundAddIn });
					}
					if (foundAddIn.Action != AddInAction.Install) {
						foundAddIn.Action = AddInAction.Update;
					}
				} else {
					addInPackage.Install(false);
				}
			}
			RefreshAddInList();
		}
		#endregion
		
		#region Uninstall AddIns
		void UninstallButtonClick(object sender, EventArgs e)
		{
			ICSharpCode.Core.AddInManager.RemoveExternalAddIns(selected);
			InstallableAddIn.Uninstall(selected);
			RefreshAddInList();
		}
		#endregion
		
		#region Drag'N'Drop
		void Panel1DragEnter(object sender, DragEventArgs e)
		{
			if (!e.Data.GetDataPresent(DataFormats.FileDrop)) {
				e.Effect = DragDropEffects.None;
				return;
			}
			string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
			int addInCount = 0;
			int packageCount = 0;
			foreach (string file in files) {
				switch (Path.GetExtension(file).ToLowerInvariant()) {
					case ".addin":
						addInCount += 1;
						break;
					case ".sdaddin":
					case ".zip":
						packageCount += 1;
						break;
					default:
						e.Effect = DragDropEffects.None;
						return;
				}
			}
			if (addInCount == 0 && packageCount == 0) {
				e.Effect = DragDropEffects.None;
			} else if (addInCount == 0) {
				e.Effect = DragDropEffects.Copy;
			} else {
				e.Effect = DragDropEffects.Link;
			}
		}
		
		void Panel1DragDrop(object sender, DragEventArgs e)
		{
			if (!e.Data.GetDataPresent(DataFormats.FileDrop))
				return;
			ShowInstallableAddIns((string[])e.Data.GetData(DataFormats.FileDrop));
		}
		#endregion
		
		void CloseButtonClick(object sender, EventArgs e)
		{
			Close();
		}
		
		protected override void OnClosed(EventArgs e)
		{
			base.OnClosed(e);
			instance = null;
		}
		
		public void TryRunAction(AddIn addIn, AddInAction action)
		{
			foreach (AddInControl ctl in splitContainer.Panel1.Controls) {
				ctl.Selected = ctl.AddIn == addIn;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -