2017-12-11 14:15:50 -08:00
|
|
|
|
/*
|
2018-05-07 13:12:32 -07:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2017-12-11 14:15:50 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-06-24 13:48:20 -07:00
|
|
|
|
using System;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.Platform;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2018-07-20 14:40:41 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
public class RunningTaskRow : FlowLayoutWidget
|
|
|
|
|
|
{
|
2018-06-24 17:18:37 -07:00
|
|
|
|
internal RunningTaskDetails taskDetails;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
|
2018-06-24 17:18:37 -07:00
|
|
|
|
private ProgressBar progressBar;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
private ExpandCheckboxButton expandButton;
|
2018-06-24 17:18:37 -07:00
|
|
|
|
private ThemeConfig theme;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
|
|
|
|
|
|
public RunningTaskRow(string title, RunningTaskDetails taskDetails, ThemeConfig theme)
|
|
|
|
|
|
: base(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.taskDetails = taskDetails;
|
2018-06-24 17:18:37 -07:00
|
|
|
|
this.theme = theme;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
|
2020-10-26 07:00:13 -07:00
|
|
|
|
this.MinimumSize = new Vector2(100 * GuiWidget.DeviceScale, 20 * GuiWidget.DeviceScale);
|
2017-12-11 14:15:50 -08:00
|
|
|
|
|
|
|
|
|
|
var detailsPanel = new GuiWidget()
|
|
|
|
|
|
{
|
2017-12-12 08:52:13 -08:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var rowContainer = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
};
|
|
|
|
|
|
this.AddChild(rowContainer);
|
|
|
|
|
|
|
|
|
|
|
|
var topRow = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Padding = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
rowContainer.AddChild(topRow);
|
|
|
|
|
|
|
|
|
|
|
|
progressBar = new ProgressBar()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2020-08-05 10:07:40 -07:00
|
|
|
|
Height = 2 * GuiWidget.DeviceScale,
|
2017-12-11 14:15:50 -08:00
|
|
|
|
VAnchor = VAnchor.Absolute | VAnchor.Bottom,
|
2018-10-15 18:25:53 -07:00
|
|
|
|
FillColor = theme.PrimaryAccentColor,
|
2017-12-11 14:15:50 -08:00
|
|
|
|
BorderColor = Color.Transparent,
|
2018-06-24 17:16:13 -07:00
|
|
|
|
Margin = new BorderDouble(32, 7, theme.ButtonHeight * 2 + 14, 0),
|
2019-03-17 19:29:21 -07:00
|
|
|
|
Visible = !taskDetails.IsExpanded
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
|
|
|
|
|
rowContainer.AddChild(progressBar);
|
|
|
|
|
|
|
2018-04-12 08:42:10 -07:00
|
|
|
|
expandButton = new ExpandCheckboxButton(!string.IsNullOrWhiteSpace(title) ? title : taskDetails.Title, theme, 10)
|
2017-12-11 14:15:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
VAnchor = VAnchor.Center | VAnchor.Fit,
|
2018-07-18 19:21:57 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2017-12-11 14:15:50 -08:00
|
|
|
|
Checked = false,
|
2018-10-26 22:10:49 -07:00
|
|
|
|
Padding = 0,
|
|
|
|
|
|
AlwaysShowArrow = true
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
2018-03-25 15:35:20 -07:00
|
|
|
|
expandButton.CheckedStateChanged += (s, e) =>
|
2017-12-11 14:15:50 -08:00
|
|
|
|
{
|
2018-05-07 13:12:32 -07:00
|
|
|
|
taskDetails.IsExpanded = expandButton.Checked;
|
|
|
|
|
|
SetExpansionMode(theme, detailsPanel, expandButton.Checked);
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
|
|
|
|
|
topRow.AddChild(expandButton);
|
|
|
|
|
|
|
2021-02-24 18:17:14 -08:00
|
|
|
|
GuiWidget resumeButton = null;
|
2017-12-12 17:53:32 -08:00
|
|
|
|
|
2021-02-24 18:17:14 -08:00
|
|
|
|
GuiWidget pauseButton = CreateIconOrTextButton("fa-pause_12.png",
|
|
|
|
|
|
taskDetails.Options?.PauseText,
|
|
|
|
|
|
taskDetails.Options?.PauseAction,
|
|
|
|
|
|
taskDetails.Options?.PauseToolTip ?? "Pause".Localize(),
|
|
|
|
|
|
"",
|
2021-02-24 23:00:56 -08:00
|
|
|
|
theme,
|
|
|
|
|
|
0);
|
2021-02-24 18:17:14 -08:00
|
|
|
|
|
|
|
|
|
|
if (taskDetails.Options?.IsPaused != null)
|
2018-09-17 14:31:26 -07:00
|
|
|
|
{
|
|
|
|
|
|
RunningInterval runningInterval = null;
|
|
|
|
|
|
runningInterval = UiThread.SetInterval(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if(taskDetails.Options.IsPaused())
|
|
|
|
|
|
{
|
|
|
|
|
|
pauseButton.Visible = false;
|
|
|
|
|
|
resumeButton.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
pauseButton.Visible = true;
|
|
|
|
|
|
resumeButton.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.HasBeenClosed)
|
|
|
|
|
|
{
|
2018-11-13 16:52:23 -08:00
|
|
|
|
UiThread.ClearInterval(runningInterval);
|
2018-09-17 14:31:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
}, .2);
|
|
|
|
|
|
}
|
2017-12-11 14:15:50 -08:00
|
|
|
|
pauseButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2021-02-24 23:00:56 -08:00
|
|
|
|
taskDetails.Options?.PauseAction();
|
2017-12-12 17:53:32 -08:00
|
|
|
|
pauseButton.Visible = false;
|
|
|
|
|
|
resumeButton.Visible = true;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
|
|
|
|
|
topRow.AddChild(pauseButton);
|
|
|
|
|
|
|
2021-02-24 18:17:14 -08:00
|
|
|
|
|
|
|
|
|
|
resumeButton = CreateIconOrTextButton("fa-play_12.png",
|
|
|
|
|
|
taskDetails.Options?.ResumeText,
|
|
|
|
|
|
taskDetails.Options?.ResumeAction,
|
|
|
|
|
|
taskDetails.Options?.ResumeToolTip ?? "Resume".Localize(),
|
2021-03-06 22:34:13 -08:00
|
|
|
|
"Resume Task Button",
|
2021-02-24 23:00:56 -08:00
|
|
|
|
theme,
|
|
|
|
|
|
0);
|
2021-02-24 18:17:14 -08:00
|
|
|
|
// start with it hidden
|
|
|
|
|
|
resumeButton.Visible = false;
|
|
|
|
|
|
|
2017-12-12 17:53:32 -08:00
|
|
|
|
resumeButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2021-02-24 23:00:56 -08:00
|
|
|
|
taskDetails.Options?.ResumeAction();
|
2017-12-12 17:53:32 -08:00
|
|
|
|
pauseButton.Visible = true;
|
|
|
|
|
|
resumeButton.Visible = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
topRow.AddChild(resumeButton);
|
|
|
|
|
|
|
2021-02-24 18:17:14 -08:00
|
|
|
|
var stopButton = CreateIconOrTextButton("fa-stop_12.png",
|
|
|
|
|
|
taskDetails.Options?.StopText,
|
|
|
|
|
|
taskDetails.Options?.StopAction,
|
|
|
|
|
|
taskDetails.Options?.StopToolTip ?? "Cancel".Localize(),
|
|
|
|
|
|
"Stop Task Button",
|
2021-02-24 23:00:56 -08:00
|
|
|
|
theme,
|
|
|
|
|
|
5);
|
2021-02-24 18:17:14 -08:00
|
|
|
|
|
2021-03-06 09:49:43 -08:00
|
|
|
|
stopButton.Enabled = true;
|
|
|
|
|
|
|
2017-12-11 14:15:50 -08:00
|
|
|
|
stopButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2018-05-06 08:29:24 -07:00
|
|
|
|
var stopAction = taskDetails.Options?.StopAction;
|
2017-12-12 17:53:32 -08:00
|
|
|
|
if (stopAction == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
taskDetails.CancelTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-03-19 15:11:34 -07:00
|
|
|
|
stopAction.Invoke(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
stopButton.Enabled = true;
|
|
|
|
|
|
});
|
2017-12-12 17:53:32 -08:00
|
|
|
|
}
|
2019-03-19 13:44:07 -07:00
|
|
|
|
|
|
|
|
|
|
stopButton.Enabled = false;
|
2017-12-11 14:15:50 -08:00
|
|
|
|
};
|
|
|
|
|
|
topRow.AddChild(stopButton);
|
|
|
|
|
|
|
2017-12-12 08:52:13 -08:00
|
|
|
|
this.AddChild(detailsPanel);
|
|
|
|
|
|
|
|
|
|
|
|
// Add rich progress controls
|
2018-05-06 08:29:24 -07:00
|
|
|
|
if (taskDetails.Options?.RichProgressWidget?.Invoke() is GuiWidget guiWidget)
|
2017-12-12 08:52:13 -08:00
|
|
|
|
{
|
|
|
|
|
|
detailsPanel.AddChild(guiWidget);
|
|
|
|
|
|
}
|
2018-10-26 22:10:49 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
expandButton.Expandable = false;
|
|
|
|
|
|
}
|
2017-12-12 08:52:13 -08:00
|
|
|
|
|
2018-05-06 08:29:24 -07:00
|
|
|
|
if (taskDetails.Options?.ReadOnlyReporting == true)
|
2018-04-09 16:59:17 -07:00
|
|
|
|
{
|
|
|
|
|
|
stopButton.Visible = false;
|
|
|
|
|
|
pauseButton.Visible = false;
|
|
|
|
|
|
resumeButton.Visible = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure the top row is as big as it would be with buttons
|
|
|
|
|
|
topRow.MinimumSize = new Vector2(0, resumeButton.Height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 13:12:32 -07:00
|
|
|
|
SetExpansionMode(theme, detailsPanel, taskDetails.IsExpanded);
|
|
|
|
|
|
|
2017-12-11 14:15:50 -08:00
|
|
|
|
taskDetails.ProgressChanged += TaskDetails_ProgressChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-24 23:00:56 -08:00
|
|
|
|
private static GuiWidget CreateIconOrTextButton(string iconFilename,
|
|
|
|
|
|
string buttonText,
|
|
|
|
|
|
Object clickAction,
|
|
|
|
|
|
string toolTip,
|
|
|
|
|
|
string name,
|
|
|
|
|
|
ThemeConfig theme,
|
|
|
|
|
|
double marginX)
|
2021-02-24 18:17:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(buttonText))
|
|
|
|
|
|
{
|
2021-05-21 15:23:25 -07:00
|
|
|
|
return new IconButton(StaticData.Instance.LoadIcon(iconFilename, 12, 12).SetToColor(theme.TextColor), theme)
|
2021-02-24 18:17:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
Margin = theme.ButtonSpacing,
|
|
|
|
|
|
Enabled = clickAction != null,
|
|
|
|
|
|
ToolTipText = toolTip,
|
|
|
|
|
|
Name = name,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var oldSize = theme.DefaultFontSize;
|
|
|
|
|
|
theme.DefaultFontSize = 8;
|
2021-05-21 15:23:25 -07:00
|
|
|
|
var pauseButton = new TextIconButton(buttonText, StaticData.Instance.LoadIcon(iconFilename, 12, 12).SetToColor(theme.TextColor), theme)
|
2021-02-24 18:17:14 -08:00
|
|
|
|
{
|
2021-02-24 23:00:56 -08:00
|
|
|
|
Margin = new BorderDouble(marginX, 0),
|
2021-02-24 18:17:14 -08:00
|
|
|
|
Padding = new BorderDouble(7, 3),
|
|
|
|
|
|
VAnchor = VAnchor.Fit | VAnchor.Center,
|
|
|
|
|
|
HAnchor = HAnchor.Fit,
|
2021-02-24 23:00:56 -08:00
|
|
|
|
// BackgroundColor = new Color(theme.AccentMimimalOverlay, 50),
|
2021-02-24 18:17:14 -08:00
|
|
|
|
HoverColor = theme.AccentMimimalOverlay,
|
2021-02-24 23:00:56 -08:00
|
|
|
|
BorderColor = theme.TextColor,
|
2021-02-26 10:54:33 -08:00
|
|
|
|
BackgroundOutlineWidth = 1,
|
2021-02-24 18:17:14 -08:00
|
|
|
|
|
|
|
|
|
|
// Margin = theme.ButtonSpacing,
|
|
|
|
|
|
Enabled = clickAction != null,
|
|
|
|
|
|
ToolTipText = toolTip,
|
|
|
|
|
|
Name = name,
|
|
|
|
|
|
};
|
2021-02-26 10:54:33 -08:00
|
|
|
|
((TextIconButton)pauseButton).BackgroundRadius = pauseButton.Height / 2;
|
2021-02-24 18:17:14 -08:00
|
|
|
|
theme.DefaultFontSize = oldSize;
|
|
|
|
|
|
|
|
|
|
|
|
return pauseButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-24 17:18:37 -07:00
|
|
|
|
public Color ProgressBackgroundColor
|
|
|
|
|
|
{
|
|
|
|
|
|
get => progressBar.BackgroundColor = this.BorderColor;
|
|
|
|
|
|
set => progressBar.BackgroundColor = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 13:12:32 -07:00
|
|
|
|
private void SetExpansionMode(ThemeConfig theme, GuiWidget detailsPanel, bool isExpanded)
|
|
|
|
|
|
{
|
2018-05-31 07:01:51 -07:00
|
|
|
|
expandButton.Checked = isExpanded;
|
2018-10-15 18:25:53 -07:00
|
|
|
|
progressBar.FillColor = isExpanded ? theme.Shade : theme.PrimaryAccentColor;
|
2018-05-07 13:12:32 -07:00
|
|
|
|
detailsPanel.Visible = isExpanded;
|
2019-03-17 19:29:21 -07:00
|
|
|
|
progressBar.Visible = !isExpanded;
|
2018-05-07 13:12:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2017-12-11 14:15:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
taskDetails.ProgressChanged -= TaskDetails_ProgressChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void TaskDetails_ProgressChanged(object sender, ProgressStatus e)
|
|
|
|
|
|
{
|
2018-04-09 16:59:17 -07:00
|
|
|
|
if (expandButton.Text != e.Status
|
2018-06-24 13:48:20 -07:00
|
|
|
|
&& !string.IsNullOrEmpty(e.Status)
|
|
|
|
|
|
&& !expandButton.Text.Contains(e.Status, StringComparison.OrdinalIgnoreCase))
|
2017-12-11 14:15:50 -08:00
|
|
|
|
{
|
2018-06-24 13:48:20 -07:00
|
|
|
|
expandButton.Text = e.Status.Contains(taskDetails.Title, StringComparison.OrdinalIgnoreCase) ? e.Status : $"{taskDetails.Title} - {e.Status}";
|
2017-12-11 14:15:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-18 13:22:11 -07:00
|
|
|
|
double ratio = ((int)(e.Progress0To1 * Width))/this.Width;
|
|
|
|
|
|
if (progressBar.RatioComplete != ratio)
|
|
|
|
|
|
{
|
|
|
|
|
|
progressBar.RatioComplete = ratio;
|
|
|
|
|
|
this.Invalidate();
|
|
|
|
|
|
}
|
2017-12-11 14:15:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-24 13:48:20 -07:00
|
|
|
|
|
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static bool Contains(this string text, string value, StringComparison stringComparison)
|
|
|
|
|
|
{
|
|
|
|
|
|
return text.IndexOf(value, stringComparison) >= 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-11 14:15:50 -08:00
|
|
|
|
}
|