The library selector can now return the right selected library.

This commit is contained in:
Lars Brubaker 2015-07-31 18:18:21 -07:00
parent f21881305d
commit 73fd06a39d
5 changed files with 119 additions and 308 deletions

View file

@ -30,39 +30,129 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintLibrary.Provider;
using MatterHackers.VectorMath;
using System;
using System.Globalization;
using System.Threading.Tasks;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
{
public abstract class LibrarySelectorRowItem : GuiWidget
public class LibrarySelectorRowItem : GuiWidget
{
public bool IsSelectedItem
{
get
{
return libraryDataView.SelectedItems.Contains(this);
}
}
public CheckBox selectionCheckBox;
LibraryProvider parentProvider;
PrintItemCollection printItemCollection;
public int CollectionIndex { get; private set; }
public RGBA_Bytes WidgetBackgroundColor;
public RGBA_Bytes WidgetTextColor;
protected LibrarySelectorWidget libraryDataView;
protected TextWidget partLabel;
protected SlideWidget rightButtonOverlay;
protected GuiWidget selectionCheckBoxContainer;
private bool isHoverItem = false;
private LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
private GuiWidget thumbnailWidget;
private event EventHandler unregisterEvents;
public LibrarySelectorRowItem(LibrarySelectorWidget libraryDataView, GuiWidget thumbnailWidget)
public LibrarySelectorWidget libraryDataView { get; private set; }
public LibrarySelectorRowItem(PrintItemCollection collection, int collectionIndex, LibrarySelectorWidget libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
{
this.thumbnailWidget = thumbnailWidget;
this.libraryDataView = libraryDataView;
this.CollectionIndex = collectionIndex;
this.parentProvider = parentProvider;
this.printItemCollection = collection;
this.ItemName = printItemCollection.Name;
CreateGuiElements();
}
public PrintItemCollection PrintItemCollection { get { return printItemCollection; } }
public bool Protected
{
get { return false; }
}
private void ProcessDialogResponse(bool messageBoxResponse)
{
if (messageBoxResponse)
{
libraryDataView.CurrentLibraryProvider.RemoveCollection(CollectionIndex);
}
}
private void ChangeCollection()
{
if (parentProvider == null)
{
libraryDataView.CurrentLibraryProvider = libraryDataView.CurrentLibraryProvider.GetProviderForCollection(printItemCollection);
}
else
{
libraryDataView.CurrentLibraryProvider = parentProvider;
}
UiThread.RunOnIdle(libraryDataView.RebuildView);
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
if (mouseEvent.Clicks == 2)
{
UiThread.RunOnIdle(ChangeCollection);
}
base.OnMouseDown(mouseEvent);
}
private void SetDisplayAttributes()
{
//this.VAnchor = Agg.UI.VAnchor.FitToChildren;
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
this.Height = 50 * TextWidget.GlobalPointSizeScaleRatio;
this.Padding = new BorderDouble(0);
this.Margin = new BorderDouble(6, 0, 6, 6);
}
protected SlideWidget GetItemActionButtons()
{
SlideWidget buttonContainer = new SlideWidget();
buttonContainer.VAnchor = VAnchor.ParentBottomTop;
FlowLayoutWidget buttonFlowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
buttonFlowContainer.VAnchor = VAnchor.ParentBottomTop;
TextWidget openLabel = new TextWidget("Open".Localize());
openLabel.TextColor = RGBA_Bytes.White;
openLabel.VAnchor = VAnchor.ParentCenter;
openLabel.HAnchor = HAnchor.ParentCenter;
FatFlatClickWidget openButton = new FatFlatClickWidget(openLabel);
openButton.VAnchor = VAnchor.ParentBottomTop;
openButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
openButton.Width = 100;
openButton.Click += (sender, e) =>
{
ChangeCollection();
};
buttonFlowContainer.AddChild(openButton);
buttonContainer.AddChild(buttonFlowContainer);
buttonContainer.Width = 100;
return buttonContainer;
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background and text color to new theme
this.Invalidate();
}
public string ItemName { get; protected set; }
@ -75,7 +165,7 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
if (this.isHoverItem != value)
{
this.isHoverItem = value;
if (value == true && !this.libraryDataView.EditMode)
if (value == true)
{
this.rightButtonOverlay.SlideIn();
}
@ -87,8 +177,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
}
}
public abstract bool Protected { get; }
public override void OnClosed(EventArgs e)
{
if (unregisterEvents != null)
@ -100,33 +188,15 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
public override void OnDraw(Graphics2D graphics2D)
{
if (this.libraryDataView.EditMode)
{
this.selectionCheckBox.Checked = this.IsSelectedItem;
selectionCheckBoxContainer.Visible = true;
rightButtonOverlay.Visible = false;
}
else
{
selectionCheckBoxContainer.Visible = false;
}
base.OnDraw(graphics2D);
if (this.IsSelectedItem)
{
this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
this.partLabel.TextColor = RGBA_Bytes.White;
this.selectionCheckBox.TextColor = RGBA_Bytes.White;
}
else if (this.IsHoverItem)
if (this.IsHoverItem)
{
RectangleDouble Bounds = LocalBounds;
RoundedRect rectBorder = new RoundedRect(Bounds, 0);
this.BackgroundColor = RGBA_Bytes.White;
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor);
}
@ -134,7 +204,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
{
this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255);
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
}
}
@ -164,16 +233,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
primaryFlow.HAnchor = HAnchor.ParentLeftRight;
primaryFlow.VAnchor = VAnchor.ParentBottomTop;
selectionCheckBoxContainer = new GuiWidget();
selectionCheckBoxContainer.VAnchor = VAnchor.ParentBottomTop;
selectionCheckBoxContainer.Width = 40;
selectionCheckBoxContainer.Visible = false;
selectionCheckBoxContainer.Margin = new BorderDouble(left: 6);
selectionCheckBox = new CheckBox("");
selectionCheckBox.VAnchor = VAnchor.ParentCenter;
selectionCheckBox.HAnchor = HAnchor.ParentCenter;
selectionCheckBoxContainer.AddChild(selectionCheckBox);
GuiWidget middleColumn = new GuiWidget(0.0, 0.0);
middleColumn.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
middleColumn.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
@ -184,36 +243,7 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
partLabel.MinimumSize = new Vector2(1, 18);
partLabel.VAnchor = VAnchor.ParentCenter;
middleColumn.AddChild(partLabel);
middleColumn.MouseDown += (sender, e) =>
{
if (this.libraryDataView.EditMode)
{
if (this.IsSelectedItem)
{
libraryDataView.SelectedItems.Remove(this);
}
else
{
libraryDataView.SelectedItems.Add(this);
}
}
else
{
// we only have single selection
if (this.IsSelectedItem)
{
// It is aleady selected, do nothing.
}
else
{
libraryDataView.ClearSelectedItems();
libraryDataView.SelectedItems.Add(this);
}
}
};
}
primaryFlow.AddChild(selectionCheckBoxContainer);
primaryFlow.AddChild(thumbnailWidget);
primaryFlow.AddChild(middleColumn);
@ -231,8 +261,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
AddHandlers();
}
protected abstract SlideWidget GetItemActionButtons();
private void AddHandlers()
{
MouseEnterBounds += (sender, e) =>
@ -260,27 +288,5 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
this.Invalidate();
};
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background and text color to new theme
this.Invalidate();
}
private void SetDisplayAttributes()
{
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
{
this.Height = 65;
}
else
{
this.Height = 50;
}
this.Padding = new BorderDouble(0);
this.Margin = new BorderDouble(6, 0, 6, 6);
}
}
}

View file

@ -1,148 +1 @@
/*
Copyright (c) 2014, Kevin Pope
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;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrintLibrary.Provider;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.VectorMath;
using System;
using System.Globalization;
using System.IO;
namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
{
public class LibrarySelectorRowItemCollection : LibrarySelectorRowItem
{
LibraryProvider parentProvider;
PrintItemCollection printItemCollection;
public int CollectionIndex { get; private set; }
public LibrarySelectorRowItemCollection(PrintItemCollection collection, int collectionIndex, LibrarySelectorWidget libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
: base(libraryDataView, thumbnailWidget)
{
this.CollectionIndex = collectionIndex;
this.parentProvider = parentProvider;
this.printItemCollection = collection;
this.ItemName = printItemCollection.Name;
CreateGuiElements();
}
public PrintItemCollection PrintItemCollection { get { return printItemCollection; } }
public override bool Protected
{
get { return false; }
}
private void ProcessDialogResponse(bool messageBoxResponse)
{
if (messageBoxResponse)
{
libraryDataView.CurrentLibraryProvider.RemoveCollection(CollectionIndex);
}
}
private void ChangeCollection()
{
if (parentProvider == null)
{
libraryDataView.CurrentLibraryProvider = libraryDataView.CurrentLibraryProvider.GetProviderForCollection(printItemCollection);
}
else
{
libraryDataView.CurrentLibraryProvider = parentProvider;
}
UiThread.RunOnIdle(libraryDataView.RebuildView);
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
if (mouseEvent.Clicks == 2)
{
UiThread.RunOnIdle(ChangeCollection);
}
base.OnMouseDown(mouseEvent);
}
private void SetDisplayAttributes()
{
//this.VAnchor = Agg.UI.VAnchor.FitToChildren;
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
this.Height = 50 * TextWidget.GlobalPointSizeScaleRatio;
this.Padding = new BorderDouble(0);
this.Margin = new BorderDouble(6, 0, 6, 6);
}
protected override SlideWidget GetItemActionButtons()
{
SlideWidget buttonContainer = new SlideWidget();
buttonContainer.VAnchor = VAnchor.ParentBottomTop;
FlowLayoutWidget buttonFlowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
buttonFlowContainer.VAnchor = VAnchor.ParentBottomTop;
TextWidget openLabel = new TextWidget("Open".Localize());
openLabel.TextColor = RGBA_Bytes.White;
openLabel.VAnchor = VAnchor.ParentCenter;
openLabel.HAnchor = HAnchor.ParentCenter;
FatFlatClickWidget openButton = new FatFlatClickWidget(openLabel);
openButton.VAnchor = VAnchor.ParentBottomTop;
openButton.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
openButton.Width = 100;
openButton.Click += (sender, e) =>
{
ChangeCollection();
};
buttonFlowContainer.AddChild(openButton);
buttonContainer.AddChild(buttonFlowContainer);
buttonContainer.Width = 100;
return buttonContainer;
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background and text color to new theme
this.Invalidate();
}
}
}


View file

@ -60,8 +60,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
private bool settingLocalBounds = false;
public event EventHandler<LibraryDataViewEventArgs> ChangedCurrentLibraryProvider2;
public void SetCurrentLibraryProvider(LibraryProvider libraryProvider)
{
this.currentLibraryProvider = libraryProvider;
@ -125,11 +123,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
}
currentLibraryProvider = value;
if (ChangedCurrentLibraryProvider2 != null)
{
ChangedCurrentLibraryProvider2(null, null);
}
}
}
}
@ -217,10 +210,6 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
public void ClearSelectedItems()
{
foreach (LibrarySelectorRowItem item in SelectedItems)
{
item.selectionCheckBox.Checked = false;
}
this.SelectedItems.Clear();
}
@ -348,14 +337,14 @@ namespace MatterHackers.MatterControl.CustomWidgets.LibrarySelector
if (provider != null && provider.ProviderKey != "ProviderSelectorKey")
{
PrintItemCollection parent = new PrintItemCollection("..", provider.ProviderKey);
LibrarySelectorRowItem queueItem = new LibrarySelectorRowItemCollection(parent, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage));
LibrarySelectorRowItem queueItem = new LibrarySelectorRowItem(parent, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage));
AddListItemToTopToBottom(queueItem);
}
for (int i = 0; i < provider.CollectionCount; i++)
{
PrintItemCollection item = provider.GetCollectionItem(i);
LibrarySelectorRowItem queueItem = new LibrarySelectorRowItemCollection(item, i, this, null, GetThumbnailWidget(null, item, provider.GetCollectionFolderImage(i)));
LibrarySelectorRowItem queueItem = new LibrarySelectorRowItem(item, i, this, null, GetThumbnailWidget(null, item, provider.GetCollectionFolderImage(i)));
AddListItemToTopToBottom(queueItem);
}
}