2014-01-29 19:09:30 -08:00
|
|
|
|
/*
|
2019-05-11 14:45:41 -07:00
|
|
|
|
Copyright (c) 2019, John Lewin
|
2017-05-26 11:23:41 -07:00
|
|
|
|
|
2014-01-29 19:09:30 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-01-29 19:09:30 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-05-31 12:42:44 -07:00
|
|
|
|
using System.Collections.Generic;
|
2019-06-12 17:15:19 -07:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2018-11-11 08:42:13 -08:00
|
|
|
|
using MatterHackers.MatterControl;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2017-05-26 11:23:41 -07:00
|
|
|
|
namespace MatterHackers.Agg.UI
|
2014-01-29 19:09:30 -08:00
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public class SceneOperation
|
2017-12-04 10:35:24 -08:00
|
|
|
|
{
|
2020-09-27 08:17:47 -07:00
|
|
|
|
public SceneOperation(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Id = id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Id { get; }
|
2020-09-24 06:57:19 -07:00
|
|
|
|
|
2019-02-01 16:12:12 -08:00
|
|
|
|
public Action<ISceneContext> Action { get; set; }
|
2019-05-11 14:45:41 -07:00
|
|
|
|
|
2020-09-24 22:20:27 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the type this operation outputs
|
|
|
|
|
|
/// </summary>
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public Type ResultType { get; set; }
|
|
|
|
|
|
|
2021-05-21 14:24:45 -07:00
|
|
|
|
public Func<ThemeConfig, ImageBuffer> Icon { get; set; }
|
2019-05-11 14:45:41 -07:00
|
|
|
|
|
2020-06-26 08:07:53 -07:00
|
|
|
|
public Func<ISceneContext, bool> IsEnabled { get; set; } = (sceneContext) => true;
|
2017-09-18 17:57:06 -07:00
|
|
|
|
|
2022-01-21 15:21:07 -08:00
|
|
|
|
public Func<string> HelpTextGetter { get; set; }
|
2019-06-12 17:15:19 -07:00
|
|
|
|
|
2022-01-21 15:21:07 -08:00
|
|
|
|
public string HelpText => this.HelpTextGetter?.Invoke();
|
2019-06-13 08:16:50 -07:00
|
|
|
|
|
2022-01-21 15:21:07 -08:00
|
|
|
|
public Func<string> TitleGetter { get; set; }
|
2020-06-26 08:07:53 -07:00
|
|
|
|
|
2022-01-21 15:21:07 -08:00
|
|
|
|
public string Title => this.TitleGetter?.Invoke();
|
2019-06-13 08:16:50 -07:00
|
|
|
|
|
2020-09-24 22:20:27 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the type that this operation can be applied to
|
|
|
|
|
|
/// </summary>
|
2020-05-30 08:59:32 -07:00
|
|
|
|
public Type OperationType { get; set; }
|
2020-09-24 13:53:49 -07:00
|
|
|
|
|
2020-09-25 23:20:58 -07:00
|
|
|
|
/// <summary>
|
2020-09-26 18:46:08 -07:00
|
|
|
|
/// Gets or sets if this operation should be shown in right click and modify menu.
|
2020-09-25 23:20:58 -07:00
|
|
|
|
/// </summary>
|
2020-09-26 18:46:08 -07:00
|
|
|
|
public Func<ISceneContext, bool> ShowInModifyMenu { get; set; }
|
2018-01-10 11:38:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public class SceneSelectionSeparator : SceneOperation
|
2017-05-31 12:42:44 -07:00
|
|
|
|
{
|
2020-09-27 08:17:47 -07:00
|
|
|
|
public SceneSelectionSeparator()
|
|
|
|
|
|
: base(null)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2017-05-31 12:42:44 -07:00
|
|
|
|
}
|
2019-06-13 08:16:50 -07:00
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public class OperationGroup : SceneOperation
|
2019-06-13 08:16:50 -07:00
|
|
|
|
{
|
2020-09-27 08:17:47 -07:00
|
|
|
|
public OperationGroup(string id)
|
|
|
|
|
|
: base(id)
|
2019-06-13 08:28:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public List<SceneOperation> Operations { get; set; } = new List<SceneOperation>();
|
2019-06-13 08:16:50 -07:00
|
|
|
|
|
2020-09-26 18:46:08 -07:00
|
|
|
|
public int InitialSelectionIndex { get; set; } = 0;
|
2020-09-24 07:19:30 -07:00
|
|
|
|
|
2020-09-27 08:17:47 -07:00
|
|
|
|
public string GroupRecordId => $"ActiveButton_{this.Id}_Group";
|
2019-06-17 12:09:18 -07:00
|
|
|
|
|
2021-09-14 14:15:51 -07:00
|
|
|
|
public EventHandler CollapseChanged;
|
|
|
|
|
|
|
2021-09-14 17:18:48 -07:00
|
|
|
|
private static string CollapseKey(string opperationGroupName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $"scene_operation_collapse_{opperationGroupName}";
|
|
|
|
|
|
}
|
2021-09-14 14:15:51 -07:00
|
|
|
|
|
|
|
|
|
|
public bool Collapse
|
|
|
|
|
|
{
|
2021-09-14 17:18:48 -07:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return UserSettings.Instance.Fields.GetBool(CollapseKey(this.Id), true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-14 14:15:51 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2021-09-14 17:18:48 -07:00
|
|
|
|
if (Collapse != value)
|
2021-09-14 14:15:51 -07:00
|
|
|
|
{
|
2021-09-14 17:18:48 -07:00
|
|
|
|
UserSettings.Instance.Fields.SetBool(CollapseKey(Id), value);
|
2021-09-14 14:15:51 -07:00
|
|
|
|
CollapseChanged?.Invoke(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-06-20 13:29:58 -07:00
|
|
|
|
|
2021-09-14 17:18:48 -07:00
|
|
|
|
public EventHandler VisibleChanged;
|
|
|
|
|
|
|
2021-09-15 17:44:24 -07:00
|
|
|
|
private static string VisibleKey(string opperationGroupName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return $"scene_operation_visible_{opperationGroupName}";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool GetVisible(string id, bool defaultIfNotSet)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UserSettings.Instance.Fields.GetBool(VisibleKey(id), defaultIfNotSet);
|
|
|
|
|
|
}
|
2021-09-14 17:18:48 -07:00
|
|
|
|
|
|
|
|
|
|
public bool Visible
|
|
|
|
|
|
{
|
2021-09-15 17:44:24 -07:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetVisible(this.Id, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-14 17:18:48 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2021-09-15 17:44:24 -07:00
|
|
|
|
if (Visible != value)
|
2021-09-14 17:18:48 -07:00
|
|
|
|
{
|
2021-09-15 17:44:24 -07:00
|
|
|
|
UserSettings.Instance.Fields.SetBool(VisibleKey(Id), value);
|
2021-09-14 17:18:48 -07:00
|
|
|
|
VisibleChanged?.Invoke(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public SceneOperation GetDefaultOperation()
|
2019-06-17 12:09:18 -07:00
|
|
|
|
{
|
2020-10-01 19:34:55 -07:00
|
|
|
|
if (!int.TryParse(UserSettings.Instance.get(GroupRecordId), out int activeButtonID))
|
2019-06-17 12:09:18 -07:00
|
|
|
|
{
|
2020-10-01 19:34:55 -07:00
|
|
|
|
activeButtonID = InitialSelectionIndex;
|
2019-06-17 12:09:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-01 19:34:55 -07:00
|
|
|
|
activeButtonID = agg_basics.Clamp(activeButtonID, 0, this.Operations.Count - 1);
|
|
|
|
|
|
|
|
|
|
|
|
return this.Operations[activeButtonID];
|
2019-06-17 12:09:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|