Changeset 16318


Ignore:
Timestamp:
11/22/18 15:17:42 (17 months 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
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2845_EnhancedProgress/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs

    r16317 r16318  
    8181      base.RegisterContentEvents();
    8282      matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged;
    83       MainForm.Progress.AddProgressToView(this, progress);
     83      MainForm.Progress.Show(this, progress);
    8484    }
    8585
    8686    protected override void DeregisterContentEvents() {
    8787      matrixView.DataGridView.SelectionChanged -= DataGridView_SelectionChanged;
    88       MainForm.Progress.RemoveProgressFromView(this, false);
     88      MainForm.Progress.Hide(this, false);
    8989      base.DeregisterContentEvents();
    9090    }
  • branches/2845_EnhancedProgress/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r16317 r16318  
    7575      Content.Loaded += new EventHandler(Content_Loaded);
    7676      Content.TaskReceived += new EventHandler(Content_TaskReceived);
    77       Progress.AddProgressToView(this, Content.Progress);
     77      Progress.Show(this, Content.Progress);
    7878    }
    7979
     
    9090      Content.Loaded -= new EventHandler(Content_Loaded);
    9191      Content.TaskReceived -= new EventHandler(Content_TaskReceived);
    92       Progress.RemoveProgressFromView(this, false);
     92      Progress.Hide(this, false);
    9393      DeregisterHiveExperimentEvents();
    9494      DeregisterHiveTasksEvents();
  • branches/2845_EnhancedProgress/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r16317 r16318  
    5858      base.RegisterContentEvents();
    5959      Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
    60       Progress.AddProgressToView(this, Content.Progress);
     60      Progress.Show(this, Content.Progress);
    6161    }
    6262
    6363    protected override void DeregisterContentEvents() {
    6464      Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
    65       Progress.RemoveProgressFromView(this, false);
     65      Progress.Hide(this, false);
    6666      base.DeregisterContentEvents();
    6767    }
  • 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    }
  • branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r16317 r16318  
    154154      Content.ProblemDataChanged += Content_Changed;
    155155      treeChart.Repainted += treeChart_Repainted;
    156       Progress.AddProgressToControl(grpSimplify, progress);
     156      Progress.ShowOnControl(grpSimplify, progress);
    157157      progress.StopRequested += progress_StopRequested;
    158158    }
     
    162162      Content.ProblemDataChanged -= Content_Changed;
    163163      treeChart.Repainted -= treeChart_Repainted;
    164       Progress.RemoveProgressFromControl(grpSimplify, false);
     164      Progress.HideFromControl(grpSimplify, false);
    165165      progress.StopRequested -= progress_StopRequested;
    166166    }
Note: See TracChangeset for help on using the changeset viewer.