Changeset 3389
- Timestamp:
- 04/18/10 02:08:29 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs
r2961 r3389 34 34 public object Content { 35 35 get { return content; } 36 protectedset {36 set { 37 37 if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value))) 38 38 throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name)); -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs
r2992 r3389 12 12 InitializeComponent(); 13 13 this.menuItems = new Dictionary<Type, ToolStripMenuItem>(); 14 this.ignoredViewTypes = new List<Type>(); 14 15 } 15 16 … … 30 31 } 31 32 33 private List<Type> ignoredViewTypes; 34 public IEnumerable<Type> IgnoredViewTypes { 35 get { return this.ignoredViewTypes; } 36 set { this.ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); } 37 } 38 32 39 private Dictionary<Type, ToolStripMenuItem> menuItems; 33 40 public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems { … … 42 49 ToolStripMenuItem menuItem; 43 50 IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(),true); 44 foreach (Type t in types ) {51 foreach (Type t in types.Except(IgnoredViewTypes)) { 45 52 menuItem = new ToolStripMenuItem(); 46 53 menuItem.Tag = t; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs
r3388 r3389 27 27 28 28 namespace HeuristicLab.MainForm.WindowsForms { 29 public sealed partial class ViewHost : View { 30 private Dictionary<Type, IView> cachedViews; 29 [Content(typeof(object))] 30 public sealed partial class ViewHost : ContentView { 31 private Dictionary<Type, IContentView> cachedViews; 31 32 public ViewHost() { 32 33 InitializeComponent(); 33 cachedViews = new Dictionary<Type, I View>();34 cachedViews = new Dictionary<Type, IContentView>(); 34 35 viewType = null; 35 36 Content = null; 37 viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) }; 36 38 } 37 public ViewHost( bool readOnly)39 public ViewHost(object content) 38 40 : this() { 39 this. ReadOnly = readOnly;41 this.Content = content; 40 42 } 41 43 … … 54 56 } 55 57 56 private object content; 57 public object Content { 58 get { return this.content; } 58 public new object Content { 59 get { return base.Content; } 59 60 set { 60 if (value != this.content) { 61 if (value == null || this.content == null || value.GetType() != this.content.GetType()) 62 cachedViews.Clear(); 63 viewContextMenuStrip.Item = value; 64 this.viewsLabel.Enabled = value != null; 65 this.content = value; 66 this.OnContentChanged(); 67 } 68 61 if (value == null || this.Content == null || value.GetType() != this.Content.GetType()) 62 cachedViews.Clear(); 63 viewContextMenuStrip.Item = value; 64 this.viewsLabel.Enabled = value != null; 65 base.Content = value; 69 66 } 70 67 } … … 82 79 protected override void OnReadOnlyChanged() { 83 80 base.OnReadOnlyChanged(); 84 foreach (I View view in cachedViews.Values)81 foreach (IContentView view in cachedViews.Values) 85 82 view.ReadOnly = this.ReadOnly; 86 83 } 87 84 88 pr ivate void OnContentChanged() {85 protected override void OnContentChanged() { 89 86 messageLabel.Visible = false; 90 87 viewsLabel.Visible = false; … … 100 97 101 98 if (!ViewCanShowContent(viewType, Content)) { 102 viewType = MainFormManager.GetDefaultViewType(Content.GetType());99 ViewType = MainFormManager.GetDefaultViewType(Content.GetType()); 103 100 if ((viewType == null) && (viewContextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 104 viewType = (Type)viewContextMenuStrip.Items[0].Tag;101 ViewType = (Type)viewContextMenuStrip.Items[0].Tag; 105 102 } 106 UpdateView(); 103 foreach (IContentView view in cachedViews.Values) 104 view.Content = this.Content; 105 } else { 106 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 107 viewPanel.Controls.Clear(); 108 cachedViews.Clear(); 107 109 } 108 110 } … … 120 122 121 123 UpdateActiveMenuItem(); 122 I View view;124 IContentView view; 123 125 if (cachedViews.ContainsKey(ViewType)) 124 126 view = cachedViews[ViewType]; 125 127 else { 126 128 view = MainFormManager.CreateView(viewType, Content, ReadOnly); 127 cachedViews.Add(viewType, ((IView)view));129 cachedViews.Add(viewType, view); 128 130 } 129 131 -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IContentView.cs
r2961 r3389 27 27 namespace HeuristicLab.MainForm { 28 28 public interface IContentView : IView { 29 object Content { get; }29 object Content { get; set; } 30 30 bool SaveEnabled { get; } 31 31 } -
trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs
r3375 r3389 50 50 MainFormManager.mainform = mainForm; 51 51 IEnumerable<Type> types = 52 from t in ApplicationManager.Manager.GetTypes(typeof(I View))52 from t in ApplicationManager.Manager.GetTypes(typeof(IContentView)) 53 53 where !t.IsAbstract && !t.IsInterface && ContentAttribute.HasContentAttribute(t) 54 54 select t; … … 102 102 } 103 103 104 public static bool ViewCanViewObject(I View view, object content) {104 public static bool ViewCanViewObject(IContentView view, object content) { 105 105 return ContentAttribute.CanViewType(view.GetType(), content.GetType()); 106 106 } … … 141 141 } 142 142 143 public static I View CreateDefaultView(object content) {143 public static IContentView CreateDefaultView(object content) { 144 144 Type t = GetDefaultViewType(content.GetType()); 145 145 if (t == null) 146 146 return null; 147 147 148 return (I View)Activator.CreateInstance(t, content);149 } 150 public static I View CreateDefaultView(object content, bool readOnly) {151 I View view = CreateDefaultView(content);148 return (IContentView)Activator.CreateInstance(t, content); 149 } 150 public static IContentView CreateDefaultView(object content, bool readOnly) { 151 IContentView view = CreateDefaultView(content); 152 152 if (view != null) 153 153 view.ReadOnly = readOnly; … … 155 155 } 156 156 157 public static I View CreateView(Type viewType) {158 if (!typeof(I View).IsAssignableFrom(viewType))157 public static IContentView CreateView(Type viewType) { 158 if (!typeof(IContentView).IsAssignableFrom(viewType)) 159 159 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView."); 160 160 if (viewType.IsGenericTypeDefinition) 161 161 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is a generic type definition."); 162 162 163 return (I View)Activator.CreateInstance(viewType);164 } 165 public static I View CreateView(Type viewType, bool readOnly) {166 I View view = CreateView(viewType);163 return (IContentView)Activator.CreateInstance(viewType); 164 } 165 public static IContentView CreateView(Type viewType, bool readOnly) { 166 IContentView view = CreateView(viewType); 167 167 view.ReadOnly = readOnly; 168 168 return view; 169 169 } 170 170 171 public static I View CreateView(Type viewType, object content) {172 if (!typeof(I View).IsAssignableFrom(viewType))171 public static IContentView CreateView(Type viewType, object content) { 172 if (!typeof(IContentView).IsAssignableFrom(viewType)) 173 173 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView."); 174 174 Type view = viewType; … … 176 176 view = TransformGenericTypeDefinition(view, content.GetType()); 177 177 178 return (I View)Activator.CreateInstance(view, content);179 } 180 public static I View CreateView(Type viewType, object content, bool readOnly) {181 I View view = CreateView(viewType, content);178 return (IContentView)Activator.CreateInstance(view, content); 179 } 180 public static IContentView CreateView(Type viewType, object content, bool readOnly) { 181 IContentView view = CreateView(viewType, content); 182 182 view.ReadOnly = readOnly; 183 183 return view;
Note: See TracChangeset
for help on using the changeset viewer.