コード例 #1
0
ファイル: OutputStyleDef.cs プロジェクト: manpl/nppsharp
        /// <summary>
        /// Initializes default styles.
        /// </summary>
        internal static void InitStyles()
        {
            // Get the preferred font that is installed on the machine.
            string preferredFontName = "";

            string[] preferredFonts     = new string[] { "Consolas", "Lucida Console", "Courier New", "Courier" };
            InstalledFontCollection ifc = new InstalledFontCollection();

            foreach (string fontName in preferredFonts)
            {
                bool found = false;
                foreach (FontFamily ff in ifc.Families)
                {
                    if (ff.Name.Equals(fontName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        preferredFontName = ff.Name;
                        found             = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }

            // Set standard styles (can be overridden by the user)
            OutputStyleDef osd = GetStyleDef(OutputStyle.Normal);

            osd.FontName  = preferredFontName;
            osd.Size      = 9;
            osd.Bold      = false;
            osd.Italic    = false;
            osd.Underline = false;
            osd.ForeColor = Color.Black;
            osd.BackColor = Color.White;

            osd           = GetStyleDef(OutputStyle.Warning);
            osd.ForeColor = Color.DarkOrange;

            osd           = GetStyleDef(OutputStyle.Error);
            osd.ForeColor = Color.Red;

            osd           = GetStyleDef(OutputStyle.Comment);
            osd.ForeColor = Color.DarkGreen;

            osd           = GetStyleDef(OutputStyle.Important);
            osd.ForeColor = Color.Blue;

            osd           = GetStyleDef(OutputStyle.NotImportant);
            osd.ForeColor = Color.Gray;

            foreach (OutputStyleDef s in _styles.Values)
            {
                s.LoadSettings();
                s.Apply();
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="npp">The Notepad++ interface object.</param>
        public static void Initialize(INpp npp)
        {
            _npp    = npp;
            _output = new OutputView();

            ScriptManager.Compile();
            OutputStyleDef.InitStyles();

            _npp.GetCommands          += OnGetCommands;
            _npp.RegisterToolbarIcons += OnRegisterToolbarIcons;
            _npp.CommandExecuted      += OnCommandExecuted;
        }
コード例 #3
0
ファイル: OutputStyleDef.cs プロジェクト: manpl/nppsharp
        /// <summary>
        /// Gets the style definition object for the specified style number.
        /// </summary>
        /// <param name="style">The style number.</param>
        /// <returns>The style definition object.  If it does not exist yet, a new one will be created with default values.</returns>
        internal static OutputStyleDef GetStyleDef(OutputStyle style)
        {
            OutputStyleDef osd;

            if (_styles.TryGetValue(style, out osd))
            {
                return(osd);
            }

            osd = new OutputStyleDef(style);
            _styles.Add(style, osd);
            return(osd);
        }
コード例 #4
0
ファイル: SettingsForm.cs プロジェクト: manpl/nppsharp
        private OutputStyleDef GetWorkingOutputStyleDef(OutputStyle style)
        {
            OutputStyleDef osd;

            if (_styles.TryGetValue(style, out osd))
            {
                return(osd);
            }

            osd = OutputStyleDef.GetStyleDef(style).Clone();
            _styles.Add(style, osd);
            return(osd);
        }
コード例 #5
0
ファイル: OutputStyleDef.cs プロジェクト: manpl/nppsharp
        /// <summary>
        /// Creates a duplicate of this style definition.
        /// </summary>
        /// <returns>A new object with the same style elements.</returns>
        public OutputStyleDef Clone()
        {
            OutputStyleDef osd = new OutputStyleDef(_style);

            osd._fontName  = _fontName;
            osd._size      = _size;
            osd._bold      = _bold;
            osd._italic    = _italic;
            osd._underline = _underline;
            osd._foreColor = _foreColor;
            osd._backColor = _backColor;

            return(osd);
        }
コード例 #6
0
ファイル: OutputStyleDef.cs プロジェクト: manpl/nppsharp
        /// <summary>
        /// Applies the style to the output window.
        /// </summary>
        internal void Apply()
        {
            OutputStyleDef osd = GetStyleDef(_style);

            osd._fontName  = _fontName;
            osd._size      = _size;
            osd._bold      = _bold;
            osd._italic    = _italic;
            osd._underline = _underline;
            osd._foreColor = _foreColor;
            osd._backColor = _backColor;

            OutputStyleDef defaultOsd = _style == OutputStyle.Normal ? null : GetStyleDef(OutputStyle.Normal);

            Plugin.NppIntf.SetOutputStyleDef(osd, defaultOsd);
        }
コード例 #7
0
ファイル: SettingsForm.cs プロジェクト: manpl/nppsharp
        private void ApplyOutputWindowStyles()
        {
            OutputStyleDef defaultOsd = GetWorkingOutputStyleDef(OutputStyle.Normal);

            defaultOsd.Apply();
            defaultOsd.SaveSettings();

            foreach (OutputStyle style in Enum.GetValues(typeof(OutputStyle)))
            {
                if (style == OutputStyle.Normal)
                {
                    continue;
                }

                OutputStyleDef osd = GetWorkingOutputStyleDef(style);
                osd.Apply();
                osd.SaveSettings();
            }
        }
コード例 #8
0
ファイル: SettingsForm.cs プロジェクト: cmrazek/NppSharp
        private void lstOutputStyles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (lstOutputStyles.SelectedItem == null) return;

                _styleChanging = true;

                _currentStyle = (OutputStyle)Enum.Parse(typeof(OutputStyle), lstOutputStyles.SelectedItem.ToString());
                _currentStyleDef = GetWorkingOutputStyleDef(_currentStyle);

                // Refresh font list
                if (string.IsNullOrEmpty(_currentStyleDef.FontName))
                {
                    cmbOutputFonts.SelectedIndex = 0;
                }
                else
                {
                    bool found = false;
                    foreach (string f in cmbOutputFonts.Items)
                    {
                        if (f.Equals(_currentStyleDef.FontName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            cmbOutputFonts.SelectedItem = f;
                            found = true;
                            break;
                        }
                    }
                    if (!found) cmbOutputFonts.SelectedIndex = 0;
                }

                // Refresh font size
                if (_currentStyleDef.Size.HasValue)
                {
                    txtOutputSize.Text = _currentStyleDef.Size.Value.ToString();
                }
                else
                {
                    txtOutputSize.Text = string.Empty;
                }

                // Font style
                switch (_currentStyleDef.Bold)
                {
                    case true:
                        chkBold.CheckState = CheckState.Checked;
                        break;
                    case false:
                        chkBold.CheckState = CheckState.Unchecked;
                        break;
                    default:
                        chkBold.CheckState = CheckState.Indeterminate;
                        break;
                }

                switch (_currentStyleDef.Italic)
                {
                    case true:
                        chkItalic.CheckState = CheckState.Checked;
                        break;
                    case false:
                        chkItalic.CheckState = CheckState.Unchecked;
                        break;
                    default:
                        chkItalic.CheckState = CheckState.Indeterminate;
                        break;
                }

                switch (_currentStyleDef.Underline)
                {
                    case true:
                        chkUnderline.CheckState = CheckState.Checked;
                        break;
                    case false:
                        chkUnderline.CheckState = CheckState.Unchecked;
                        break;
                    default:
                        chkUnderline.CheckState = CheckState.Indeterminate;
                        break;
                }

                // Refresh colors
                clrFore.Color = _currentStyleDef.ForeColor;
                clrBack.Color = _currentStyleDef.BackColor;

                _styleChanging = false;
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
コード例 #9
0
ファイル: OutputStyleDef.cs プロジェクト: cmrazek/NppSharp
        /// <summary>
        /// Gets the style definition object for the specified style number.
        /// </summary>
        /// <param name="style">The style number.</param>
        /// <returns>The style definition object.  If it does not exist yet, a new one will be created with default values.</returns>
        internal static OutputStyleDef GetStyleDef(OutputStyle style)
        {
            OutputStyleDef osd;
            if (_styles.TryGetValue(style, out osd)) return osd;

            osd = new OutputStyleDef(style);
            _styles.Add(style, osd);
            return osd;
        }
コード例 #10
0
ファイル: OutputStyleDef.cs プロジェクト: cmrazek/NppSharp
        /// <summary>
        /// Creates a duplicate of this style definition.
        /// </summary>
        /// <returns>A new object with the same style elements.</returns>
        public OutputStyleDef Clone()
        {
            OutputStyleDef osd = new OutputStyleDef(_style);
            osd._fontName = _fontName;
            osd._size = _size;
            osd._bold = _bold;
            osd._italic = _italic;
            osd._underline = _underline;
            osd._foreColor = _foreColor;
            osd._backColor = _backColor;

            return osd;
        }
コード例 #11
0
ファイル: SettingsForm.cs プロジェクト: manpl/nppsharp
        private void lstOutputStyles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (lstOutputStyles.SelectedItem == null)
                {
                    return;
                }

                _styleChanging = true;

                _currentStyle    = (OutputStyle)Enum.Parse(typeof(OutputStyle), lstOutputStyles.SelectedItem.ToString());
                _currentStyleDef = GetWorkingOutputStyleDef(_currentStyle);

                // Refresh font list
                if (string.IsNullOrEmpty(_currentStyleDef.FontName))
                {
                    cmbOutputFonts.SelectedIndex = 0;
                }
                else
                {
                    bool found = false;
                    foreach (string f in cmbOutputFonts.Items)
                    {
                        if (f.Equals(_currentStyleDef.FontName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            cmbOutputFonts.SelectedItem = f;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        cmbOutputFonts.SelectedIndex = 0;
                    }
                }

                // Refresh font size
                if (_currentStyleDef.Size.HasValue)
                {
                    txtOutputSize.Text = _currentStyleDef.Size.Value.ToString();
                }
                else
                {
                    txtOutputSize.Text = string.Empty;
                }

                // Font style
                switch (_currentStyleDef.Bold)
                {
                case true:
                    chkBold.CheckState = CheckState.Checked;
                    break;

                case false:
                    chkBold.CheckState = CheckState.Unchecked;
                    break;

                default:
                    chkBold.CheckState = CheckState.Indeterminate;
                    break;
                }

                switch (_currentStyleDef.Italic)
                {
                case true:
                    chkItalic.CheckState = CheckState.Checked;
                    break;

                case false:
                    chkItalic.CheckState = CheckState.Unchecked;
                    break;

                default:
                    chkItalic.CheckState = CheckState.Indeterminate;
                    break;
                }

                switch (_currentStyleDef.Underline)
                {
                case true:
                    chkUnderline.CheckState = CheckState.Checked;
                    break;

                case false:
                    chkUnderline.CheckState = CheckState.Unchecked;
                    break;

                default:
                    chkUnderline.CheckState = CheckState.Indeterminate;
                    break;
                }

                // Refresh colors
                clrFore.Color = _currentStyleDef.ForeColor;
                clrBack.Color = _currentStyleDef.BackColor;

                _styleChanging = false;
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }