Extract embedded types to new files

This commit is contained in:
John Lewin 2017-09-07 08:11:52 -07:00
parent 801441e945
commit 19d14d0856
6 changed files with 309 additions and 174 deletions

View file

@ -295,14 +295,17 @@
<Compile Include="SlicerConfiguration\UIFields\BasicField.cs" />
<Compile Include="SlicerConfiguration\UIFields\DoubleField.cs" />
<Compile Include="SlicerConfiguration\UIFields\DoubleOrPercentField.cs" />
<Compile Include="SlicerConfiguration\UIFields\DropMenuWrappedField.cs" />
<Compile Include="SlicerConfiguration\UIFields\IntField.cs" />
<Compile Include="SlicerConfiguration\UIFields\IntOrMmField.cs" />
<Compile Include="SlicerConfiguration\UIFields\CheckboxField.cs" />
<Compile Include="SlicerConfiguration\UIFields\MultilineStringField.cs" />
<Compile Include="SlicerConfiguration\UIFields\ComPortField.cs" />
<Compile Include="SlicerConfiguration\UIFields\ListField.cs" />
<Compile Include="SlicerConfiguration\UIFields\ExtruderOffsetField.cs" />
<Compile Include="SlicerConfiguration\UIFields\NumberField.cs" />
<Compile Include="SlicerConfiguration\UIFields\TextField.cs" />
<Compile Include="SlicerConfiguration\UIFields\Vector2Field.cs" />
<Compile Include="SlicerConfiguration\UIFields\IntField.cs" />
<Compile Include="SlicerConfiguration\UIFields\PositiveDoubleField.cs" />
<Compile Include="SlicerConfiguration\SettingsContext.cs" />
<Compile Include="SlicerConfiguration\UIFields\IUIField.cs" />

View file

@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
@ -71,176 +70,4 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ValueChanged?.Invoke(this, fieldChangedEventArgs);
}
}
public class IntField : NumberField
{
private int intValue;
protected override string ConvertValue(string newValue)
{
decimal.TryParse(this.Value, out decimal currentValue);
intValue = (int)currentValue;
return intValue.ToString();
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
numberEdit.ActuallNumberEdit.Value = intValue;
base.OnValueChanged(fieldChangedEventArgs);
}
}
public abstract class NumberField : BasicField, IUIField
{
protected MHNumberEdit numberEdit;
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
public virtual void Initialize(int tabIndex)
{
numberEdit = new MHNumberEdit(0, pixelWidth: ControlWidth, tabIndex: tabIndex)
{
ToolTipText = this.HelpText,
SelectAllOnFocus = true,
Name = this.Name,
};
numberEdit.ActuallNumberEdit.EditComplete += (s, e) =>
{
if (this.Value != numberEdit.Value.ToString())
{
this.SetValue(
numberEdit.Value.ToString(),
userInitiated: true);
}
};
this.Content = numberEdit;
}
}
public class TextField : BasicField, IUIField
{
protected MHTextEditWidget textEditWidget;
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
public virtual void Initialize(int tabIndex)
{
textEditWidget = new MHTextEditWidget("", pixelWidth: ControlWidth, tabIndex: tabIndex)
{
ToolTipText = this.HelpText,
SelectAllOnFocus = true,
Name = this.Name,
};
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
{
if (this.Value != textEditWidget.Text)
{
this.SetValue(
textEditWidget.Text,
userInitiated: true);
}
};
this.Content = textEditWidget;
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
if (this.Value != textEditWidget.Text)
{
textEditWidget.Text = this.Value;
}
base.OnValueChanged(fieldChangedEventArgs);
}
}
public class DropMenuWrappedField : IUIField
{
private IUIField uiField;
private SliceSettingData settingData;
public DropMenuWrappedField(IUIField uiField, SliceSettingData settingData)
{
this.settingData = settingData;
this.uiField = uiField;
}
public void SetValue(string newValue, bool userInitiated)
{
uiField.SetValue(newValue, userInitiated);
}
public string Value { get => uiField.Value; }
public GuiWidget Content { get; private set; }
public event EventHandler<FieldChangedEventArgs> ValueChanged;
public void Initialize(int tabIndex)
{
var totalContent = new FlowLayoutWidget();
var selectableOptions = new DropDownList("Custom", maxHeight: 200);
selectableOptions.Margin = new BorderDouble(0, 0, 10, 0);
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
{
string valueLocal = nameValue.Value;
MenuItem newItem = selectableOptions.AddItem(nameValue.MenuName);
if (uiField.Value == valueLocal)
{
selectableOptions.SelectedLabel = nameValue.MenuName;
}
newItem.Selected += (s, e) =>
{
uiField.SetValue(valueLocal, userInitiated: true);
};
}
totalContent.AddChild(selectableOptions);
uiField.Content.VAnchor = VAnchor.Center;
totalContent.AddChild(uiField.Content);
EventHandler localUnregisterEvents = null;
ActiveSliceSettings.SettingChanged.RegisterEvent((sender, e) =>
{
if (e is StringEventArgs stringArgs
&& stringArgs.Data == settingData.SlicerConfigName)
{
bool foundSetting = false;
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
{
string localName = nameValue.MenuName;
string newSliceSettingValue = uiField.Value;
if (newSliceSettingValue == nameValue.Value)
{
selectableOptions.SelectedLabel = localName;
foundSetting = true;
break;
}
}
if (!foundSetting)
{
selectableOptions.SelectedLabel = "Custom";
}
}
}, ref localUnregisterEvents);
totalContent.Closed += (s, e) =>
{
localUnregisterEvents?.Invoke(s, null);
};
this.Content = totalContent;
}
}
}

View file

@ -0,0 +1,121 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
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.
*/
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class DropMenuWrappedField : IUIField
{
private IUIField uiField;
private SliceSettingData settingData;
public DropMenuWrappedField(IUIField uiField, SliceSettingData settingData)
{
this.settingData = settingData;
this.uiField = uiField;
}
public void SetValue(string newValue, bool userInitiated)
{
uiField.SetValue(newValue, userInitiated);
}
public string Value { get => uiField.Value; }
public GuiWidget Content { get; private set; }
public event EventHandler<FieldChangedEventArgs> ValueChanged;
public void Initialize(int tabIndex)
{
var totalContent = new FlowLayoutWidget();
var selectableOptions = new DropDownList("Custom", maxHeight: 200);
selectableOptions.Margin = new BorderDouble(0, 0, 10, 0);
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
{
string valueLocal = nameValue.Value;
MenuItem newItem = selectableOptions.AddItem(nameValue.MenuName);
if (uiField.Value == valueLocal)
{
selectableOptions.SelectedLabel = nameValue.MenuName;
}
newItem.Selected += (s, e) =>
{
uiField.SetValue(valueLocal, userInitiated: true);
};
}
totalContent.AddChild(selectableOptions);
uiField.Content.VAnchor = VAnchor.Center;
totalContent.AddChild(uiField.Content);
EventHandler localUnregisterEvents = null;
ActiveSliceSettings.SettingChanged.RegisterEvent((sender, e) =>
{
if (e is StringEventArgs stringArgs
&& stringArgs.Data == settingData.SlicerConfigName)
{
bool foundSetting = false;
foreach (QuickMenuNameValue nameValue in settingData.QuickMenuSettings)
{
string localName = nameValue.MenuName;
string newSliceSettingValue = uiField.Value;
if (newSliceSettingValue == nameValue.Value)
{
selectableOptions.SelectedLabel = localName;
foundSetting = true;
break;
}
}
if (!foundSetting)
{
selectableOptions.SelectedLabel = "Custom";
}
}
}, ref localUnregisterEvents);
totalContent.Closed += (s, e) =>
{
localUnregisterEvents?.Invoke(s, null);
};
this.Content = totalContent;
}
}
}

View file

@ -0,0 +1,51 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
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.
*/
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class IntField : NumberField
{
private int intValue;
protected override string ConvertValue(string newValue)
{
decimal.TryParse(this.Value, out decimal currentValue);
intValue = (int)currentValue;
return intValue.ToString();
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
numberEdit.ActuallNumberEdit.Value = intValue;
base.OnValueChanged(fieldChangedEventArgs);
}
}
}

View file

@ -0,0 +1,61 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
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.
*/
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public abstract class NumberField : BasicField, IUIField
{
protected MHNumberEdit numberEdit;
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
public virtual void Initialize(int tabIndex)
{
numberEdit = new MHNumberEdit(0, pixelWidth: ControlWidth, tabIndex: tabIndex)
{
ToolTipText = this.HelpText,
SelectAllOnFocus = true,
Name = this.Name,
};
numberEdit.ActuallNumberEdit.EditComplete += (s, e) =>
{
if (this.Value != numberEdit.Value.ToString())
{
this.SetValue(
numberEdit.Value.ToString(),
userInitiated: true);
}
};
this.Content = numberEdit;
}
}
}

View file

@ -0,0 +1,72 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
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.
*/
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class TextField : BasicField, IUIField
{
protected MHTextEditWidget textEditWidget;
private readonly int ControlWidth = (int)(60 * GuiWidget.DeviceScale + .5);
public virtual void Initialize(int tabIndex)
{
textEditWidget = new MHTextEditWidget("", pixelWidth: ControlWidth, tabIndex: tabIndex)
{
ToolTipText = this.HelpText,
SelectAllOnFocus = true,
Name = this.Name,
};
textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
{
if (this.Value != textEditWidget.Text)
{
this.SetValue(
textEditWidget.Text,
userInitiated: true);
}
};
this.Content = textEditWidget;
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
{
if (this.Value != textEditWidget.Text)
{
textEditWidget.Text = this.Value;
}
base.OnValueChanged(fieldChangedEventArgs);
}
}
}