mattercontrol/original/MatterControlLib/PartSheet/PartSheetPlugin.cs

76 lines
3.1 KiB
C#
Raw Permalink Normal View History

/*
Copyright (c) 2023, Lars Brubaker, Kevin Pope, John Lewin
All rights reserved.
*/
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.Extensibility;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.PrintQueue;
using System.Linq;
namespace MatterHackers.MatterControl
{
public class PartSheetPlugin : IApplicationPlugin
{
public PluginInfo MetaData { get; } = new PluginInfo()
{
Name = "Part Sheets",
UUID = "580D8EF3-885C-4DD3-903A-4DB136AFD84B",
About = "A part sheet plugin",
Developer = "MatterHackers, Inc.",
Url = "https://www.matterhackers.com"
};
public void Initialize()
{
// PDF export is limited to Windows
if (AggContext.OperatingSystem != OSType.Windows)
{
return;
}
// Needed for PDFSharp on .NET core.
// https://stackoverflow.com/questions/50858209/system-notsupportedexception-no-data-is-available-for-encoding-1252
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
ApplicationController.Instance.Library.MenuExtensions.Add(
new LibraryAction(ActionScope.ListItem)
{
Title = "Create Part Sheet".Localize(),
Action = (selectedLibraryItems, listView) =>
{
UiThread.RunOnIdle(() =>
{
var printItems = selectedLibraryItems.OfType<ILibraryAssetStream>();
if (printItems.Any())
{
AggContext.FileDialogs.SaveFileDialog(
new SaveFileDialogParams("Save Parts Sheet|*.pdf")
{
ActionButtonLabel = "Save Parts Sheet".Localize(),
Title = ApplicationController.Instance.ProductName + " - " + "Save".Localize()
},
(saveParams) =>
{
if (!string.IsNullOrEmpty(saveParams.FileName))
{
var currentPartsInQueue = new PartsSheet(printItems, saveParams.FileName);
currentPartsInQueue.SaveSheets().ConfigureAwait(false);
}
});
}
});
},
IsEnabled = (selectedListItems, listView) =>
{
// Multiselect - disallow containers
return listView.SelectedItems.Any()
&& listView.SelectedItems.All(i => !(i.Model is ILibraryContainerLink));
}
});
}
}
}