Beispiel #1
0
        private void InitFontNameCombo(string selectedName)
        {
            selectedName = Fonts.ValidateFontName(selectedName);

            List <string> fonts = Fonts.GetFontList();

            foreach (string name in fonts)
            {
                _fontNameCombo.Items.Add(name);

                if (name == selectedName)
                {
                    _fontNameCombo.SelectedItem = name;
                }
            }
        }
        /// <summary>
        /// Load editor settings from a configuration file.
        /// </summary>
        /// <param name="documentType">The document type of the file being edited.</param>
        public void LoadSettings(DocumentType documentType)
        {
            string scintillaConfig = Path.Combine(
                applicationManager.QuickSharpHome,
                Constants.CONFIG_DIR_NAME);

            /*
             * Look for theme specific sub-folder.
             */

            string themePath = applicationManager.
                GetSelectedThemeProviderKey();

            if (!String.IsNullOrEmpty(themePath))
            {
                string themeConfig = Path.Combine(
                    scintillaConfig, themePath);

                if (Directory.Exists(themeConfig))
                    scintillaConfig = themeConfig;
            }

            /*
             * Update scintilla if the location exists.
             */
            
            if (Directory.Exists(scintillaConfig))
                scintilla.ConfigurationManager.CustomLocation =
                    scintillaConfig;

            /*
             * Apply any lexer aliases.
             */

            Dictionary<String, String> lexerAliasMap =
                documentManager.LexerAliasMap;

            foreach (string alias in lexerAliasMap.Keys)
                if (!scintilla.Lexing.LexerLanguageMap.ContainsKey(alias))
                    scintilla.Lexing.LexerLanguageMap.Add(
                        alias, lexerAliasMap[alias]);

            /*
             * Language will be requested language or default.
             */

            string language = documentManager.GetDocumentLanguage(documentType);
            scintilla.ConfigurationManager.Language = language;

            /*
             * Set config from external files and internal settings.
             */

            scintilla.ConfigurationManager.IsUserEnabled = true;
            scintilla.UseFont = false;

            if (_settingsManager.OverrideConfigFiles)
            { 
                // Line numbers
                scintilla.Margins.Margin0.Type = MarginType.Number;
                scintilla.Margins.Margin0.Width = _settingsManager.LineNumberMarginSize;
                
                // Bookmarks
                scintilla.NativeInterface.SendMessageDirect(
                    ScintillaNet.Constants.SCI_MARKERDEFINE,
                        Constants.BOOKMARK_MARKER,
                        ScintillaNet.Constants.SC_MARK_SMALLRECT);
                scintilla.NativeInterface.SendMessageDirect(
                    ScintillaNet.Constants.SCI_MARKERSETFORE,
                        Constants.BOOKMARK_MARKER, 0);
                scintilla.NativeInterface.SendMessageDirect(
                    ScintillaNet.Constants.SCI_MARKERSETBACK,
                    Constants.BOOKMARK_MARKER, GetColor(Color.LightGreen));

                scintilla.Margins.Margin1.Type = MarginType.Symbol;
                scintilla.Margins.Margin1.Width = 8;

                // Folding
                scintilla.Margins.Margin2.Type = MarginType.Symbol;
                scintilla.Margins.Margin2.Width = 16;

                // Not used
                scintilla.Margins.Margin3.Width = 0;
                scintilla.Margins.Margin3.Type = MarginType.Back;

                scintilla.Indentation.ShowGuides =
                    _settingsManager.ShowIndentationGuides;
                scintilla.Indentation.TabWidth = _settingsManager.TabSize;
                scintilla.Indentation.UseTabs = _settingsManager.UseTabs;
                scintilla.Indentation.BackspaceUnindents =
                    _settingsManager.BackspaceUnindents;

                scintilla.Folding.IsEnabled = _settingsManager.ShowFolding;
                scintilla.Folding.Flags = _settingsManager.Flags;
                scintilla.Folding.MarkerScheme = _settingsManager.MarkerScheme;

                string fontName = Fonts.ValidateFontName(_settingsManager.FontName);
                float fontSize = Fonts.ValidateFontSize(_settingsManager.FontSize);
                scintilla.Font = new Font(fontName, fontSize);
                scintilla.UseFont = true;
            }

            /*
             * Global settings (not covered by config files)
             */

            scintilla.IsBraceMatching = _settingsManager.MatchBraces;
            scintilla.LineWrap.Mode = _settingsManager.WordWrap
                ? WrapMode.Word : WrapMode.None;

            scintilla.Printing.PageSettings.ColorMode = 
                _settingsManager.PrintingColorMode;
        }