public override Innovator.Client.IPromise<CompletionContext> ShowCompletions(EditorWinForm control)
    {
      var length = control.Editor.Document.TextLength;
      var caret = control.Editor.CaretOffset;
      var data = new CompletionContext();

      if (caret > 0)
      {
        string[][] completions = null;
        if (control.Editor.Document.GetCharAt(caret - 1) == '\\')
          completions = _completionInfo;
        else if (control.Editor.Document.GetCharAt(caret - 1) == '$')
          completions = _replacementTypes;

        if (completions != null)
        {
          data.Items = completions
            .OrderBy(i => i[0].ToLowerInvariant())
            .ThenBy(i => i[1])
            .Select(i => new BasicCompletionData() {
              Content = GetSpan(new Run(i[0] + " "), new Run(i[1])
              {
                Foreground = Brushes.Gray
              }),
              Text = i[0],
              Action = () => i[0]
            });
        }
      }

      if (data.Items.Any())
      {
        var items = data.Items.ToArray();
        var contextItems = items.OfType<IContextCompletions>();
        foreach (var contextItem in contextItems)
        {
          contextItem.SetContext(this, control);
        }

        control.ShowCompletionWindow(items, data.Overlap);
      }

      return Promises.Resolved(data);
    }
Exemplo n.º 2
0
            public override Innovator.Client.IPromise <CompletionContext> ShowCompletions(EditorWinForm control)
            {
                var context = new CompletionContext();

                try
                {
                    var caret     = control.Editor.CaretOffset;
                    var text      = control.Editor.Text;
                    var current   = text.Substring(0, caret);
                    var lastMacro = current.LastIndexOf('$');
                    var preMacro  = lastMacro > 0 ? current.Substring(0, lastMacro).Trim() : current;

                    if (lastMacro >= 0 && current.LastIndexOf(')') < lastMacro)
                    {
                        var overlap = current.Substring(lastMacro);
                        var filter  = overlap.TrimStart('$', '(');
                        var items   = Macros.Select(m => new BasicCompletionData()
                        {
                            Text   = m,
                            Action = () => "(" + m + ")",
                            Image  = Icons.Operator16.Wpf
                        })
                                      .Where(i => i.Text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
                                      .OrderBy(i => i.Text);
                        context.Items = items;
                        control.ShowCompletionWindow(items, overlap.Length - 1);
                    }
                    else if (File.Exists(preMacro))
                    {
                        var items = Macros.Select(m => new BasicCompletionData()
                        {
                            Text   = m,
                            Action = () => "$(" + m + ")",
                            Image  = Icons.Operator16.Wpf
                        })
                                    .OrderBy(i => i.Text);
                        context.Items = items;
                        control.ShowCompletionWindow(items, 0);
                    }
                    else if (current.Length >= 3)
                    {
                        var dir     = (current.EndsWith("/") || current.EndsWith("\\")) ? current : Path.GetDirectoryName(current) + "\\";
                        var overlap = current.Length > dir.Length ? current.Substring(dir.Length) : string.Empty;
                        IEnumerable <ICompletionData> items;

                        if (dir.StartsWith(@"\\") && dir.Trim('\\').IndexOf(@"\") < 0)
                        {
                            items = ShareCollection.GetShares(dir)
                                    .Select(s => new BasicCompletionData()
                            {
                                Text  = s.NetName,
                                Image = Icons.Folder16.Wpf
                            });
                        }
                        else
                        {
                            items = new DirectoryInfo(dir).GetFileSystemInfos()
                                    .Select(e => new BasicCompletionData()
                            {
                                Text  = e.Name,
                                Image = (e.Attributes & FileAttributes.Directory) > 0 ? Icons.Folder16.Wpf : Icons.EnumValue16.Wpf
                            });
                        }
                        items = items
                                .Where(i => i.Text.IndexOf(overlap, StringComparison.OrdinalIgnoreCase) >= 0)
                                .OrderBy(i => i.Text);
                        context.Items = items;
                        control.ShowCompletionWindow(items, overlap.Length);
                    }
                }
                catch (IOException) { }
                catch (ArgumentException) { }
                return(Innovator.Client.Promises.Resolved(context));
            }
Exemplo n.º 3
0
    public override IPromise<CompletionContext> ShowCompletions(EditorWinForm control)
    {
      var length = control.Editor.Document.TextLength;
      var caret = control.Editor.CaretOffset;

      if (control.Editor.CaretOffset >= 2 && control.Editor.Document.GetText(control.Editor.CaretOffset - 2, 2) == "<!")
      {
        var context = new CompletionContext()
        {
          Items = new ICompletionData[] {
            new BasicCompletionData() {
              Text = "--",
              Content = "-- (Comment)",
              Action = () => "---->",
              CaretOffset = -3
            },
            new BasicCompletionData() {
              Text = "[CDATA[",
              Action = () => "[CDATA[]]>",
              CaretOffset = -3
            }
          }
        };

        control.ShowCompletionWindow(context.Items, context.Overlap);

        return Promises.Resolved(context);
      }
      else
      {
        return this.GetCompletions(control.Document, control.Editor.CaretOffset, this.SoapAction)
          .ToPromise()
          .UiPromise(control)
          .Convert(data => {
            if (length != control.Editor.Document.TextLength
              || caret != control.Editor.CaretOffset)
            {
              ShowCompletions(control);
              return null;
            }

            if (data.Items.Any())
            {
              var items = data.Items.ToArray();
              var contextItems = items.OfType<IContextCompletions>();
              foreach (var contextItem in contextItems)
              {
                contextItem.SetContext(this, control);
              }

              control.ShowCompletionWindow(items, data.Overlap);
            }

            return data;
          });
      }

    }
Exemplo n.º 4
0
    public override Innovator.Client.IPromise<CompletionContext> ShowCompletions(CodeEditor control)
    {
      var length = control.Editor.Document.TextLength;
      var caret = control.Editor.CaretOffset;
      var data = new CompletionContext();

      if (caret > 0 && control.Editor.Document.GetCharAt(caret - 1) == '\\')
      {
        data.Items = _completionInfo
          .OrderBy(i => i[0].ToLowerInvariant())
          .ThenBy(i => i[1])
          .Select(i => new BasicCompletionData() {
            Content = FormatText.Span(FormatText.Text(i[0] + " "), FormatText.MutedText(i[1])),
            Text = i[0],
            Action = () => i[0]
          });
      }

      if (data.Items.Any())
      {
        var items = data.Items.ToArray();
        var contextItems = items.OfType<IContextCompletions>();
        foreach (var contextItem in contextItems)
        {
          contextItem.SetContext(this, control);
        }

        control.ShowCompletionWindow(items, data.Overlap);
      }

      return Promises.Resolved(data);
    }