using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Collections;
using System.ComponentModel.Design;
using AnticipatingMinds.Genesis.CodeDOM;
using AnticipatingMinds.PlatformServices.Globalization;
namespace AnticipatingMinds.Genesis.KnowledgeManagement{
public class StringCollectionTypeConverter : TypeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string))
{
StringCollection stringCollection = value as StringCollection;
if(stringCollection.Count == 0)
return "(any)";
int itemsProcessed = 0;
string displayValue = "";
foreach(string stringValue in stringCollection)
{
if(itemsProcessed != 0)
displayValue += ",";
displayValue += stringValue;
itemsProcessed++;
if(itemsProcessed == 3)
{
displayValue += "...";
return displayValue;
}
}
return displayValue;
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
public class RegExpTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if(sourceType == typeof(string))
return true;
else
return false;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if(destinationType == typeof(string))
return true;
else
return false;
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if(value.ToString() == "(any)" || value.ToString() == string.Empty)
return null;
else
return new Regex(value.ToString());
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string))
{
if(value == null)
return "(any)";
return (value as Regex).ToString();
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
public class MethodParameterApplicabilityScopeCollectionConverter : CollectionConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string) && value == null)
return "(any)";
else
return base.ConvertTo (context, culture, value, destinationType);
}
}
public class MethodParameterApplicabilityScopeCollectionEditor : CollectionEditor
{
public MethodParameterApplicabilityScopeCollectionEditor():base(typeof(MethodParameterApplicabilityScopeCollection))
{
}
protected override object CreateInstance(System.Type itemType)
{
return new MethodParameterApplicabilityScope();
}
protected override System.Type CreateCollectionItemType()
{
return typeof ( MethodParameterApplicabilityScope );
}
protected override object SetItems(object editValue, object[] value)
{
if(editValue == null)
editValue = new MethodParameterApplicabilityScopeCollection();
return base.SetItems (editValue, value);
}
protected override object[] GetItems(object editValue)
{
return base.GetItems (editValue);
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
object retValue = base.EditValue (context, provider, value);
if(retValue == null || (retValue as MethodParameterApplicabilityScopeCollection).Count == 0)
{
if(MessageBox.Show(messagesResourceManager.GetString("AnyOrNoArgumentsQuestion"),messagesResourceManager.GetString("MethodArguments"),MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
return new MethodParameterApplicabilityScopeCollection();
else
return null;
}
else
{
return retValue;
}
}
static AssemblyResourceManager messagesResourceManager = AssemblyResourceManager.GetInstance("AnticipatingMinds.Genesis.KnowledgeManagement.Messages");
}
public class StringCollectionEditor : CollectionEditor
{
public StringCollectionEditor():base(typeof(StringCollection))
{
}
protected override object CreateInstance(System.Type
itemType)
{
return "" ;
}
protected override System.Type CreateCollectionItemType
()
{
return typeof ( string );
}
public override string ToString()
{
return "";
}
}
public class ApplicabilityScopeEditor : UITypeEditor
{
[Flags]
public enum AvailableScopeTypes
{
Type = 2,
TypeReference = 4,
TypeMember = 8,
VariableDeclaration = 16,
Location = 32
}
private AvailableScopeTypes scopeTypes = 0;
public ApplicabilityScopeEditor(AvailableScopeTypes scopeTypes)
{
this.scopeTypes = scopeTypes;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
ApplicabilityScopeProperties scopeProperties = new ApplicabilityScopeProperties();
scopeProperties.AvailableScopes.Clear();
if((scopeTypes & AvailableScopeTypes.Type) != 0)
{
scopeProperties.AvailableScopes.Add(new TypeApplicabilityScope());
scopeProperties.AvailableScopes.Add(new ClassApplicabilityScope());
scopeProperties.AvailableScopes.Add(new InterfaceApplicabilityScope());
scopeProperties.AvailableScopes.Add(new StructApplicabilityScope());
scopeProperties.AvailableScopes.Add(new EnumApplicabilityScope());
scopeProperties.AvailableScopes.Add(new DelegateApplicabilityScope());
}
if((scopeTypes & AvailableScopeTypes.TypeReference) != 0)
{
scopeProperties.AvailableScopes.Add(new TypeReferenceApplicabilityScope());
}
if((scopeTypes & AvailableScopeTypes.TypeMember) != 0)
{
scopeProperties.AvailableScopes.Add(new FieldApplicabilityScope());
scopeProperties.AvailableScopes.Add(new PropertyApplicabilityScope());
scopeProperties.AvailableScopes.Add(new EventApplicabilityScope());
scopeProperties.AvailableScopes.Add(new MethodApplicabilityScope());
}
if((scopeTypes & AvailableScopeTypes.VariableDeclaration) != 0)
scopeProperties.AvailableScopes.Add(new VariableApplicabilityScope());
if((scopeTypes & AvailableScopeTypes.Location) != 0)
scopeProperties.AvailableScopes.Add(new FileApplicabilityScope());
if(value != null)
scopeProperties.SelectedScope = (value as ICloneable).Clone() as ApplicabilityScope;
if(scopeProperties.ShowDialog() == DialogResult.OK)
return scopeProperties.SelectedScope;
else
return value;
}
}
public class TypeApplicabilityScopeEditor : ApplicabilityScopeEditor
{
public TypeApplicabilityScopeEditor():base(ApplicabilityScopeEditor.AvailableScopeTypes.Type)
{
}
}
public class TypeReferenceScopeEditor : ApplicabilityScopeEditor
{
public TypeReferenceScopeEditor():base(ApplicabilityScopeEditor.AvailableScopeTypes.TypeReference)
{
}
}
public class ApplicabilityScopeTypeConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(string))
{
if(value == null)
return "(any)";
return (value as ApplicabilityScope).Description;
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
}
|