mattercontrol/ApplicationView/MenuRow/MenuOptionFile.cs

155 lines
4.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;
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 event EventHandler<StringEventArgs> AddLocalFolderToLibrary;
public EventHandler RedeemDesignCode;
2015-04-08 15:20:10 -07:00
public MenuOptionFile()
: base("File".Localize())
2015-04-08 15:20:10 -07:00
{
2015-08-03 17:31:53 -07:00
CurrentMenuOptionFile = this;
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>>
{
{"Add Printer".Localize(), addPrinter_Click},
2015-08-03 16:46:57 -07:00
{"Add File To Queue".Localize(), importFile_Click},
2015-08-05 18:33:18 -07:00
{"Add Folder To Library".Localize(), addFolderToLibrar_Click},
2015-08-03 17:31:53 -07:00
{"Redeem Design Code".Localize(), redeemDesignCode_Click},
2015-08-05 18:33:18 -07:00
{"Enter Share Code".Localize(), redeemDesignCode_Click},
{"------------------------", nothing_Click},
{"Exit".Localize(), exit_Click},
};
2015-04-08 15:20:10 -07:00
}
private bool nothing_Click()
{
return true;
}
2015-08-03 17:31:53 -07:00
private bool redeemDesignCode_Click()
{
if (RedeemDesignCode != null)
{
RedeemDesignCode(this, null);
}
return true;
}
2015-08-03 16:46:57 -07:00
private bool addFolderToLibrar_Click()
{
2015-08-03 17:31:53 -07:00
if (AddLocalFolderToLibrary != null)
{
if (createFolderWindow == null)
{
UiThread.RunOnIdle(() =>
2015-08-03 17:31:53 -07:00
{
createFolderWindow = new CreateFolderWindow((returnInfo) =>
{
AddLocalFolderToLibrary(this, new StringEventArgs(returnInfo.newName));
});
createFolderWindow.Closed += (sender2, e2) => { createFolderWindow = null; };
2015-08-03 17:31:53 -07:00
});
}
else
{
createFolderWindow.BringToFront();
}
}
2015-08-03 16:46:57 -07:00
return true;
}
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)
{
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
{
QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(loadedFileName), Path.GetFullPath(loadedFileName))));
}
2015-04-08 15:20:10 -07:00
}
}
});
});
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
}
}
}