public override void OnClosing(out bool CancelClose)
        {
            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            if (PrinterCommunication.Instance.PrinterIsPrinting)
            {
                StyledMessageBox.ShowMessageBox("Oop! You cannot exit while a print is active.", "Unable to Exit");
                CancelClose = true;
            }
            else if (PartsSheet.IsSaving())
            {
                if (!StyledMessageBox.ShowMessageBox("You are currently saving a parts sheet, are you sure you want to exit?", "Confirm Exit", StyledMessageBox.MessageType.YES_NO))
                {
                    CancelClose = true;
                }
                else
                {
                    base.OnClosing(out CancelClose);
                }
            }
            else
            {
                base.OnClosing(out CancelClose);
            }
        }
        public override void OnClosing(out bool cancelClose)
        {
            cancelClose = false;
            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set(ApplicationSettingsKey.MainWindowMaximized, this.Maximized.ToString().ToLower());

            if (!this.Maximized)
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.WindowSize, string.Format("{0},{1}", Width, Height));
                ApplicationSettings.Instance.set(ApplicationSettingsKey.DesktopPosition, string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));
            }

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            // If we are waiting for a response and get another request, just cancel the close until we get a response.
            if (closeMessageBoxIsOpen)
            {
                cancelClose = true;
            }

            if (!closeHasBeenConfirmed &&
                !closeMessageBoxIsOpen &&
                PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
            {
                cancelClose = true;
                // Record that we are waiting for a response to the request to close
                closeMessageBoxIsOpen = true;

                if (PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.PrintingFromSd)
                {
                    // Needed as we can't assign to CancelClose inside of the lambda below
                    StyledMessageBox.ShowMessageBox(ConditionalyCloseNow,
                                                    "Are you sure you want to abort the current print and close MatterControl?".Localize(),
                                                    "Abort Print".Localize(),
                                                    StyledMessageBox.MessageType.YES_NO);
                }
                else
                {
                    StyledMessageBox.ShowMessageBox(
                        ConditionalyCloseNow,
                        "Are you sure you want exit while a print is running from SD Card?\n\nNote: If you exit, it is recommended you wait until the print is completed before running MatterControl again.".Localize(),
                        "Exit while printing".Localize(),
                        StyledMessageBox.MessageType.YES_NO);
                }
            }
            else if (PartsSheet.IsSaving())
            {
                StyledMessageBox.ShowMessageBox(onConfirmExit, savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO);
                cancelClose = true;
            }
            else if (!cancelClose)            // only check if we have not already canceled
            {
                base.OnClosing(out cancelClose);
            }
        }
        public override void OnClosing(out bool CancelClose)
        {
            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set("WindowSize", string.Format("{0},{1}", Width, Height));
            ApplicationSettings.Instance.set("DesktopPosition", string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
            {
                // Needed as we can't assign to CancelClose inside of the lambda below
                bool continueWithShutdown = false;

                StyledMessageBox.ShowMessageBox(
                    (shutdownConfirmed) => continueWithShutdown = shutdownConfirmed,
                    "Are you sure you want to abort the current print and close MatterControl?".Localize(),
                    "Abort Print".Localize(),
                    StyledMessageBox.MessageType.YES_NO);

                if (continueWithShutdown)
                {
                    if (PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.PrintingFromSd)
                    {
                        PrinterConnectionAndCommunication.Instance.Disable();
                    }
                    this.Close();
                }

                // It's safe to cancel an active print because PrinterConnectionAndCommunication.Disable will be called
                // when MatterControlApplication.OnClosed is invoked
                CancelClose = true;
            }
            else if (PartsSheet.IsSaving())
            {
                StyledMessageBox.ShowMessageBox(onConfirmExit, savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO);
                CancelClose = true;
            }
            else
            {
                base.OnClosing(out CancelClose);
            }
        }
        public override void OnClosing(out bool CancelClose)
        {
            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set("WindowSize", string.Format("{0},{1}", Width, Height));
            ApplicationSettings.Instance.set("DesktopPosition", string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
            {
                StyledMessageBox.ShowMessageBox(null, unableToExitMessage, unableToExitTitle);
                CancelClose = true;
            }
            else if (PartsSheet.IsSaving())
            {
                StyledMessageBox.ShowMessageBox(onConfirmExit, savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO);
                CancelClose = true;
            }
            else
            {
                base.OnClosing(out CancelClose);
            }
        }
Exemplo n.º 5
0
        public override void OnClosing(ClosingEventArgs eventArgs)
        {
            if (this.HasBeenClosed)
            {
                return;
            }

            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set(ApplicationSettingsKey.MainWindowMaximized, this.Maximized.ToString().ToLower());

            if (!this.Maximized)
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.WindowSize, string.Format("{0},{1}", Width, Height));
                ApplicationSettings.Instance.set(ApplicationSettingsKey.DesktopPosition, string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));
            }

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            // If we are waiting for a response and get another request, just cancel the close until we get a response.
            if (exitDialogOpen)
            {
                eventArgs.Cancel = true;
            }

            string caption = null;
            string message = null;

            if (!ApplicationController.Instance.ApplicationExiting &&
                !exitDialogOpen &&
                ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting)
            {
                if (ApplicationController.Instance.ActivePrinter.Connection.CommunicationState != CommunicationStates.PrintingFromSd)
                {
                    caption = "Abort Print".Localize();
                    message = "Are you sure you want to abort the current print and close MatterControl?".Localize();
                }
                else
                {
                    caption = "Exit while printing".Localize();
                    message = "Are you sure you want exit while a print is running from SD Card?\n\nNote: If you exit, it is recommended you wait until the print is completed before running MatterControl again.".Localize();
                }
            }
#if !__ANDROID__
            else if (PartsSheet.IsSaving())
            {
                caption = "Confirm Exit".Localize();
                message = "You are currently saving a parts sheet, are you sure you want to exit?".Localize();
            }
#endif
            if (caption != null)
            {
                // Record that we are waiting for a response to the request to close
                exitDialogOpen = true;

                // We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
                eventArgs.Cancel = true;

                UiThread.RunOnIdle(() =>
                {
                    StyledMessageBox.ShowMessageBox(
                        (exitConfirmed) =>
                    {
                        // Record that the exitDialog has closed
                        exitDialogOpen = false;

                        // Continue with the original shutdown request if exit confirmed by user
                        if (exitConfirmed)
                        {
                            ApplicationController.Instance.ApplicationExiting = true;
                            ApplicationController.Instance.Shutdown();

                            // Always call PrinterConnection.Disable on exit unless PrintingFromSd
                            PrinterConnection printerConnection = ApplicationController.Instance.ActivePrinter.Connection;
                            switch (printerConnection.CommunicationState)
                            {
                            case CommunicationStates.PrintingFromSd:
                            case CommunicationStates.Paused when printerConnection.PrePauseCommunicationState == CommunicationStates.PrintingFromSd:
                                break;

                            default:
                                printerConnection.Disable();
                                break;
                            }

                            this.CloseOnIdle();
                        }
                    },
                        message,
                        caption,
                        StyledMessageBox.MessageType.YES_NO_WITHOUT_HIGHLIGHT);
                });
            }
            else
            {
                ApplicationController.Instance.ApplicationExiting = true;
                // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running.
                ApplicationController.Instance.Shutdown();
            }
        }
Exemplo n.º 6
0
        public override void OnClosing(out bool CancelClose)
        {
            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set(ApplicationSettingsKey.MainWindowMaximized, this.Maximized.ToString().ToLower());

            if (!this.Maximized)
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.WindowSize, string.Format("{0},{1}", Width, Height));
                ApplicationSettings.Instance.set(ApplicationSettingsKey.DesktopPosition, string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));
            }

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
            {
                if (PrinterConnectionAndCommunication.Instance.CommunicationState != PrinterConnectionAndCommunication.CommunicationStates.PrintingFromSd)
                {
                    // Needed as we can't assign to CancelClose inside of the lambda below
                    bool continueWithShutdown = false;

                    StyledMessageBox.ShowMessageBox(
                        (shutdownConfirmed) => continueWithShutdown = shutdownConfirmed,
                        "Are you sure you want to abort the current print and close MatterControl?".Localize(),
                        "Abort Print".Localize(),
                        StyledMessageBox.MessageType.YES_NO);

                    if (continueWithShutdown)
                    {
                        PrinterConnectionAndCommunication.Instance.Disable();
                        this.Close();
                        CancelClose = false;
                    }
                    else
                    {
                        // It's safe to cancel an active print because PrinterConnectionAndCommunication.Disable will be called
                        // when MatterControlApplication.OnClosed is invoked
                        CancelClose = true;
                    }
                }
                else
                {
                    bool continueWithShutdown = false;

                    StyledMessageBox.ShowMessageBox(
                        (shutdownConfirmed) => continueWithShutdown = shutdownConfirmed,
                        "Are you sure you want exit while a print is running from SD Card?\n\nNote: If you exit, it is recommended you wait until the print is completed before running MatterControl again.".Localize(),
                        "Exit while printing".Localize(),
                        StyledMessageBox.MessageType.YES_NO);

                    if (continueWithShutdown)
                    {
                        PrinterConnectionAndCommunication.Instance.Disable();
                        this.Close();
                        CancelClose = false;
                    }
                    else
                    {
                        // It's safe to cancel an active print because PrinterConnectionAndCommunication.Disable will be called
                        // when MatterControlApplication.OnClosed is invoked
                        CancelClose = true;
                    }
                }
            }
            else if (PartsSheet.IsSaving())
            {
                StyledMessageBox.ShowMessageBox(onConfirmExit, savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO);
                CancelClose = true;
            }
            else
            {
                base.OnClosing(out CancelClose);
            }
        }
        public override void OnClosing(ClosingEventArgs eventArgs)
        {
            if (this.HasBeenClosed)
            {
                return;
            }

            // save the last size of the window so we can restore it next time.
            ApplicationSettings.Instance.set(ApplicationSettingsKey.MainWindowMaximized, this.Maximized.ToString().ToLower());

            if (!this.Maximized)
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.WindowSize, string.Format("{0},{1}", Width, Height));
                ApplicationSettings.Instance.set(ApplicationSettingsKey.DesktopPosition, string.Format("{0},{1}", DesktopPosition.x, DesktopPosition.y));
            }

            //Save a snapshot of the prints in queue
            QueueData.Instance.SaveDefaultQueue();

            // If we are waiting for a response and get another request, just cancel the close until we get a response.
            if (exitDialogOpen)
            {
                eventArgs.Cancel = true;
            }

            string caption = null;
            string message = null;

            if (!ApplicationController.Instance.ApplicationExiting &&
                !exitDialogOpen)
            {
                int printingCount = 0;
                int sdPrinting    = 0;
                foreach (var printer in ApplicationController.Instance.ActivePrinters)
                {
                    if (printer.Connection.PrinterIsPrinting)
                    {
                        if (printer.Connection.CommunicationState == CommunicationStates.PrintingFromSd)
                        {
                            sdPrinting++;
                        }
                        printingCount++;
                    }
                }

                if (sdPrinting > 0)
                {
                    caption = "Exit while printing".Localize();
                    message = "Are you sure you want to exit while a print is running from SD Card?\n\nNote: If you exit, it is recommended you wait until the print is completed before running MatterControl again.".Localize();
                }
                else if (printingCount > 0)
                {
                    caption = "Abort Print".Localize();
                    message = "Are you sure you want to abort the current print and close MatterControl?".Localize();
                }
            }
#if !__ANDROID__
            else if (PartsSheet.IsSaving())
            {
                caption = "Confirm Exit".Localize();
                message = "You are currently saving a parts sheet, are you sure you want to exit?".Localize();
            }
#endif
            if (caption != null)
            {
                // Record that we are waiting for a response to the request to close
                exitDialogOpen = true;

                // We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
                eventArgs.Cancel = true;

                UiThread.RunOnIdle(() =>
                {
                    StyledMessageBox.ShowMessageBox(
                        (exitConfirmed) =>
                    {
                        // Record that the exitDialog has closed
                        exitDialogOpen = false;

                        // Continue with the original shutdown request if exit confirmed by user
                        if (exitConfirmed)
                        {
                            ApplicationController.Instance.ApplicationExiting = true;
                            ApplicationController.Instance.Shutdown();

                            foreach (var printer in ApplicationController.Instance.ActivePrinters)
                            {
                                // the will shutdown any active (and non-sd) prints that are running
                                printer.Connection.Disable();
                            }

                            this.CloseOnIdle();
                        }
                    },
                        message,
                        caption,
                        StyledMessageBox.MessageType.YES_NO_WITHOUT_HIGHLIGHT);
                });
            }
            else if (!ApplicationController.Instance.ApplicationExiting)
            {
                // cancel the close so that we can save all our active work spaces
                eventArgs.Cancel = true;

                UiThread.RunOnIdle(async() =>
                {
                    var application = ApplicationController.Instance;
                    // Save changes before close
                    foreach (var printer in ApplicationController.Instance.ActivePrinters)
                    {
                        if (printer != PrinterConfig.EmptyPrinter)
                        {
                            await application.Tasks.Execute("Saving Print Bed".Localize() + "...", printer.Bed.SaveChanges);
                        }
                    }

                    foreach (var workspace in application.Workspaces)
                    {
                        await application.Tasks.Execute("Saving Print Bed".Localize() + "...", workspace.SceneContext.SaveChanges);
                    }

                    application.ApplicationExiting = true;
                    // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running.
                    application.Shutdown();
                    this.CloseOnIdle();
                });
            }

            // we are exiting and have finished saving
        }