Arguments for char-added events.
Наследование: System.EventArgs
Пример #1
0
		public void OnCharAdded(CharAddedEventArgs e)
		{
#if !DISABLE
			var app = ProbeNppPlugin.Instance;

			if (!app.Settings.Editor.SmartIndent) return;

			if (e.Character == '\n')
			{
				var curLine = app.CurrentLine;
				var curPos = app.CurrentLocation;
				var prevLineText = curLine > 1 ? app.GetLineText(curLine - 1) : "";
				if (app.IsProbeLanguage)
				{
					if (IndentNextLine(prevLineText))
					{
						var indent = GetIndentText(prevLineText, "\t");
						app.SetSelection(app.GetLineStartPos(curLine), curPos);
						app.Insert(indent);
					}
					else
					{
						var indent = GetIndentText(prevLineText);
						app.SetSelection(app.GetLineStartPos(curLine), curPos);
						app.Insert(indent);
					}
				}
				else
				{
					var indent = GetIndentText(prevLineText);
					app.SetSelection(app.GetLineStartPos(curLine), curPos);
					app.Insert(indent);
				}
			}
			else if (e.Character == '}' && app.IsProbeLanguage)
			{
				var curLoc = app.CurrentLocation;
				var curLine = app.CurrentLine;
				if (app.GetText(app.GetLineStartPos(curLoc.Line), curLoc).TrimStart() == "}")
				{
					TextLocation openLoc;
					if (TryFindOpeningBrace(curLoc, out openLoc))
					{
						var openIndent = app.GetText(app.GetLineStartPos(openLoc.Line), GetIndentLocation(openLoc.Line));
						app.SetSelection(app.GetLineStartPos(curLine), GetIndentLocation(curLine));
						app.Insert(openIndent);
						curLoc = app.CurrentLocation + 1;
						app.SetSelection(curLoc, curLoc);
					}
				}
			}
#endif
		}
Пример #2
0
 void ProbeNppPlugin_CharAdded(object sender, CharAddedEventArgs e)
 {
     try
     {
         _smartIndentManager.OnCharAdded(e);
         if (IsProbeLanguage)
         {
             _autoCompletionManager.OnCharAdded(e);
         }
     }
     catch (Exception ex)
     {
         Output.WriteLine(OutputStyle.Error, ex.ToString());
     }
 }
Пример #3
0
        public void OnCharAdded(CharAddedEventArgs e)
        {
            var app = ProbeNppPlugin.Instance;

            if (!app.Settings.Editor.AutoCompletion) return;
            if (!IsAutoCompletionAllowedHere(app.CurrentLocation)) return;

            if (e.Character == '.')
            {
                var wordEnd = app.CurrentLocation - 1;
                var wordStart = app.GetWordStartPos(wordEnd, false);
                var word = app.GetText(wordStart, wordEnd);

                if (!string.IsNullOrWhiteSpace(word))
                {
                    var table = ProbeEnvironment.GetTable(word);
                    if (table == null) return;

                    var fields = table.Fields;
                    if (!fields.Any()) return;
                    app.ShowAutoCompletion(0, (from f in fields orderby f.Name.ToLower() select f.Name), true);
                }
            }
            else if (char.IsLetterOrDigit(e.Character))
            {
                if (!app.AutoCompletionIsActive)
                {
                    var lineText = app.GetText(app.GetLineStartPos(app.CurrentLine), app.CurrentLocation);

                    Match match;
                    ProbeTable table;
                    if ((match = _rxTableField.Match(lineText)).Success &&
                        (table = ProbeEnvironment.GetTable(match.Groups[1].Value)) != null)
                    {
                        var field = match.Groups[2].Value;
                        app.ShowAutoCompletion(field.Length, (from f in table.Fields orderby f.Name select f.Name), true);
                    }
                    else if ((match = _rxAutoCompleteWord.Match(lineText)).Success)
                    {
                        var word = match.Value;

                        var model = app.CurrentModel;
                        if (model != null)
                        {
                            app.ShowAutoCompletion(word.Length, GetSoloAutoCompletionItems(app.CurrentLocation, word));
                        }
                    }
                }
            }
            else if (e.Character == '(')
            {
                if (!app.FunctionSignatureIsActive)
                {
                    var lineText = app.GetText(app.GetLineStartPos(app.CurrentLine), app.CurrentLocation);

                    Match match;
                    if ((match = _rxFuncCall.Match(lineText)).Success)
                    {
                        var funcName = match.Groups[1].Value;

                        var entered = match.Length - (match.Groups[1].Index - match.Index);
                        var callTipPos = new TextLocation(app.CurrentLine, app.CurrentLocation.CharPosition - entered);

                        var funcSig = GetFunctionSignature(funcName);
                        if (!string.IsNullOrEmpty(funcSig))
                        {
                            app.ShowFunctionSignature(callTipPos, funcSig);

                            int highlightStart, highlightLength;
                            if (GetFunctionSignatureHighlightRange(funcSig, 0, out highlightStart, out highlightLength))
                            {
                                app.SetFunctionSignatureHighlight(highlightStart, highlightLength);
                            }
                        }
                    }
                }
            }
            else if (e.Character == ',')
            {
                var sigParser = new FunctionSignatureParser();
                if (sigParser.GetFuncSigName(app.CurrentLocation))
                {
                    var funcSig = GetFunctionSignature(sigParser.FunctionName);
                    if (!string.IsNullOrEmpty(funcSig))
                    {
                        app.ShowFunctionSignature(app.CurrentLocation, funcSig);

                        int highlightStart, highlightLength;
                        if (GetFunctionSignatureHighlightRange(funcSig, sigParser.CommaCount, out highlightStart, out highlightLength))
                        {
                            app.SetFunctionSignatureHighlight(highlightStart, highlightLength);
                        }
                    }
                }
            }
            else if (e.Character == ')')
            {
                if (app.FunctionSignatureIsActive) app.CancelFunctionSignature();
            }
        }
Пример #4
0
 internal void OnCharAdded(object sender, CharAddedEventArgs e)
 {
     CharAddedEventHandler ev = CharAdded;
     if (ev != null) ev(this, e);
 }