//
//
//
//
// $Revision: 1185 $
//
using System;
using System.Collections;
namespace ICSharpCode.Core
{
///
/// Includes one or multiple items from another location in the addin tree.
/// You can use the attribute "item" (to include a single item) OR the
/// attribute "path" (to include all items from the target path).
///
///
/// When this attribute is used, the include doozer builds the item that is at the
/// addin tree location specified by this attribute.
///
///
/// When this attribute is used, the include doozer builds all items inside the
/// path addin tree location specified by this attribute and returns an
/// which includes all items in the output list.
///
/// Everywhere
///
/// Any object, depending on the included codon(s).
///
public class IncludeDoozer : IDoozer
{
///
/// Gets if the doozer handles codon conditions on its own.
/// If this property return false, the item is excluded when the condition is not met.
///
public bool HandleConditions {
get {
return false;
}
}
public object BuildItem(object caller, Codon codon, ArrayList subItems)
{
string item = codon.Properties["item"];
string path = codon.Properties["path"];
if (item != null && item.Length > 0) {
// include item
return AddInTree.BuildItem(item, caller);
} else if (path != null && path.Length > 0) {
// include path (=multiple items)
return new IncludeReturnItem(caller, path);
} else {
MessageService.ShowMessage(" requires the attribute 'item' (to include one item) or the attribute 'path' (to include multiple items)");
return null;
}
}
class IncludeReturnItem : IBuildItemsModifier
{
string path;
object caller;
public IncludeReturnItem(object caller, string path)
{
this.caller = caller;
this.path = path;
}
public void Apply(IList items)
{
AddInTreeNode node;
try {
node = AddInTree.GetTreeNode(path);
foreach (object o in node.BuildChildItems(caller)) {
items.Add(o);
}
} catch (TreePathNotFoundException) {
MessageService.ShowError("IncludeDoozer: AddinTree-Path not found: " + path);
}
}
}
}
}