public void ReadXml(System.Xml.XmlReader reader)
 {
     reader.Read();
     while (reader.NodeType != XmlNodeType.EndElement)
     {
         WindowPosition p = new WindowPosition();
         reader.ReadStartElement("window");
         string name = reader.ReadElementString("name");
         p.state =
             (FormWindowState)TypeDescriptor.GetConverter(typeof(FormWindowState))
             .ConvertFromString(reader.ReadElementString("state"));
         p.rect =
             (Rectangle)TypeDescriptor.GetConverter(typeof(Rectangle))
             .ConvertFromString(reader.ReadElementString("position"));
         reader.ReadEndElement();
         this.Add(name, p);
     }
     reader.ReadEndElement();
 }
        /// <summary>
        /// Save the position of a form to the user settings. Hides the window
        /// as a side-effect.
        /// </summary>
        /// <param name="name">The name to use when writing the position to the
        /// settings</param>
        protected void SavePosition(String name)
        {
            WindowPosition p = new WindowPosition();

            // Get the windows's visibility state:
            p.state =
                this.WindowState == FormWindowState.Maximized ?
                FormWindowState.Maximized : FormWindowState.Normal;

            // Get the window's position:
            p.rect = this.WindowState == FormWindowState.Normal ?
                this.DesktopBounds : this.RestoreBounds;

            // Write to the user settings:
            if (GitUI.Properties.Settings.Default.WindowPositions == null)
                GitUI.Properties.Settings.Default.WindowPositions
                    = new WindowPositionList();
            GitUI.Properties.Settings.Default.WindowPositions[name] = p;
            GitUI.Properties.Settings.Default.Save();
        }
        /// <summary>
        ///   Save the position of a form to the user settings. Hides the window
        ///   as a side-effect.
        /// </summary>
        /// <param name = "name">The name to use when writing the position to the
        ///   settings</param>
        private void SavePosition(String name)
        {
            try
            {
                var rectangle =
                    WindowState == FormWindowState.Normal
                        ? DesktopBounds
                        : RestoreBounds;

                var formWindowState =
                    WindowState == FormWindowState.Maximized
                        ? FormWindowState.Maximized
                        : FormWindowState.Normal;

                // Write to the user settings:
                if (Properties.Settings.Default.WindowPositions == null)
                    Properties.Settings.Default.WindowPositions = new WindowPositionList();
                WindowPosition windowPosition = (WindowPosition)Properties.Settings.Default.WindowPositions[name];
                // Don't save location when we center modal form
                if (windowPosition != null && Owner != null && _windowCentred)
                {
                    if (rectangle.Width <= windowPosition.Rect.Width && rectangle.Height <= windowPosition.Rect.Height)
                        rectangle.Location = windowPosition.Rect.Location;
                }

                var position = new WindowPosition(rectangle, formWindowState);
                Properties.Settings.Default.WindowPositions[name] = position;
                Properties.Settings.Default.Save();
            }
            catch (ConfigurationException)
            {
                //TODO: howto restore a corrupted config? Properties.Settings.Default.Reset() doesn't work.
            }
        }
        /// <summary>
        ///   Save the position of a form to the user settings. Hides the window
        ///   as a side-effect.
        /// </summary>
        /// <param name = "name">The name to use when writing the position to the
        ///   settings</param>
        private void SavePosition(String name)
        {
            try
            {
                var rectangle =
                    WindowState == FormWindowState.Normal
                        ? DesktopBounds
                        : RestoreBounds;

                var formWindowState =
                    WindowState == FormWindowState.Maximized
                        ? FormWindowState.Maximized
                        : FormWindowState.Normal;

                // Write to the user settings:
                if (_windowPositionList == null)
                    _windowPositionList = WindowPositionList.Load(); 
                WindowPosition windowPosition = _windowPositionList.Get(name);
                // Don't save location when we center modal form
                if (windowPosition != null && Owner != null && _windowCentred)
                {
                    if (rectangle.Width <= windowPosition.Rect.Width && rectangle.Height <= windowPosition.Rect.Height)
                        rectangle.Location = windowPosition.Rect.Location;
                }

                var position = new WindowPosition(rectangle, formWindowState, name);
                _windowPositionList.AddOrUpdate(position);
                _windowPositionList.Save();
            }
            catch (Exception)
            {
                //TODO: howto restore a corrupted config?
            }
        }
        /// <summary>
        ///   Save the position of a form to the user settings. Hides the window
        ///   as a side-effect.
        /// </summary>
        /// <param name = "name">The name to use when writing the position to the
        ///   settings</param>
        protected void SavePosition(String name)
        {
            var rectangle =
                WindowState == FormWindowState.Normal
                    ? DesktopBounds
                    : RestoreBounds;

            var formWindowState =
                WindowState == FormWindowState.Maximized
                    ? FormWindowState.Maximized
                    : FormWindowState.Normal;

            var position = new WindowPosition(rectangle, formWindowState);

            // Write to the user settings:
            if (Properties.Settings.Default.WindowPositions == null)
                Properties.Settings.Default.WindowPositions = new WindowPositionList();
            Properties.Settings.Default.WindowPositions[name] = position;
            Properties.Settings.Default.Save();
        }
 public void AddOrUpdate(WindowPosition pos)
 {
     WindowPositions.RemoveAll(r => r.Name == pos.Name);
     WindowPositions.Add(pos);
 }
        /// <summary>
        ///   Save the position of a form to the user settings. Hides the window
        ///   as a side-effect.
        /// </summary>
        /// <param name = "name">The name to use when writing the position to the
        ///   settings</param>
        protected void SavePosition(String name)
        {
            try
            {
                var rectangle =
                    WindowState == FormWindowState.Normal
                        ? DesktopBounds
                        : RestoreBounds;

                var formWindowState =
                    WindowState == FormWindowState.Maximized
                        ? FormWindowState.Maximized
                        : FormWindowState.Normal;

                var position = new WindowPosition(rectangle, formWindowState);

                // Write to the user settings:
                if (Properties.Settings.Default.WindowPositions == null)
                    Properties.Settings.Default.WindowPositions = new WindowPositionList();
                Properties.Settings.Default.WindowPositions[name] = position;
                Properties.Settings.Default.Save();
            }
            catch (ConfigurationException)
            {
                //TODO: howto restore a corrupted config? Properties.Settings.Default.Reset() doesn't work.
            }
        }
 public void AddOrUpdate(WindowPosition pos)
 {
     WindowPositions.RemoveAll(r => r.Name == pos.Name);
     WindowPositions.Add(pos);
 }