public void Complete(TextArea textArea, ISegment completionSegment,
             EventArgs insertionRequestEventArgs)
        {
            textArea.Document.Replace(completionSegment, this.Text);
            if (autocompleteAgain_)
            {
                var completionWindow = new CompletionWindow(textArea);
                completionWindow.Width = 256;
                IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                var functions = App.MainViewModel.AutoCompleteCache.GetFunctions(Content as string);
                (functions as List<ErlangEditor.AutoComplete.AcEntity>).Sort(new Tools.Reverser<ErlangEditor.AutoComplete.AcEntity>(new AutoComplete.AcEntity().GetType(), "FunctionName", Tools.ReverserInfo.Direction.ASC));
                foreach (var i in functions)
                {
                    data.Add(new CompletionData(false) { Text = "\'" + i.FunctionName + "\'(", Content = i.FunctionName + "/" + i.Arity, Description = i.Desc });
                }
                completionWindow.Show();
                completionWindow.Closed += delegate
                {
                    completionWindow = null;
                };
            }
        }
        public static void InvokeCompletionWindow(TextEditor textEditor)
        {
            completionWindow = new CompletionWindow(textEditor.TextArea);

            completionWindow.Closed += delegate
            {
                completionWindow = null;
            };

            var text = textEditor.Text;
            var offset = textEditor.TextArea.Caret.Offset;

            var completedInput = CommandCompletion.CompleteInput(text, offset, null, PSConsolePowerShell.PowerShellInstance);
            // var r = CommandCompletion.MapStringInputToParsedInput(text, offset);

            "InvokeCompletedInput".ExecuteScriptEntryPoint(completedInput.CompletionMatches);

            if (completedInput.CompletionMatches.Count > 0)
            {
                completedInput.CompletionMatches.ToList()
                    .ForEach(record =>
                    {
                        completionWindow.CompletionList.CompletionData.Add(
                            new CompletionData
                            {
                                CompletionText = record.CompletionText,
                                ToolTip = record.ToolTip,
                                Resultype = record.ResultType,
                                ReplacementLength = completedInput.ReplacementLength
                            });
                    });

                completionWindow.Show();
            }
        }
		private void textEditor_TextEntered(object sender, TextCompositionEventArgs e)
		{
			if (e.Text == "<" || e.Text == " ")
			{
				CompletionData[] completions1;
				if (completions.TryGetValue("!" + e.Text + "!" + GetActiveElement(1), out completions1))
				{
					completionWindow = new CompletionWindow(textEditor.TextArea);
					var completions2 = completionWindow.CompletionList.CompletionData;

					foreach (var completion in completions1)
						completions2.Add(completion);

					completionWindow.Show();
					completionWindow.Closed += delegate
					{
						completionWindow = null;
					};
				}
			}
			if (e.Text == ">")
			{
				var tag = GetOpenTag(1);
				if (tag != string.Empty)
					textEditor.Document.Insert(textEditor.CaretOffset, tag.Insert(1, "/") + ">");
			}
		}
Beispiel #4
0
 /// <summary>
 /// Shows completion window for passed functions.
 /// </summary>
 /// <param name="identifierSegment">optional segment that should be included in the progressive search: eg. part of an identifier that's already typed before code completion was started</param>
 /// <param name="functions"></param>
 public void ShowCompletionWindow(ISegment identifierSegment, IList<Function> functions)
 {
     FunctionCompletionData first = null;
     _completionWindow = new CompletionWindow(textEditor.TextArea);
     foreach (var function in functions)
     {
         var tooltip = string.IsNullOrWhiteSpace(function.Definition) ? function.Description : string.Format("{0}\n\n{1}", function.Definition.Replace("|", Environment.NewLine), function.Description);
         var item = new FunctionCompletionData(function.Name, tooltip);
         if (first == null) first = item;
         _completionWindow.CompletionList.CompletionData.Add(item);
     }
     _completionWindow.StartOffset = identifierSegment.Offset;
     _completionWindow.EndOffset = identifierSegment.EndOffset;
     if (first != null)
     {
         _completionWindow.CompletionList.SelectedItem = first;
     }
     _completionWindow.Show();
     _completionWindow.Closed += (sender, args) => _completionWindow = null;
     _completionWindow.PreviewTextInput += (sender, args) =>
     {
         if (args.Text == "(")
         {
             _completionWindow.CompletionList.RequestInsertion(EventArgs.Empty);
         }
         var c = args.Text[args.Text.Length - 1];
         args.Handled = !char.IsLetterOrDigit(c) && c != '_';
     };
 }
        public CompletionWindow Resolve()
        {
            var hiName = string.Empty;
            if (_target.SyntaxHighlighting != null)
            {
                hiName = _target.SyntaxHighlighting.Name;
            }

            var cdata = _dataProviders.SelectMany(x => x.GetData(_text, _position, _input, hiName)).ToList();
            int count = cdata.Count;
            if (count > 0)
            {
                var completionWindow = new CompletionWindow(_target.TextArea);

                var data = completionWindow.CompletionList.CompletionData;

                foreach (var completionData in cdata)
                {
                    data.Add(completionData);
                }

                completionWindow.Show();
                completionWindow.Closed += delegate
                                           	{
                                           		completionWindow = null;
                                           	};
                return completionWindow;

            }
            return null;
        }
Beispiel #6
0
        private void AttributeCompletionAvailable(object sender, AttributeCompletionEventArgs e)
        {
            _completionWindow = new CompletionWindow(txtPlugin.TextArea);

            IList<ICompletionData> data = _completionWindow.CompletionList.CompletionData;
            foreach (CompletableXMLAttribute tag in e.Suggestions)
                data.Add(new XMLAttributeCompletionData(tag, _completer));

            _completionWindow.Show();
        }
    public void ShowCompletion(TextArea area)
    {
      var window = new CompletionWindow(area);

      IList<ICompletionData> data = window.CompletionList.CompletionData;

      foreach (CompletionData item in GenerateCompletionData("test.boo", area))
      {
        data.Add(item);
      }

      window.Show();
    }
 public void TextEditorTextAreaTextEntered(object sender, TextCompositionEventArgs e)
 {
     if (e.Text == ".")
     {
         // Open code completion after the user has pressed dot:
         _completionWindow = new CompletionWindow(sender as TextArea);
         IList<ICompletionData> data = _completionWindow.CompletionList.CompletionData;
         data.Add(new MyCompletionData("Query"));
         data.Add(new MyCompletionData("All()"));
         data.Add(new MyCompletionData("ToString()"));
         _completionWindow.Show();
         _completionWindow.Closed += delegate { _completionWindow = null; };
     }
 }
        private void edSQL_TextArea_Sense(object sender, TextCompositionEventArgs e)
        {
            completionWindow = new CompletionWindow(edSQL.TextArea);
            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

            // fill data (completion options) based on e (position, context etc)
            completionHelper.Initialize(e, data);
            completionWindow.Show();
            completionWindow.CompletionList.IsFiltering = false;
            completionWindow.CompletionList.SelectItem(completionHelper.Currentword);
            completionWindow.Closed += delegate
            {
                completionWindow = null;
            };
        }
Beispiel #10
0
 void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
 {
     if (e.Text == ".")
     {
         // open code completion after the user has pressed dot:
         completionWindow = new CompletionWindow(textEditor.TextArea);
         // provide AvalonEdit with the data:
         IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
         data.Add(new MyCompletionData("zapline"));
         data.Add(new MyCompletionData("is"));
         data.Add(new MyCompletionData("a"));
         data.Add(new MyCompletionData("sb"));
         completionWindow.Show();
         completionWindow.Closed += delegate
         {
             completionWindow = null;
         };
     }
 }
 private async Task ShowCompletionWindow()
 {
     if (Recommender == null) return;
     _completionWindow = new CompletionWindow(TextArea);
     var data = _completionWindow.CompletionList.CompletionData;
     var list = await Recommender.GetCompletionData(Text, TextArea.Caret.Offset - 1);
     foreach (var item in list)
     {
         data.Add(item);
     }
     if (0 < data.Count)
     {
         _completionWindow.Show();
         _completionWindow.Closed += (obj, e) => _completionWindow = null;
     }
     else
     {
         _completionWindow = null;
     }
 }
Beispiel #12
0
 public CommandResult Complete(WishArgs wishArgs)
 {
     var command = _repl.Read(wishArgs.TextEditor.Text);
     var args = command.Arguments.ToList();
     string completionTarget;
     List<string> completions;
     if(args.Any())
     {
         var arg = args.Last();
         completionTarget = arg.PartialPath.CompletionTarget;
         completions = command.Complete().ToList();
     }
     else
     {
         completionTarget = command.Function.Name;
         completions = command.Function.Complete().ToList();
     }
     if(completions.Count() == 0) return new CommandResult { FullyProcessed = true, Handled = true };
     _completionWindow = new CompletionWindow(wishArgs.TextEditor.TextArea)
                                      {
                                          SizeToContent = SizeToContent.WidthAndHeight,
                                          MinWidth = 150
                                      };
     var completionData = _completionWindow.CompletionList.CompletionData;
     foreach (var completion in completions)
     {
         completionData.Add(new CompletionData(completionTarget, completion));
     }
     if (completionData.Count == 0) return new CommandResult { FullyProcessed = true, Handled = true };
     _completionWindow.Show();
     _completionWindow.Closed += delegate
                                     {
                                         wishArgs.OnClosed.Invoke();
                                         _completionWindow = null;
                                     };
     return new CommandResult{ FullyProcessed = true, Handled = false, State = Common.State.Tabbing  };
 }
        protected void showCodeCompletion(DomParser.KeysCommand cmd)
        {
            if(completionWindow != null) {
                return;
            }
            if(dom == null) {
                Log.Debug("Use the codeCompletionInit() for work with Code Completion");
                return;
            }

            IEnumerable<ICompletionData> data = dom.find(_.TextArea.Document.Text, _.TextArea.Caret.Offset, cmd);
            if(data == null) {
                return;
            }

            completionWindow = new CompletionWindow(_.TextArea) { Width = 270 };
            completionWindow.Closed += delegate {
                completionWindow = null;
            };

            foreach(ICompletionData item in data) {
                completionWindow.CompletionList.CompletionData.Add(item);
            }
            completionWindow.Show();
        }
        //Executed after key press
        void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            if (e.Text == ".") {
                // open code completion after the user has pressed dot:
                completionWindow = new CompletionWindow(textEditor.TextArea);
                // provide AvalonEdit with the data:
                IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                data.Add(new MyCompletionData("Item1"));
                data.Add(new MyCompletionData("Item2"));
                data.Add(new MyCompletionData("Item3"));
                data.Add(new MyCompletionData("Another item"));
                completionWindow.Show();
                completionWindow.Closed += delegate {
                    completionWindow = null;
                };
            }

            if (e.Text == "\n") {
                if (textualContent.LogOrPrintResult() == TextualContent.LogOrPrint.print) {
                    writeText(textualContent.OutputString);
                } if (textualContent.LogOrPrintResult() == TextualContent.LogOrPrint.log) {
                    printText(textualContent.OutputString);
                }
            }
        }
Beispiel #15
0
 private void TextEntered(object sender, TextCompositionEventArgs e)
 {
     UpdateUndoRedoEnabled();
     if (e.Text == "<")
     {
         m_completionWindow = new CompletionWindow(textEditor.TextArea);
         dynamic data = m_completionWindow.CompletionList.CompletionData;
         data.Add(new CompletionData("object"));
         data.Add(new CompletionData("command"));
         m_completionWindow.Show();
         m_completionWindow.Closed += m_completionWindow_Closed;
     }
 }
Beispiel #16
0
        void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            completionWindow = new CompletionWindow(editor.TextArea);

            data = completionWindow.CompletionList.CompletionData;
            data.Clear();

            if (e.Text == "." && e.Text == ";")
            {
                return;
            }
            else if (e.Text == "(")
            {
                insightWindow = new OverloadInsightWindow(editor.TextArea);
                insightWindow.Provider = new OverloadProvider();

                insightWindow.Show();
                insightWindow.Closed += (o, args) => insightWindow = null;
            }

            else
            {
                foreach (var func in Functions)
                {
                    data.Add(new MyCompletionData(func.Name, Properties.Resources.Method_636));
                }
                data.AddRange("function|delete|break|continue");

                foreach (var obj in objects)
                {
                    if(obj is Delegate)
                    {
                        data.Add(new MyCompletionData(obj.Key, Properties.Resources.Method_636));
                    }
                    else
                    {
                        data.Add(new MyCompletionData(obj.Key, Properties.Resources.Object_554));
                    }
                }
            }

            if (data.Any())
            {
                completionWindow.Show();
            }

            completionWindow.Closed += delegate
            {
                completionWindow = null;
            };
        }
Beispiel #17
0
        private void codeEditor_TextEntered(object sender, TextCompositionEventArgs e)
        {
            if (e.Text == ".")
            {
                ICSharpCode.AvalonEdit.Editing.TextArea area = (sender as ICSharpCode.AvalonEdit.Editing.TextArea);
                ICSharpCode.AvalonEdit.Document.TextDocument doc = area.Document;
                int startoff = area.Caret.Offset-1;
                int off = area.Caret.Offset-2;
                while (true)
                {
                    char o = doc.GetCharAt(off);
                    if (!char.IsLetter(o))
                        break;
                    if (off == 0)
                        break;
                    off--;
                }
                string prevToken = doc.GetText(off, startoff - off);

                // Open code completion after the user has pressed dot:
                completionWindow = new CompletionWindow(CodeEditor.TextArea);
                completionWindow.Margin = new Thickness(0);
                IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                try
                {
                    List<string> items = CompletionDatabase.completionDatabase[prevToken];
                    foreach (string item in items)
                        data.Add(new CompletionData(item));
                    completionWindow.Show();
                    completionWindow.Closed += delegate
                    {
                        completionWindow = null;
                    };
                }catch(Exception)
                {

                }
            }
        }
        private void ShowCompletion(string enteredText, bool controlSpace)
        {
            if (!controlSpace)
                Debug.WriteLine("Code Completion: TextEntered: " + enteredText);
            else
                Debug.WriteLine("Code Completion: Ctrl+Space");

            //only process csharp files
            if (String.IsNullOrEmpty(textEditor.Document.FileName))
                return;
            var fileExtension = Path.GetExtension(textEditor.Document.FileName);
            fileExtension = fileExtension != null ? fileExtension.ToLower() : null;
            //check file extension to be a c# file (.cs, .csx, etc.)
            if (fileExtension == null || (!fileExtension.StartsWith(".cs")))
                return;

            if (completionWindow == null)
            {
                CodeCompletionResult results = null;
                try
                {
                    results = CSharpCompletion.GetCompletions(textEditor.Document, textEditor.CaretOffset, controlSpace);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine("Error in getting completion: " + exception);
                }
                if (results == null)
                    return;

                if (insightWindow == null && results.OverloadProvider != null)
                {
                    insightWindow = new OverloadInsightWindow(textEditor.TextArea);
                    insightWindow.Provider = results.OverloadProvider;
                    insightWindow.Show();
                    insightWindow.Closed += (o, args) => insightWindow = null;
                    return;
                }

                if (completionWindow == null && results != null && results.CompletionData.Any())
                {
                    // Open code completion after the user has pressed dot:
                    completionWindow = new CompletionWindow(textEditor.TextArea);
                    completionWindow.CloseWhenCaretAtBeginning = controlSpace;
                    completionWindow.StartOffset -= results.TriggerWordLength;
                    //completionWindow.EndOffset -= results.TriggerWordLength;

                    IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                    foreach (var completion in results.CompletionData.OrderBy(item => item.Text))
                    {
                        data.Add(completion);
                    }
                    if (results.TriggerWordLength > 0)
                    {
                        //completionWindow.CompletionList.IsFiltering = false;
                        completionWindow.CompletionList.SelectItem(results.TriggerWord);
                    }
                    completionWindow.Show();
                    completionWindow.Closed += (o, args) => completionWindow = null;
                }
            }//end if

            //update the insight window
            if (!string.IsNullOrEmpty(enteredText) && insightWindow != null)
            {
                //whenver text is entered update the provider
                var provider = insightWindow.Provider as CSharpOverloadProvider;
                if (provider != null)
                {
                    //since the text has not been added yet we need to tread it as if the char has already been inserted
                    provider.Update(textEditor.Document, textEditor.CaretOffset);
                    //if the windows is requested to be closed we do it here
                    if (provider.RequestClose)
                    {
                        insightWindow.Close();
                        insightWindow = null;
                    }
                }
            }
        }
        private void ShowCompletionWindow(IEnumerable<ICompletionData> completions, bool completeWhenTyping = false)
        {
            // TODO: Need to make this more efficient by instantiating 'completionWindow'
            // just once and updating its contents each time

            // This implementation has been referenced from
            // http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor
            if (completionWindow != null)
            {
                completionWindow.Close();
            }

            completionWindow = new CompletionWindow(this.InnerTextEditor.TextArea)
            {
                AllowsTransparency = true,
                SizeToContent = SizeToContent.WidthAndHeight
            };

            if (completeWhenTyping)
            {
                // As opposed to complete on '.', in complete while typing mode 
                // the first character typed should also be considered for matches
                // while generating options in completion window
                completionWindow.StartOffset--;

                // As opposed to complete on '.', in complete while typing mode 
                // erasing the first character of the string being completed
                // should close the completion window
                completionWindow.CloseWhenCaretAtBeginning = true;
            }

            var data = completionWindow.CompletionList.CompletionData;

            foreach (var completion in completions)
                data.Add(completion);

            completionWindow.Closed += delegate
            {
                completionWindow = null;
            };

            completionWindow.Show();
        }
Beispiel #20
0
        private async Task ShowCompletion(bool controlSpace)
        {
            if (CompletionProvider == null)
            {
                return;
            }

            if (_completionWindow == null)
            {
                int offset;
                GetCompletionDocument(out offset);
                var completionChar = controlSpace ? (char?)null : Document.GetCharAt(offset - 1);
                var results = await CompletionProvider.GetCompletionData(offset + PreText.Length, completionChar).ConfigureAwait(true);
                if (_insightWindow == null && results.OverloadProvider != null)
                {
                    _insightWindow = new OverloadInsightWindow(TextArea)
                    {
                        Provider = results.OverloadProvider,
                        Background = CompletionBackground,
                    };
                    _insightWindow.Show();
                    _insightWindow.Closed += (o, args) => _insightWindow = null;
                    return;
                }

                if (_completionWindow == null && results.CompletionData.Any())
                {
                    // Open code completion after the user has pressed dot:
                    _completionWindow = new CompletionWindow(TextArea)
                    {
                        Background = CompletionBackground,
                        CloseWhenCaretAtBeginning = controlSpace
                    };
                    if (completionChar != null && char.IsLetterOrDigit(completionChar.Value))
                    {
                        _completionWindow.StartOffset -= 1;
                    }

                    var data = _completionWindow.CompletionList.CompletionData;
                    ICompletionDataEx selected = null;
                    foreach (var completion in results.CompletionData) //.OrderBy(item => item.SortText))
                    {
                        if (completion.IsSelected)
                        {
                            selected = completion;
                        }
                        data.Add(completion);
                    }
                    if (selected != null)
                    {
                        _completionWindow.CompletionList.SelectedItem = selected;
                    }
                    _completionWindow.Show();
                    _completionWindow.Closed += (o, args) =>
                    {
                        _completionWindow = null;
                    };
                }
            }

            //if (!string.IsNullOrEmpty(enteredText) && _insightWindow != null)
            //{
            //    //whenver text is entered update the provider
            //    var provider = _insightWindow.Provider as CSharpOverloadProvider;
            //    if (provider != null)
            //    {
            //        //since the text has not been added yet we need to tread it as if the char has already been inserted
            //        var offset = 0;
            //        var doc = GetCompletionDocument(out offset);
            //        provider.Update(doc, offset);
            //        //if the windows is requested to be closed we do it here
            //        if (provider.RequestClose)
            //        {
            //            _insightWindow.Close();
            //            _insightWindow = null;
            //        }
            //    }
            //}
        }
Beispiel #21
0
 private void OpenCompletionWindow(IEnumerable<CompletionData> completions)
 {
     if (this._completionWindow != null) return;
     var wnd = new CompletionWindow(this.TextArea);
     wnd.Closed += (o, e) =>
     {
         if (this._completionWindow == wnd)
             this._completionWindow = null;
     };
     var elems = wnd.CompletionList.CompletionData;
     completions.ForEach(wnd.CompletionList.CompletionData.Add);
     // insert elements
     this._completionWindow = wnd;
     wnd.Show();
 }
 void tbEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
 {
     if (e.Text == ".")
     {
         // open code completion after the user has pressed dot:
         completionWindow = new CompletionWindow(tbEditor.TextArea);
         // provide AvalonEdit with the data:
         IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
         data.Add(new CoolCompletionData("Item1"));
         data.Add(new CoolCompletionData("Item2"));
         data.Add(new CoolCompletionData("Item3"));
         data.Add(new CoolCompletionData("Another item"));
         completionWindow.Show();
         completionWindow.Closed += delegate
         {
             completionWindow = null;
         };
     }
 }
        private async Task ShowCompletion(TriggerMode triggerMode)
        {
            if (CompletionProvider == null)
            {
                return;
            }

            int offset;
            GetCompletionDocument(out offset);
            var completionChar = triggerMode == TriggerMode.Text ? Document.GetCharAt(offset - 1) : (char?)null;
            var results = await CompletionProvider.GetCompletionData(offset, completionChar,
                        triggerMode == TriggerMode.SignatureHelp).ConfigureAwait(true);
            if (results.OverloadProvider != null)
            {
                results.OverloadProvider.Refresh();

                if (_insightWindow != null && _insightWindow.IsVisible)
                {
                    _insightWindow.Provider = results.OverloadProvider;
                }
                else
                {
                    _insightWindow = new OverloadInsightWindow(TextArea)
                    {
                        Provider = results.OverloadProvider,
                        Background = CompletionBackground,
                        Style = TryFindResource(typeof(InsightWindow)) as Style
                    };
                    _insightWindow.Show();
                    _insightWindow.Closed += (o, args) => _insightWindow = null;
                }
                return;
            }

            if (_completionWindow == null && results.CompletionData?.Any() == true)
            {
                _insightWindow?.Close();

                // Open code completion after the user has pressed dot:
                _completionWindow = new CompletionWindow(TextArea)
                {
                    MinWidth = 200,
                    Background = CompletionBackground,
                    CloseWhenCaretAtBeginning = triggerMode == TriggerMode.Completion
                };
                if (completionChar != null && char.IsLetterOrDigit(completionChar.Value))
                {
                    _completionWindow.StartOffset -= 1;
                }

                var data = _completionWindow.CompletionList.CompletionData;
                ICompletionDataEx selected = null;
                foreach (var completion in results.CompletionData) //.OrderBy(item => item.SortText))
                {
                    if (completion.IsSelected)
                    {
                        selected = completion;
                    }
                    data.Add(completion);
                }
                if (selected != null)
                {
                    _completionWindow.CompletionList.SelectedItem = selected;
                }
                _completionWindow.Show();
                _completionWindow.Closed += (o, args) => { _completionWindow = null; };
            }
        }
Beispiel #24
0
        private void ShowCodeCompletionsCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            if (!EnableCodeCompletion)
                return;

            // Open code completion window
            completionWindow = new CompletionWindow(TextArea);
            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
            codeCompleter.GetCompletions(Document, CaretOffset, data);
            // use the word at current cursor position to filter the list 
            // (i.e., if we type bla<CTRL+SPACE>, the list should be filtered by bla
            int LineStartOffset = Document.GetLineByOffset(CaretOffset).Offset;
            string curLineToCursor = Document.GetText(LineStartOffset, CaretOffset - LineStartOffset);
            string[] words = Regex.Split(curLineToCursor, @"\W+"); // split at non-word characters
            if (words.Length > 0 && words.Last() != "")
            {
                completionWindow.CompletionList.SelectItem(words.Last());
                completionWindow.StartOffset = CaretOffset - words.Last().Length;
            }

            completionWindow.Show();
            completionWindow.Closed += delegate
            {
                completionWindow = null;
            };
        }
        void ValueCompletionAvailable(object sender, ValueCompletionEventArgs e)
        {
            _completionWindow = new CompletionWindow(txtPlugin.TextArea);

            var data = _completionWindow.CompletionList.CompletionData;
            foreach (var tag in e.Suggestions)
                data.Add(new XMLValueCompletionData(tag));

            _completionWindow.Show();
        }
Beispiel #26
0
        private void TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            Debug.WriteLine("TextArea_TextEntered:" + e.Text);

            if (completionWindow == null &&
                (e.Text == "." || e.Text == " " || e.Text == "\t" || e.Text == "(" || e.Text == "["))
            {
                // Open code completion after the user has pressed dot:
                completionWindow = new CompletionWindow(Editor.TextArea);
                completionWindow.Width = 300;
                var data = completionWindow.CompletionList.CompletionData;
                _workspace.GetIntellisenseItems(this._document, Editor.CaretOffset, e.Text != ".", Editor.Text, null, data);
                completionWindow.Show();
                completionWindow.Closed += delegate
                {
                    completionWindow = null;
                };
            }

            if (e.Text == "\n")
            {
                this.Validated();
                this.OnValueChanged?.Invoke(this, null);
            }
        }
        private void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            if (e.Text == "<")
            {
                // open code completion after the user has pressed dot:
                completionWindow = new CompletionWindow(textEditor.TextArea);
                // provide AvalonEdit with the data:
                IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                foreach (IScriptCommand command in ServiceProvider.ScriptManager.AvaiableCommands)
                {
                    data.Add(new MyCompletionData(command.DefaultValue, command.Description, command.Name.ToLower()));
                }
                completionWindow.Show();
                completionWindow.Closed += delegate { completionWindow = null; };
            }
            if (e.Text == ".")
            {
                string word = textEditor.GetWordBeforeDot();
                if (word == "{session" || word == "session")
                {
                    IList<PropertyInfo> props = new List<PropertyInfo>(typeof (PhotoSession).GetProperties());
                    completionWindow = new CompletionWindow(textEditor.TextArea);
                    // provide AvalonEdit with the data:
                    IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                    foreach (PropertyInfo prop in props)
                    {
                        //object propValue = prop.GetValue(myObject, null);
                        if (prop.PropertyType == typeof (string) || prop.PropertyType == typeof (int) ||
                            prop.PropertyType == typeof (bool))
                        {
                            data.Add(new MyCompletionData(prop.Name.ToLower(), "", prop.Name.ToLower()));
                        }
                        // Do something with propValue
                    }
                    completionWindow.Show();
                    completionWindow.Closed += delegate { completionWindow = null; };
                }
                if (word == "{camera" && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
                {
                    completionWindow = new CompletionWindow(textEditor.TextArea);
                    IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                    CameraPreset preset = new CameraPreset();
                    preset.Get(ServiceProvider.DeviceManager.SelectedCameraDevice);
                    foreach (ValuePair value in preset.Values)
                    {
                        data.Add(new MyCompletionData(value.Name.Replace(" ", "").ToLower(),
                                                      "Current value :" + value.Value,
                                                      value.Name.Replace(" ", "").ToLower()));
                    }
                    completionWindow.Show();
                    completionWindow.Closed += delegate { completionWindow = null; };
                }
            }
            if (e.Text == " ")
            {
                string line = textEditor.GetLine();

                if (line.StartsWith("setcamera"))
                {
                    if (!line.Contains("property") && !line.Contains("value"))
                    {
                        completionWindow = new CompletionWindow(textEditor.TextArea);
                        IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                        data.Add(new MyCompletionData("property", "", "property"));
                        completionWindow.Show();
                        completionWindow.Closed += delegate { completionWindow = null; };
                    }
                    if (line.Contains("property") && !line.Contains("value"))
                    {
                        completionWindow = new CompletionWindow(textEditor.TextArea);
                        IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                        data.Add(new MyCompletionData("value", "", "value"));
                        completionWindow.Show();
                        completionWindow.Closed += delegate { completionWindow = null; };
                    }
                }
            }


            if (e.Text == "=" && ServiceProvider.DeviceManager.SelectedCameraDevice != null)
            {
                string line = textEditor.GetLine();
                string word = textEditor.GetWordBeforeDot();
                if (line.StartsWith("setcamera"))
                {
                    if (word == "property")
                    {
                        completionWindow = new CompletionWindow(textEditor.TextArea);
                        IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
                        data.Add(new MyCompletionData("\"" + "aperture" + "\"", "", "aperture"));
                        data.Add(new MyCompletionData("\"" + "iso" + "\"", "", "iso"));
                        data.Add(new MyCompletionData("\"" + "shutter" + "\"", "", "shutter"));
                        data.Add(new MyCompletionData("\"" + "ec" + "\"", "Exposure Compensation", "ec"));
                        data.Add(new MyCompletionData("\"" + "wb" + "\"", "White Balance", "wb"));
                        data.Add(new MyCompletionData("\"" + "cs" + "\"", "Compression Setting", "cs"));
                        completionWindow.Show();
                        completionWindow.Closed += delegate { completionWindow = null; };
                    }
                    if (word == "value")
                    {
                        if (line.Contains("property=\"aperture\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.FNumber != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (string value in ServiceProvider.DeviceManager.SelectedCameraDevice.FNumber.Values)
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                        if (line.Contains("property=\"iso\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.IsoNumber != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (string value in ServiceProvider.DeviceManager.SelectedCameraDevice.IsoNumber.Values
                                )
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                        if (line.Contains("property=\"shutter\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.ShutterSpeed != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (
                                string value in ServiceProvider.DeviceManager.SelectedCameraDevice.ShutterSpeed.Values)
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                        if (line.Contains("property=\"ec\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.ExposureCompensation != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (
                                string value in
                                    ServiceProvider.DeviceManager.SelectedCameraDevice.ExposureCompensation.Values)
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                        if (line.Contains("property=\"wb\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.WhiteBalance != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (
                                string value in
                                    ServiceProvider.DeviceManager.SelectedCameraDevice.WhiteBalance.Values)
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                        if (line.Contains("property=\"cs\"") &&
                            ServiceProvider.DeviceManager.SelectedCameraDevice.CompressionSetting != null)
                        {
                            completionWindow = new CompletionWindow(textEditor.TextArea);
                            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                            foreach (
                                string value in
                                    ServiceProvider.DeviceManager.SelectedCameraDevice.CompressionSetting.Values)
                            {
                                data.Add(new MyCompletionData("\"" + value + "\"", value, value));
                            }
                            completionWindow.Show();
                            completionWindow.Closed += delegate { completionWindow = null; };
                        }
                    }
                }
            }
        }
        private void TextArea_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
            {
                if (e.Key == Key.Space) // show intelli seince
                {
                    e.Handled = true;

                    mIntelliSeinceWindow = new CompletionWindow(this);
                    mIntelliSeinceWindow.CompletionList.CompletionData.Clear();
                    mIntelliSeinceWindow.CompletionList.CompletionData.AddRange(IntelliSienceManager.IntelliSienceCollection);
                    mIntelliSeinceWindow.Show();
                    mIntelliSeinceWindow.Closed += (se, ee) => mIntelliSeinceWindow = null;

                    var filter = this.CurrentWordToCursor;
                    if (filter != "")
                    {
                        mIntelliSeinceWindow.CompletionList.IsFiltering = true;
                        mIntelliSeinceWindow.CompletionList.SelectItem(filter);
                    }
                }
            }
            if (e.Key == Key.Escape) // cencel
            {
                if (mToolTip != null && mToolTip.IsOpen)
                {
                    mToolTip.IsOpen = false;
                    mToolTip = null;
                }
            }
        }
Beispiel #29
0
        void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
        {
            try
            {
                if (e.Text == ".")
                {
                    _completionWindow = new CompletionWindow(_editWindow.editText.TextArea);
                    var data = _completionWindow.CompletionList.CompletionData;

                    var completions =
                        _completionProvider.GetCompletionData(_editWindow.editText.Text.Substring(0,
                                                                                                _editWindow.editText
                                                                                                          .CaretOffset));

                    if (completions.Length == 0)
                        return;

                    foreach (var ele in completions)
                    {
                        data.Add(ele);
                    }

                    _completionWindow.Show();

                    _completionWindow.Closed += delegate
                        {
                            _completionWindow = null;
                        };
                }
            }
            catch (Exception ex)
            {
                DynamoLogger.Instance.Log("Failed to perform python autocomplete with exception:");
                DynamoLogger.Instance.Log(ex.Message);
                DynamoLogger.Instance.Log(ex.StackTrace);
            }
        }
Beispiel #30
0
        public void ShowCompletionWindow(int offset, string enteredText, bool isDelimiter)
        {
            if (IsShowingCompletionWindow)
                return;

            IsShowingCompletionWindow = true;

            // create window
            completionWindow = new CompletionWindow(Editor.TextArea);
            completionWindow.StartOffset = offset;

            // data
            foreach (var item in completionItems)
                completionWindow.CompletionList.CompletionData.Add(item);

            //// tooltip
            //completionWindow.ToolTip = new ToolTip() {
            //    HorizontalOffset = 20,
            //};

            // select text
            if (!isDelimiter)
                completionWindow.CompletionList.SelectItem(enteredText);

            // show
            completionWindow.Show();

            // events
            completionWindow.Closed += (s, e) => {
                IsShowingCompletionWindow = false;
            };
        }