Пример #1
0
        internal static void ApplyPluginOptionsForScintilla()
        {
            if (!_hasBeenInit || !Npp.PreviousFile.IsProgress)
            {
                // read default options
                _tabWidth       = Sci.TabWidth;
                _indentWithTabs = Sci.UseTabs;
                _whitespaceMode = Sci.ViewWhitespace;
                AnnotationMode  = Sci.AnnotationVisible;
                _hasBeenInit    = true;
            }

            Sci.TabWidth = Config.Instance.CodeTabSpaceNb;
            Sci.UseTabs  = false;
            if (Config.Instance.CodeShowSpaces)
            {
                Sci.ViewWhitespace = WhitespaceMode.VisibleAlways;
            }

            // apply style
            Style.SetSyntaxStyles();
            var currentStyle = Style.Current;

            Sci.SetIndentGuideColor(currentStyle.WhiteSpace.BackColor, currentStyle.WhiteSpace.ForeColor);
            Sci.SetWhiteSpaceColor(true, Color.Transparent, currentStyle.WhiteSpace.ForeColor);
            Sci.SetSelectionColor(true, currentStyle.Selection.BackColor, Color.Transparent);
            Sci.CaretLineBackColor = currentStyle.CaretLine.BackColor;
            Sci.CaretColor         = currentStyle.CaretColor.ForeColor;
            Sci.SetFoldMarginColors(true, currentStyle.FoldMargin.BackColor, currentStyle.FoldMargin.BackColor);
            Sci.SetFoldMarginMarkersColor(currentStyle.FoldMargin.ForeColor, currentStyle.FoldMargin.BackColor, currentStyle.FoldActiveMarker.ForeColor);
        }
Пример #2
0
        internal static void ApplyPluginOptionsForScintilla()
        {
            if (!_hasBeenInit || !Npp.PreviousFileInfo.IsProgress)
            {
                // read default options
                _tabWidth       = Sci.TabWidth;
                _indentWithTabs = Sci.UseTabs;
                _whitespaceMode = Sci.ViewWhitespace;
                AnnotationMode  = Sci.AnnotationVisible;
                _hasBeenInit    = true;
            }

            Sci.TabWidth = Config.Instance.CodeTabSpaceNb;
            Sci.UseTabs  = false;
            if (Config.Instance.CodeShowSpaces)
            {
                Sci.ViewWhitespace = WhitespaceMode.VisibleAlways;
            }

            // apply style
            ScintillaTheme.CurrentTheme.SetScintillaStyles();

            // activate syntax highlighting
            SyntaxHighlight.ActivateHighlight();
        }
Пример #3
0
		protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
		{
			var value = new StringBuilder();
			foreach (var node in Children)
				value.Append(node.ToFormattedString(mode, indentation, currentDepth + 1));

			return value.ToString();
		}
Пример #4
0
		protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
		{
			var value = string.Format("<?{0}?>", Value);
			if(mode == WhitespaceMode.Insert) {
				value = string.Format("\n{0}{1}", indentation.Repeat(currentDepth - 1), value);
			}
			return value;
		}
Пример #5
0
		protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
		{
			var value = string.Format("<!DOCTYPE {0} PUBLIC \"{1}\" \"{2}\" >", Name, m_publicIdentifier, m_systemIdentifier);
			if (mode == WhitespaceMode.Insert)
			{
				value = string.Format("\n{0}{1}", indentation.Repeat(currentDepth - 1), value);
			}
			return value;
		}
Пример #6
0
        private void whitespaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WhitespaceMode whitespaceMode = whitespaceToolStripMenuItem.Checked
                                                ? WhitespaceMode.VisibleAlways
                                                : WhitespaceMode.Invisible;

            foreach (LispEditor editor in this.dockPanel1.Documents)
            {
                editor.Scintilla.Whitespace.Mode = whitespaceMode;
            }
        }
Пример #7
0
        internal static void ApplyPluginOptionsForScintilla()
        {
            if (!_hasBeenInit || !IsPreviousFileProgress)
            {
                // read default options
                _tabWidth       = Npp.TabWidth;
                _indentWithTabs = Npp.UseTabs;
                _whitespaceMode = Npp.ViewWhitespace;
                AnnotationMode  = Npp.AnnotationVisible;
            }
            _hasBeenInit = true;

            // need to do this stuff uniquely for both scintilla
            var curScintilla = Npp.CurrentScintilla; // 0 or 1

            if (_initiatedScintilla[curScintilla] == 0)
            {
                // Extra settings at the start
                Npp.MouseDwellTime = Config.Instance.ToolTipmsBeforeShowing;
                Npp.EndAtLastLine  = false;
                Npp.EventMask      = (int)(SciMsg.SC_MOD_INSERTTEXT | SciMsg.SC_MOD_DELETETEXT | SciMsg.SC_PERFORMED_USER | SciMsg.SC_PERFORMED_UNDO | SciMsg.SC_PERFORMED_REDO);
                _initiatedScintilla[curScintilla] = 1;
            }

            Npp.TabWidth = Config.Instance.CodeTabSpaceNb;
            Npp.UseTabs  = false;
            if (Config.Instance.CodeShowSpaces)
            {
                Npp.ViewWhitespace = WhitespaceMode.VisibleAlways;
            }

            // apply style
            Style.SetSyntaxStyles();
            var currentStyle = Style.Current;

            Npp.SetIndentGuideColor(currentStyle.WhiteSpace.BackColor, currentStyle.WhiteSpace.ForeColor);
            Npp.SetWhiteSpaceColor(true, Color.Transparent, currentStyle.WhiteSpace.ForeColor);
            Npp.SetSelectionColor(true, currentStyle.Selection.BackColor, Color.Transparent);
            Npp.CaretLineBackColor = currentStyle.CaretLine.BackColor;
            Npp.CaretColor         = currentStyle.CaretColor.ForeColor;
            Npp.SetFoldMarginColors(true, currentStyle.FoldMargin.BackColor, currentStyle.FoldMargin.BackColor);
            Npp.SetFoldMarginMarkersColor(currentStyle.FoldMargin.ForeColor, currentStyle.FoldMargin.BackColor, currentStyle.FoldActiveMarker.ForeColor);

            // we want the default auto-completion to not show
            // we block on a scintilla level (pretty bad solution because it slows down npp on big documents)
            Npp.AutoCStops(@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_");
            // and we also block it in Npp (pull request on going for v6.9.?)
            if (Config.IsDevelopper)
            {
                WinApi.SendMessage(Npp.HandleNpp, NppMsg.NPPM_SETAUTOCOMPLETIONDISABLEDONCHARADDED, 0, 1);
            }
        }
Пример #8
0
 protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
 {
     var value = Value;
     if(mode == WhitespaceMode.Strip) {
         value = value.Trim();
     } else if(mode == WhitespaceMode.Insert) {
         value = value.Trim();
         if(value.Length > 0) {
             value = string.Format("\n{0}{1}", indentation.Repeat(currentDepth - 1), value.Trim());
         }
     }
     return value;
 }
        /// <summary>
        /// Mimics CommandLineToArgvW's argument splitting behavior, plus bug fixes.
        /// </summary>
        /// <param name="input">The command line to split into arguments.</param>
        /// <returns>The values of the arguments supplied in the input.</returns>
        public static List <string> CommandLineToArgvW(string input)
        {
            // This function mimics CommandLineToArgvW's escaping behavior, documented here:
            // http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391.aspx

            //
            // We used to P/Invoke to the real CommandLineToArgvW, but re-implement it here
            // as a workaround for the following:
            //
            // * CommandLineToArgvW does not treat newlines as whitespace (twcsec-tfs01 bug # 17291)
            // * CommandLineToArgvW returns the executable name for the empty string, not the empty set
            // * CommandLineToArgvW chokes on leading whitespace (twcsec-tfs01 bug# 17378)
            //
            // and as a result of the above we expect to find more nasty edge cases in the future.
            //

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            WhitespaceMode whitespaceMode = WhitespaceMode.Ignore;
            int            slashCount     = 0;

            var result = new List <string>();
            var sb     = new StringBuilder();

            foreach (char c in input)
            {
                if (whitespaceMode == WhitespaceMode.Ignore && char.IsWhiteSpace(c))
                {
                    // Purposely do nothing
                }
                else if (whitespaceMode == WhitespaceMode.EndArgument && char.IsWhiteSpace(c))
                {
                    AddSlashes(sb, ref slashCount);
                    EmitArgument(result, sb);
                    whitespaceMode = WhitespaceMode.Ignore;
                }
                else if (c == '\\')
                {
                    ++slashCount;
                    if (whitespaceMode == WhitespaceMode.Ignore)
                    {
                        whitespaceMode = WhitespaceMode.EndArgument;
                    }
                }
                else if (c == '\"')
                {
                    bool quoteIsEscaped = (slashCount & 1) == 1;
                    slashCount >>= 1; // Using >> to avoid C# bankers rounding
                    // 2n backslashes followed by a quotation mark produce n slashes followed by a quotation mark
                    AddSlashes(sb, ref slashCount);

                    if (quoteIsEscaped)
                    {
                        sb.Append(c);
                    }
                    else if (whitespaceMode == WhitespaceMode.PartOfArgument)
                    {
                        whitespaceMode = WhitespaceMode.EndArgument;
                    }
                    else
                    {
                        whitespaceMode = WhitespaceMode.PartOfArgument;
                    }
                }
                else
                {
                    AddSlashes(sb, ref slashCount);
                    sb.Append(c);
                    if (whitespaceMode == WhitespaceMode.Ignore)
                    {
                        whitespaceMode = WhitespaceMode.EndArgument;
                    }
                }
            }

            AddSlashes(sb, ref slashCount);
            if (sb.Length != 0)
            {
                EmitArgument(result, sb);
            }

            return(result);
        }
Пример #10
0
        protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
        {
            var indent = "";
            if(mode == WhitespaceMode.Insert) {
                indent = string.Format("\n{0}", indentation.Repeat(currentDepth - 1));
            }

            var attr = new StringBuilder();
            foreach (var attribute in Attributes)
                attr.AppendFormat(" {0}", attribute);

            var value = new StringBuilder();
            if (m_childNodes == null)
            {
                value.AppendFormat("{0}<{1}{2} />", indent, Name, attr);
            }
            else
            {
                value.AppendFormat("{0}<{1}{2}>", indent, Name, attr);
                foreach (var node in m_childNodes)
                    value.Append(node.ToFormattedString(mode, indentation, currentDepth + 1));
                value.AppendFormat("{0}</{1}>", indent, Name);
            }
            return value.ToString();
        }
Пример #11
0
		protected override string ToString(WhitespaceMode mode, string indentation, int currentDepth)
		{
			// todo add indent if necessary
			return string.Format("<!-- {0} -->", Value);
		}
Пример #12
0
        // whitespace processing needs to happen in two phases. the first is where we collapse whitespace and handle new lines
        // the second is what to do with trailing space and wrapping.
        public static int ProcessWhitespace(WhitespaceMode whitespaceMode, ref char[] buffer, char[] input, int inputSize = -1)
        {
            if (inputSize < 0)
            {
                inputSize = input.Length;
            }

            if (inputSize == 0)
            {
                return(0);
            }

            bool collapseSpaceAndTab = (whitespaceMode & WhitespaceMode.CollapseWhitespace) != 0;
            bool preserveNewLine     = (whitespaceMode & WhitespaceMode.PreserveNewLines) != 0;
            bool trimStart           = (whitespaceMode & WhitespaceMode.TrimStart) != 0;
            bool trimEnd             = (whitespaceMode & WhitespaceMode.TrimEnd) != 0;

            bool collapsing = false;

            if (buffer == null)
            {
                buffer = ArrayPool <char> .GetMinSize(inputSize);
            }

            if (buffer.Length < inputSize)
            {
                ArrayPool <char> .Resize(ref buffer, inputSize);
            }

            int writeIndex = 0;
            int start      = 0;
            int end        = inputSize;

            if (trimStart)
            {
                for (int i = 0; i < end; i++)
                {
                    char c = input[i];

                    bool isWhiteSpace = c == ' ' || c >= '\t' && c <= '\r' || (c == ' ' || c == '\x0085');

                    if (!isWhiteSpace)
                    {
                        start = i;
                        break;
                    }
                }
            }

            if (trimEnd)
            {
                for (int i = end - 1; i >= start; i--)
                {
                    char c = input[i];

                    bool isWhiteSpace = c == ' ' || c >= '\t' && c <= '\r' || (c == ' ' || c == '\x0085');

                    if (!isWhiteSpace)
                    {
                        end = i + 1;
                        break;
                    }
                }
            }

            for (int i = start; i < end; i++)
            {
                char c = input[i];

                if (c == '\n' && !preserveNewLine)
                {
                    continue;
                }

                bool isWhiteSpace = c == ' ' || c >= '\t' && c <= '\r' || (c == ' ' || c == '\x0085');

                if (c == '\n')
                {
                    if (preserveNewLine)
                    {
                        buffer[writeIndex++] = c;
                        continue;
                    }
                }

                if (collapsing)
                {
                    if (!isWhiteSpace)
                    {
                        buffer[writeIndex++] = c;
                        collapsing           = false;
                    }
                }
                else if (isWhiteSpace)
                {
                    collapsing           = collapseSpaceAndTab;
                    buffer[writeIndex++] = ' ';
                }
                else
                {
                    buffer[writeIndex++] = c;
                }
            }


            return(writeIndex);
        }