Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/18 15:17:42 (6 years ago)
Author:
pfleck
Message:

#2845 Add optional stop and cancel handler to the Show helpers. Replaced the AddProgressTo... and RemoveProgressFrom... methods with the existing Show and Hide methods.

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

Legend:

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

    r16317 r16318  
    353353    /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content.
    354354    /// </summary>
    355     internal void AddProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
     355    internal void AddProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects) {
    356356      if (InvokeRequired) {
    357357        Invoke((Action<IContent, IProgress, bool>)AddProgressToContent, content, progress, addToObjectGraphObjects);
     
    405405    /// Removes an existing <see cref="ProgressView"/> from the <see cref="ContentView"/>s showing the specified content.
    406406    /// </summary>
    407     internal void RemoveProgressFromContent(IContent content, bool finishProgress = true) {
     407    internal void RemoveProgressFromContent(IContent content, bool finishProgress) {
    408408      if (InvokeRequired) {
    409409        Invoke((Action<IContent, bool>)RemoveProgressFromContent, content, finishProgress);
     
    426426    /// Removes an existing <see cref="ProgressView"/> from the specified view.
    427427    /// </summary>
    428     internal void RemoveProgressFromControl(Control control, bool finishProgress = true) {
     428    internal void RemoveProgressFromControl(Control control, bool finishProgress) {
    429429      if (InvokeRequired) {
    430430        Invoke((Action<Control, bool>)RemoveProgressFromControl, control, finishProgress);
  • branches/2845_EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Progress.cs

    r16317 r16318  
    129129    }
    130130
    131     #region Show/Hide Progress
     131    #region Show and Hide Progress
    132132    /// <summary>
    133133    /// Shows a started Progress on all Views of the specified content.
    134134    /// </summary>
    135     public static IProgress Show(IContent content, string progressMessage, ProgressMode mode = ProgressMode.Determinate, bool addToObjectGraphObjects = true) {
     135    public static IProgress Show(IContent content, string progressMessage, ProgressMode mode = ProgressMode.Determinate, Action stopRequestHandler = null, Action cancelRequestHandler = null, bool addToObjectGraphObjects = true) {
     136      var progress = CreateAndStartProgress(progressMessage, mode, stopRequestHandler, cancelRequestHandler);
     137      Show(content, progress, addToObjectGraphObjects);
     138      return progress;
     139    }
     140
     141    /// <summary>
     142    /// Shows a started Progress on the specified view.
     143    /// </summary>
     144    public static IProgress Show(IView view, string progressMessage, ProgressMode mode = ProgressMode.Determinate, Action stopRequestHandler = null, Action cancelRequestHandler = null) {
     145      var progress = CreateAndStartProgress(progressMessage, mode, stopRequestHandler, cancelRequestHandler);
     146      Show(view, progress);
     147      return progress;
     148    }
     149    /// <summary>
     150    /// Shows a started Progress on the specified control.
     151    /// </summary>
     152    /// <remarks>For backwards compatibility. Use Progress.Show(IView, ...) if possible.</remarks>
     153    public static IProgress ShowOnControl(Control control, string progressMessage, ProgressMode mode = ProgressMode.Determinate, Action stopRequestHandler = null, Action cancelRequestHandler = null) {
     154      var progress = CreateAndStartProgress(progressMessage, mode, stopRequestHandler, cancelRequestHandler);
     155      ShowOnControl(control, progress);
     156      return progress;
     157    }
     158
     159    private static IProgress CreateAndStartProgress(string progressMessage, ProgressMode mode, Action stopRequestHandler, Action cancelRequestHandler) {
    136160      var progress = new Progress();
     161      if (stopRequestHandler != null) {
     162        progress.CanBeStopped = true;
     163        progress.StopRequested += (s, a) => stopRequestHandler();
     164      }
     165      if (cancelRequestHandler != null) {
     166        progress.CanBeCanceled = true;
     167        progress.CancelRequested += (s, a) => cancelRequestHandler();
     168      }
    137169      progress.Start(progressMessage, mode);
    138       AddProgressToContent(content, progress, addToObjectGraphObjects);
    139       return progress;
    140     }
    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) {
    146       var progress = new Progress();
    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) {
    156       var progress = new Progress();
    157       progress.Start(progressMessage, mode);
    158       AddProgressToControl(control, progress);
     170      return progress;
     171    }
     172
     173    /// <summary>
     174    /// Shows an existing progress on all Views of the specified content.
     175    /// </summary>
     176    public static IProgress Show(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
     177      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToContent(content, progress, addToObjectGraphObjects);
     178      return progress;
     179    }
     180    /// <summary>
     181    /// Shows an existing progress on the specified View.
     182    /// </summary>
     183    public static IProgress Show(IView view, IProgress progress) {
     184      return ShowOnControl((Control)view, progress);
     185    }
     186    /// <summary>
     187    /// Shows an existing progress on the specified control.
     188    /// </summary>
     189    /// <remarks>For backwards compatibility. Use Progress.Show(IView, ...) if possible.</remarks>
     190    public static IProgress ShowOnControl(Control control, IProgress progress) {
     191      MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToControl(control, progress);
    159192      return progress;
    160193    }
     
    163196    /// Hides the Progress from all Views of the specified content.
    164197    /// </summary>
    165     public static void Hide(IContent content) {
    166       RemoveProgressFromContent(content);
     198    public static void Hide(IContent content, bool finishProgress = true) {
     199      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromContent(content, finishProgress);
    167200    }
    168201    /// <summary>
    169202    /// Hides the Progress from the specified view.
    170203    /// </summary>
    171     public static void Hide(IView view) {
    172       RemoveProgressFromView(view);
     204    public static void Hide(IView view, bool finishProgress = true) {
     205      HideFromControl((Control)view, finishProgress);
    173206    }
    174207    /// <summary>
    175208    /// Hides the Progress from the specified control.
    176209    /// </summary>
    177     /// <remarks>Use Progress.Hide(IView) if possible.</remarks>
    178     public static void HideFromControl(Control control) {
    179       RemoveProgressFromControl(control);
    180     }
    181     #endregion
    182 
    183     #region Interface to MainForm
    184     public static IProgress AddProgressToContent(IContent content, IProgress progress, bool addToObjectGraphObjects = true) {
    185       MainFormManager.GetMainForm<WindowsForms.MainForm>().AddProgressToContent(content, progress, addToObjectGraphObjects);
    186       return progress;
    187     }
    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);
    194       return progress;
    195     }
    196 
    197     public static void RemoveProgressFromContent(IContent content, bool finishProgress = true) {
    198       MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromContent(content, finishProgress);
    199     }
    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) {
     210    /// <remarks>For backwards compatibility. Use Progress.Hide(IView) if possible.</remarks>
     211    public static void HideFromControl(Control control, bool finishProgress = true) {
    205212      MainFormManager.GetMainForm<WindowsForms.MainForm>().RemoveProgressFromControl(control, finishProgress);
    206213    }
Note: See TracChangeset for help on using the changeset viewer.