Beispiel #1
0
        private void LoadOption <T>(EditorOptionKey <T> key)
        {
            string collection = GetCollectionName(key.Name);
            string property   = GetPropertyName(key.Name);

            int ivalue = 0;

            if (VSConstants.S_OK == _store.CollectionExists(collection, out ivalue))
            {
                ivalue = 2;
            }

            string svalue;

            if (VSConstants.S_OK == _store.GetString(collection, property, out svalue))
            {
                if (typeof(T) == typeof(bool))
                {
                    bool value = bool.Parse(svalue);
                    _options.SetOptionValue(key.Name, value);
                }
                else if (typeof(T) == typeof(uint))
                {
                    uint argb = uint.Parse(svalue);
                    _options.SetOptionValue(key.Name, argb);
                }
            }
        }
        /// <summary>
        /// Applies settings to the local text editor instance
        /// </summary>
        private void ApplyLocalSettings()
        {
            IEditorOptions options = view.Options;

            if (settings.TabWidth != null)
            {
                int value = settings.TabWidth.Value;
                options.SetOptionValue <int>(DefaultOptions.TabSizeOptionId, value);
            }

            if (settings.IndentSize != null)
            {
                int value = settings.IndentSize.Value;
                options.SetOptionValue <int>(DefaultOptions.IndentSizeOptionId, value);
            }

            if (settings.ConvertTabsToSpaces != null)
            {
                bool value = settings.ConvertTabsToSpaces.Value;
                options.SetOptionValue <bool>(DefaultOptions.ConvertTabsToSpacesOptionId, value);
            }

            if (settings.EndOfLine != null)
            {
                string value = settings.EndOfLine;
                options.SetOptionValue <string>(DefaultOptions.NewLineCharacterOptionId, value);
                options.SetOptionValue <bool>(DefaultOptions.ReplicateNewLineCharacterOptionId, false);
            }
        }
 public void CopyTo(TextEditorSettingsImpl textEditorSettings, IEditorOptions editorOptions)
 {
     textEditorSettings.FontFamily = FontFamily;
     textEditorSettings.FontSize   = FontSize;
     editorOptions.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, ShowLineNumbers);
     editorOptions.SetOptionValue(DefaultDnSpyTextViewOptions.ReferenceHighlightingId, HighlightReferences);
 }
 /// <summary>
 /// Sets options stored in <see cref="IGlobalOptionService"/> that are read by command handlers from the text editor to given <see cref="IEditorOptions"/>.
 /// </summary>
 public static void SetEditorOptions(this IGlobalOptionService globalOptions, IEditorOptions editorOptions, string language)
 {
     editorOptions.SetOptionValue(DefaultOptions.IndentStyleId, globalOptions.GetOption(FormattingOptions2.SmartIndent, language).ToEditorIndentStyle());
     editorOptions.SetOptionValue(DefaultOptions.NewLineCharacterOptionId, globalOptions.GetOption(FormattingOptions2.NewLine, language));
     editorOptions.SetOptionValue(DefaultOptions.TabSizeOptionId, globalOptions.GetOption(FormattingOptions2.TabSize, language));
     editorOptions.SetOptionValue(DefaultOptions.IndentSizeOptionId, globalOptions.GetOption(FormattingOptions2.IndentationSize, language));
     editorOptions.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, !globalOptions.GetOption(FormattingOptions2.UseTabs, language));
 }
Beispiel #5
0
        public void Sync_TabStop()
        {
            _localSettings.TabStop = 42;
            Assert.Equal(42, _editorOptions.GetOptionValue(DefaultOptions.TabSizeOptionId));

            _editorOptions.SetOptionValue(DefaultOptions.TabSizeOptionId, 13);
            Assert.Equal(13, _localSettings.TabStop);
        }
        /// <summary>
        /// Applies settings to the local text editor instance
        /// </summary>
        private void ApplyLocalSettings()
        {
            IEditorOptions options = view.Options;

            if (settings.ContainsKey("tab_width"))
            {
                try
                {
                    int value = Convert.ToInt32(settings["tab_width"]);
                    options.SetOptionValue <int>(DefaultOptions.TabSizeOptionId, value);
                }
                catch { }
            }

            if (settings.ContainsKey("indent_size"))
            {
                try
                {
                    int value = Convert.ToInt32(settings["indent_size"]);
                    options.SetOptionValue <int>(DefaultOptions.IndentSizeOptionId, value);
                }
                catch { }
            }

            if (settings.ContainsKey("indent_style"))
            {
                string value = settings["indent_style"];
                if (value == "tab")
                {
                    options.SetOptionValue <bool>(DefaultOptions.ConvertTabsToSpacesOptionId, false);
                }
                else if (value == "space")
                {
                    options.SetOptionValue <bool>(DefaultOptions.ConvertTabsToSpacesOptionId, true);
                }
            }

            if (settings.ContainsKey("end_of_line"))
            {
                string value = settings["end_of_line"];
                if (value == "lf")
                {
                    options.SetOptionValue <string>(DefaultOptions.NewLineCharacterOptionId, "\n");
                    options.SetOptionValue <bool>(DefaultOptions.ReplicateNewLineCharacterOptionId, false);
                }
                else if (value == "cr")
                {
                    options.SetOptionValue <string>(DefaultOptions.NewLineCharacterOptionId, "\r");
                    options.SetOptionValue <bool>(DefaultOptions.ReplicateNewLineCharacterOptionId, false);
                }
                else if (value == "crlf")
                {
                    options.SetOptionValue <string>(DefaultOptions.NewLineCharacterOptionId, "\r\n");
                    options.SetOptionValue <bool>(DefaultOptions.ReplicateNewLineCharacterOptionId, false);
                }
            }
        }
        internal static void SetEditorOptions(IEditorOptions options, Guid languageServiceGuid)
        {
            IVsTextManager textMgr = (IVsTextManager)InteractiveWindowPackage.GetGlobalService(typeof(SVsTextManager));
            var langPrefs = new LANGPREFERENCES[1];
            langPrefs[0].guidLang = languageServiceGuid;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));

            options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
            options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, langPrefs[0].fInsertTabs == 0);
            options.SetOptionValue(DefaultOptions.TabSizeOptionId, (int)langPrefs[0].uTabSize);
            options.SetOptionValue(DefaultOptions.IndentSizeOptionId, (int)langPrefs[0].uIndentSize);
        }
Beispiel #8
0
        private void SetGlobalEditorOptions()
        {
            IEditorOptions options = EditorOptionsFactoryService.GlobalOptions;

            options.SetOptionValue("IsCodeLensEnabled", false);

            options.SetOptionValue <bool>(DefaultTextViewOptions.UseVisibleWhitespaceId, true);
            options.SetOptionValue <bool>(DefaultTextViewOptions.BraceCompletionEnabledOptionId, true);

            options.SetOptionValue <bool>(DefaultTextViewHostOptions.LineNumberMarginId, true);
            options.SetOptionValue <bool>(DefaultTextViewHostOptions.OutliningMarginId, true);
        }
Beispiel #9
0
        private void SetEditorOptions(IEditorOptions options, Guid languageServiceGuid)
        {
            IVsTextManager textMgr   = (IVsTextManager)InteractiveWindowPackage.GetGlobalService(typeof(SVsTextManager));
            var            langPrefs = new LANGPREFERENCES[1];

            langPrefs[0].guidLang = languageServiceGuid;
            ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));

            options.SetOptionValue(DefaultTextViewHostOptions.ChangeTrackingId, false);
            options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, langPrefs[0].fInsertTabs == 0);
            options.SetOptionValue(DefaultOptions.TabSizeOptionId, (int)langPrefs[0].uTabSize);
            options.SetOptionValue(DefaultOptions.IndentSizeOptionId, (int)langPrefs[0].uIndentSize);
        }
Beispiel #10
0
 void ToggleWordWrap()
 {
     editorOptions.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, editorOptions.WordWrapStyle() ^ WordWrapStyles.WordWrap);
     if ((editorOptions.WordWrapStyle() & WordWrapStyles.WordWrap) != 0 && appSettings.UseNewRenderer_TextEditor)
     {
         messageBoxManager.ShowIgnorableMessage(new Guid("AA6167DA-827C-49C6-8EF3-0797FE8FC5E6"), dnSpy_Resources.TextEditorNewFormatterWarningMsg);
     }
 }
Beispiel #11
0
        private void SetupNewClojureBuffersWithSpacingOptions()
        {
            var componentModel = (IComponentModel)GetService(typeof(SComponentModel));
            ITextEditorFactoryService editorFactoryService = componentModel.GetService <ITextEditorFactoryService>();

            editorFactoryService.TextViewCreated +=
                (o, e) =>
            {
                if (e.TextView.TextSnapshot.ContentType.TypeName.ToLower() != "clojure")
                {
                    return;
                }
                IEditorOptions editorOptions = componentModel.GetService <IEditorOptionsFactoryService>().GetOptions(e.TextView);
                editorOptions.SetOptionValue(new ConvertTabsToSpaces().Key, true);
                editorOptions.SetOptionValue(new IndentSize().Key, 2);
            };
        }
        /// <summary>
        /// Set the maximum zoomlevel.
        /// </summary>
        /// <param name="options">The <see cref="IEditorOptions"/>.</param>
        /// <param name="maxZoomLevel">The new maximum zoom level.</param>
        public static void SetMaxZoomLevel(this IEditorOptions options, double maxZoomLevel)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.SetOptionValue(
                DefaultTextViewOptions.MaxZoomLevelId,
                maxZoomLevel);
        }
        /// <summary>
        /// Set the persisted zoomlevel.
        /// </summary>
        /// <param name="options">The <see cref="IEditorOptions"/>.</param>
        /// <param name="zoomLevel">The new zoom level. This value will be
        /// clamped to fit between <see cref="MinZoom"/>
        /// and <see cref="MaxZoom"/></param>
        public static void SetZoomLevel(this IEditorOptions options, double zoomLevel)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.SetOptionValue(
                DefaultTextViewOptions.ZoomLevelId,
                Math.Min(options.MaxZoom(), Math.Max(options.MinZoom(), zoomLevel)));
        }
Beispiel #14
0
        /// <summary>
        /// Save the options that are selected into the global options
        /// </summary>
        public void Apply()
        {
            foreach (CheckBox box in _allOptions)
            {
                LabeledOptionDefinition definition = box.Tag as LabeledOptionDefinition;
                if (definition != null)
                {
                    bool oldValue = _globalOptions.GetOptionValue <bool>(definition.Name);
                    if (box.IsChecked != oldValue)
                    {
                        _globalOptions.SetOptionValue(definition.Name, box.IsChecked);

                        this.SaveOption(definition.Name);
                    }
                }
            }
        }
 public void Initialize(IEditorOptions globalOptions)
 {
     if (this.globalOptions != null)
     {
         throw new InvalidOperationException();
     }
     this.globalOptions           = globalOptions;
     globalOptions.OptionChanged += EditorOptions_OptionChanged;
     globalOptions.SetOptionValue(DefaultWpfViewOptions.EnableHighlightCurrentLineId, textEditorSettings.HighlightCurrentLine);
     globalOptions.SetOptionValue(DefaultWpfViewOptions.ZoomLevelId, textEditorSettings.TextViewZoomLevel);
     globalOptions.SetOptionValue(DefaultDnSpyWpfViewOptions.ForceClearTypeIfNeededId, textEditorSettings.ForceClearTypeIfNeeded);
     globalOptions.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, textEditorSettings.ShowLineNumbers);
     globalOptions.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, textEditorSettings.WordWrapStyle);
     globalOptions.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, textEditorSettings.ConvertTabsToSpaces);
     globalOptions.SetOptionValue(DefaultDnSpyTextViewOptions.ReferenceHighlightingId, textEditorSettings.HighlightReferences);
 }
Beispiel #16
0
        public bool LoadOption(IEditorOptions options, string optionName)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            EditorOptionDefinition optionDefinition = null;

            while (true)
            {
                optionDefinition = GetMatchingOption(options, optionName);
                if (optionDefinition != null)
                {
                    break;
                }

                options = options.Parent;
                if (options == null)
                {
                    return(false);       //Unable to load option.
                }
            }

            IVsSettingsManager manager = this.SettingsManagerService;
            IVsSettingsStore   store;

            Marshal.ThrowExceptionForHR(manager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out store));

            string result;

            Marshal.ThrowExceptionForHR(store.GetStringOrDefault("Text Editor", optionName, string.Empty, out result));

            if (result == string.Empty)
            {
                //No corresponding entry in the registery. Save the option to make it finable and editable.
                this.SaveOption(options, optionName);
            }
            else
            {
                try
                {
                    if (optionDefinition.ValueType == typeof(bool))
                    {
                        options.SetOptionValue(optionName, bool.Parse(result));
                        return(true);
                    }
                    else if (optionDefinition.ValueType == typeof(int))
                    {
                        options.SetOptionValue(optionName, int.Parse(result));
                        return(true);
                    }
                    else if (optionDefinition.ValueType == typeof(double))
                    {
                        options.SetOptionValue(optionName, double.Parse(result));
                        return(true);
                    }
                    else if (optionDefinition.ValueType == typeof(string))
                    {
                        options.SetOptionValue(optionName, result);
                        return(true);
                    }
                    else if (optionDefinition.ValueType == typeof(Color))
                    {
                        //Color's saved by Color.ToString() have a leading # sign ... strip that off before we parse.
                        uint argb = uint.Parse(result.Substring(1), NumberStyles.AllowHexSpecifier);
                        options.SetOptionValue(optionName, Color.FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb));
                        return(true);
                    }
                }
                catch (System.FormatException)
                {
                    //If we get a format exception, then the data for the option is invalid: overwrite it with something in the correct format.
                    this.SaveOption(options, optionName);
                }
            }

            return(false);
        }
Beispiel #17
0
 public override void Execute(IMenuItemContext context) => editorOptions.SetOptionValue(DefaultWpfViewOptions.EnableHighlightCurrentLineId, !editorOptions.GetOptionValue(DefaultWpfViewOptions.EnableHighlightCurrentLineId));
Beispiel #18
0
 public override void Execute(IMenuItemContext context) => editorOptions.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, editorOptions.WordWrapStyle() ^ WordWrapStyles.WordWrap);