2014-03-25 17:33:57 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Kevin Pope
|
|
|
|
|
|
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-03-25 17:33:57 -07: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-03-25 17:33:57 -07: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-03-25 17:33:57 -07: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-03-25 17:33:57 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2015-07-01 13:37:59 -07:00
|
|
|
|
using MatterHackers.Agg.Image;
|
|
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2015-06-17 15:43:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
|
|
|
|
|
using MatterHackers.MatterControl.PrintLibrary.Provider;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
using MatterHackers.MatterControl.PrintQueue;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
using System;
|
2015-07-01 13:37:59 -07:00
|
|
|
|
using System.IO;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrintLibrary
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class LibraryDataView : ScrollableWidget
|
|
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public SelectedListItems<LibraryRowItem> SelectedItems = new SelectedListItems<LibraryRowItem>();
|
|
|
|
|
|
|
|
|
|
|
|
protected FlowLayoutWidget topToBottomItemList;
|
|
|
|
|
|
|
|
|
|
|
|
private static LibraryProvider currentLibraryProvider;
|
|
|
|
|
|
|
|
|
|
|
|
private RGBA_Bytes baseColor = new RGBA_Bytes(255, 255, 255);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
private bool editMode = false;
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private RGBA_Bytes hoverColor = new RGBA_Bytes(204, 204, 204, 255);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private int hoverIndex = -1;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private RGBA_Bytes selectedColor = new RGBA_Bytes(180, 180, 180, 255);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private int selectedIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
private bool settingLocalBounds = false;
|
|
|
|
|
|
|
2015-07-01 14:35:46 -07:00
|
|
|
|
public static RootedObjectEventHandler ChangedCurrentLibraryProvider = new RootedObjectEventHandler();
|
|
|
|
|
|
|
2015-07-27 10:27:22 -07:00
|
|
|
|
private static LibraryDataView libraryDataViewInstance = null;
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public LibraryDataView()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-07-27 10:27:22 -07:00
|
|
|
|
if (libraryDataViewInstance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("There should only ever be one of these, Lars.");
|
|
|
|
|
|
}
|
|
|
|
|
|
libraryDataViewInstance = this;
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
// set the display attributes
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
this.AnchorAll();
|
|
|
|
|
|
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
|
|
|
|
|
this.ScrollArea.Padding = new BorderDouble(3, 3, 5, 3);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
ScrollArea.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
|
|
|
|
|
|
AutoScroll = true;
|
|
|
|
|
|
topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
topToBottomItemList.HAnchor = HAnchor.ParentLeftRight;
|
|
|
|
|
|
AddChild(topToBottomItemList);
|
|
|
|
|
|
|
|
|
|
|
|
AddAllItems();
|
|
|
|
|
|
|
|
|
|
|
|
this.MouseLeaveBounds += new EventHandler(control_MouseLeaveBounds);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
public delegate void HoverValueChangedEventHandler(object sender, EventArgs e);
|
|
|
|
|
|
|
|
|
|
|
|
public event HoverValueChangedEventHandler HoverValueChanged;
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public event Action<object, EventArgs> SelectedValueChanged;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private event EventHandler unregisterEvents;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public static LibraryProvider CurrentLibraryProvider
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (currentLibraryProvider == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentLibraryProvider = LibraryProviderSelector.Instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return currentLibraryProvider;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
set
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-07-02 18:34:10 -07:00
|
|
|
|
if (currentLibraryProvider != value)
|
|
|
|
|
|
{
|
2015-07-27 10:27:22 -07:00
|
|
|
|
// unhook the update we were getting
|
|
|
|
|
|
currentLibraryProvider.DataReloaded -= libraryDataViewInstance.LibraryDataReloaded;
|
|
|
|
|
|
// and hook the new one
|
|
|
|
|
|
value.DataReloaded += libraryDataViewInstance.LibraryDataReloaded;
|
|
|
|
|
|
|
2015-07-02 18:34:10 -07:00
|
|
|
|
bool isChildOfCurrent = value.ParentLibraryProvider == currentLibraryProvider;
|
|
|
|
|
|
|
|
|
|
|
|
// Dispose of all children below this one.
|
2015-07-27 10:27:22 -07:00
|
|
|
|
while (!isChildOfCurrent && currentLibraryProvider != value
|
|
|
|
|
|
&& currentLibraryProvider.ParentLibraryProvider != null)
|
2015-07-02 18:34:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
LibraryProvider parent = currentLibraryProvider.ParentLibraryProvider;
|
|
|
|
|
|
currentLibraryProvider.Dispose();
|
|
|
|
|
|
currentLibraryProvider = parent;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentLibraryProvider = value;
|
|
|
|
|
|
|
|
|
|
|
|
ChangedCurrentLibraryProvider.CallEvents(null, null);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool EditMode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return editMode; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (this.editMode != value)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
this.editMode = value;
|
|
|
|
|
|
if (this.editMode == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.ClearSelectedItems();
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int HoverIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return hoverIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value < -1 || value >= topToBottomItemList.Children.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (value != hoverIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
hoverIndex = value;
|
|
|
|
|
|
OnHoverIndexChanged();
|
|
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < topToBottomItemList.Children.Count; index++)
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget child = topToBottomItemList.Children[index];
|
|
|
|
|
|
if (index == HoverIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
((LibraryRowItem)child.Children[0]).IsHoverItem = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (((LibraryRowItem)child.Children[0]).IsHoverItem == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
((LibraryRowItem)child.Children[0]).IsHoverItem = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
child.Invalidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override RectangleDouble LocalBounds
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
set
|
2015-06-16 18:10:30 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (!settingLocalBounds)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector2 currentTopLeftOffset = new Vector2();
|
|
|
|
|
|
if (Parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentTopLeftOffset = TopLeftOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
settingLocalBounds = true;
|
|
|
|
|
|
if (topToBottomItemList != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (VerticalScrollBar.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
topToBottomItemList.Width = Math.Max(0, value.Width - ScrollArea.Padding.Width - topToBottomItemList.Margin.Width - VerticalScrollBar.Width);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
topToBottomItemList.Width = Math.Max(0, value.Width - ScrollArea.Padding.Width - topToBottomItemList.Margin.Width);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
base.LocalBounds = value;
|
|
|
|
|
|
if (Parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
TopLeftOffset = currentTopLeftOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
settingLocalBounds = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-06-15 12:12:18 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public int SelectedIndex
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
get
|
2015-06-12 17:21:51 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
return selectedIndex;
|
2015-06-12 17:21:51 -07:00
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
set
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (value < -1 || value >= topToBottomItemList.Children.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
|
}
|
|
|
|
|
|
selectedIndex = value;
|
|
|
|
|
|
OnSelectedIndexChanged();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public GuiWidget SelectedItem
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
get
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (SelectedIndex != -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Children[SelectedIndex];
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2015-06-16 18:10:30 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
set
|
2015-06-16 18:10:30 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
for (int i = 0; i < Children.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Children[SelectedIndex] == value)
|
|
|
|
|
|
{
|
|
|
|
|
|
SelectedIndex = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-06-16 18:10:30 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public PrintItemWrapper SelectedPart
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
get
|
2015-06-16 18:10:30 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (SelectedIndex >= 0)
|
|
|
|
|
|
{
|
2015-07-14 16:16:58 -07:00
|
|
|
|
return LibraryDataView.CurrentLibraryProvider.GetPrintItemWrapperAsync(SelectedIndex).Result;
|
2015-06-29 18:03:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2015-06-16 18:10:30 -07:00
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private int Count
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
return topToBottomItemList.Children.Count;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-12 17:21:51 -07:00
|
|
|
|
public void AddListItemToTopToBottom(GuiWidget child, int indexInChildrenList = -1)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget itemHolder = new FlowLayoutWidget();
|
2015-06-12 17:21:51 -07:00
|
|
|
|
itemHolder.Name = "list item holder";
|
2015-04-08 15:20:10 -07:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
itemHolder.MouseEnterBounds += new EventHandler(itemToAdd_MouseEnterBounds);
|
|
|
|
|
|
itemHolder.MouseLeaveBounds += new EventHandler(itemToAdd_MouseLeaveBounds);
|
|
|
|
|
|
itemHolder.ParentChanged += new EventHandler(itemHolder_ParentChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void ClearSelected()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (selectedIndex != -1)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
selectedIndex = -1;
|
|
|
|
|
|
OnSelectedIndexChanged();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void ClearSelectedItems()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (LibraryRowItem item in SelectedItems)
|
|
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
item.isSelectedItem = false;
|
|
|
|
|
|
item.selectionCheckBox.Checked = false;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
this.SelectedItems.Clear();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-07-27 10:27:22 -07:00
|
|
|
|
currentLibraryProvider.DataReloaded -= LibraryDataReloaded;
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (unregisterEvents != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
unregisterEvents(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
base.OnClosed(e);
|
2015-07-27 10:27:22 -07:00
|
|
|
|
libraryDataViewInstance = null;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
//activeView.OnDraw(graphics2D);
|
|
|
|
|
|
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnHoverIndexChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
if (HoverValueChanged != null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
HoverValueChanged(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override void OnMouseDown(MouseEventArgs mouseEvent)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
base.OnMouseDown(mouseEvent);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override void OnMouseMove(MouseEventArgs mouseEvent)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
base.OnMouseMove(mouseEvent);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public override void OnMouseUp(MouseEventArgs mouseEvent)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
base.OnMouseUp(mouseEvent);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void OnSelectedIndexChanged()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
Invalidate();
|
|
|
|
|
|
if (SelectedValueChanged != null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
SelectedValueChanged(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void RebuildView()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
AddAllItems();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void RemoveChild(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
topToBottomItemList.RemoveChild(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void RemoveChild(GuiWidget childToRemove)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = topToBottomItemList.Children.Count - 1; i >= 0; i--)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
GuiWidget itemHolder = topToBottomItemList.Children[i];
|
|
|
|
|
|
if (itemHolder == childToRemove || itemHolder.Children[0] == childToRemove)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
topToBottomItemList.RemoveChild(itemHolder);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void RemoveSelectedIndex()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (SelectedIndex >= 0 && SelectedIndex < Count)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
RemoveChild(SelectedIndex);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
public void RemoveSelectedItems()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
foreach (LibraryRowItem item in SelectedItems)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
//item.RemoveFromParentCollection();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-24 14:00:27 -07:00
|
|
|
|
protected GuiWidget GetThumbnailWidget(LibraryProvider parentProvider, PrintItemCollection printItemCollection, ImageBuffer imageBuffer)
|
2015-07-01 13:37:59 -07:00
|
|
|
|
{
|
2015-07-17 13:42:54 -07:00
|
|
|
|
Vector2 expectedSize = new Vector2((int)(50 * TextWidget.GlobalPointSizeScaleRatio), (int)(50 * TextWidget.GlobalPointSizeScaleRatio));
|
|
|
|
|
|
if (imageBuffer.Width != expectedSize.x)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageBuffer scaledImageBuffer = new ImageBuffer((int)expectedSize.x, (int)expectedSize.y, 32, new BlenderBGRA());
|
|
|
|
|
|
scaledImageBuffer.NewGraphics2D().Render(imageBuffer, 0, 0, scaledImageBuffer.Width, scaledImageBuffer.Height);
|
|
|
|
|
|
imageBuffer = scaledImageBuffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-01 13:37:59 -07:00
|
|
|
|
ImageWidget folderThumbnail = new ImageWidget(imageBuffer);
|
|
|
|
|
|
folderThumbnail.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
|
2015-07-07 17:47:52 -07:00
|
|
|
|
|
|
|
|
|
|
Button clickThumbnail = new Button(0, 0, folderThumbnail);
|
|
|
|
|
|
clickThumbnail.Cursor = Cursors.Hand;
|
|
|
|
|
|
|
|
|
|
|
|
clickThumbnail.Click += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parentProvider == null)
|
|
|
|
|
|
{
|
2015-07-22 18:30:22 -07:00
|
|
|
|
LibraryDataView.CurrentLibraryProvider = LibraryDataView.CurrentLibraryProvider.GetProviderForCollection(printItemCollection);
|
2015-07-07 17:47:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LibraryDataView.CurrentLibraryProvider = parentProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UiThread.RunOnIdle(RebuildView);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return clickThumbnail;
|
2015-07-01 13:37:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private void AddAllItems()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
topToBottomItemList.RemoveAllChildren();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-07-13 13:07:26 -07:00
|
|
|
|
var provider = LibraryDataView.CurrentLibraryProvider;
|
|
|
|
|
|
|
2015-07-14 20:17:42 -07:00
|
|
|
|
if (provider != null && provider.ProviderKey != "ProviderSelectorKey")
|
2015-06-29 18:03:56 -07:00
|
|
|
|
{
|
2015-07-13 13:07:26 -07:00
|
|
|
|
PrintItemCollection parent = new PrintItemCollection("..", provider.ProviderKey);
|
2015-07-24 14:00:27 -07:00
|
|
|
|
LibraryRowItem queueItem = new LibraryRowItemCollection(parent, -1, this, provider.ParentLibraryProvider, GetThumbnailWidget(provider.ParentLibraryProvider, parent, LibraryProvider.UpFolderImage));
|
2015-06-29 18:03:56 -07:00
|
|
|
|
AddListItemToTopToBottom(queueItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-13 13:07:26 -07:00
|
|
|
|
for (int i = 0; i < provider.CollectionCount; i++)
|
2015-06-29 18:03:56 -07:00
|
|
|
|
{
|
2015-07-13 13:07:26 -07:00
|
|
|
|
PrintItemCollection item = provider.GetCollectionItem(i);
|
2015-07-24 14:00:27 -07:00
|
|
|
|
LibraryRowItem queueItem = new LibraryRowItemCollection(item, i, this, null, GetThumbnailWidget(null, item, provider.GetCollectionFolderImage(i)));
|
2015-06-29 18:03:56 -07:00
|
|
|
|
AddListItemToTopToBottom(queueItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-13 13:07:26 -07:00
|
|
|
|
for (int i = 0; i < provider.ItemCount; i++)
|
2015-06-29 18:03:56 -07:00
|
|
|
|
{
|
2015-07-13 13:07:26 -07:00
|
|
|
|
GuiWidget thumbnailWidget = provider.GetItemThumbnail(i);
|
|
|
|
|
|
LibraryRowItem queueItem = new LibraryRowItemPart(provider, i, this, thumbnailWidget);
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
AddListItemToTopToBottom(queueItem);
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private void control_MouseLeaveBounds(object sender, EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
HoverIndex = -1;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private void itemHolder_ParentChanged(object sender, EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
FlowLayoutWidget itemHolder = (FlowLayoutWidget)sender;
|
|
|
|
|
|
itemHolder.MouseEnterBounds -= new EventHandler(itemToAdd_MouseEnterBounds);
|
|
|
|
|
|
itemHolder.MouseLeaveBounds -= new EventHandler(itemToAdd_MouseLeaveBounds);
|
|
|
|
|
|
itemHolder.ParentChanged -= new EventHandler(itemHolder_ParentChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void itemToAdd_MouseEnterBounds(object sender, EventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
GuiWidget widgetEntered = ((GuiWidget)sender);
|
|
|
|
|
|
for (int index = 0; index < topToBottomItemList.Children.Count; index++)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
GuiWidget child = topToBottomItemList.Children[index];
|
|
|
|
|
|
if (child == widgetEntered)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
HoverIndex = index;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2015-06-29 18:03:56 -07:00
|
|
|
|
private void itemToAdd_MouseLeaveBounds(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget widgetLeft = ((GuiWidget)sender);
|
|
|
|
|
|
|
|
|
|
|
|
if (SelectedIndex >= 0)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
if (widgetLeft != topToBottomItemList.Children[SelectedIndex])
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2015-06-29 18:03:56 -07:00
|
|
|
|
widgetLeft.BackgroundColor = new RGBA_Bytes();
|
|
|
|
|
|
widgetLeft.Invalidate();
|
|
|
|
|
|
Invalidate();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-06-29 18:03:56 -07:00
|
|
|
|
|
|
|
|
|
|
private void LibraryDataReloaded(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2015-07-07 09:52:48 -07:00
|
|
|
|
UiThread.RunOnIdle(AddAllItems);
|
2015-06-29 18:03:56 -07:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
}
|