public void AddNotesMenu(PopupMenu popupMenu, IEnumerable <PrintTask> printTasks, Action notesChanged)
        {
            var addNotest = popupMenu.CreateMenuItem(string.IsNullOrEmpty(printTask.Note) ? "Add Note...".Localize() : "Edit Note...".Localize());

            addNotest.Enabled = printTasks.Any();
            addNotest.Click  += (s, e) =>
            {
                var inputBoxPage = new InputBoxPage(
                    "Print History Note".Localize(),
                    "Note".Localize(),
                    printTask.Note == null ? "" : printTask.Note,
                    "Enter Note Here".Localize(),
                    string.IsNullOrEmpty(printTask.Note) ? "Add Note".Localize() : "Update".Localize(),
                    (newNote) =>
                {
                    printTask.Note = newNote;
                    printTask.Commit();
                    popupMenu.Unfocus();
                    notesChanged();
                })
                {
                    AllowEmpty = true,
                };

                inputBoxPage.ContentRow.AddChild(CreateDefaultOptions(inputBoxPage));

                DialogWindow.Show(inputBoxPage);

                inputBoxPage.Parent.Height += 40 * GuiWidget.DeviceScale;
            };
        }
        public static void CheckIfNeedToRecoverPrint(PrinterConfig printer)
        {
            string printRecoveryWarningMessage = "WARNING: In order to perform print recovery, your printer must move down to reach its home position.\nIf your print is too large, part of your printer may collide with it when moving down.\nMake sure it is safe to perform this operation before proceeding.".Localize();

            PrintTask lastPrint = PrintHistoryData.Instance.GetHistoryForPrinter(printer.Settings.ID.GetHashCode()).FirstOrDefault();

            if (lastPrint != null)
            {
                if (RecoveryAvailable(printer))
                {
                    bool safeHomingDirection = printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max);

                    StyledMessageBox.ShowMessageBox(
                        (messageBoxResponse) =>
                    {
                        if (messageBoxResponse)
                        {
                            UiThread.RunOnIdle(async() =>
                            {
                                if (printer.Connection.CommunicationState == CommunicationStates.Connected)
                                {
                                    printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;

                                    // TODO: Reimplement
                                    //await printer.Connection.StartPrint(lastPrint.PrintingGCodeFileName, lastPrint);

                                    // This needs to be reworked to support the PrintServer owning the PrintTask/Job

                                    System.Diagnostics.Debugger.Break();
                                    //printer.Connection.StartPrint(lastPrint.PrintingGCodeFileName);

                                    ApplicationController.Instance.MonitorPrintTask(printer);
                                }
                            });
                        }
                        else                                 // the recovery has been canceled
                        {
                            lastPrint.PrintingGCodeFileName = null;
                            lastPrint.Commit();
                        }
                    },
                        "It appears your last print failed to complete.\n\nWould your like to attempt to recover from the last know position?".Localize()
                        + (safeHomingDirection ? "" : "\n\n" + printRecoveryWarningMessage),
                        "Recover Last Print".Localize(),
                        StyledMessageBox.MessageType.YES_NO,
                        "Recover Print".Localize(),
                        "Cancel".Localize());
                }
            }
        }
        public static void CheckIfNeedToRecoverPrint(PrinterConfig printer)
        {
            string recoverPrint   = "Recover Print".Localize();
            string cancelRecovery = "Cancel".Localize();
            string printRecoveryWarningMessage = "WARNING: In order to perform print recovery, your printer must move down to reach its home position.\nIf your print is too large, part of your printer may collide with it when moving down.\nMake sure it is safe to perform this operation before proceeding.".Localize();
            string printRecoveryMessage        = "It appears your last print failed to complete.\n\nWould your like to attempt to recover from the last know position?".Localize();
            string recoverPrintTitle           = "Recover Last Print".Localize();

            PrintTask lastPrint = PrintHistoryData.Instance.GetHistoryForPrinter(printer.Settings.ID.GetHashCode()).FirstOrDefault();

            if (lastPrint != null)
            {
                if (!lastPrint.PrintComplete &&              // Top Print History Item is not complete
                    !string.IsNullOrEmpty(lastPrint.PrintingGCodeFileName) &&                     // PrintingGCodeFileName is set
                    File.Exists(lastPrint.PrintingGCodeFileName) &&                     // PrintingGCodeFileName is still on disk
                    lastPrint.PercentDone > 0 &&                     // we are actually part way into the print
                    printer.Settings.GetValue <bool>(SettingsKey.recover_is_enabled) &&
                    !printer.Settings.GetValue <bool>(SettingsKey.has_hardware_leveling))
                {
                    bool safeHomingDirection = printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max);

                    StyledMessageBox.ShowMessageBox(
                        (messageBoxResponse) =>
                    {
                        if (messageBoxResponse)
                        {
                            UiThread.RunOnIdle(async() =>
                            {
                                if (printer.Connection.CommunicationState == CommunicationStates.Connected)
                                {
                                    printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
                                    await printer.Connection.StartPrint(lastPrint.PrintingGCodeFileName, lastPrint);
                                    ApplicationController.Instance.MonitorPrintTask(printer);
                                }
                            });
                        }
                        else                                 // the recovery has been canceled
                        {
                            lastPrint.PrintingGCodeFileName = null;
                            lastPrint.Commit();
                        }
                    },
                        (safeHomingDirection) ? printRecoveryMessage : printRecoveryMessage + "\n\n" + printRecoveryWarningMessage,
                        recoverPrintTitle,
                        StyledMessageBox.MessageType.YES_NO,
                        recoverPrint,
                        cancelRecovery);
                }
            }
        }
 private static void ResumeFailedPrintProcessDialogResponse(bool messageBoxResponse)
 {
     if (messageBoxResponse)
     {
         UiThread.RunOnIdle(() =>
         {
             if (PrinterConnectionAndCommunication.Instance.CommunicationState == PrinterConnectionAndCommunication.CommunicationStates.Connected)
             {
                 PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint;
                 PrinterConnectionAndCommunication.Instance.StartPrint(lastPrintTask.PrintingGCodeFileName, lastPrintTask);
             }
         });
     }
     else             // the resume has been canceled
     {
         lastPrintTask.PrintingGCodeFileName = null;
         lastPrintTask.Commit();
     }
 }