Making print history clearable and update with new data

fixing warnings
This commit is contained in:
Lars Brubaker 2020-07-03 12:05:28 -07:00
parent 215e86eb5a
commit 78d4059c80
16 changed files with 447 additions and 247 deletions

View file

@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Localizations;
@ -36,18 +37,37 @@ namespace MatterHackers.MatterControl.Library
{
public class PrintHistoryContainer : LibraryContainer
{
private EventHandler unregisterEvents;
public PrintHistoryContainer()
{
this.ChildContainers = new List<ILibraryContainerLink>();
this.Items = new List<ILibraryItem>();
this.Name = "Print History".Localize();
this.DefaultView = typeof(HistoryListView);
PrintHistoryData.Instance.HistoryCleared.RegisterEvent(HistoryChanged, ref unregisterEvents);
ApplicationController.Instance.AnyPrintStarted += HistoryChanged;
ApplicationController.Instance.AnyPrintCanceled += HistoryChanged;
ApplicationController.Instance.AnyPrintComplete += HistoryChanged;
}
private void HistoryChanged(object sender, EventArgs e)
{
ReloadContent();
}
public override void Dispose()
{
unregisterEvents?.Invoke(this, null);
base.Dispose();
}
public override void Load()
{
// PrintItems projected onto FileSystemFileItem
Items = PrintHistoryData.Instance.GetHistoryItems(25).Select(f => new PrintHistoryItem(f)).ToList<ILibraryItem>();
Items = PrintHistoryData.Instance.GetHistoryItems(50).Select(f => new PrintHistoryItem(f)).ToList<ILibraryItem>();
}
}
}

View file

@ -0,0 +1,53 @@
/*
Copyright (c) 2017, 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 System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintQueue;
namespace MatterHackers.MatterControl.Library
{
public class SqliteFileItem : FileSystemFileItem
{
public PrintItem PrintItem { get; }
public SqliteFileItem(PrintItem printItem)
: base(printItem.FileLocation)
{
this.PrintItem = printItem;
}
public override string Name { get => this.PrintItem.Name; set => this.PrintItem.Name = value; }
}
}

View file

@ -38,19 +38,6 @@ using MatterHackers.MatterControl.PrintQueue;
namespace MatterHackers.MatterControl.Library
{
public class SqliteFileItem : FileSystemFileItem
{
public PrintItem PrintItem { get; }
public SqliteFileItem(PrintItem printItem)
: base(printItem.FileLocation)
{
this.PrintItem = printItem;
}
public override string Name { get => this.PrintItem.Name; set => this.PrintItem.Name = value; }
}
public class SqliteLibraryContainer : WritableContainer, ICustomSearch
{
private string keywordFilter = "";
@ -106,7 +93,7 @@ namespace MatterHackers.MatterControl.Library
else
{
return new MessageItem($"{printItem.Name} (Missing)");
//return new MissingFileItem() // Needs to return a content specific icon with a missing overlay - needs to lack all print operations
// return new MissingFileItem() // Needs to return a content specific icon with a missing overlay - needs to lack all print operations
}
}).ToList();
}
@ -120,15 +107,19 @@ namespace MatterHackers.MatterControl.Library
switch (item)
{
case CreateFolderItem newFolder:
var newFolderCollection = new PrintItemCollection(newFolder.Name, "");
newFolderCollection.ParentCollectionID = this.CollectionID;
var newFolderCollection = new PrintItemCollection(newFolder.Name, "")
{
ParentCollectionID = this.CollectionID
};
newFolderCollection.Commit();
break;
case ILibraryContainerLink containerInfo:
var newCollection = new PrintItemCollection(containerInfo.Name, "");
newCollection.ParentCollectionID = this.CollectionID;
var newCollection = new PrintItemCollection(containerInfo.Name, "")
{
ParentCollectionID = this.CollectionID
};
newCollection.Commit();
break;
@ -176,13 +167,13 @@ namespace MatterHackers.MatterControl.Library
public override void Remove(IEnumerable<ILibraryItem> items)
{
// TODO: Handle Containers
foreach(var item in items)
foreach (var item in items)
{
if (item is SqliteFileItem sqlItem)
{
sqlItem.PrintItem.Delete();
}
else if (item is LocalLibraryZipContainerLink link)
else if (item is LocalLibraryZipContainerLink link)
{
string sql = $"SELECT * FROM PrintItem WHERE ID = @id";
var container = Datastore.Instance.dbSQLite.Query<PrintItem>(sql, link.RowID).FirstOrDefault();

View file

@ -33,11 +33,15 @@ namespace MatterHackers.MatterControl.CustomWidgets
public interface IListContentView
{
int ThumbWidth { get; }
int ThumbHeight { get; }
ListViewItemBase AddItem(ListViewItem item);
void ClearItems();
void BeginReload();
void EndReload();
}
}

View file

@ -144,6 +144,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
else if (stashedContentView != null)
{
// Switch back to the original view
stashedContentView.ClearRemovedFlag();
this.ListContentView = stashedContentView;
stashedContentView = null;
}
@ -158,6 +159,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
Ascending = this.Ascending
};
}
this.ActiveSort = activeContainer.DefaultSort.SortKey;
this.Ascending = activeContainer.DefaultSort.Ascending;
}
@ -413,11 +415,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
var y = height / 2 - originalImage.Height / 2;
var center = new RectangleInt(x, y + originalImage.Height, x + originalImage.Width, y);
//renderGraphics.FillRectangle(center, this.ThumbnailForeground);
// renderGraphics.FillRectangle(center, this.ThumbnailForeground);
renderGraphics.ImageRenderQuality = Graphics2D.TransformQuality.Best;
//originalImage = originalImage.Multiply(this.ThumbnailBackground);
// originalImage = originalImage.Multiply(this.ThumbnailBackground);
renderGraphics.Render(originalImage, width /2 - originalImage.Width /2, height /2 - originalImage.Height /2);

View file

@ -180,12 +180,14 @@ namespace MatterHackers.MatterControl.CustomWidgets
get
{
bool isContentItem = listViewItem.Model is ILibraryObject3D;
bool isValidStream = (listViewItem.Model is ILibraryAssetStream stream
&& ApplicationController.Instance.Library.IsContentFileType(stream.FileName));
bool isValidStream = listViewItem.Model is ILibraryAssetStream stream
&& ApplicationController.Instance.Library.IsContentFileType(stream.FileName);
bool isContainerLink = listViewItem.Model is ILibraryContainerLink;
bool isGCode = listViewItem.Model is FileSystemFileItem item && Path.GetExtension(item.Name).IndexOf(".gco", StringComparison.OrdinalIgnoreCase) == 0
|| listViewItem.Model is SDCardFileItem sdItem && Path.GetExtension(sdItem.Name).IndexOf(".gco", StringComparison.OrdinalIgnoreCase) == 0;
bool isGCode = (listViewItem.Model is FileSystemFileItem item
&& Path.GetExtension(item.Name).IndexOf(".gco", StringComparison.OrdinalIgnoreCase) == 0)
|| (listViewItem.Model is SDCardFileItem sdItem
&& Path.GetExtension(sdItem.Name).IndexOf(".gco", StringComparison.OrdinalIgnoreCase) == 0);
return isContentItem || isValidStream || isContainerLink || isGCode;
}
@ -404,6 +406,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
public virtual bool IsHoverItem { get; set; }
public virtual bool EditMode { get; set; }
private bool isSelected = false;
@ -418,11 +421,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
return isSelected;
}
set
{
if (isSelected != value)
{
//selectionCheckBox.Checked = value;
// selectionCheckBox.Checked = value;
isSelected = value;
UpdateColors();