Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/18 12:37:04 (6 years ago)
Author:
pfleck
Message:

#2845 Combined separate Show methods into single one with enum parameter specifying the ProgressMode. Renamed Continuous and Marquee to Determinate and Indeterminate.

Location:
branches/2845_EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2845_EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r16311 r16317  
    163163      }
    164164
    165       if (content.ProgressBarMode == ProgressBarMode.Continuous) {
    166         progressBar.Style = ProgressBarStyle.Continuous;
    167         progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
    168       } else {
    169         progressBar.Style = ProgressBarStyle.Marquee;
    170         progressBar.Value = 0;
     165      switch (content.ProgressMode) {
     166        case ProgressMode.Determinate:
     167          progressBar.Style = ProgressBarStyle.Continuous;
     168          progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
     169          break;
     170        case ProgressMode.Indeterminate:
     171          progressBar.Style = ProgressBarStyle.Marquee;
     172          progressBar.Value = 0;
     173          break;
     174        default:
     175          throw new NotImplementedException($"Invalid Progress Mode: {content.ProgressMode}");
    171176      }
    172177    }
  • branches/2845_EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r16314 r16317  
    381381    /// Adds a <see cref="ProgressView"/> to the specified view.
    382382    /// </summary>
    383     internal void AddProgressToView(Control control, IProgress progress) {
     383    internal void AddProgressToControl(Control control, IProgress progress) {
    384384      if (InvokeRequired) {
    385         Invoke((Action<Control, IProgress>)AddProgressToView, control, progress);
     385        Invoke((Action<Control, IProgress>)AddProgressToControl, control, progress);
    386386        return;
    387387      }
     
    426426    /// Removes an existing <see cref="ProgressView"/> from the specified view.
    427427    /// </summary>
    428     internal void RemoveProgressFromView(Control control, bool finishProgress = true) {
     428    internal void RemoveProgressFromControl(Control control, bool finishProgress = true) {
    429429      if (InvokeRequired) {
    430         Invoke((Action<Control, bool>)RemoveProgressFromView, control, finishProgress);
     430        Invoke((Action<Control, bool>)RemoveProgressFromControl, control, finishProgress);
    431431        return;
    432432      }
  • branches/2845_EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Progress.cs

    r16314 r16317  
    4848    }
    4949
    50     private ProgressBarMode progressBarMode;
    51     public ProgressBarMode ProgressBarMode {
    52       get { return progressBarMode; }
    53       set {
    54         if (progressBarMode != value) {
    55           progressBarMode = value;
     50    private ProgressMode progressMode;
     51    public ProgressMode ProgressMode {
     52      get { return progressMode; }
     53      set {
     54        if (progressMode != value) {
     55          progressMode = value;
    5656          OnProgressBarModeChanged();
    5757        }
     
    6363      get { return progressValue; }
    6464      set {
    65         if (progressBarMode == ProgressBarMode.Marquee)
    66           throw new InvalidOperationException("Cannot set ProgressValue while ProgressBar is in Marquee-Mode");
     65        if (progressMode == ProgressMode.Indeterminate)
     66          throw new InvalidOperationException("Cannot set ProgressValue while ProgressBar is in Indeterminate-Mode");
    6767        if (progressValue != value) {
    6868          progressValue = Math.Max(Math.Min(value, 1.0), 0.0);
     
    9898      canBeStopped = false;
    9999      canBeCanceled = false;
    100       progressBarMode = ProgressBarMode.Marquee;
     100      progressMode = ProgressMode.Indeterminate;
    101101      progressValue = 0.0;
    102102    }
    103103
    104     public void Start(string message, double progressValue = 0) {
     104    public void Start(string message, ProgressMode mode = ProgressMode.Determinate) {
    105105      ProgressState = ProgressState.Started;
    106       ProgressBarMode = ProgressBarMode.Continuous;
    107       ProgressValue = progressValue;
     106      ProgressMode = mode;
     107      if (mode == ProgressMode.Determinate)
     108        ProgressValue = 0.0;
    108109      Message = message;
    109110    }
    110     public void StartMarquee(string message) {
    111       ProgressState = ProgressState.Started;
    112       ProgressBarMode = ProgressBarMode.Marquee;
    113       Message = message;
    114     }
    115111
    116112    public void Finish() {
    117       if (ProgressBarMode == ProgressBarMode.Continuous && ProgressValue != 1.0)
     113      if (ProgressMode == ProgressMode.Determinate && ProgressValue != 1.0)
    118114        ProgressValue = 1.0;
    119115      ProgressState = ProgressState.Finished;
     
    135131    #region Show/Hide Progress
    136132    /// <summary>
    137     /// Shows a started Progress in Continuous-mode on all Views of the specified content.
    138     /// </summary>
    139     public static IProgress Show(IContent content, string progressMessage, double initialProgressValue = 0, bool addToObjectGraphObjects = true) {
     133    /// Shows a started Progress on all Views of the specified content.
     134    /// </summary>
     135    public static IProgress Show(IContent content, string progressMessage, ProgressMode mode = ProgressMode.Determinate, bool addToObjectGraphObjects = true) {
    140136      var progress = new Progress();
    141       progress.Start(progressMessage, initialProgressValue);
     137      progress.Start(progressMessage, mode);
    142138      AddProgressToContent(content, progress, addToObjectGraphObjects);
    143139      return progress;
    144140    }
    145     /// <summary>
    146     /// Shows a started Progress in Marquee-mode on all Views of the specified content.
    147     /// </summary>
    148     public static IProgress ShowMarquee(IContent content, string progressMessage, bool addToObjectGraphObjects = true) {
     141
     142    /// <summary>
     143    /// Shows a started Progress on the specified view.
     144    /// </summary>
     145    public static IProgress Show(IView view, string progressMessage, ProgressMode mode = ProgressMode.Determinate) {
    149146      var progress = new Progress();
    150       progress.StartMarquee(progressMessage);
    151       AddProgressToContent(content, progress, addToObjectGraphObjects);
    152       return progress;
    153     }
    154 
    155     /// <summary>
    156     /// Shows a started Progress in Continuous-mode on the specified view.
    157     /// </summary>
    158     public static IProgress Show(Control control, string progressMessage, double initialProgressValue = 0) {
     147      progress.Start(progressMessage, mode);
     148      AddProgressToView(view, progress);
     149      return progress;
     150    }
     151    /// <summary>
     152    /// Shows a started Progress on the specified control.
     153    /// </summary>
     154    /// <remarks>Use Progress.Show(IView, ...) if possible.</remarks>
     155    public static IProgress ShowOnControl(Control control, string progressMessage, ProgressMode mode = ProgressMode.Determinate) {
    159156      var progress = new Progress();
    160       progress.Start(progressMessage, initialProgressValue);
    161       AddProgressToView(control, progress);
    162       return progress;
    163     }
    164     /// <summary>
    165     /// Shows a started Progress in Marquee-mode on the specified view.
    166     /// </summary>
    167     public static IProgress ShowMarquee(Control control, string progressMessage) {
    168       var progress = new Progress();
    169       progress.StartMarquee(progressMessage);
    170       AddProgressToView(control, progress);
     157      progress.Start(progressMessage, mode);
     158      AddProgressToControl(control, progress);
    171159      return progress;
    172160    }
     
    181169    /// Hides the Progress from the specified view.
    182170    /// </summary>
    183     public static void Hide(Control control) {
    184       RemoveProgressFromView(control);
     171    public static void Hide(IView view) {
     172      RemoveProgressFromView(view);
     173    }
     174    /// <summary>
     175    /// Hides the Progress from the specified control.
     176    /// </summary>
     177    /// <remarks>Use Progress.Hide(IView) if possible.</remarks>
     178    public static void HideFromControl(Control control) {
     179      RemoveProgressFromControl(control);
    185180    }
    186181    #endregion
    187182
    188     #region Interface to from MainForm
     183    #region Interface to MainForm
    189184    public static IProgress AddProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
    190185      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToContent(content, progress, addToObjectGraphObjects);
    191186      return progress;
    192187    }
    193     public static IProgress AddProgressToView(Control control, IProgress progress) {
    194       MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToView(control, progress);
     188    public static IProgress AddProgressToView(IView view, IProgress progress) {
     189      //return AddProgressToControl(MainFormManager.GetMainForm<WindowsForms.MainForm>().GetForm(view), progress);
     190      return AddProgressToControl((Control)view, progress);
     191    }
     192    public static IProgress AddProgressToControl(Control control, IProgress progress) {
     193      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToControl(control, progress);
    195194      return progress;
    196195    }
     
    199198      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromContent(content, finishProgress);
    200199    }
    201     public static void RemoveProgressFromView(Control control, bool finishProgress = true) {
    202       MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromView(control, finishProgress);
     200    public static void RemoveProgressFromView(IView view, bool finishProgress = true) {
     201      //RemoveProgressFromControl(MainFormManager.GetMainForm<WindowsForms.MainForm>().GetForm(view), finishProgress);
     202      RemoveProgressFromControl((Control)view, finishProgress);
     203    }
     204    public static void RemoveProgressFromControl(Control control, bool finishProgress = true) {
     205      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromControl(control, finishProgress);
    203206    }
    204207    #endregion
Note: See TracChangeset for help on using the changeset viewer.