mattercontrol/ApplicationView/MenuRow/MenuOptionFile.cs

87 lines
2.6 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrintQueue;
using System.Collections.Generic;
using MatterHackers.VectorMath;
2015-04-08 15:20:10 -07:00
using System;
using System.IO;
2016-04-18 11:31:31 -07:00
using System.Linq;
namespace MatterHackers.MatterControl
{
public class MenuOptionFile : MenuBase
2015-04-08 15:20:10 -07:00
{
2015-08-03 17:31:53 -07:00
private static CreateFolderWindow createFolderWindow = null;
public static MenuOptionFile CurrentMenuOptionFile = null;
public EventHandler RedeemDesignCode;
2016-04-18 11:31:31 -07:00
public EventHandler EnterShareCode;
2015-08-03 17:31:53 -07:00
2015-04-08 15:20:10 -07:00
public MenuOptionFile()
: base("File".Localize())
2015-04-08 15:20:10 -07:00
{
2015-08-20 10:24:28 -07:00
Name = "File Menu";
2015-08-03 17:31:53 -07:00
CurrentMenuOptionFile = this;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
}
2016-04-18 11:31:31 -07:00
protected override IEnumerable<MenuItemAction> GetMenuItems()
2015-04-08 15:20:10 -07:00
{
return new List<MenuItemAction>
{
2016-04-18 11:31:31 -07:00
new MenuItemAction("Add Printer".Localize(), () => ConnectionWizard.Show()),
new MenuItemAction("Add File To Queue".Localize(), importFile_Click),
new MenuItemAction("Redeem Design Code".Localize(), () => RedeemDesignCode?.Invoke(this, null)),
new MenuItemAction("Enter Share Code".Localize(), () => EnterShareCode?.Invoke(this, null)),
new MenuItemAction("------------------------", null),
2016-04-18 11:31:31 -07:00
new MenuItemAction("Exit".Localize(), () =>
2015-08-03 17:31:53 -07:00
{
2016-04-18 11:31:31 -07:00
MatterControlApplication app = this.Parents<MatterControlApplication>().FirstOrDefault();
app.RestartOnClose = false;
app.Close();
})
};
2015-04-08 15:20:10 -07:00
}
private void importFile_Click()
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
FileDialog.OpenFileDialog(
new OpenFileDialogParams(ApplicationSettings.OpenPrintableFileParams)
{
MultiSelect = true,
ActionButtonLabel = "Add to Queue",
Title = "MatterControl: Select A File"
},
(openParams) =>
{
if (openParams.FileNames != null)
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
foreach (string loadedFileName in openParams.FileNames)
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if (Path.GetExtension(loadedFileName).ToUpper() == ".ZIP")
{
ProjectFileHandler project = new ProjectFileHandler(null);
List<PrintItem> partFiles = project.ImportFromProjectArchive(loadedFileName);
if (partFiles != null)
{
foreach (PrintItem part in partFiles)
{
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(part.Name, part.FileLocation)));
}
}
}
else
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), Path.GetFullPath(loadedFileName))));
2015-04-08 15:20:10 -07:00
}
}
2016-04-18 11:31:31 -07:00
}
});
2015-04-08 15:20:10 -07:00
}
}
}