/// <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; }
/// <summary> /// Create the editor options page. /// </summary> public EditorOptionsPage() { Name = Constants.UI_OPTIONS_PAGE_EDITOR; PageText = Resources.OptionsPageTextEditor; GroupText = Resources.OptionsGroupText; _editorGroupBox = new GroupBox(); _useTabsCheckBox = new CheckBox(); _tabSizeLabel = new Label(); _tabSizeSelector = new NumericUpDown(); _backspaceUnindentsCheckBox = new CheckBox(); _lnMarginSizeLabel = new Label(); _lnMarginSizeSelector = new NumericUpDown(); _showGuidesCheckBox = new CheckBox(); _showFoldingCheckBox = new CheckBox(); _foldStyleLabel = new Label(); _foldStyleCombo = new ComboBox(); _foldMarkerStyleLabel = new Label(); _foldMarkerStyleCombo = new ComboBox(); _fontNameLabel = new Label(); _fontNameCombo = new ComboBox(); _fontSizeSelector = new NumericUpDown(); _overrideConfigFilesCheckBox = new CheckBox(); Controls.Add(_editorGroupBox); _editorGroupBox.Controls.Add(_useTabsCheckBox); _editorGroupBox.Controls.Add(_tabSizeLabel); _editorGroupBox.Controls.Add(_tabSizeSelector); _editorGroupBox.Controls.Add(_backspaceUnindentsCheckBox); _editorGroupBox.Controls.Add(_lnMarginSizeLabel); _editorGroupBox.Controls.Add(_lnMarginSizeSelector); _editorGroupBox.Controls.Add(_showGuidesCheckBox); _editorGroupBox.Controls.Add(_showFoldingCheckBox); _editorGroupBox.Controls.Add(_foldStyleLabel); _editorGroupBox.Controls.Add(_foldStyleCombo); _editorGroupBox.Controls.Add(_foldMarkerStyleLabel); _editorGroupBox.Controls.Add(_foldMarkerStyleCombo); _editorGroupBox.Controls.Add(_fontNameLabel); _editorGroupBox.Controls.Add(_fontNameCombo); _editorGroupBox.Controls.Add(_fontSizeSelector); Controls.Add(_overrideConfigFilesCheckBox); #region Form Layout _editorGroupBox.Text = Resources.OptionsEditorSettings; _editorGroupBox.Name = m_editorGroupBox; _editorGroupBox.Location = new Point(0, 0); _editorGroupBox.Size = new Size(430, 222); _useTabsCheckBox.AutoSize = true; _useTabsCheckBox.Location = new Point(19, 22); _useTabsCheckBox.Name = m_useTabsCheckbox; _useTabsCheckBox.TabIndex = 2; _useTabsCheckBox.Text = Resources.OptionsUseTabs; _useTabsCheckBox.UseVisualStyleBackColor = true; _tabSizeLabel.AutoSize = true; _tabSizeLabel.Location = new Point(230, 23); _tabSizeLabel.Name = m_tabSizeLabel; _tabSizeLabel.TabIndex = 3; _tabSizeLabel.Text = Resources.OptionsTabSize; _tabSizeSelector.Location = new Point(364, 21); _tabSizeSelector.Maximum = new decimal(new int[] { 20, 0, 0, 0 }); _tabSizeSelector.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); _tabSizeSelector.Name = m_tabSizeSelector; _tabSizeSelector.Size = new Size(44, 20); _tabSizeSelector.TabIndex = 4; _tabSizeSelector.Value = new decimal(new int[] { 1, 0, 0, 0 }); _backspaceUnindentsCheckBox.AutoSize = true; _backspaceUnindentsCheckBox.Location = new Point(19, 45); _backspaceUnindentsCheckBox.Name = m_backspaceUnindentsCheckBox; _backspaceUnindentsCheckBox.TabIndex = 5; _backspaceUnindentsCheckBox.Text = Resources.OptionsBackspaceUnindents; _backspaceUnindentsCheckBox.UseVisualStyleBackColor = true; _lnMarginSizeLabel.AutoSize = true; _lnMarginSizeLabel.Location = new Point(230, 56); _lnMarginSizeLabel.Name = m_lnMarginSizeLabel; _lnMarginSizeLabel.TabIndex = 6; _lnMarginSizeLabel.Text = Resources.OptionsLnMarginSize; _lnMarginSizeSelector.Location = new Point(364, 54); _lnMarginSizeSelector.Maximum = new decimal(new int[] { 99, 0, 0, 0 }); _lnMarginSizeSelector.Minimum = new decimal(new int[] { 0, 0, 0, 0 }); _lnMarginSizeSelector.Name = m_lnMarginSizeSelector; _lnMarginSizeSelector.Size = new Size(44, 20); _lnMarginSizeSelector.TabIndex = 7; _lnMarginSizeSelector.Value = new decimal(new int[] { 1, 0, 0, 0 }); _showGuidesCheckBox.AutoSize = true; _showGuidesCheckBox.Location = new Point(19, 68); _showGuidesCheckBox.Name = m_showGuidesCheckBox; _showGuidesCheckBox.TabIndex = 8; _showGuidesCheckBox.Text = Resources.OptionsShowIndentationGuides; _showGuidesCheckBox.UseVisualStyleBackColor = true; _showFoldingCheckBox.AutoSize = true; _showFoldingCheckBox.Location = new Point(19, 91); _showFoldingCheckBox.Name = m_showFoldingCheckbox; _showFoldingCheckBox.TabIndex = 9; _showFoldingCheckBox.Text = Resources.OptionsShowFolding; _showFoldingCheckBox.UseVisualStyleBackColor = true; _showFoldingCheckBox.CheckedChanged += delegate { SetFoldingState(); }; _foldStyleLabel.AutoSize = true; _foldStyleLabel.Location = new Point(160, 92); _foldStyleLabel.Name = m_foldStyleLabel; _foldStyleLabel.TabIndex = 10; _foldStyleLabel.Text = Resources.OptionsFoldStyle; _foldStyleCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; _foldStyleCombo.FormattingEnabled = true; _foldStyleCombo.Items.AddRange(new object[] { Resources.OptionsNone, Resources.OptionsLineBeforeContracted, Resources.OptionsLineAfterContracted }); _foldStyleCombo.Location = new Point(268, 88); _foldStyleCombo.Name = m_foldStyleCombo; _foldStyleCombo.Size = new Size(140, 21); _foldStyleCombo.TabIndex = 11; _foldMarkerStyleLabel.AutoSize = true; _foldMarkerStyleLabel.Location = new Point(160, 115); _foldMarkerStyleLabel.Name = m_foldMarkerStyleLabel; _foldMarkerStyleLabel.TabIndex = 12; _foldMarkerStyleLabel.Text = Resources.OptionsFoldMarkerStyle; _foldMarkerStyleCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; _foldMarkerStyleCombo.FormattingEnabled = true; _foldMarkerStyleCombo.Items.AddRange(new object[] { Resources.OptionsBoxPlusMinus, Resources.OptionsCirclePlusMinus, Resources.OptionsPlusMinus, Resources.OptionsArrows }); _foldMarkerStyleCombo.Location = new Point(268, 111); _foldMarkerStyleCombo.Name = m_foldMarkerStyleCombo; _foldMarkerStyleCombo.Size = new Size(140, 21); _foldMarkerStyleCombo.TabIndex = 13; _fontNameLabel.AutoSize = true; _fontNameLabel.Location = new Point(98, 149); _fontNameLabel.Name = m_fontNameLabel; _fontNameLabel.TabIndex = 14; _fontNameLabel.Text = Resources.OptionsFontName; _fontNameCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; _fontNameCombo.FormattingEnabled = true; _fontNameCombo.Location = new Point(160, 145); _fontNameCombo.Name = m_fontNameCombo; _fontNameCombo.Size = new Size(200, 21); _fontNameCombo.TabIndex = 15; _fontSizeSelector.Location = new Point(364, 145); _fontSizeSelector.Maximum = new decimal(new int[] { 30, 0, 0, 0 }); _fontSizeSelector.Minimum = new decimal(new int[] { 5, 0, 0, 0 }); _fontSizeSelector.Name = m_fontSizeSelector; _fontSizeSelector.Size = new Size(44, 20); _fontSizeSelector.TabIndex = 16; _fontSizeSelector.Value = new decimal(new int[] { 10, 0, 0, 0 }); _overrideConfigFilesCheckBox.AutoSize = true; _overrideConfigFilesCheckBox.Location = new Point(2, 229); _overrideConfigFilesCheckBox.Name = m_overrideConfigFilesCheckbox; _overrideConfigFilesCheckBox.TabIndex = 0; _overrideConfigFilesCheckBox.Text = Resources.OptionsOverrideConfigFiles; _overrideConfigFilesCheckBox.UseVisualStyleBackColor = true; _overrideConfigFilesCheckBox.CheckedChanged += delegate { SetOverrideState(); }; #endregion _settingsManager = SettingsManager.GetInstance(); _useTabsCheckBox.Checked = _settingsManager.UseTabs; _tabSizeSelector.Value = _settingsManager.TabSize; _backspaceUnindentsCheckBox.Checked = _settingsManager.BackspaceUnindents; _lnMarginSizeSelector.Value = _settingsManager.LineNumberMarginSize; _showGuidesCheckBox.Checked = _settingsManager.ShowIndentationGuides; _showFoldingCheckBox.Checked = _settingsManager.ShowFolding; _foldStyleCombo.SelectedIndex = _settingsManager.FoldStyle; _foldMarkerStyleCombo.SelectedIndex = _settingsManager.FoldMarkerStyle; _fontSizeSelector.Value = (decimal)Fonts.ValidateFontSize(_settingsManager.FontSize); _overrideConfigFilesCheckBox.Checked = _settingsManager.OverrideConfigFiles; InitFontNameCombo(_settingsManager.FontName); SetOverrideState(); SetFoldingState(); }