Changeset 9849
- Timestamp:
- 08/05/13 16:16:31 (11 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 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 -
trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r9456 r9849 28 28 public interface IProgress : IContent { 29 29 /// <summary> 30 /// Gets the currently associated status text with the progress.30 /// Gets or sets the currently associated status text with the progress. 31 31 /// </summary> 32 string Status { get; }32 string Status { get; set; } 33 33 /// <summary> 34 /// Gets the currently associated progress value in the range (0;1].34 /// Gets or sets the currently associated progress value in the range (0;1]. 35 35 /// Values outside this range are permitted and need to be handled in some feasible manner. 36 36 /// </summary> 37 double ProgressValue { get; }37 double ProgressValue { get; set; } 38 38 /// <summary> 39 /// Gets the current state of the progress. Every progress starts in state39 /// Gets or sets the current state of the progress. Every progress starts in state 40 40 /// Started and then becomes either Canceled or Finished. 41 41 /// If it is reused it may be Started again. 42 42 /// </summary> 43 ProgressState ProgressState { get; }43 ProgressState ProgressState { get; set; } 44 44 /// <summary> 45 45 /// Returns whether the operation can be canceled or not. … … 56 56 /// <param name="timeoutMs">The operation is given a certain timeout to cancel. If the operation doesn't cancel in this time it will be forcibly closed.</param> 57 57 void Cancel(int timeoutMs); 58 /// <summary> 59 /// Sets the ProgressValue to 1 and the ProgressState to Finished. 60 /// </summary> 61 void Finish(); 58 62 59 63 /// <summary> -
trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
r9456 r9849 86 86 } 87 87 88 /// <summary>89 /// Sets the ProgressValue to 1 and the ProgressState to Finished.90 /// </summary>91 88 public void Finish() { 92 89 if (ProgressValue != 1.0) ProgressValue = 1.0; -
trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs
r9456 r9849 22 22 using System; 23 23 using System.Collections.Generic; 24 using System. Linq;24 using System.IO; 25 25 using System.Windows.Forms; 26 26 using HeuristicLab.Common; … … 98 98 SaveAs(view); 99 99 else { 100 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).SetAppStartingCursor();100 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 101 101 SetEnabledStateOfContentViews(content, false); 102 102 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted); … … 123 123 124 124 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 125 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).SetAppStartingCursor();125 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 126 126 SetEnabledStateOfContentViews(content, false); 127 127 if (saveFileDialog.FilterIndex == 1) { … … 135 135 private static void SavingCompleted(IStorableContent content, Exception error) { 136 136 try { 137 SetEnabledStateOfContentViews(content, true);138 137 if (error != null) throw error; 139 138 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); … … 143 142 } 144 143 finally { 145 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor(); 144 SetEnabledStateOfContentViews(content, true); 145 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().ResetAppStartingCursor(); 146 146 } 147 147 } … … 152 152 // removed the InvokeRequired check because of Mono 153 153 mainForm.Invoke((Action)delegate { 154 var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList(); 155 views.ForEach(v => v.Enabled = enabled); 154 if (enabled) 155 mainForm.RemoveOperationProgressFromContent(content); 156 else 157 mainForm.AddOperationProgressToContent(content, new Progress(string.Format("Saving file \"{0}\"...", Path.GetFileName(content.Filename)))); 156 158 }); 157 159 #endregion
Note: See TracChangeset
for help on using the changeset viewer.