Added scrollbar to slice preset details. Added 'import' button directly to slice preset list.

This commit is contained in:
kevinepope 2014-06-15 14:21:05 -07:00
parent b802255afd
commit e372f38f2a
3 changed files with 101 additions and 7 deletions

View file

@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
initSlicePreset();
}
linkButtonFactory.fontSize = 10;
linkButtonFactory.fontSize = 8;
linkButtonFactory.textColor = ActiveTheme.Instance.SecondaryAccentColor;
buttonFactory = new TextImageButtonFactory();
@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SettingsDropDownList settingDropDownList;
FlowLayoutWidget addSettingsContainer;
FlowLayoutWidget settingsRowContainer;
PresetListControl settingsRowContainer;
FlowLayoutWidget errorMessageContainer;
FlowLayoutWidget GetMiddleRow()
@ -187,9 +187,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
addContainer.AddChild(addSettingsContainer);
addContainer.AddChild(errorMessageContainer);
settingsRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
settingsRowContainer = new PresetListControl();
settingsRowContainer.HAnchor = HAnchor.ParentLeftRight;
settingsRowContainer.Padding = new BorderDouble(3);
LoadSettingsRows();
@ -383,7 +382,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
void LoadSettingsRows()
{
settingsRowContainer.RemoveAllChildren();
settingsRowContainer.RemoveScrollChildren();
UiThread.RunOnIdle((state) =>
{
foreach (KeyValuePair<String, DataStorage.SliceSetting> item in this.windowController.ActivePresetLayer.settingsDictionary)
@ -393,7 +392,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
row.Padding = new BorderDouble(3, 3, 3, 6);
settingsRowContainer.AddChild(row);
settingsRowContainer.AddChild(new HorizontalLine());
HorizontalLine horizontalLine = new HorizontalLine();
horizontalLine.BackgroundColor = ActiveTheme.Instance.SecondaryTextColor;
settingsRowContainer.AddChild(horizontalLine);
}
});
}
@ -967,6 +968,40 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
class PresetListControl : ScrollableWidget
{
FlowLayoutWidget topToBottomItemList;
public PresetListControl()
{
this.AnchorAll();
this.AutoScroll = true;
this.ScrollArea.HAnchor |= Agg.UI.HAnchor.ParentLeftRight;
topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom);
topToBottomItemList.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
topToBottomItemList.Margin = new BorderDouble(top: 3);
base.AddChild(topToBottomItemList);
}
public void RemoveScrollChildren()
{
topToBottomItemList.RemoveAllChildren();
}
public override void AddChild(GuiWidget child, int indexInChildrenList = -1)
{
FlowLayoutWidget itemHolder = new FlowLayoutWidget();
itemHolder.Margin = new BorderDouble(0, 0, 0, 0);
itemHolder.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
itemHolder.AddChild(child);
itemHolder.VAnchor = VAnchor.FitToChildren;
topToBottomItemList.AddChild(itemHolder, indexInChildrenList);
}
}
public class SettingsDropDownList : DropDownList
{
static RGBA_Bytes whiteSemiTransparent = new RGBA_Bytes(255, 255, 255, 100);

View file

@ -51,6 +51,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
TextImageButtonFactory buttonFactory;
LinkButtonFactory linkButtonFactory;
PresetListControl presetListControl;
Button importPresetButton;
public SlicePresetListWidget(SlicePresetsWindow windowController)
{
@ -67,6 +68,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
buttonFactory.borderWidth = 0;
AddElements();
AddHandlers();
}
void AddElements()
@ -82,6 +84,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
this.AddChild(mainContainer);
}
void AddHandlers()
{
importPresetButton.Click += new ButtonBase.ButtonEventHandler(importPreset_Click);
}
FlowLayoutWidget GetTopRow()
{
FlowLayoutWidget container = new FlowLayoutWidget();
@ -129,6 +136,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
});
};
importPresetButton = buttonFactory.Generate(LocalizedString.Get("Import"));
Button closeButton = buttonFactory.Generate(LocalizedString.Get("Close"));
closeButton.Click += (sender, e) =>
{
@ -139,12 +148,62 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
};
container.AddChild(addPresetButton);
container.AddChild(importPresetButton);
container.AddChild(new HorizontalSpacer());
container.AddChild(closeButton);
return container;
}
void importPreset_Click(object sender, MouseEventArgs mouseEvent)
{
OpenFileDialogParams openParams = new OpenFileDialogParams("Load Slice Preset|*.slice;*.ini");
openParams.ActionButtonLabel = "Load Slice Preset";
openParams.Title = "MatterControl: Select A File";
FileDialog.OpenFileDialog(ref openParams);
if (openParams.FileNames != null)
{
DataStorage.SliceSettingsCollection settingsCollection;
try
{
if (File.Exists(openParams.FileName))
{
settingsCollection = new SliceSettingsCollection();
settingsCollection.Tag = windowController.filterTag;
settingsCollection.PrinterId = ActivePrinterProfile.Instance.ActivePrinter.Id;
settingsCollection.Name = System.IO.Path.GetFileNameWithoutExtension(openParams.FileName);
settingsCollection.Commit();
string[] lines = System.IO.File.ReadAllLines(openParams.FileName);
foreach (string line in lines)
{
//Ignore commented lines
if (!line.StartsWith("#"))
{
string[] settingLine = line.Split('=');
string keyName = settingLine[0].Trim();
string settingDefaultValue = settingLine[1].Trim();
DataStorage.SliceSetting sliceSetting = new DataStorage.SliceSetting();
sliceSetting.Name = keyName;
sliceSetting.Value = settingDefaultValue;
sliceSetting.SettingsCollectionId = settingsCollection.Id;
sliceSetting.Commit();
}
}
windowController.ChangeToSlicePresetList();
}
}
catch (Exception e)
{
// Error loading configuration
}
}
}
IEnumerable<DataStorage.SliceSettingsCollection> GetCollections()
{
IEnumerable<DataStorage.SliceSettingsCollection> results = Enumerable.Empty<DataStorage.SliceSettingsCollection>();