Changeset 9849 for trunk/sources/HeuristicLab.MainForm.WindowsForms
- Timestamp:
- 08/05/13 16:16:31 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r9456 r9849 29 29 public partial class ProgressView : AsynchronousContentView { 30 30 private const int DefaultCancelTimeoutMs = 3000; 31 private ContentView parentView;31 private readonly IView parentView; 32 32 33 33 [Category("Custom"), Description("The time that the process is allowed to exit.")] … … 41 41 } 42 42 43 private Control Control { 44 get { return (Control)parentView; } 45 } 46 47 public bool DisposeOnFinish { get; set; } 48 43 49 public ProgressView() { 44 50 InitializeComponent(); … … 48 54 Content = progress; 49 55 } 50 public ProgressView( ContentView parentView)56 public ProgressView(IView parentView) 51 57 : this() { 52 58 if (parentView == null) throw new ArgumentNullException("parentView", "The parent view is null."); 59 if (!(parentView is Control)) throw new ArgumentException("The parent view is not a control.", "parentView"); 53 60 this.parentView = parentView; 54 61 } 55 public ProgressView( ContentView parentView, IProgress progress)62 public ProgressView(IView parentView, IProgress progress) 56 63 : this(parentView) { 57 64 Content = progress; 65 } 66 67 public static ProgressView Attach(IView parentView, IProgress progress, bool disposeOnFinish = false) { 68 return new ProgressView(parentView, progress) { 69 DisposeOnFinish = disposeOnFinish 70 }; 58 71 } 59 72 … … 94 107 else { 95 108 if (parentView != null) { 96 this.Left = ( parentView.ClientRectangle.Width / 2) - (this.Width / 2);97 this.Top = ( parentView.ClientRectangle.Height / 2) - (this.Height / 2);109 this.Left = (Control.ClientRectangle.Width / 2) - (this.Width / 2); 110 this.Top = (Control.ClientRectangle.Height / 2) - (this.Height / 2); 98 111 this.Anchor = AnchorStyles.None; 99 112 100 113 LockBackground(); 101 114 102 if (! parentView.Controls.Contains(this))103 parentView.Controls.Add(this);115 if (!Control.Controls.Contains(this)) 116 Control.Controls.Add(this); 104 117 105 118 BringToFront(); … … 115 128 else { 116 129 if (parentView != null) { 117 if ( parentView.Controls.Contains(this))118 parentView.Controls.Remove(this);130 if (Control.Controls.Contains(this)) 131 Control.Controls.Remove(this); 119 132 120 133 UnlockBackground(); … … 133 146 134 147 private void Content_ProgressStateChanged(object sender, EventArgs e) { 135 if (Content.ProgressState == ProgressState.Finished 136 || Content.ProgressState == ProgressState.Canceled) 137 HideProgress(); 138 if (Content.ProgressState == ProgressState.Started) 139 ShowProgress(); 148 switch (Content.ProgressState) { 149 case ProgressState.Finished: 150 HideProgress(); 151 if (DisposeOnFinish) { 152 Content = null; 153 Dispose(); 154 } 155 break; 156 case ProgressState.Canceled: HideProgress(); break; 157 case ProgressState.Started: ShowProgress(); break; 158 } 140 159 } 141 160 … … 148 167 Invoke((Action)LockBackground); 149 168 } else { 150 parentView.Locked = true; 151 parentView.ReadOnly = true; 152 Locked = false; 153 ReadOnly = false; 169 parentView.Enabled = false; 170 Enabled = true; 154 171 } 155 172 } … … 158 175 if (InvokeRequired) Invoke((Action)UnlockBackground); 159 176 else { 160 parentView.Locked = false; 161 parentView.ReadOnly = false; 162 Locked = true; 163 ReadOnly = true; 177 parentView.Enabled = true; 178 Enabled = false; 164 179 } 165 180 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r9626 r9849 30 30 namespace HeuristicLab.MainForm.WindowsForms { 31 31 public partial class MainForm : Form, IMainForm { 32 private readonly Dictionary<IContent, IProgress> contentProgressLookup; 33 private readonly Dictionary<IView, IProgress> viewProgressLookup; 32 34 private bool initialized; 33 35 private int appStartingCursors; … … 39 41 this.views = new Dictionary<IView, Form>(); 40 42 this.userInterfaceItems = new List<IUserInterfaceItem>(); 43 this.contentProgressLookup = new Dictionary<IContent, IProgress>(); 44 this.viewProgressLookup = new Dictionary<IView, IProgress>(); 41 45 this.initialized = false; 42 46 this.showContentInViewHost = false; … … 343 347 CloseView(view, closeReason); 344 348 } 349 350 /// <summary> 351 /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content. 352 /// </summary> 353 public void AddOperationProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) { 354 if (contentProgressLookup.ContainsKey(content)) 355 throw new ArgumentException("A progress is already registered for the specified content.", "content"); 356 357 var contentViews = Enumerable.Empty<IContentView>(); 358 if (addToObjectGraphObjects) { 359 var containedObjects = content.GetObjectGraphObjects(); 360 contentViews = views.Keys.OfType<IContentView>().Where(v => containedObjects.Contains(v.Content)); 361 } else 362 contentViews = views.Keys.OfType<IContentView>().Where(v => v.Content == content); 363 364 foreach (var contentView in contentViews) 365 ProgressView.Attach(contentView, progress, true); 366 367 contentProgressLookup[content] = progress; 368 } 369 370 /// <summary> 371 /// Adds a <see cref="ProgressView"/> to the specified view. 372 /// </summary> 373 public void AddOperationProgressToView(IView view, Progress progress) { 374 if (viewProgressLookup.ContainsKey(view)) 375 throw new ArgumentException("A progress is already registered for the specified view.", "view"); 376 377 ProgressView.Attach(view, progress, true); 378 viewProgressLookup[view] = progress; 379 } 380 381 /// <summary> 382 /// Removes an existing <see cref="ProgressView"/> from the <see cref="ContentView"/>s showing the specified content. 383 /// </summary> 384 public void RemoveOperationProgressFromContent(IContent content) { 385 IProgress progress; 386 if (!contentProgressLookup.TryGetValue(content, out progress)) 387 throw new ArgumentException("No progress is registered for the specified content.", "content"); 388 389 progress.Finish(); 390 contentProgressLookup.Remove(content); 391 } 392 393 /// <summary> 394 /// Removes an existing <see cref="ProgressView"/> from the specified view. 395 /// </summary> 396 public void RemoveOperationProgressFromView(IView view) { 397 IProgress progress; 398 if (!viewProgressLookup.TryGetValue(view, out progress)) 399 throw new ArgumentException("No progress is registered for the specified view.", "view"); 400 401 progress.Finish(); 402 viewProgressLookup.Remove(view); 403 } 345 404 #endregion 346 405
Note: See TracChangeset
for help on using the changeset viewer.