GetIntProperty() 공개 메소드

Gets the int value of property in the best settings group (trying local first then global) and creates the (global) property with the default value if it doesn't exist yet.
public GetIntProperty ( string name, int defaultValue ) : int
name string
defaultValue int
리턴 int
예제 #1
0
        private void SetSplitterDistance()
        {
            int sizeOfSharedDimension = Orientation == Orientation.Vertical ? Width : Height;
            // If the default size is specified in the XML file, use that,
            // otherwise compute something reasonable.
            string defaultLoc = XmlUtils.GetOptionalAttributeValue(m_configurationParameters,
                                                                   "defaultFixedPaneSizePoints",
                                                                   "50%");
            int defaultLocation;

            // Find 'total', which will be the height or width,
            // depending on the orientation of the multi pane.
            bool proportional = defaultLoc.EndsWith("%");
            int  total;
            Size size = Size;

            if (m_parentSizeHint.Width != 0 && !proportional)
            {
                size = m_parentSizeHint;
            }
            if (Orientation == Orientation.Vertical)
            {
                total = size.Width;
            }
            else
            {
                total = size.Height;
            }

            if (proportional)
            {
                string percentStr = defaultLoc.Substring(0, defaultLoc.Length - 1);
                int    percent    = Int32.Parse(percentStr);
                float  loc        = (total * (((float)percent) / 100));
                double locD       = Math.Round(loc);
                defaultLocation = (int)locD;
            }
            else
            {
                defaultLocation = Int32.Parse(defaultLoc);
            }

            if (m_mediator != null)
            {
                // NB GetIntProperty RECORDS the default as if it had really been set by the user.
                // This behavior is disastrous here, where if we haven't truly persisted something,
                // we want to stick to computing the percent whenever the parent resizes.
                // So, first see whether there is a value in the property table at all.
                if (m_propertyTable.PropertyExists(SplitterDistancePropertyName))
                {
                    defaultLocation = m_propertyTable.GetIntProperty(SplitterDistancePropertyName, defaultLocation);
                }
            }
            if (defaultLocation < kCollapsedSize)
            {
                defaultLocation = kCollapsedSize;
            }

            if (SplitterDistance != defaultLocation)
            {
                int originalSD = SplitterDistance;
                try
                {
                    // Msg: SplitterDistance (aka: defaultLocation) must be between Panel1MinSize and Width - Panel2MinSize.
                    if (defaultLocation >= Panel1MinSize && defaultLocation <= (sizeOfSharedDimension - Panel2MinSize))
                    {
                        // We do NOT want to persist this computed position!
                        bool old = m_fOkToPersistSplit;
                        m_fOkToPersistSplit = false;
                        SplitterDistance    = defaultLocation;
                        m_fOkToPersistSplit = old;
                    }
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err.Message);
                    string msg = string.Format("Orientation: {0} Width: {1} Height: {2} Original SD: {3} New SD: {4} Panel1MinSize: {5} Panel2MinSize: {6} ID: {7} Panel1Collapsed: {8} Panel2Collapsed: {9}",
                                               Orientation.ToString(), Width, Height, originalSD, defaultLocation,
                                               Panel1MinSize, Panel2MinSize,
                                               XmlUtils.GetAttributeValue(m_configurationParameters, "id", "NOID"),
                                               Panel1Collapsed, Panel2Collapsed);
                    throw new ArgumentOutOfRangeException(msg, err);
                }
            }
        }