Merge pull request #3045 from jlewin/design_tools
Implement library/listview sorting
This commit is contained in:
commit
ce0d8a5bac
14 changed files with 168 additions and 88 deletions
|
|
@ -39,6 +39,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
string Name { get; }
|
||||
bool IsProtected { get; }
|
||||
bool IsVisible { get; }
|
||||
DateTime DateModified { get; }
|
||||
DateTime DateCreated { get; }
|
||||
}
|
||||
|
||||
public interface ILibraryObject3D : ILibraryAsset
|
||||
|
|
|
|||
|
|
@ -40,5 +40,9 @@ namespace MatterHackers.MatterControl.Library
|
|||
public bool IsProtected => false;
|
||||
|
||||
public bool IsVisible => true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public bool IsReadOnly { get; set; } = false;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
private ImageBuffer thumbnail;
|
||||
private Func<ILibraryContainer> containerCreator;
|
||||
private Func<bool> visibilityResolver;
|
||||
|
|
|
|||
|
|
@ -159,10 +159,11 @@ namespace MatterHackers.MatterControl.Library
|
|||
containers = new List<ILibraryContainerLink>();
|
||||
}
|
||||
|
||||
var matchedFiles = (filter == "") ? nonZipFiles : nonZipFiles.Where(filePath =>
|
||||
var matchedFiles = nonZipFiles.Where(filePath =>
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
return FileNameContainsFilter(filePath, filter)
|
||||
|
||||
return (filter == "" || FileNameContainsFilter(filePath, filter))
|
||||
&& ApplicationController.Instance.Library.IsContentFileType(fileName);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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.IO;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
|
|
@ -48,10 +49,39 @@ namespace MatterHackers.MatterControl.Library
|
|||
public FileSystemItem(string path)
|
||||
{
|
||||
this.Path = path;
|
||||
|
||||
var type = GetType();
|
||||
|
||||
try
|
||||
{
|
||||
if (type == typeof(FileSystemFileItem))
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
||||
this.DateCreated = fileInfo.CreationTime;
|
||||
this.DateModified = fileInfo.LastWriteTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(path);
|
||||
|
||||
this.DateCreated = directoryInfo.CreationTime;
|
||||
this.DateModified = directoryInfo.LastWriteTime;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.DateCreated = DateTime.Now;
|
||||
this.DateModified = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string ID => this.Path.GetHashCode().ToString();
|
||||
|
||||
public DateTime DateCreated { get; }
|
||||
|
||||
public DateTime DateModified { get; }
|
||||
|
||||
public virtual string Name
|
||||
{
|
||||
get
|
||||
|
|
@ -79,5 +109,9 @@ namespace MatterHackers.MatterControl.Library
|
|||
public bool IsProtected => true;
|
||||
|
||||
public bool IsVisible => true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,10 @@ namespace MatterHackers.MatterControl.Library
|
|||
public bool IsProtected { get; set; }
|
||||
public bool IsVisible => true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
public Color Color { get; set; }
|
||||
|
||||
public long FileSize => 0;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public bool IsVisible => true;
|
||||
|
||||
public DateTime DateCreated => this.PrintTask.PrintStart;
|
||||
|
||||
public DateTime DateModified => this.PrintTask.PrintEnd;
|
||||
|
||||
public bool LocalContentExists => true;
|
||||
|
||||
public string Category => "General";
|
||||
|
|
|
|||
|
|
@ -31,16 +31,10 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.PrintQueue;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.PolygonMesh.Processors;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -148,7 +142,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
case ILibraryAssetStream streamItem:
|
||||
|
||||
var fileName = (streamItem as ILibraryAssetStream)?.FileName;
|
||||
var fileName = (streamItem as ILibraryAssetStream)?.FileName;
|
||||
|
||||
using (var streamInfo = await streamItem.GetStream(null))
|
||||
{
|
||||
|
|
@ -225,7 +219,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a database PrintItem entity, copies the source file to a new library
|
||||
/// Creates a database PrintItem entity, copies the source file to a new library
|
||||
/// path and updates the PrintItem to point at the new target
|
||||
/// </summary>
|
||||
private void AddItem(Stream stream, string extension, string displayName)
|
||||
|
|
@ -270,6 +264,10 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public bool IsVisible { get; set; } = true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
public Task<ILibraryContainer> GetContainer(Action<double, string> reportProgress)
|
||||
{
|
||||
return Task.FromResult<ILibraryContainer>(
|
||||
|
|
|
|||
|
|
@ -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.Threading.Tasks;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.Platform;
|
||||
|
|
@ -55,6 +56,10 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public bool IsVisible { get; set; } = true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
public ImageBuffer Thumbnail { get; set; }
|
||||
|
||||
public MessageItem(string name)
|
||||
|
|
|
|||
|
|
@ -42,5 +42,9 @@ namespace MatterHackers.MatterControl.Library
|
|||
public bool IsProtected { get; } = true;
|
||||
|
||||
public bool IsVisible { get; } = true;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,38 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
ModifiedDate
|
||||
}
|
||||
|
||||
public SortKey ActiveSort { get; set; } = SortKey.Name;
|
||||
private SortKey _activeSort = SortKey.Name;
|
||||
public SortKey ActiveSort
|
||||
{
|
||||
get => _activeSort;
|
||||
set
|
||||
{
|
||||
if (_activeSort != value)
|
||||
{
|
||||
_activeSort = value;
|
||||
this.ApplySort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _ascending = true;
|
||||
public bool Ascending
|
||||
{
|
||||
get => _ascending;
|
||||
set
|
||||
{
|
||||
if (_ascending != value)
|
||||
{
|
||||
_ascending = value;
|
||||
this.ApplySort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySort()
|
||||
{
|
||||
this.Reload().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Empties the list children and repopulates the list with the source container content
|
||||
|
|
@ -175,14 +206,15 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
|
||||
itemsContentView.BeginReload();
|
||||
|
||||
var containerItems = from item in sourceContainer.ChildContainers
|
||||
IEnumerable<ILibraryItem> containerItems = from item in sourceContainer.ChildContainers
|
||||
where item.IsVisible && this.ContainerFilter(item)
|
||||
orderby item.Name
|
||||
select item;
|
||||
|
||||
// Folder items
|
||||
foreach (var childContainer in containerItems)
|
||||
foreach (var childContainer in this.SortItems(containerItems))
|
||||
{
|
||||
Console.WriteLine($"{childContainer.Name}:{childContainer.DateCreated}");
|
||||
|
||||
var listViewItem = new ListViewItem(childContainer, this);
|
||||
listViewItem.DoubleClick += listViewItem_DoubleClick;
|
||||
items.Add(listViewItem);
|
||||
|
|
@ -200,20 +232,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
&& this.ItemFilter(item)
|
||||
select item;
|
||||
|
||||
filteredResults = filteredResults.OrderBy(item =>
|
||||
{
|
||||
switch (ActiveSort)
|
||||
{
|
||||
case SortKey.Name:
|
||||
return item.Name;
|
||||
|
||||
default:
|
||||
return item.Name;
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var item in filteredResults)
|
||||
foreach (var item in this.SortItems(filteredResults))
|
||||
{
|
||||
Console.WriteLine($"{item.Name}:{item.DateCreated}");
|
||||
var listViewItem = new ListViewItem(item, this);
|
||||
listViewItem.DoubleClick += listViewItem_DoubleClick;
|
||||
items.Add(listViewItem);
|
||||
|
|
@ -223,7 +244,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
}
|
||||
|
||||
itemsContentView.EndReload();
|
||||
|
||||
}
|
||||
|
||||
if (sourceContainer is ILibraryWritableContainer writableContainer)
|
||||
|
|
@ -236,6 +256,30 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
this.ContentReloaded?.Invoke(this, null);
|
||||
}
|
||||
|
||||
private IEnumerable<ILibraryItem> SortItems(IEnumerable<ILibraryItem> items)
|
||||
{
|
||||
switch (ActiveSort)
|
||||
{
|
||||
case SortKey.CreatedDate when this.Ascending:
|
||||
return items.OrderBy(item => item.DateCreated);
|
||||
|
||||
case SortKey.CreatedDate when !this.Ascending:
|
||||
return items.OrderByDescending(item => item.DateCreated);
|
||||
|
||||
case SortKey.ModifiedDate when this.Ascending:
|
||||
return items.OrderBy(item => item.DateModified);
|
||||
|
||||
case SortKey.ModifiedDate when !this.Ascending:
|
||||
return items.OrderByDescending(item => item.DateModified);
|
||||
|
||||
case SortKey.Name when !this.Ascending:
|
||||
return items.OrderByDescending(item => item.Name);
|
||||
|
||||
default:
|
||||
return items.OrderBy(item => item.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void WritableContainer_ItemContentChanged(object sender, ItemChangedEventArgs e)
|
||||
{
|
||||
var firstItem = items.Where(i => i.Model.ID == e.LibraryItem.ID).FirstOrDefault();
|
||||
|
|
|
|||
|
|
@ -109,69 +109,37 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
toolbar.OverflowButton.Name = "Print Library View Options";
|
||||
toolbar.ExtendOverflowMenu = (popupMenu) =>
|
||||
{
|
||||
var sortActions = new List<PrintItemAction>()
|
||||
{
|
||||
new PrintItemAction()
|
||||
{
|
||||
Title = "Date Created",
|
||||
Action = (items, listview) =>
|
||||
{
|
||||
}
|
||||
},
|
||||
new PrintItemAction()
|
||||
{
|
||||
Title = "Date Modified",
|
||||
Action = (items, listview) =>
|
||||
{
|
||||
}
|
||||
},
|
||||
new PrintItemAction()
|
||||
{
|
||||
Title = "Name",
|
||||
Action = (items, listview) =>
|
||||
{
|
||||
}
|
||||
},
|
||||
new MenuSeparator(""),
|
||||
new PrintItemAction()
|
||||
{
|
||||
Title = "Ascending",
|
||||
Action = (items, listview) =>
|
||||
{
|
||||
}
|
||||
},
|
||||
new PrintItemAction()
|
||||
{
|
||||
Title = "Descending",
|
||||
Action = (items, listview) =>
|
||||
{
|
||||
}
|
||||
}
|
||||
};
|
||||
popupMenu.CreateBoolMenuItem(
|
||||
"Date Created".Localize(),
|
||||
() => libraryView.ActiveSort == ListView.SortKey.CreatedDate,
|
||||
(v) => libraryView.ActiveSort = ListView.SortKey.CreatedDate,
|
||||
useRadioStyle: true);
|
||||
|
||||
// Create menu items in the DropList for each element in this.menuActions
|
||||
foreach (var menuAction in sortActions)
|
||||
{
|
||||
if (menuAction is MenuSeparator)
|
||||
{
|
||||
popupMenu.CreateHorizontalLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
var menuItem = popupMenu.CreateMenuItem(menuAction.Title);
|
||||
menuItem.Name = $"{menuAction.Title} Menu Item";
|
||||
popupMenu.CreateBoolMenuItem(
|
||||
"Date Modified".Localize(),
|
||||
() => libraryView.ActiveSort == ListView.SortKey.ModifiedDate,
|
||||
(v) => libraryView.ActiveSort = ListView.SortKey.ModifiedDate,
|
||||
useRadioStyle: true);
|
||||
|
||||
menuItem.Enabled = menuAction.Action != null;
|
||||
menuItem.ClearRemovedFlag();
|
||||
menuItem.Click += (s, e) =>
|
||||
{
|
||||
menuAction.Action?.Invoke(libraryView.SelectedItems.Select(i => i.Model), libraryView);
|
||||
};
|
||||
popupMenu.CreateBoolMenuItem(
|
||||
"Name".Localize(),
|
||||
() => libraryView.ActiveSort == ListView.SortKey.Name,
|
||||
(v) => libraryView.ActiveSort = ListView.SortKey.Name,
|
||||
useRadioStyle: true);
|
||||
|
||||
// Store a reference to the newly created MenuItem back on the MenuAction definition
|
||||
menuAction.MenuItem = menuItem;
|
||||
}
|
||||
}
|
||||
popupMenu.CreateHorizontalLine();
|
||||
|
||||
popupMenu.CreateBoolMenuItem(
|
||||
"Ascending".Localize(),
|
||||
() => libraryView.Ascending,
|
||||
(v) => libraryView.Ascending = true,
|
||||
useRadioStyle: true);
|
||||
|
||||
popupMenu.CreateBoolMenuItem(
|
||||
"Descending".Localize(),
|
||||
() => !libraryView.Ascending,
|
||||
(v) => libraryView.Ascending = false,
|
||||
useRadioStyle: true);
|
||||
};
|
||||
|
||||
toolbar.Padding = theme.ToolbarPadding;
|
||||
|
|
|
|||
|
|
@ -468,6 +468,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
public bool IsVisible => existingItem.Visible;
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
public string ContentType => "mcx";
|
||||
|
||||
public string Category => "General";
|
||||
|
|
|
|||
|
|
@ -1395,6 +1395,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
public bool IsVisible { get; set; }
|
||||
|
||||
public DateTime DateCreated { get; } = DateTime.Now;
|
||||
|
||||
public DateTime DateModified { get; } = DateTime.Now;
|
||||
|
||||
public long FileSize => 0;
|
||||
|
||||
public string AssetPath => "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue