2015-06-12 17:21:51 -07:00
/ *
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 ;
2015-06-15 12:12:18 -07:00
using MatterHackers.Agg.Image ;
using MatterHackers.Agg.PlatformAbstract ;
2015-06-12 17:21:51 -07:00
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.PrintLibrary
{
public class LibraryRowItemCollection : LibraryRowItem
{
2015-06-29 18:03:56 -07:00
LibraryProvider parentProvider ;
2015-07-07 10:27:38 -07:00
PrintItemCollection printItemCollection ;
2015-06-12 17:21:51 -07:00
2015-07-01 13:37:59 -07:00
public LibraryRowItemCollection ( PrintItemCollection collection , LibraryDataView libraryDataView , LibraryProvider parentProvider , GuiWidget thumbnailWidget )
: base ( libraryDataView , thumbnailWidget )
2015-06-12 17:21:51 -07:00
{
2015-06-29 18:03:56 -07:00
this . parentProvider = parentProvider ;
2015-07-07 10:27:38 -07:00
this . printItemCollection = collection ;
2015-06-12 17:21:51 -07:00
CreateGuiElements ( ) ;
}
2015-07-07 10:27:38 -07:00
public override PrintItemWrapper PrintItemWrapper { get { return null ; } }
public override PrintItemCollection PrintItemCollection { get { return printItemCollection ; } }
2015-06-12 17:21:51 -07:00
public override void Export ( )
{
throw new NotImplementedException ( ) ;
}
public override void Edit ( )
{
throw new NotImplementedException ( ) ;
}
2015-07-02 18:34:10 -07:00
private static string collectionNotEmtyMessage = "The collection you are trying to delete '{0}' is not empty. Would you like to delete it anyway?" . Localize ( ) ;
private static string collectionNotEmtyTitle = "Collection not Empty" . Localize ( ) ;
private static string deleteNow = "Delete" . Localize ( ) ;
private static string doNotDelete = "Do NOT Delete" . Localize ( ) ;
2015-06-12 17:21:51 -07:00
public override void RemoveFromCollection ( )
{
2015-07-07 10:27:38 -07:00
using ( LibraryProvider collectionProvider = LibraryDataView . CurrentLibraryProvider . GetProviderForItem ( printItemCollection ) )
2015-07-02 18:34:10 -07:00
{
if ( collectionProvider . ItemCount > 0 | | collectionProvider . CollectionCount > 0 )
{
2015-07-07 10:27:38 -07:00
collectionNotEmtyMessage = collectionNotEmtyMessage . FormatWith ( printItemCollection . Name ) ;
2015-07-02 18:34:10 -07:00
UiThread . RunOnIdle ( ( ) = >
{
// Let the user know this collection is not empty and check if they want to delete it.
StyledMessageBox . ShowMessageBox ( ProcessDialogResponse , collectionNotEmtyMessage , collectionNotEmtyTitle , StyledMessageBox . MessageType . YES_NO , deleteNow , doNotDelete ) ;
} ) ;
}
else
{
2015-07-07 10:27:38 -07:00
LibraryDataView . CurrentLibraryProvider . RemoveCollection ( printItemCollection ) ;
2015-07-02 18:34:10 -07:00
}
}
}
private void ProcessDialogResponse ( bool messageBoxResponse )
{
if ( messageBoxResponse )
{
2015-07-07 10:27:38 -07:00
LibraryDataView . CurrentLibraryProvider . RemoveCollection ( printItemCollection ) ;
2015-07-02 18:34:10 -07:00
}
2015-06-12 17:21:51 -07:00
}
public override void AddToQueue ( )
{
throw new NotImplementedException ( ) ;
}
private ConditionalClickWidget primaryClickContainer ;
protected override string GetItemName ( )
{
2015-07-07 10:27:38 -07:00
return printItemCollection . Name ;
2015-06-12 17:21:51 -07:00
}
2015-06-15 12:12:18 -07:00
protected override SlideWidget GetItemActionButtons ( )
2015-06-12 17:21:51 -07:00
{
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 ) = >
{
2015-06-16 18:10:30 -07:00
ChangeCollection ( ) ;
2015-06-12 17:21:51 -07:00
} ;
buttonFlowContainer . AddChild ( openButton ) ;
buttonContainer . AddChild ( buttonFlowContainer ) ;
2015-06-15 12:12:18 -07:00
buttonContainer . Width = 100 ;
2015-06-12 17:21:51 -07:00
return buttonContainer ;
}
2015-06-16 18:10:30 -07:00
private void ChangeCollection ( )
{
2015-06-29 18:03:56 -07:00
if ( parentProvider = = null )
2015-06-16 18:10:30 -07:00
{
2015-07-07 10:27:38 -07:00
LibraryDataView . CurrentLibraryProvider = LibraryDataView . CurrentLibraryProvider . GetProviderForItem ( printItemCollection ) ;
2015-06-16 18:10:30 -07:00
}
else
{
2015-06-29 18:03:56 -07:00
LibraryDataView . CurrentLibraryProvider = parentProvider ;
2015-06-16 18:10:30 -07:00
}
UiThread . RunOnIdle ( libraryDataView . RebuildView ) ;
}
public override void OnMouseDown ( MouseEventArgs mouseEvent )
{
if ( mouseEvent . Clicks = = 2 )
{
UiThread . RunOnIdle ( ChangeCollection ) ;
}
base . OnMouseDown ( mouseEvent ) ;
}
2015-06-12 17:21:51 -07:00
private void SetDisplayAttributes ( )
{
//this.VAnchor = Agg.UI.VAnchor.FitToChildren;
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 ) ;
}
private void onAddLinkClick ( object sender , EventArgs e )
{
}
protected override void RemoveThisFromPrintLibrary ( )
{
throw new NotImplementedException ( ) ;
}
private void onRemoveLinkClick ( object sender , EventArgs e )
{
UiThread . RunOnIdle ( RemoveThisFromPrintLibrary ) ;
}
private void onThemeChanged ( object sender , EventArgs e )
{
//Set background and text color to new theme
this . Invalidate ( ) ;
}
}
}