示例#1
0
        private void RestoreWindowPosition(WindowPlacementInfo wp)
        {
            _ = wp ?? throw new ArgumentNullException(nameof(wp));

            // Validation routine will cope with Null being passed and if it finds an error, it returns null.
            wp = ValidateScreenPosition(wp);

            if (wp != null)
            {
                Log.TraceFormat(
                    "Window position being restored to ({0},{1})-({2},{3}) {4}",
                    wp.Top,
                    wp.Left,
                    wp.Top + wp.Height,
                    wp.Left + wp.Width,
                    wp.WindowState);

                Top    = wp.Top;
                Left   = wp.Left;
                Width  = wp.Width;
                Height = wp.Height;

                // TODO: would it make sense to start up minimized if that was how it was terminated?
                WindowState = wp.WindowState;
            }
        }
示例#2
0
        private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp)
        {
            if (wp != null)
            {
                var virtualScreen = new Rect(
                    SystemParameters.VirtualScreenLeft,
                    SystemParameters.VirtualScreenTop,
                    SystemParameters.VirtualScreenWidth,
                    SystemParameters.VirtualScreenHeight);
                var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height);
                return(virtualScreen.IntersectsWith(window) ? wp : null);
            }

            return(null);
        }
示例#3
0
        private void OnClosed(object sender, CancelEventArgs e)
        {
            var windowInfo = new WindowPlacementInfo
            {
                Height      = (int)Height,
                Top         = (int)Top,
                Left        = (int)Left,
                Width       = (int)Width,
                WindowState = WindowState,
            };

            var filename = Path.ChangeExtension(persistingFilename, ".json");

            PersistingSettings.Save(filename, windowInfo, Preferences);

            var recentFileInfo = new RecentFileInfo {
                RecentFilePaths = RecentFiles.ToList()
            };

            JsonHelper.SerializeToFile(recentFileInfo, Path.ChangeExtension(persistingRecentFileName, ".json"));
        }
示例#4
0
        internal static void Save(string fileName, WindowPlacementInfo placementInfo, IUserPreferences userPreferences)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(fileName));
            }

            var wrapper = new PersistingSettings
            {
                WindowPlacementInfo = placementInfo,
                UserPreferences     = userPreferences,
            };

            try
            {
                JsonHelper.SerializeToFile(wrapper, fileName);
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to write persistence file: {e.Message}");
            }
        }
示例#5
0
        private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp)
        {
            if (wp == null)
            {
                return(null);
            }

            try
            {
                var virtualScreen = new Rect(
                    SystemParameters.VirtualScreenLeft,
                    SystemParameters.VirtualScreenTop,
                    SystemParameters.VirtualScreenWidth,
                    SystemParameters.VirtualScreenHeight);
                var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height);
                return(virtualScreen.IntersectsWith(window) ? wp : null);
            }
            catch (Exception e)
            {
                log.Error("Unable to calculate rectangle or perform intersection with window", e);
            }

            return(null);
        }
示例#6
0
        private void OnClosed(object sender, CancelEventArgs e)
        {
            var windowInfo = new WindowPlacementInfo
                {
                    Height = (int)Height,
                    Top = (int)Top,
                    Left = (int)Left,
                    Width = (int)Width,
                    WindowState = WindowState
                };

            var filename = Path.ChangeExtension(persistingFilename, ".json");
            JsonHelper.SerializeToFile(windowInfo, filename);

            var recentFileInfo = new RecentFileInfo
            {
                RecentFilePaths = RecentFiles.ToList(),
            };

            JsonHelper.SerializeToFile(recentFileInfo, Path.ChangeExtension(persistingRecentFileName, ".json"));
        }
示例#7
0
        private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp)
        {
            if (wp == null)
            {
                return null;
            }

            try
            {
                var virtualScreen = new Rect(
                    SystemParameters.VirtualScreenLeft,
                    SystemParameters.VirtualScreenTop,
                    SystemParameters.VirtualScreenWidth,
                    SystemParameters.VirtualScreenHeight);
                var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height);
                return virtualScreen.IntersectsWith(window) ? wp : null;
            }
            catch (Exception e)
            {
                log.Error("Unable to calculate rectangle or perform intersection with window", e);
            }

            return null;
        }
示例#8
0
        private static WindowPlacementInfo ValidateScreenPosition(WindowPlacementInfo wp)
        {
            if (wp != null)
            {
                var virtualScreen = new Rect(
                    SystemParameters.VirtualScreenLeft,
                    SystemParameters.VirtualScreenTop,
                    SystemParameters.VirtualScreenWidth,
                    SystemParameters.VirtualScreenHeight);
                var window = new Rect(wp.Left, wp.Top, wp.Width, wp.Height);
                return virtualScreen.IntersectsWith(window) ? wp : null;
            }

            return null;
        }