mattercontrol/ApplicationView/MenuRow/MenuOptionFile.cs

89 lines
2.3 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 MatterHackers.VectorMath;
2015-04-08 15:20:10 -07:00
using System;
using System.IO;
namespace MatterHackers.MatterControl
{
public class MenuOptionFile : MenuBase
2015-04-08 15:20:10 -07:00
{
public MenuOptionFile()
: base("File".Localize())
2015-04-08 15:20:10 -07:00
{
}
override protected TupleList<string, Func<bool>> GetMenuItems()
2015-04-08 15:20:10 -07:00
{
return new TupleList<string, Func<bool>>
{
{LocalizedString.Get("Add Printer"), addPrinter_Click},
{LocalizedString.Get("Add File"), importFile_Click},
{LocalizedString.Get("Exit"), exit_Click},
};
2015-04-08 15:20:10 -07:00
}
private bool addPrinter_Click()
{
UiThread.RunOnIdle(ConnectionWindow.Show);
2015-04-08 15:20:10 -07:00
return true;
}
private bool importFile_Click()
{
UiThread.RunOnIdle(() =>
2015-04-08 15:20:10 -07:00
{
FileDialog.OpenFileDialog(
new OpenFileDialogParams(ApplicationSettings.OpenPrintableFileParams)
{
MultiSelect = true,
ActionButtonLabel = "Add to Queue",
Title = "MatterControl: Select A File"
},
(openParams) =>
{
if (openParams.FileNames != null)
{
foreach (string loadedFileName in openParams.FileNames)
{
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), Path.GetFullPath(loadedFileName))));
}
}
});
});
return true;
}
2015-04-08 15:20:10 -07:00
private string cannotExitWhileActiveMessage = "Oops! You cannot exit while a print is active.".Localize();
private string cannotExitWhileActiveTitle = "Unable to Exit";
2015-04-08 15:20:10 -07:00
private bool exit_Click()
{
UiThread.RunOnIdle(() =>
2015-04-08 15:20:10 -07:00
{
GuiWidget parent = this;
while (parent as MatterControlApplication == null)
{
parent = parent.Parent;
}
2015-04-08 15:20:10 -07:00
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
{
2015-04-08 15:20:10 -07:00
StyledMessageBox.ShowMessageBox(null, cannotExitWhileActiveMessage, cannotExitWhileActiveTitle);
}
else
{
2015-04-08 15:20:10 -07:00
MatterControlApplication app = parent as MatterControlApplication;
app.RestartOnClose = false;
app.Close();
}
2015-04-08 15:20:10 -07:00
});
return true;
2015-04-08 15:20:10 -07:00
}
}
}