Changeset 3350 for trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Timestamp:
- 04/15/10 01:34:27 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs
r3301 r3350 31 31 this.isShown = false; 32 32 this.closeReason = CloseReason.None; 33 } 34 35 private string myCaption; 33 this.readOnly = false; 34 } 35 36 public View(bool readOnly) 37 : this() { 38 this.readOnly = readOnly; 39 } 40 41 private string caption; 36 42 public string Caption { 37 get { return myCaption; }43 get { return caption; } 38 44 set { 39 45 if (InvokeRequired) { … … 41 47 Invoke(action, value); 42 48 } else { 43 if (value != myCaption) {44 myCaption = value;49 if (value != caption) { 50 caption = value; 45 51 OnCaptionChanged(); 52 } 53 } 54 } 55 } 56 57 private bool readOnly; 58 public virtual bool ReadOnly { 59 get { return this.readOnly; } 60 set { 61 if (InvokeRequired) { 62 Action<bool> action = delegate(bool b) { this.ReadOnly = b; }; 63 Invoke(action, value); 64 } else { 65 if (value != readOnly) { 66 readOnly = value; 67 OnReadOnlyChanged(); 46 68 } 47 69 } … … 95 117 public event EventHandler CaptionChanged; 96 118 protected virtual void OnCaptionChanged() { 97 if (CaptionChanged != null) 98 CaptionChanged(this, EventArgs.Empty); 99 } 100 119 if (InvokeRequired) 120 Invoke((MethodInvoker)OnCaptionChanged); 121 else { 122 EventHandler handler = CaptionChanged; 123 if (handler != null) 124 handler(this, EventArgs.Empty); 125 } 126 } 127 public event EventHandler ReadOnlyChanged; 128 protected virtual void OnReadOnlyChanged() { 129 if (InvokeRequired) 130 Invoke((MethodInvoker)OnReadOnlyChanged); 131 else { 132 EventHandler handler = ReadOnlyChanged; 133 if (handler != null) 134 handler(this, EventArgs.Empty); 135 foreach (Control control in this.Controls) { 136 IView view = control as IView; 137 if (view != null) 138 view.ReadOnly = this.readOnly; 139 ViewHost viewHost = control as ViewHost; 140 if (viewHost != null) 141 viewHost.ReadOnly = this.readOnly; 142 } 143 } 144 } 101 145 public event EventHandler Changed; 102 146 protected virtual void OnChanged() { 103 147 if (InvokeRequired) 104 148 Invoke((MethodInvoker)OnChanged); 105 else if (Changed != null) 106 Changed(this, EventArgs.Empty); 149 else { 150 EventHandler handler = Changed; 151 if (handler != null) 152 handler(this, EventArgs.Empty); 153 } 107 154 } 108 155 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs
r3281 r3350 28 28 namespace HeuristicLab.MainForm.WindowsForms { 29 29 public sealed partial class ViewHost : UserControl { 30 private Dictionary<Type, IView> cachedViews; 31 public ViewHost() { 32 InitializeComponent(); 33 viewType = null; 34 content = null; 35 cachedViews = new Dictionary<Type, IView>(); 36 Initialize(); 37 } 38 public ViewHost(bool readOnly) 39 : this() { 40 this.ReadOnly = readOnly; 41 } 42 30 43 private Type viewType; 31 44 public Type ViewType { … … 49 62 content = value; 50 63 viewContextMenuStrip.Item = content; 64 cachedViews.Clear(); 51 65 Initialize(); 52 66 } … … 59 73 this.SuspendRepaint(); 60 74 base.Enabled = value; 75 this.viewsLabel.Enabled = value; 61 76 this.ResumeRepaint(true); 62 77 } 63 78 } 79 private bool readOnly; 80 public bool ReadOnly { 81 get { return this.readOnly; } 82 set { 83 if (InvokeRequired) { 84 Action<bool> action = delegate(bool b) { this.ReadOnly = b; }; 85 Invoke(action, value); 86 } else { 87 if (value != readOnly) { 88 readOnly = value; 89 OnReadOnlyChanged(); 90 } 91 } 92 } 93 } 64 94 65 public ViewHost() { 66 InitializeComponent(); 67 viewType = null; 68 content = null; 69 Initialize(); 95 public event EventHandler ReadOnlyChanged; 96 private void OnReadOnlyChanged() { 97 if (InvokeRequired) 98 Invoke((MethodInvoker)OnReadOnlyChanged); 99 else { 100 EventHandler handler = ReadOnlyChanged; 101 if (handler != null) 102 handler(this, EventArgs.Empty); 103 foreach (IView view in cachedViews.Values) 104 view.ReadOnly = this.readOnly; 105 } 70 106 } 71 107 72 108 private void Initialize() { 73 109 viewsLabel.Visible = false; 74 viewsLabel.Enabled = false;75 viewContextMenuStrip.Enabled = false;76 messageLabel.Visible = false;77 78 110 viewPanel.Visible = false; 79 111 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); … … 81 113 82 114 if (Content != null) { 83 if (viewContextMenuStrip.Items.Count == 0) {115 if (viewContextMenuStrip.Items.Count == 0) 84 116 messageLabel.Visible = true; 85 } else {117 else 86 118 viewsLabel.Visible = true; 87 viewsLabel.Enabled = viewContextMenuStrip.Items.Count > 1;88 viewContextMenuStrip.Enabled = viewContextMenuStrip.Items.Count > 1; ;89 }90 119 91 120 if (!ViewCanShowContent(viewType, Content)) { … … 110 139 111 140 UpdateActiveMenuItem(); 112 Control view = (Control)MainFormManager.CreateView(viewType, Content); 113 viewPanel.Tag = view; 141 cachedViews.Clear(); 142 Control view = (Control)MainFormManager.CreateView(viewType, Content,ReadOnly); 143 cachedViews.Add(viewType, ((IView)view)); 114 144 view.Dock = DockStyle.Fill; 115 145 viewPanel.Controls.Add(view); … … 138 168 139 169 private void viewsLabel_DoubleClick(object sender, EventArgs e) { 140 MainFormManager.CreateView(viewType, Content ).Show();170 MainFormManager.CreateView(viewType, Content,ReadOnly).Show(); 141 171 } 142 172
Note: See TracChangeset
for help on using the changeset viewer.