Changeset 2837
- Timestamp:
- 02/19/10 11:45:51 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.Designer.cs
r2545 r2837 28 28 // ViewContextMenuStrip 29 29 // 30 this.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ViewContextMenuStrip_ItemClicked);31 30 this.ResumeLayout(false); 32 33 31 } 34 32 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs
r2696 r2837 8 8 9 9 namespace HeuristicLab.MainForm.WindowsForms { 10 public partial class ViewContextMenuStrip : ContextMenuStrip { 11 private object item; 10 public sealed partial class ViewContextMenuStrip : ContextMenuStrip { 12 11 public ViewContextMenuStrip() { 13 12 InitializeComponent(); 13 this.menuItems = new Dictionary<Type, ToolStripMenuItem>(); 14 14 } 15 15 16 public ViewContextMenuStrip(object item) :this() {17 if (item != null) {18 this.item = item;19 IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType());20 if (types != null) { 21 foreach (Type t in types) {22 ToolStripMenuItem menuItem = new ToolStripMenuItem(){23 Text = t.Name,24 Tag = t25 };26 this.Items.Add(menuItem);27 }16 public ViewContextMenuStrip(object item) 17 : this() { 18 this.Item = item; 19 } 20 21 private object item; 22 public object Item { 23 get { return this.item; } 24 set { 25 if (this.item != value) { 26 this.item = value; 27 this.RefreshMenuItems(); 28 28 } 29 29 } 30 30 } 31 31 32 private void ViewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 33 if (item != null) { 34 Type viewType = e.ClickedItem.Tag as Type; 35 IView view = MainFormManager.CreateView(viewType, this.item); 36 view.Show(); 32 private Dictionary<Type, ToolStripMenuItem> menuItems; 33 public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems { 34 get { return this.menuItems; } 35 } 36 37 private void RefreshMenuItems() { 38 this.Items.Clear(); 39 this.menuItems.Clear(); 40 41 if (this.item != null) { 42 ToolStripMenuItem menuItem; 43 IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType()); 44 foreach (Type t in types) { 45 menuItem = new ToolStripMenuItem(); 46 menuItem.Tag = t; 47 menuItem.Text = ViewAttribute.GetViewName(t); 48 49 this.menuItems.Add(t, menuItem); 50 this.Items.Add(menuItem); 51 } 37 52 } 38 53 } 39 40 54 } 41 55 } -
trunk/sources/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj
r2754 r2837 82 82 <ItemGroup> 83 83 <None Include="HeuristicLabMainFormPlugin.cs.frame" /> 84 <Compile Include="ViewAttribute.cs" /> 84 85 <Compile Include="Interfaces\IContentView.cs" /> 85 86 <Compile Include="Interfaces\IActionUserInterfaceItem.cs" /> -
trunk/sources/HeuristicLab.MainForm/3.2/ViewAttribute.cs
r2835 r2837 27 27 28 28 namespace HeuristicLab.MainForm { 29 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]30 public sealed class ContentAttribute : Attribute {31 public ContentAttribute(Type contentType) {32 this. contentType = contentType;29 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 30 public sealed class ViewAttribute : Attribute { 31 public ViewAttribute(string name) { 32 this.name = name; 33 33 } 34 34 35 public ContentAttribute(Type contentType, bool isDefaultView) 36 : this(contentType) { 37 this.isDefaultView = isDefaultView; 35 private string name; 36 public string Name { 37 get { return this.name; } 38 set { this.name = value; } 38 39 } 39 40 40 private bool isDefaultView; 41 public bool IsDefaultView { 42 get { return this.isDefaultView; } 43 set { this.isDefaultView = value; } 44 } 45 46 private Type contentType; 47 public Type ContentType { 48 get { return this.contentType; } 49 } 50 51 public static bool HasContentAttribute(MemberInfo viewType) { 52 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 41 public static bool HasViewAttribute(MemberInfo viewType) { 42 ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false); 53 43 return attributes.Length != 0; 54 44 } 55 45 56 public static bool CanViewType(MemberInfo viewType, Type content) { 57 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 58 return attributes.Any(a => content.IsAssignableTo(a.contentType)); 59 } 60 61 internal static IEnumerable<Type> GetDefaultViewableTypes(Type viewType) { 62 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 63 return from a in attributes 64 where a.isDefaultView 65 select a.contentType; 66 } 67 68 internal static IEnumerable<Type> GetViewableTypes(Type viewType) { 69 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 70 return from a in attributes 71 select a.contentType; 46 public static string GetViewName(MemberInfo viewType) { 47 ViewAttribute[] attributes = (ViewAttribute[])viewType.GetCustomAttributes(typeof(ViewAttribute), false); 48 if (attributes.Length == 1) 49 return attributes[0].Name; 50 return viewType.Name; 72 51 } 73 52 }
Note: See TracChangeset
for help on using the changeset viewer.