<commit_before>﻿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;
using System;
using System.IO;

namespace MatterHackers.MatterControl
{
	public class MenuOptionFile : MenuBase
	{
		public MenuOptionFile()
			: base("File".Localize())
		{
		}

		override protected TupleList<string, Func<bool>> GetMenuItems()
		{
			return new TupleList<string, Func<bool>>
            {
                {LocalizedString.Get("Add Printer"), addPrinter_Click},
                {LocalizedString.Get("Add File"), importFile_Click},
				{LocalizedString.Get("Exit"), exit_Click},
            };
		}

		private bool addPrinter_Click()
		{
			UiThread.RunOnIdle(ConnectionWindow.Show);
			return true;
		}

		private bool importFile_Click()
		{
			UiThread.RunOnIdle(() =>
			{
				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;
		}

		private string cannotExitWhileActiveMessage = "Oops! You cannot exit while a print is active.".Localize();
		private string cannotExitWhileActiveTitle = "Unable to Exit";

		private bool exit_Click()
		{
			UiThread.RunOnIdle(() =>
			{
				GuiWidget parent = this;
				while (parent as MatterControlApplication == null)
				{
					parent = parent.Parent;
				}

				if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
				{
					StyledMessageBox.ShowMessageBox(null, cannotExitWhileActiveMessage, cannotExitWhileActiveTitle);
				}
				else
				{
					MatterControlApplication app = parent as MatterControlApplication;
					app.RestartOnClose = false;
					app.Close();
				}
			});
			return true;
		}
	}
}<commit_msg>Fixed Bug: Previously you could not add zip files to the queue using the Add File menu item in the File dropdown.<commit_after>﻿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;
using System;
using System.IO;

namespace MatterHackers.MatterControl
{
	public class MenuOptionFile : MenuBase
	{
		public MenuOptionFile()
			: base("File".Localize())
		{
		}

		override protected TupleList<string, Func<bool>> GetMenuItems()
		{
			return new TupleList<string, Func<bool>>
            {
                {LocalizedString.Get("Add Printer"), addPrinter_Click},
                {LocalizedString.Get("Add File"), importFile_Click},
				{LocalizedString.Get("Exit"), exit_Click},
            };
		}

		private bool addPrinter_Click()
		{
			UiThread.RunOnIdle(ConnectionWindow.Show);
			return true;
		}

		private bool importFile_Click()
		{
			UiThread.RunOnIdle(() =>
			{
				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))));
                                }
							}
						}
					});
			});
			return true;
		}

		private string cannotExitWhileActiveMessage = "Oops! You cannot exit while a print is active.".Localize();
		private string cannotExitWhileActiveTitle = "Unable to Exit";

		private bool exit_Click()
		{
			UiThread.RunOnIdle(() =>
			{
				GuiWidget parent = this;
				while (parent as MatterControlApplication == null)
				{
					parent = parent.Parent;
				}

				if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
				{
					StyledMessageBox.ShowMessageBox(null, cannotExitWhileActiveMessage, cannotExitWhileActiveTitle);
				}
				else
				{
					MatterControlApplication app = parent as MatterControlApplication;
					app.RestartOnClose = false;
					app.Close();
				}
			});
			return true;
		}
	}
}
{'fraction_non_alphanumeric': 0.0891599381549562, 'fraction_numerical': 0.0, 'mean_word_length': 2.453143534994069, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1677089', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1571, 'n_words': 314}