mattercontrol/ApplicationView/MenuRow/MenuOptionFile.cs

124 lines
4 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;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl
{
public class MenuOptionFile : MenuBase
2015-04-08 15:20:10 -07:00
{
2015-08-03 17:31:53 -07:00
public static MenuOptionFile CurrentMenuOptionFile = null;
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
}
protected override IEnumerable<MenuItemAction> GetMenuActions()
2015-04-08 15:20:10 -07:00
{
return new List<MenuItemAction>
{
// TODO: Helper while building printing window prototype... remove once finalized
new MenuItemAction("Printing Window...".Localize(), () => PrintingWindow.Show(() => Console.WriteLine())),
new MenuItemAction("------------------------", null),
new MenuItemAction("Add Printer".Localize(), AddPrinter_Click),
new MenuItemAction("Import Printer".Localize(), ImportPrinter),
2016-04-18 11:31:31 -07:00
new MenuItemAction("Add File To Queue".Localize(), importFile_Click),
new MenuItemAction("Redeem Design Code".Localize(), () => ApplicationController.Instance.RedeemDesignCode?.Invoke()),
new MenuItemAction("Enter Share Code".Localize(), () => ApplicationController.Instance.EnterShareCode?.Invoke()),
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 ImportPrinter()
{
FileDialog.OpenFileDialog(
new OpenFileDialogParams("settings files|*.ini;*.printer;*.slice"),
(dialogParams) =>
{
if (!string.IsNullOrEmpty(dialogParams.FileName))
{
ImportSettingsFile(dialogParams.FileName);
}
});
}
private void ImportSettingsFile(string settingsFilePath)
{
if(!ProfileManager.ImportFromExisting(settingsFilePath))
{
StyledMessageBox.ShowMessageBox(null, "Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
}
}
private void AddPrinter_Click()
{
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting
|| PrinterConnectionAndCommunication.Instance.PrinterIsPaused)
{
UiThread.RunOnIdle(() =>
StyledMessageBox.ShowMessageBox(null, "Please wait until the print has finished and try again.".Localize(), "Can't add printers while printing".Localize())
);
}
else
{
WizardWindow.ShowPrinterSetup(true);
}
}
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
}
}
}