//
//
//
//
// $Revision: 4498 $
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Resources;
namespace ICSharpCode.Core
{
///
/// Static class containing the AddInTree. Contains methods for accessing tree nodes and building items.
///
public static class AddInTree
{
static List addIns = new List();
static AddInTreeNode rootNode = new AddInTreeNode();
static Dictionary doozers = new Dictionary();
static Dictionary conditionEvaluators = new Dictionary();
static AddInTree()
{
doozers.Add("Class", new ClassDoozer());
doozers.Add("FileFilter", new FileFilterDoozer());
doozers.Add("String", new StringDoozer());
doozers.Add("Icon", new IconDoozer());
doozers.Add("MenuItem", new MenuItemDoozer());
doozers.Add("ToolbarItem", new ToolbarItemDoozer());
doozers.Add("Include", new IncludeDoozer());
conditionEvaluators.Add("Compare", new CompareConditionEvaluator());
conditionEvaluators.Add("Ownerstate", new OwnerStateConditionEvaluator());
ApplicationStateInfoService.RegisterStateGetter("Installed 3rd party AddIns", GetInstalledThirdPartyAddInsListAsString);
}
static object GetInstalledThirdPartyAddInsListAsString()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (AddIn addIn in AddIns) {
// Skip preinstalled AddIns (show only third party AddIns)
if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, addIn.FileName)) {
string hidden = addIn.Properties["addInManagerHidden"];
if (string.Equals(hidden, "true", StringComparison.OrdinalIgnoreCase) || string.Equals(hidden, "preinstalled", StringComparison.OrdinalIgnoreCase))
continue;
}
if (sb.Length > 0) sb.Append(", ");
sb.Append("[");
sb.Append(addIn.Name);
if (addIn.Version != null) {
sb.Append(' ');
sb.Append(addIn.Version.ToString());
}
if (!addIn.Enabled) {
sb.Append(", Enabled=");
sb.Append(addIn.Enabled);
}
if (addIn.Action != AddInAction.Enable) {
sb.Append(", Action=");
sb.Append(addIn.Action.ToString());
}
sb.Append("]");
}
return sb.ToString();
}
///
/// Gets the list of loaded AddIns.
///
public static IList AddIns {
get {
return addIns.AsReadOnly();
}
}
///
/// Gets a dictionary of registered doozers.
///
public static Dictionary Doozers {
get {
return doozers;
}
}
///
/// Gets a dictionary of registered condition evaluators.
///
public static Dictionary ConditionEvaluators {
get {
return conditionEvaluators;
}
}
///
/// Checks whether the specified path exists in the AddIn tree.
///
public static bool ExistsTreeNode(string path)
{
if (path == null || path.Length == 0) {
return true;
}
string[] splittedPath = path.Split('/');
AddInTreeNode curPath = rootNode;
int i = 0;
while (i < splittedPath.Length) {
// curPath = curPath.ChildNodes[splittedPath[i]] - check if child path exists
if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath)) {
return false;
}
++i;
}
return true;
}
///
/// Gets the representing the specified path.
/// This method throws a when the
/// path does not exist.
///
public static AddInTreeNode GetTreeNode(string path)
{
return GetTreeNode(path, true);
}
///
/// Gets the representing the specified path.
///
/// The path of the AddIn tree node
///
/// If set to true, this method throws a
/// when the path does not exist.
/// If set to false, null is returned for non-existing paths.
///
public static AddInTreeNode GetTreeNode(string path, bool throwOnNotFound)
{
if (path == null || path.Length == 0) {
return rootNode;
}
string[] splittedPath = path.Split('/');
AddInTreeNode curPath = rootNode;
int i = 0;
while (i < splittedPath.Length) {
if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath)) {
if (throwOnNotFound)
throw new TreePathNotFoundException(path);
else
return null;
}
// curPath = curPath.ChildNodes[splittedPath[i]]; already done by TryGetValue
++i;
}
return curPath;
}
///
/// Builds a single item in the addin tree.
///
/// A path to the item in the addin tree.
/// The owner used to create the objects.
/// The path does not
/// exist or does not point to an item.
public static object BuildItem(string path, object caller)
{
int pos = path.LastIndexOf('/');
string parent = path.Substring(0, pos);
string child = path.Substring(pos + 1);
AddInTreeNode node = GetTreeNode(parent);
return node.BuildChildItem(child, caller, new ArrayList(BuildItems