Esempio n. 1
0
        public void ShowContentInWindow()
        {
            if (widgetWithPopContent.HasBeenClosed)
            {
                if (systemWindowWithPopContent != null)
                {
                    systemWindowWithPopContent.Close();
                }

                return;
            }

            if (systemWindowWithPopContent == null)
            {
                // So the window is open now only change this is we close it.
                UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, true);

                string windowSize = UserSettings.Instance.get(WindowSizeKey);
                int    width      = 600;
                int    height     = 400;
                if (windowSize != null && windowSize != "")
                {
                    string[] sizes = windowSize.Split(',');
                    width  = Math.Max(int.Parse(sizes[0]), (int)minSize.x);
                    height = Math.Max(int.Parse(sizes[1]), (int)minSize.y);
                }

                systemWindowWithPopContent                   = new SystemWindow(width, height);
                systemWindowWithPopContent.Padding           = new BorderDouble(3);
                systemWindowWithPopContent.Title             = windowTitle;
                systemWindowWithPopContent.AlwaysOnTopOfMain = true;
                systemWindowWithPopContent.BackgroundColor   = ActiveTheme.Instance.PrimaryBackgroundColor;
                systemWindowWithPopContent.Closing          += SystemWindow_Closing;
                if (widgetWithPopContent.Children.Count == 1)
                {
                    GuiWidget child = widgetWithPopContent.Children[0];
                    widgetWithPopContent.RemoveChild(child);
                    child.ClearRemovedFlag();
                    widgetWithPopContent.AddChild(CreateContentForEmptyControl());
                    systemWindowWithPopContent.AddChild(child);
                }
                systemWindowWithPopContent.ShowAsSystemWindow();

                systemWindowWithPopContent.MinimumSize = minSize;
                string desktopPosition = UserSettings.Instance.get(PositionKey);
                if (desktopPosition != null && desktopPosition != "")
                {
                    string[] sizes = desktopPosition.Split(',');

                    //If the desktop position is less than -10,-10, override
                    int xpos = Math.Max(int.Parse(sizes[0]), -10);
                    int ypos = Math.Max(int.Parse(sizes[1]), -10);
                    systemWindowWithPopContent.DesktopPosition = new Point2D(xpos, ypos);
                }
            }
            else
            {
                systemWindowWithPopContent.BringToFront();
            }
        }
Esempio n. 2
0
 void WidgetWhosContentsPopOutIsClosing()
 {
     if (PopedOutSystemWindow != null)
     {
         SaveSizeAndPosition();
         PopedOutSystemWindow.CloseAndRemoveAllChildren();
         PopedOutSystemWindow.Close();
     }
 }
Esempio n. 3
0
        private GuiWidget CreateContentForEmptyControl()
        {
            GuiWidget allContent = new GuiWidget()
            {
                HAnchor = HAnchor.ParentLeftRight,
                VAnchor = VAnchor.ParentBottomTop,
            };

            allContent.Padding = new BorderDouble(5, 10, 5, 10);

            FlowLayoutWidget flowWidget = new FlowLayoutWidget();

            flowWidget.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;
            flowWidget.HAnchor         = HAnchor.ParentLeftRight;
            flowWidget.VAnchor         = VAnchor.ParentTop;
            flowWidget.Padding         = new BorderDouble(10, 0);
            flowWidget.Height          = 60;

            TextImageButtonFactory bringBackButtonFactory = new TextImageButtonFactory();

            bringBackButtonFactory.normalFillColor = RGBA_Bytes.Gray;
            bringBackButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;

            Button bringBackToTabButton = bringBackButtonFactory.Generate("Restore".Localize());

            bringBackToTabButton.ToolTipText = "Bring the Window back into this Tab".Localize();
            bringBackToTabButton.VAnchor     = VAnchor.ParentCenter;
            bringBackToTabButton.Cursor      = Cursors.Hand;
            bringBackToTabButton.Click      += (sender, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    SaveWindowShouldStartClosed();
                    SystemWindow temp = systemWindowWithPopContent;
                    SystemWindow_Closing(null, null);
                    temp.Close();
                });
            };

            TextWidget windowedModeMessage = new TextWidget("WINDOWED MODE: This tab has been moved to a separate window.".Localize(),
                                                            pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);

            windowedModeMessage.VAnchor = VAnchor.ParentCenter;

            flowWidget.AddChild(windowedModeMessage);
            flowWidget.AddChild(new HorizontalSpacer());
            flowWidget.AddChild(bringBackToTabButton);

            allContent.AddChild(flowWidget);

            return(allContent);
        }
Esempio n. 4
0
        public void InstallUpdate(object sender, MouseEventArgs e)
        {
            string downloadToken = ApplicationSettings.Instance.get("CurrentBuildToken");

            string updateFileName   = System.IO.Path.Combine(updateFileLocation, string.Format("{0}.{1}", downloadToken, InstallerExtension));
            string releaseVersion   = ApplicationSettings.Instance.get("CurrentReleaseVersion");
            string friendlyFileName = System.IO.Path.Combine(updateFileLocation, string.Format("MatterControlSetup-{0}.{1}", releaseVersion, InstallerExtension));

            if (System.IO.File.Exists(friendlyFileName))
            {
                System.IO.File.Delete(friendlyFileName);
            }

            try
            {
                //Change download file to friendly file name
                System.IO.File.Move(updateFileName, friendlyFileName);

                int tries = 0;
                do
                {
                    Thread.Sleep(10);
                } while (tries++ < 100 && !File.Exists(friendlyFileName));

                //Run installer file
                Process installUpdate = new Process();
                installUpdate.StartInfo.FileName = friendlyFileName;
                installUpdate.Start();

                GuiWidget parent = Parent;
                while (parent != null && parent as SystemWindow == null)
                {
                    parent = parent.Parent;
                }

                //Attempt to close current application
                SystemWindow topSystemWindow = parent as SystemWindow;
                if (topSystemWindow != null)
                {
                    topSystemWindow.Close();
                }
            }
            catch
            {
                installUpdateLink.Visible = false;
                updateStatusText.Text     = string.Format(new LocalizedString("Oops! Unable to install update.").Translated);
                if (System.IO.File.Exists(friendlyFileName))
                {
                    System.IO.File.Delete(friendlyFileName);
                }
            }
        }
Esempio n. 5
0
        public static async Task RunTest(
            AutomationTest testMethod,
            string staticDataPathOverride      = null,
            double maxTimeToRun                = 60,
            QueueTemplate queueItemFolderToAdd = QueueTemplate.None,
            int overrideWidth        = -1,
            int overrideHeight       = -1,
            string defaultTestImages = null)
        {
            // Walk back a step in the stack and output the callers name
            //StackTrace st = new StackTrace(false);
            //Debug.WriteLine("\r\n ***** Running automation test: {0} {1} ", st.GetFrames().Skip(1).First().GetMethod().Name, DateTime.Now);

            if (staticDataPathOverride == null)
            {
                // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
                staticDataPathOverride = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "StaticData");
            }

#if DEBUG
            string outputDirectory = "Debug";
#else
            string outputDirectory = "Release";
#endif

            Environment.CurrentDirectory = TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl", "bin", outputDirectory);

            // Override the default SystemWindow type without config.json
            AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.OpenGLWinformsWindowProvider, agg_platform_win32";

#if !__ANDROID__
            // Set the static data to point to the directory of MatterControl
            AggContext.StaticData = new FileSystemStaticData(staticDataPathOverride);
#endif
            // Popping one directory above MatterControl, then back down into MatterControl ensures this works in MCCentral as well and MatterControl
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(5, "MatterControl"));

            if (queueItemFolderToAdd != QueueTemplate.None)
            {
                MatterControlUtilities.AddItemsToQueue(queueItemFolderToAdd.ToString());
            }

            if (defaultTestImages == null)
            {
                defaultTestImages = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestImages");
            }

            UserSettings.Instance.set(UserSettingsKey.ThumbnailRenderingMode, "orthographic");
            //GL.HardwareAvailable = false;

            var config = TestAutomationConfig.Load();
            if (config.UseAutomationDialogs)
            {
                AggContext.Config.ProviderTypes.DialogProvider = "MatterHackers.Agg.Platform.AutomationDialogProvider, GuiAutomation";
            }

            // Extract mouse speed from config
            AutomationRunner.TimeToMoveMouse = config.TimeToMoveMouse;
            AutomationRunner.UpDelaySeconds  = config.MouseUpDelay;

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";
            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var(width, height) = RootSystemWindow.GetStartupBounds();

            rootSystemWindow = Application.LoadRootWindow(
                overrideWidth == -1 ? width : overrideWidth,
                overrideHeight == -1 ? height : overrideHeight);

            OemSettings.Instance.ShowShopButton = false;

            if (!config.UseAutomationMouse)
            {
                AutomationRunner.InputMethod = new WindowsInputMethods();
            }

            await AutomationRunner.ShowWindowAndExecuteTests(
                rootSystemWindow,
                testMethod,
                maxTimeToRun,
                defaultTestImages,
                closeWindow : () =>
            {
                if (ApplicationController.Instance.ActivePrinter.Connection.CommunicationState == CommunicationStates.Printing)
                {
                    ApplicationController.Instance.ActivePrinter.Connection.Disable();
                }

                rootSystemWindow.Close();
            });
        }
Esempio n. 6
0
 public static void CloseMatterControl(this AutomationRunner testRunner)
 {
     rootSystemWindow?.Close();
 }