Remove ISettingsField type

This commit is contained in:
John Lewin 2017-09-05 07:01:37 -07:00
parent 7e93caf274
commit 393db7ba79
4 changed files with 4 additions and 106 deletions

View file

@ -75,7 +75,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private SettingsContext settingsContext;
PrinterConnection printerConnection;
private PrinterConnection printerConnection;
private Dictionary<string, IUIField> allUiFields = new Dictionary<string, IUIField>();
private EventHandler unregisterEvents;
@ -121,18 +123,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (e is StringEventArgs stringEvent)
{
string settingsKey = stringEvent.Data;
if (allFields.TryGetValue(settingsKey, out ISettingsField field))
{
string currentValue = settingsContext.GetValue(settingsKey);
if (field.Value != currentValue
|| settingsKey == "com_port")
{
field.Value = currentValue;
field.OnValueChanged(currentValue);
field.UpdateStyle();
}
}
if (allUiFields.TryGetValue(settingsKey, out IUIField field2))
{
string currentValue = settingsContext.GetValue(settingsKey);
@ -855,9 +845,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ref tabIndex);
}
Dictionary<string, ISettingsField> allFields = new Dictionary<string, ISettingsField>();
Dictionary<string, IUIField> allUiFields = new Dictionary<string, IUIField>();
private GuiWidget CreateSettingInfoUIControls(
PrinterConnection printerConnection,
SliceSettingData settingData,
@ -867,7 +854,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
string sliceSettingValue = settingsContext.GetValue(settingData.SlicerConfigName);
ISettingsField OLDFIELDXXXXX = null;
IUIField uiField = null;
bool useDefaultSavePattern = true;
@ -1017,18 +1003,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
if (OLDFIELDXXXXX != null)
{
allFields[settingData.SlicerConfigName] = OLDFIELDXXXXX;
OLDFIELDXXXXX.Value = sliceSettingValue;
settingsRow.AddContent(
OLDFIELDXXXXX.Create(settingsContext, settingData, tabIndexForItem++));
OLDFIELDXXXXX.UpdateStyle = settingsRow.UpdateStyle;
}
if (uiField != null)
{
allUiFields[settingData.SlicerConfigName] = uiField;

View file

@ -55,14 +55,4 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
GuiWidget Content { get; }
}
public interface ISettingsField
{
void OnValueChanged(string text);
Action UpdateStyle { get; set; }
string Value { get; set; }
GuiWidget Create(SettingsContext settingsContext, SliceSettingData settingData, int tabIndex);
}
}

View file

@ -1,65 +0,0 @@
/*
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.UI;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class StringField : ISettingsField
{
private MHTextEditWidget editWidget;
public Action UpdateStyle { get; set; }
public string Value { get; set; }
public GuiWidget Create(SettingsContext settingsContext, SliceSettingData settingData, int tabIndex)
{
editWidget = new MHTextEditWidget(this.Value, pixelWidth: settingData.ShowAsOverride ? 120 : 200, tabIndex: tabIndex)
{
Name = settingData.PresentationName + " Edit",
};
editWidget.ToolTipText = settingData.HelpText;
editWidget.ActualTextEditWidget.EditComplete += (sender, e) =>
{
settingsContext.SetValue(settingData.SlicerConfigName, ((TextEditWidget)sender).Text);
this.UpdateStyle();
};
return editWidget;
}
public void OnValueChanged(string text)
{
editWidget.Text = text;
}
}
}