The code completion window.
Inheritance: CompletionWindowBase
Esempio n. 1
1
        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;
                };
            }
        }
Esempio n. 2
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 != '_';
     };
 }
Esempio n. 3
0
		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, "/") + ">");
			}
		}
Esempio n. 4
0
        private void OnKeyReleased(object sender, KeyEventArgs e)
        {
            // If we press the backspace key when completionWindow is open, we
            // close the window.
            if ((e.Key == Key.Back || e.Key == Key.Space) && _completionWindow != null)
            {
                _completionWindow.Close();
                _completionWindow = null;

                return;
            }

            // If enter or tab is pressed when the completionWindow is open,
            // request insertion of the selected word.
            if ((e.Key == Key.Enter || e.Key == Key.Tab) && _completionWindow != null)
            {
                _completionWindow.CompletionList.RequestInsertion(e);

                return;
            }

            // Debugging
            if (_debuggerService.IsActiveDebugging)
            {
                switch (e.Key)
                {
                    case Key.F10:
                        _debuggerService.StepOver();
                        break;
                    case Key.F11:
                        _debuggerService.StepInto();
                        break;
                }
            }
        }
        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;
        }
		public ScriptEditDialog(string text) : base("Script edit", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) {
			InitializeComponent();
			Extensions.SetMinimalSize(this);

			AvalonLoader.Load(_textEditor);
			AvalonLoader.SetSyntax(_textEditor, "Script");

			string script = ItemParser.Format(text, 0);
			_textEditor.Text = script;
			_textEditor.TextArea.TextEntered += new TextCompositionEventHandler(_textArea_TextEntered);
			_textEditor.TextArea.TextEntering += new TextCompositionEventHandler(_textArea_TextEntering);

			_completionWindow = new CompletionWindow(_textEditor.TextArea);
			_li = _completionWindow.CompletionList;
			ListView lv = _li.ListBox;
			lv.SelectionMode = SelectionMode.Single;

			//Image
			Extensions.GenerateListViewTemplate(lv, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
				new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "Image", TextAlignment = TextAlignment.Center, FixedWidth = 22, MaxHeight = 22, SearchGetAccessor = "Commands"},
				new ListViewDataTemplateHelper.GeneralColumnInfo {Header = "Commands", DisplayExpression = "Text", TextAlignment = TextAlignment.Left, IsFill = true, ToolTipBinding = "Description"}
			}, null, new string[] { }, "generateHeader", "false");

			_completionWindow.Content = null;
			_completionWindow = null;

			WindowStartupLocation = WindowStartupLocation.CenterOwner;
		}
        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();
            }
        }
Esempio n. 8
0
        private void OnTextEntered(object sender, TextCompositionEventArgs e)
        {
            if (CaretOffset <= 0) return;

            var isTrigger = _scriptManager.IsCompletionTriggerCharacter(CaretOffset - 1);
            if (!isTrigger) return;

            _completionWindow = new CompletionWindow(TextArea);

            var data = _completionWindow.CompletionList.CompletionData;

            var completion = _scriptManager.GetCompletion(CaretOffset, Text[CaretOffset - 1]).ToList();
            if (!completion.Any())
            {
                _completionWindow = null;
                return;
            }

            foreach (var completionData in completion)
            {
                data.Add(new CompletionData(completionData));
            }

            _completionWindow.Show();
            _completionWindow.Closed += (o, args) => _completionWindow = null;
        }
Esempio n. 9
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();
        }
Esempio n. 10
0
        /// <summary>
        /// Makes suggestsions for auto-completion
        /// </summary>
        /// <param name="suggestions">Suggestions</param>
        public override void Suggest(IEnumerable <ICompletionData> suggestions)
        {
            bool mustShow = false;

            if (this._c == null)
            {
                this._c = new AvComplete.CompletionWindow(this.Control.TextArea);
                this._c.SizeToContent             = System.Windows.SizeToContent.WidthAndHeight;
                this._c.StartOffset               = this.CaretOffset - 1;
                this._c.CloseAutomatically        = true;
                this._c.CloseWhenCaretAtBeginning = true;
                this._c.Closed += (sender, args) =>
                {
                    this.EndSuggestion();
                    this.AutoCompleter.DetectState();
                };
                this._c.KeyDown += (sender, args) =>
                {
                    if (args.Key == Key.Space && args.KeyboardDevice.Modifiers == ModifierKeys.Control)
                    {
                        this._c.CompletionList.RequestInsertion(args);
                        this.Control.Document.Insert(this.CaretOffset, " ");
                        args.Handled = true;
                    }
                    else if (this.AutoCompleter.State == AutoCompleteState.Keyword || this.AutoCompleter.State == AutoCompleteState.KeywordOrQName)
                    {
                        if (args.Key == Key.D9 && args.KeyboardDevice.Modifiers == ModifierKeys.Shift)
                        {
                            this._c.CompletionList.RequestInsertion(args);
                        }
                        else if (args.Key == Key.OemOpenBrackets && args.KeyboardDevice.Modifiers == ModifierKeys.Shift)
                        {
                            this._c.CompletionList.RequestInsertion(args);
                            this.Control.Document.Insert(this.CaretOffset, " ");
                        }
                    }
                    else if (this.AutoCompleter.State == AutoCompleteState.Variable || this.AutoCompleter.State == AutoCompleteState.BNode)
                    {
                        if (args.Key == Key.D0 && args.KeyboardDevice.Modifiers == ModifierKeys.Shift)
                        {
                            this._c.CompletionList.RequestInsertion(args);
                        }
                    }
                };
                mustShow = true;
            }
            foreach (ICompletionData data in suggestions)
            {
                this._c.CompletionList.CompletionData.Add(new WpfCompletionData(data));
            }
            if (mustShow)
            {
                this._c.Show();
            }
        }
 protected void SetupCompletionWindow(TextArea area)
 {
     this._c = new CompletionWindow(area);
     this._c.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
     this._c.CompletionList.InsertionRequested += new EventHandler(CompletionList_InsertionRequested);
     this._c.CloseAutomatically = true;
     this._c.CloseWhenCaretAtBeginning = true;
     this._c.Closed += new EventHandler(this.CompletionWindowClosed);
     this._c.KeyDown += new KeyEventHandler(CompletionWindowKeyDown);
     this._startOffset = this._c.StartOffset;
 }
Esempio n. 12
0
 /// <summary>
 /// Ends auto-complete suggestion
 /// </summary>
 public override void EndSuggestion()
 {
     if (this._c != null)
     {
         this._c.Close();
         this._c = null;
     }
     if (this.AutoCompleter != null)
     {
         this.AutoCompleter.State = AutoCompleteState.None;
     }
 }
    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();
    }
 private void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
 {
     if (e.Text != ".") return;
     // open code completion after the user has pressed dot:
     completionWindow = new CompletionWindow(TextEditor.TextArea);
     // provide AvalonEdit with the data:
     var 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; };
 }
 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; };
     }
 }
Esempio n. 16
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();
 }
        CompletionWindow CreateNewCompletionWindow() {

            if(_completionWindow != null)
                _completionWindow.Close();

            _completionWindow = new CompletionWindow(_texteditor.TextArea);
            //_completionWindow.CompletionList.IsFiltering = false;
            _completionWindow.StartOffset -= 1;

            _completionWindow.Closed += delegate
            {
                _completionWindow = null;
            };
            return _completionWindow;
        }
Esempio n. 18
0
        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;
            };
        }
Esempio n. 19
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;
     }
 }
		private void _update() {
			// Open code completion after the user has pressed dot:
			if (_completionWindow == null || !_completionWindow.IsVisible) {
				if (_li.Parent != null) {
					((CompletionWindow)_li.Parent).Content = null;
				}

				_completionWindow = new CompletionWindow(_textEditor.TextArea, _li);
				_completionWindow.Changed += new EventHandler(_completionWindow_Changed);

				_completionWindow.Closed += delegate {
					if (_completionWindow != null) _completionWindow.Content = null;
					_completionWindow = null;
				};
			}

			RangeObservableCollectionX<ICompletionData> data = (RangeObservableCollectionX<ICompletionData>)_li.CompletionData;
			data.Clear();

			string word = AvalonLoader.GetWholeWord(_textEditor.TextArea.Document, _textEditor);

			List<string> words = ScriptEditorList.Words.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList();
			List<string> constants = ScriptEditorList.Constants.Where(p => p.IndexOf(word, StringComparison.OrdinalIgnoreCase) != -1).OrderBy(p => p).ToList();

			if (words.Count == 0 && constants.Count == 0) {
				_completionWindow.Close();
				return;
			}

			IEnumerable<ICompletionData> results = words.Select(p => (ICompletionData)new MyCompletionData(p, _textEditor, DataType.Function)).
				Concat(constants.Select(p => (ICompletionData)new MyCompletionData(p, _textEditor, DataType.Constant)));

			data.AddRange(results);

			_completionWindow.CompletionList.ListBox.ItemsSource = data;

			_completionWindow.Show();
			_completionWindow.CompletionList.SelectedItem = _completionWindow.CompletionList.CompletionData.FirstOrDefault(p => String.Compare(p.Text, word, StringComparison.OrdinalIgnoreCase) >= 0);
			TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_completionWindow.CompletionList.ListBox, _completionWindow.CompletionList.SelectedItem);
		}
Esempio n. 22
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  };
 }
Esempio n. 23
0
        private CompletionSelection(CompletionContext context, Action onComplete)
        {
            _context = context;
            _onComplete = onComplete;
            ResultSet results = _context.ResultProvider.GetResults(_context.Path.Str, _context.Line, _context.Column, this);
            if (results == null)
                throw new System.Exception();

            _completionWindow = new CompletionWindow(_context.TextArea);
            foreach (IResult cd in results.Results)
            {
                _completionWindow.CompletionList.CompletionData.Add(cd);
            }

            _completionWindow.StartOffset = _context.Offset;
            _completionWindow.EndOffset = _completionWindow.StartOffset + _context.TriggerWord.Length;

            if (_context.TriggerWord.Length > 0)
            {
                _completionWindow.CompletionList.SelectItem(_context.TriggerWord);
                if(_completionWindow.CompletionList.SelectedItem == null) //nothing to display
                {
                    _completionWindow = null;
                    _onComplete();
                    ;return;
                }
            }

            _completionWindow.Show();
            
            _completionWindow.Closed += (o, args) =>
            {   
                _completionWindow = null;
                _onComplete();
            };
        }
Esempio n. 24
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);
            }
        }
Esempio n. 25
0
        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; };
            }
        }
        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; };
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        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();
        }
Esempio n. 28
0
        private void ShowCompletion(string text, bool controlSpace)
        {
            if (string.IsNullOrEmpty(Document.FileName) || this.IsCaretInString() == true)
            {
                return;
            }

            if (this.completionWindow == null)
            {
                this.completionWindow = new CompletionWindow(this.TextArea);
                this.completionWindow.CloseWhenCaretAtBeginning = controlSpace;
                IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;

                foreach (ICompletionData completion in this.Completion.GetCompletions().OrderBy(item => item.Text))
                {
                    data.Add(completion);
                }

                this.completionWindow.Show();
                this.completionWindow.Closed += (sender, e) => completionWindow = null;
            }

            this.completionWindow.StartOffset--;
        }
Esempio n. 29
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;
     }
 }
Esempio n. 30
0
 void m_completionWindow_Closed(object sender, EventArgs e)
 {
     m_completionWindow.Closed -= m_completionWindow_Closed;
     m_completionWindow = null;
 }
Esempio n. 31
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;
            };
        }
Esempio n. 32
0
 public InputHandler(CompletionWindow window)
 {
     Debug.Assert(window != null);
     this.window = window;
 }
Esempio n. 33
0
        void ShowCodeCompletionWindow(string EnteredText)
        {
            try
            {
                if ((EnteredText != null && EnteredText.Length > 0 && !(
                    EnteredText == "@" ||
                    EnteredText == "(" ||
                    EnteredText == " " ||
                    AbstractCompletionProvider.IsIdentifierChar(EnteredText[0]) ||
                    EnteredText[0] == '.')) ||
                    !DCodeCompletionSupport.CanShowCompletionWindow(this) ||
                    Editor.IsReadOnly)
                    return;

                /*
                 * Note: Once we opened the completion list, it's not needed to care about a later refill of that list.
                 * The completionWindow will search the items that are partly typed into the editor automatically and on its own.
                 * - So there's just an initial filling required.
                 */

                if (completionWindow != null)
                    return;
                /*
                if (showCompletionWindowOperation != null &&showCompletionWindowOperation.Status != DispatcherOperationStatus.Completed)
                    showCompletionWindowOperation.Abort();
                */

                var cData = new List<ICompletionData>();

                var sw = new Stopwatch();
                sw.Start();
                DCodeCompletionSupport.BuildCompletionData(
                    this,
                    cData,
                    EnteredText,
                    out lastCompletionListResultPath);
                sw.Stop();

                if (GlobalProperties.Instance.ShowSpeedInfo)
                    CoreManager.Instance.MainWindow.ThirdStatusText = sw.ElapsedMilliseconds + "ms (Completion)";

                // If no data present, return
                if (cData.Count < 1)
                {
                    completionWindow = null;
                    return;
                }
                else
                {
                    // Init completion window

                    completionWindow = new CompletionWindow(Editor.TextArea);
                    completionWindow.CompletionList.InsertionRequested += new EventHandler(CompletionList_InsertionRequested);
                    //completionWindow.CloseAutomatically = true;

                    //HACK: Fill in data directly instead of iterating through the data
                    foreach (var e in cData)
                        completionWindow.CompletionList.CompletionData.Add(e);
                }

                // Care about item pre-selection
                var selectedString = "";

                if (lastCompletionListResultPath != null &&
                    !LastSelectedCCItems.TryGetValue(lastCompletionListResultPath, out selectedString))
                    LastSelectedCCItems.Add(lastCompletionListResultPath, "");

                if (!string.IsNullOrEmpty(selectedString))
                {
                    // Prevent hiding all items that are not named as 'selectedString' .. after having selected our item, reset the filter property
                    completionWindow.CompletionList.IsFiltering = false;
                    completionWindow.CompletionList.SelectItem(selectedString);
                    completionWindow.CompletionList.IsFiltering = true;
                }
                else // Select first item by default
                    completionWindow.CompletionList.SelectedItem = completionWindow.CompletionList.CompletionData[0];

                completionWindow.Closed += (object o, EventArgs _e) =>
                {
                    // 'Backup' the selected completion data
                    lastSelectedCompletionData = completionWindow.CompletionList.SelectedItem;
                    completionWindow = null; // After the window closed, reset it to null
                };
                completionWindow.Show();
            }
            catch (Exception ex) { ErrorLogger.Log(ex); completionWindow = null; }
        }
        public void ProcessTextEntered(object sender, System.Windows.Input.TextCompositionEventArgs e, ref ICSharpCode.AvalonEdit.CodeCompletion.CompletionWindow completionWindow)
        {
            if (HasThrownException)
            {
                return;                     // exit here if intellisense has previous thrown and exception
            }
            try
            {
                if (completionWindow != null)
                {
                    // close the completion window if it has no items
                    if (!completionWindow.CompletionList.ListBox.HasItems)
                    {
                        completionWindow.Close();
                        return;
                    }
                    // close the completion window if the current text is a 100% match for the current item
                    var txt = ((TextArea)sender).Document.GetText(new TextSegment()
                    {
                        StartOffset = completionWindow.StartOffset, EndOffset = completionWindow.EndOffset
                    });
                    var selectedItem = completionWindow.CompletionList.SelectedItem;
                    if (string.Compare(selectedItem.Text, txt, true) == 0 || string.Compare(selectedItem.Content.ToString(), txt, true) == 0)
                    {
                        completionWindow.Close();
                    }

                    return;
                }

                if (char.IsLetterOrDigit(e.Text[0]) || "\'[".Contains(e.Text[0]))
                {
                    // exit if the completion window is already showing
                    if (completionWindow != null)
                    {
                        return;
                    }

                    // exit if we are inside a string or comment
                    _daxState = ParseLine();
                    var lineState = _daxState.LineState;
                    if (lineState == LineState.String || _editor.IsInComment())
                    {
                        return;
                    }

                    // don't show intellisense if we are in the measure name of a DEFINE block
                    if (DaxLineParser.IsLineMeasureDefinition(GetCurrentLine()))
                    {
                        return;
                    }

                    // TODO add insights window for Function parameters
                    //InsightWindow insightWindow = new InsightWindow(sender as ICSharpCode.AvalonEdit.Editing.TextArea);

                    completionWindow = new CompletionWindow(sender as ICSharpCode.AvalonEdit.Editing.TextArea);
                    completionWindow.CloseAutomatically = false;

                    completionWindow.CompletionList.BorderThickness = new System.Windows.Thickness(1);

                    if (char.IsLetterOrDigit(e.Text[0]))
                    {
                        // if the window was opened by a letter or digit include it in the match segment
                        //completionWindow.StartOffset -= 1;
                        completionWindow.StartOffset = _daxState.StartOffset;
                        System.Diagnostics.Debug.WriteLine("Setting Completion Offset: {0}", _daxState.StartOffset);
                    }

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

                    switch (e.Text)
                    {
                    case "[":

                        string tableName = GetPreceedingTableName();
                        if (string.IsNullOrWhiteSpace(tableName))
                        {
                            PopulateCompletionData(data, IntellisenseMetadataTypes.Measures);
                        }
                        else
                        {
                            PopulateCompletionData(data, IntellisenseMetadataTypes.Columns, _daxState);
                        }
                        break;

                    case "'":
                        PopulateCompletionData(data, IntellisenseMetadataTypes.Tables);
                        break;

                    default:
                        switch (_daxState.LineState)
                        {
                        case LineState.Column:
                            PopulateCompletionData(data, IntellisenseMetadataTypes.Columns, _daxState);
                            break;

                        case LineState.Table:
                            PopulateCompletionData(data, IntellisenseMetadataTypes.Tables, _daxState);
                            break;

                        case LineState.Measure:
                            PopulateCompletionData(data, IntellisenseMetadataTypes.Measures);
                            break;

                        case LineState.Dmv:
                            PopulateCompletionData(data, IntellisenseMetadataTypes.DMV);
                            break;

                        default:
                            PopulateCompletionData(data, IntellisenseMetadataTypes.ALL);
                            break;
                        }
                        break;
                    }
                    if (data.Count > 0)
                    {
                        //var line = GetCurrentLine();
                        //System.Diagnostics.Debug.Assert(line.Length >= _daxState.EndOffset);
                        var txt = _editor.DocumentGetText(new TextSegment()
                        {
                            StartOffset = _daxState.StartOffset, EndOffset = _daxState.EndOffset
                        });
                        //var txt = line.Substring(_daxState.StartOffset,_daxState.EndOffset - _daxState.StartOffset);

                        completionWindow.CompletionList.SelectItem(txt);
                        // only show the completion window if we have valid items to display
                        if (completionWindow.CompletionList.ListBox.HasItems)
                        {
                            Log.Verbose("InsightWindow == null : {IsNull}", _editor.InsightWindow == null);
                            if (_editor.InsightWindow != null && _editor.InsightWindow.IsVisible)
                            {
                                Log.Verbose("hiding insight window");
                                _editor.InsightWindow.Visibility = Visibility.Collapsed;
                                //_editor.InsightWindow = null;
                            }

                            Log.Verbose("CW null: {CompletionWindowNull} CW.Vis: {CompletionWindowVisible} IW null: {insightWindowNull} IW.Vis: {InsightWindowVisible}", completionWindow == null, completionWindow.Visibility.ToString(), _editor.InsightWindow == null, completionWindow.Visibility.ToString());

                            completionWindow.Show();
                            completionWindow.Closing      += completionWindow_Closing;
                            completionWindow.PreviewKeyUp += completionWindow_PreviewKeyUp;
                            completionWindow.Closed       += delegate
                            {
                                _editor.DisposeCompletionWindow();
                            };
                        }
                        else
                        {
                            Log.Debug("{class} {method} {message}", "DaxIntellisenseProvider", "ProcessTextEntered", "Closing CompletionWindow as it has no matching items");

                            completionWindow.Close();
                            _editor.DisposeCompletionWindow();
                            completionWindow = null;
                        }
                    }
                    else
                    {
                        _editor.DisposeCompletionWindow();
                        completionWindow = null;
                    }
                }

                if (e.Text[0] == '(')
                {
                    var funcName = DaxLineParser.GetPreceedingWord(GetCurrentLine().TrimEnd('(').Trim()).ToLower();
                    Log.Verbose("Func: {Function}", funcName);
                    ShowInsight(funcName);
                }
            }
            catch (Exception ex)
            {
                HasThrownException = true;
                Log.Error("{class} {method} {exception} {stacktrace}", "DaxIntellisenseProvider", "ProcessTextEntered", ex.Message, ex.StackTrace);
                Document.OutputError(string.Format("Intellisense Disabled for this window - {0}", ex.Message));
            }
        }