Esempio n. 1
0
        /// <summary>
        /// Loads our settings to the specified XML writer
        /// </summary>
        /// <param name="reader">The VsSettings reader we read ou values from</param>
        public override void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            try
            {
                this.InitializeDefaults();
                string exePath, exeCmdLine;
                int    enablePreview;
                if (ErrorHandler.Succeeded(reader.ReadSettingString(RegPreviewExe, out exePath)) && !string.IsNullOrEmpty(exePath))
                {
                    this.PreviewToolExecutablePath = exePath;
                }

                if (ErrorHandler.Succeeded(reader.ReadSettingString(RegPreviewCmdLine, out exeCmdLine)) && !string.IsNullOrEmpty(exeCmdLine))
                {
                    this.PreviewToolCommandLine = exeCmdLine;
                }

                if (ErrorHandler.Succeeded(reader.ReadSettingBoolean(RegPreviewEnable, out enablePreview)))
                {
                    this.EnablePreview = enablePreview == 1;
                }
            }
            catch (Exception e)
            {
                Debug.Assert(false, "Error importing Slow Cheetah settings: " + e.Message);
            }
        }
        public override void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            var typeConverter = new ColorerFormatSettingsCollectionConverter();

            string buildSettingsString;
            reader.ReadSettingString("BuildOutputSettings", out buildSettingsString);

            if (!string.IsNullOrWhiteSpace(buildSettingsString))
                BuildOutputSettings = (Collection<ColorerFormatSetting>)typeConverter.ConvertFrom(buildSettingsString);

            string debugSettingsString;
            reader.ReadSettingString("BuildOutputSettings", out debugSettingsString);

            if (!string.IsNullOrWhiteSpace(buildSettingsString))
                BuildOutputSettings = (Collection<ColorerFormatSetting>)typeConverter.ConvertFrom(debugSettingsString);
        }
Esempio n. 3
0
        public void Load(IVsSettingsReader reader, string valueName)
        {
            string value;

            reader.ReadSettingString(valueName, out value);
            this.Load(value, valueName);
        }
        public static string ReadSettingString(this IVsSettingsReader reader, string keyFormat, int index)
        {
            var    key = string.Format(keyFormat, index);
            string value;

            reader.ReadSettingString(key, out value);
            return(value);
        }
        /// <summary>
        /// Loads settings from XML (on import settings)
        /// </summary>
        /// <param name="reader"></param>
        public override void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            SettingsObject.Instance.IgnorePropertyChanges = true;

            SettingsObject.Instance.ReferenceUpdateInterval = ReadIntFromXml(reader, "ReferenceUpdateInterval");
            SettingsObject.Instance.BadKeyNamePolicy        = (BAD_KEY_NAME_POLICY)ReadIntFromXml(reader, "BadKeyNamePolicy");
            SettingsObject.Instance.OptimizeSpecialSequencesInTranslation = ReadBoolFromXml(reader, "OptimizeSpecialSequencesInTranslation");

            int count = ReadIntFromXml(reader, "LanguagesCount");

            for (int i = 0; i < count; i++)
            {
                string pair;
                int    hr = reader.ReadSettingString("Language" + i, out pair);
                if (hr != VSConstants.S_OK)
                {
                    reader.ReportError("Language value cannot be read", (uint)__VSSETTINGSERRORTYPES.vsSettingsErrorTypeError);
                }

                string[] arr = pair.Split(':');

                SettingsObject.Instance.LanguagePairs.Add(new SettingsObject.LanguagePair()
                {
                    FromLanguage = arr[0],
                    ToLanguage   = arr[1]
                });
            }

            string s;
            int    r = reader.ReadSettingString("BingAppId", out s);

            if (r != VSConstants.S_OK)
            {
                reader.ReportError("BingAppId value cannot be read", (uint)__VSSETTINGSERRORTYPES.vsSettingsErrorTypeError);
            }
            SettingsObject.Instance.BingAppId = s;
            if (string.IsNullOrEmpty(SettingsObject.Instance.BingAppId))
            {
                SettingsObject.Instance.BingAppId = null;
            }


            SettingsObject.Instance.IgnorePropertyChanges = false;
            SettingsObject.Instance.NotifySettingsLoaded();
        }
Esempio n. 6
0
        public void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            string outValue;

            if (reader.ReadSettingString("ListedExtensions", out outValue) == VSConstants.S_OK)
            {
                ListedExtensionsString = outValue;
            }
        }
Esempio n. 7
0
        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Writes a VSPackage's configuration to disk using the Visual Studio settings mechanism when
        /// the export option of an Import/Export Settings feature available on the IDE’s Tools menu
        /// is selected by a user.
        /// </summary>
        /// <remarks>
        /// This method is called when the dialog page should load its default settings from the
        /// profile XML file.
        /// </remarks>
        // --------------------------------------------------------------------------------------------
        public virtual void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            _Initializing = true;
            try
            {
                object automationObject = AutomationObject;
                var    properties       = TypeDescriptor.GetProperties(automationObject,
                                                                       new Attribute[] { DesignerSerializationVisibilityAttribute.Visible });
                foreach (PropertyDescriptor property in properties)
                {
                    var converter = property.Converter;
                    if (converter.CanConvertTo(typeof(string)) && converter.CanConvertFrom(typeof(string)))
                    {
                        // --- read from the xml feed
                        object cv = null;
                        try
                        {
                            string value;
                            if (NativeMethods.Succeeded(reader.ReadSettingString(property.Name, out value)) && (value != null))
                            {
                                cv = property.Converter.ConvertFromInvariantString(value);
                            }
                        }
                        catch (Exception)
                        {
                            // --- ReadSettingString throws an exception if the property is not found and we also
                            // --- catch ConvertFromInvariantString exceptions so that we gracefully handle bad
                            // --- vssettings.
                            VsDebug.Fail("Error in ReadSettingsString ignored.");
                        }
                        // --- Not all values have to be present
                        if (cv != null)
                        {
                            property.SetValue(automationObject, cv);
                        }
                    }
                }
            }
            finally
            {
                _Initializing = false;
            }

            // --- Hook in properties
            HookProperties(true);
            OnPageDataLoaded();
        }
Esempio n. 8
0
        public void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            string valueKeysString;

            reader.ReadSettingString("ValueKeys", out valueKeysString);
            RemarkerService service = this.Service;

            foreach (var valueKey in valueKeysString.Split(';').Where(
                         valueKey => !string.IsNullOrWhiteSpace(valueKey)))
            {
                try
                {
                    service.Load(reader, valueKey);
                }
                catch (Exception)
                {
                }
            }
        }
        public static bool?ReadSettingStringToBoolean(this IVsSettingsReader reader, string keyFormat, int index)
        {
            var name = string.Format(keyFormat, index);
            int intValue;
            var readResult = reader.ReadSettingBoolean(name, out intValue);

            if (readResult == Microsoft.VisualStudio.VSConstants.S_OK)
            {
                return(Convert.ToBoolean(intValue));
            }

            // fallback for older settings
            var strValue = reader.ReadSettingString(keyFormat, index);

            if (strValue == null)
            {
                return(null);
            }
            bool rtn;

            return(bool.TryParse(strValue.ToLowerInvariant(), out rtn) && rtn);
        }
Esempio n. 10
0
        /// <include file='doc\DialogPage.uex' path='docs/doc[@for="DialogPage.LoadSettingsFromXml"]' />
        /// <devdoc>
        ///     This method is called when the dialog page should load
        ///     its default settings from the profile XML file.
        /// </devdoc>
        public virtual void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            _initializing = true;
            try {
                object automationObject = this.AutomationObject;
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(automationObject, new Attribute[] { DesignerSerializationVisibilityAttribute.Visible });

                foreach (PropertyDescriptor property in properties)
                {
                    TypeConverter converter = property.Converter;
                    if (converter.CanConvertTo(typeof(string)) && converter.CanConvertFrom(typeof(string)))
                    {
                        // read from the xml feed
                        string value = null;
                        object cv    = null;
                        try {
                            if (NativeMethods.Succeeded(reader.ReadSettingString(property.Name, out value)) && (value != null))
                            {
                                cv = property.Converter.ConvertFromInvariantString(value);
                            }
                        } catch (Exception) {
                            // ReadSettingString throws an exception if the property
                            // is not found and we also catch ConvertFromInvariantString
                            // exceptions so that we gracefully handle bad vssettings.
                        }
                        //not all values have to be present
                        if (cv != null)
                        {
                            property.SetValue(automationObject, cv);
                        }
                    }
                }
            }
            finally {
                _initializing = false; //we have loaded from storage
            }
            HookProperties(true);      //hook if this failed during construction.
        }
Esempio n. 11
0
        public void Load(IVsSettingsReader reader)
        {
            lock (_Themes) {
                _Themes.Clear();
                DefaultTheme = new IndentTheme();

                string themeKeysString;
                reader.ReadSettingString("Themes", out themeKeysString);

                foreach (var key in themeKeysString.Split(';'))
                {
                    if (string.IsNullOrWhiteSpace(key))
                    {
                        continue;
                    }

                    try {
                        var theme = IndentTheme.Load(reader, key);
                        if (theme.IsDefault)
                        {
                            DefaultTheme = theme;
                        }
                        else
                        {
                            _Themes[theme.ContentType] = theme;
                        }
                    } catch (Exception ex) {
                        Trace.WriteLine(string.Format("IndentGuide::LoadSettingsFromXML: {0}", ex));
                    }
                }

                int tempInt;
                reader.ReadSettingLong("Visible", out tempInt);
                Visible = (tempInt != 0);
            }

            OnThemesChanged();
        }
Esempio n. 12
0
        /// <include file='doc\DialogPage.uex' path='docs/doc[@for="DialogPage.LoadSettingsFromXml"]' />
        /// <devdoc>
        ///     This method is called when the dialog page should load
        ///     its default settings from the profile XML file.  
        /// </devdoc>
        public virtual void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            _initializing = true;
            try {
                object automationObject = this.AutomationObject;
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(automationObject, new Attribute[] {DesignerSerializationVisibilityAttribute.Visible});

                foreach(PropertyDescriptor property in properties) {
                    TypeConverter converter = property.Converter;
                    if (converter.CanConvertTo(typeof(string)) && converter.CanConvertFrom(typeof(string))) {
                        // read from the xml feed
                        string value = null;
                        object cv = null;
                        try {
                            if ( NativeMethods.Succeeded(reader.ReadSettingString(property.Name, out value)) && (value != null) )
                            {
                                cv = property.Converter.ConvertFromInvariantString(value);
                            }
                        } catch (Exception) {
                            // ReadSettingString throws an exception if the property
                            // is not found and we also catch ConvertFromInvariantString
                            // exceptions so that we gracefully handle bad vssettings.
                        }
                        //not all values have to be present
                        if (cv != null) {
                            property.SetValue(automationObject, cv);
                        }
                    }
                }
            }
            finally {
                _initializing = false;    //we have loaded from storage
            }
            HookProperties(true); //hook if this failed during construction.
        }
Esempio n. 13
0
        // based on information from : https://github.com/hesam/SketchSharp/blob/master/SpecSharp/SpecSharp/Microsoft.VisualStudio.Shell/DialogPage.cs
        public override void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            int multiMatch;

            reader.ReadSettingLong(ATASettings.Keys.AttachDescriptorDefaultMultipleMatchHandling, out multiMatch);
            MultipleMatchHandlingDefault = multiMatch == 0 ? MultiMatchOptionsGlobal.All: (MultiMatchOptionsGlobal)multiMatch;

            var items = new List <AttachDescriptor>();

            try
            {
                for (var i = 0; i < ATAConstants.MaxCommands; i++)
                {
                    // read from the xml feed
                    var item = new AttachDescriptor();
                    try
                    {
                        var value = reader.ReadSettingString(ATASettings.Keys.AttachDescriptorName, i);
                        if (value != null)
                        {
                            item.Name = value;
                        }

                        var enabled = reader.ReadSettingStringToBoolean(ATASettings.Keys.AttachDescriptorEnabled, i);
                        if (enabled.HasValue)
                        {
                            item.Enabled = enabled.Value;
                        }

                        var multiMatchHandling = reader.ReadSettingLong(ATASettings.Keys.AttachDescriptorMultipleMatchHandling, i);
                        item.MultiMatchHandling = multiMatchHandling == 0 ? MultiMatchOptions.Global : (MultiMatchOptions)multiMatch;

                        value = reader.ReadSettingString(ATASettings.Keys.AttachDescriptorProcessNames, i);
                        if (value != null)
                        {
                            item.ProcessNames = value.Split(new[] { ATAConstants.ProcessNamesSeparator[0] }, StringSplitOptions.RemoveEmptyEntries);
                        }

                        var parsedBool = reader.ReadSettingStringToBoolean(ATASettings.Keys.AttachDescriptorIsProcessNamesRegex, i);
                        if (parsedBool.HasValue)
                        {
                            item.IsProcessNamesRegex = parsedBool.Value;
                        }

                        value = reader.ReadSettingString(ATASettings.Keys.AttachDescriptorUsername, i);
                        if (value != null)
                        {
                            item.Username = value;
                        }

                        parsedBool = reader.ReadSettingStringToBoolean(ATASettings.Keys.AttachDescriptorIsUsernameRegex, i);
                        if (parsedBool.HasValue)
                        {
                            item.IsUsernameRegex = parsedBool.Value;
                        }

                        value = reader.ReadSettingString(ATASettings.Keys.AttachDescriptorAppPool, i);
                        if (value != null)
                        {
                            item.AppPool = value;
                        }

                        parsedBool = reader.ReadSettingStringToBoolean(ATASettings.Keys.AttachDescriptorIsAppPoolRegex, i);
                        if (parsedBool.HasValue)
                        {
                            item.IsAppPoolRegex = parsedBool.Value;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"Unhandled exception in LoadSettingsFromXml:{ex}");
                    }

                    if (!string.IsNullOrWhiteSpace(item.Name) && item.ProcessNames != null && item.ProcessNames.Any())
                    {
                        items.Add(item);
                    }
                    else
                    {
                        // this ensures it is a clean item if any of the other properties were saved previously.
                        items.Add(new AttachDescriptor());
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unhandled exception in LoadSettingsFromXml:{ex}");
            }
            Attachables = new ReadOnlyCollection <AttachDescriptor>(items);
            // notify of newly loaded settings
            OnSettingsLoaded(EventArgs.Empty);
            base.LoadSettingsFromXml(reader);
        }
        /// <summary>
        /// Loads settings from XML (on import settings)
        /// </summary>
        public override void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            SettingsObject.Instance.IgnorePropertyChanges = true;

            SettingsObject.Instance.ShowContextColumn              = ReadBoolFromXml(reader, "ShowFilterContext");
            SettingsObject.Instance.UseReflectionInAsp             = ReadBoolFromXml(reader, "UseReflectionInAsp");
            SettingsObject.Instance.MarkNotLocalizableStringsIndex = ReadIntFromXml(reader, "MarkNotLocalizableStringsIndex");
            SettingsObject.Instance.NamespacePolicyIndex           = ReadIntFromXml(reader, "NamespacePolicyIndex");
            SettingsObject.Instance.BatchMoveSplitterDistance      = ReadIntFromXml(reader, "BatchMoveSplitterDistance");
            SettingsObject.Instance.SelectedKeyIndex    = ReadIntFromXml(reader, "SelectedKeyIndex");
            SettingsObject.Instance.SelectedUseFullName = ReadBoolFromXml(reader, "SelectedUseFullName");

            int    hr;
            string tmp;

            hr = reader.ReadSettingString("SelectedResourceFilePath", out tmp);
            SettingsObject.Instance.SelectedResourceFilePath = tmp;
            Marshal.ThrowExceptionForHR(hr);

            foreach (var pair in SettingsObject.Instance.CommonLocalizabilityCriteria)
            {
                LocalizationCommonCriterion crit = pair.Value;

                string val;
                hr = reader.ReadSettingString(crit.Name, out val);
                if (hr != VSConstants.S_OK)
                {
                    throw new Exception("Error retrieving data from XML.");
                }

                if (val != null)
                {
                    crit.FromRegData(val.ToString());
                }
            }

            SettingsObject.Instance.CustomLocalizabilityCriteria.Clear();
            int customCriteriaCount = 0;

            hr = reader.ReadSettingLong("CustomCriteriaCount", out customCriteriaCount);
            if (hr != VSConstants.S_OK)
            {
                throw new Exception("Error retrieving data from XML.");
            }

            for (int i = 0; i < customCriteriaCount; i++)
            {
                string val;
                hr = reader.ReadSettingString("CustomCriteria" + i, out val);

                if (val != null)
                {
                    LocalizationCustomCriterion crit = new LocalizationCustomCriterion(LocalizationCriterionAction.VALUE, 0);
                    crit.FromRegData(val.ToString());
                    SettingsObject.Instance.CustomLocalizabilityCriteria.Add(crit);
                }
            }

            SettingsObject.Instance.IgnorePropertyChanges = false;
            SettingsObject.Instance.NotifySettingsLoaded();
        }
        public void Load(IVsSettingsReader reader)
        {
            lock (_Themes) {
                _Themes.Clear();
                DefaultTheme = new IndentTheme();

                string themeKeysString;
                reader.ReadSettingString("Themes", out themeKeysString);

                foreach (var key in themeKeysString.Split(';')) {
                    if (string.IsNullOrWhiteSpace(key)) continue;

                    try {
                        var theme = IndentTheme.Load(reader, key);
                        if (theme.IsDefault) {
                            DefaultTheme = theme;
                        } else {
                            _Themes[theme.ContentType] = theme;
                        }
                    } catch (Exception ex) {
                        Trace.WriteLine(string.Format("IndentGuide::LoadSettingsFromXML: {0}", ex));
                    }
                }

                int tempInt;
                reader.ReadSettingLong("Visible", out tempInt);
                Visible = (tempInt != 0);
            }

            OnThemesChanged();
        }
Esempio n. 16
0
        public static IndentTheme Load(IVsSettingsReader reader, string themeKey)
        {
            var theme = new IndentTheme();

            theme.ContentType = (themeKey == DefaultThemeName) ? null : themeKey;
            theme.Behavior.Load(reader, themeKey);
            string caretHandler;

            reader.ReadSettingString("CaretHandler", out caretHandler);
            theme.CaretHandler = caretHandler ?? DefaultCaretHandler;

            string subkeyNames, settingNames;

            ErrorHandler.ThrowOnFailure(reader.ReadSettingString(themeKey, out subkeyNames));
            if (!string.IsNullOrEmpty(subkeyNames))
            {
                foreach (var subkeyName in subkeyNames.Split(';'))
                {
                    if (string.IsNullOrEmpty(subkeyName))
                    {
                        continue;
                    }

                    int i = subkeyName.LastIndexOf('.');
                    if (i < 0)
                    {
                        continue;
                    }

                    var values = new Dictionary <string, string>();
                    if (ErrorHandler.Failed(reader.ReadSettingAttribute(subkeyName, "Keys", out settingNames)) ||
                        string.IsNullOrEmpty(settingNames))
                    {
                        settingNames = "LineStyle;LineColor;HighlightStyle;HighlightColor;Visible";
                    }
                    foreach (var setting in settingNames.Split(';'))
                    {
                        if (string.IsNullOrEmpty(subkeyName))
                        {
                            continue;
                        }
                        string value;
                        ErrorHandler.ThrowOnFailure(reader.ReadSettingAttribute(subkeyName, setting, out value));
                        if (!string.IsNullOrEmpty(value))
                        {
                            values[setting] = value;
                        }
                    }

                    var format = LineFormat.FromInvariantStrings(theme, values);
                    format.FormatIndexName = subkeyName.Substring(i + 1);
                    if (format.FormatIndex.HasValue)
                    {
                        theme.LineFormats[format.FormatIndex.GetValueOrDefault()] = format;
                    }
                    else
                    {
                        Trace.TraceWarning("{0}.{1} is not a valid format index.", themeKey, subkeyName);
                    }
                }
            }

            return(theme);
        }