Пример #1
0
    private void AutocompleteCommand(string text)
    {
        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant>   variants     = new List <Variant>();

        foreach (Commander.Command command in MainForm.commander.Commands)
        {
            Variant variant = new Variant();
            variant.CompletionText = command.name;
            variant.DisplayText    = command.name + (!string.IsNullOrEmpty(command.argNames) ? " <" + command.argNames + ">" : "");
            variants.Add(variant);
        }
        if (MainForm.Settings != null)
        {
            foreach (CommandData data in MainForm.Settings.command.Value)
            {
                Variant variant = new Variant();
                variant.CompletionText = data.name;
                variant.DisplayText    = data.name + " - " +
                                         (data.sequence.Length < 50 ? data.sequence : data.sequence.Substring(0, 50) + "…");
                variants.Add(variant);
            }
            foreach (Properties.Property property in MainForm.Settings.GetProperties())
            {
                variants.Add(GetPropertyVariant(property));
            }
        }
        autocomplete.Show(variants, text);
    }
Пример #2
0
 private void CloseAutocomplete()
 {
     if (autocomplete != null)
     {
         autocomplete.Close(false);
         autocomplete = null;
     }
 }
Пример #3
0
 private void Snippets_CloseAutocomplete()
 {
     if (snippetsAutocomplete != null)
     {
         snippetsAutocomplete.Close(false);
         snippetsAutocomplete = null;
     }
 }
Пример #4
0
    public void ShowAutocomplete(List <Variant> variants, string leftWord)
    {
        CloseAutocomplete();
        Buffer buffer = buffers.list.Selected != null ? buffers.list.Selected : null;

        if (buffer == null)
        {
            return;
        }
        autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Normal);
        autocomplete.Show(variants, leftWord);
    }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the AutocompleteParameters class.
 /// </summary>
 /// <param name="autocompleteMode">Specifies the mode for Autocomplete.
 /// The default is 'oneTerm'. Use 'twoTerms' to get shingles and
 /// 'oneTermWithContext' to use the current context while producing
 /// auto-completed terms. Possible values include: 'oneTerm',
 /// 'twoTerms', 'oneTermWithContext'</param>
 /// <param name="filter">An OData expression that filters the documents
 /// used to produce completed terms for the Autocomplete
 /// result.</param>
 /// <param name="useFuzzyMatching">A value indicating whether to use
 /// fuzzy matching for the autocomplete query. Default is false. When
 /// set to true, the query will find terms even if there's a
 /// substituted or missing character in the search text. While this
 /// provides a better experience in some scenarios, it comes at a
 /// performance cost as fuzzy autocomplete queries are slower and
 /// consume more resources.</param>
 /// <param name="highlightPostTag">A string tag that is appended to hit
 /// highlights. Must be set with highlightPreTag. If omitted, hit
 /// highlighting is disabled.</param>
 /// <param name="highlightPreTag">A string tag that is prepended to hit
 /// highlights. Must be set with highlightPostTag. If omitted, hit
 /// highlighting is disabled.</param>
 /// <param name="minimumCoverage">A number between 0 and 100 indicating
 /// the percentage of the index that must be covered by an autocomplete
 /// query in order for the query to be reported as a success. This
 /// parameter can be useful for ensuring search availability even for
 /// services with only one replica. The default is 80.</param>
 /// <param name="searchFields">The list of field names to consider when
 /// querying for auto-completed terms. Target fields must be included
 /// in the specified suggester.</param>
 /// <param name="top">The number of auto-completed terms to retrieve.
 /// This must be a value between 1 and 100. The default is 5.</param>
 public AutocompleteParameters(AutocompleteMode autocompleteMode = default(AutocompleteMode), string filter = default(string), bool?useFuzzyMatching = default(bool?), string highlightPostTag = default(string), string highlightPreTag = default(string), double?minimumCoverage = default(double?), IList <string> searchFields = default(IList <string>), int?top = default(int?))
 {
     AutocompleteMode = autocompleteMode;
     Filter           = filter;
     UseFuzzyMatching = useFuzzyMatching;
     HighlightPostTag = highlightPostTag;
     HighlightPreTag  = highlightPreTag;
     MinimumCoverage  = minimumCoverage;
     SearchFields     = searchFields;
     Top = top;
     CustomInit();
 }
Пример #6
0
        /// <summary>
        ///     Gets the string value for the specified
        /// </summary>
        /// <param name="value">The value.</param>
        public static string ConvertToString(this AutocompleteMode value)
        {
            switch (value)
            {
            case AutocompleteMode.Off:
                return("off");

            case AutocompleteMode.On:
                return("on");

            default:
                return("");
            }
        }
Пример #7
0
    private void AutocompleteProperty(string text)
    {
        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant>   variants     = new List <Variant>();

        if (MainForm.Settings != null)
        {
            foreach (Properties.Property property in MainForm.Settings.GetProperties())
            {
                variants.Add(GetPropertyVariant(property));
            }
            autocomplete.Show(variants, text);
        }
    }
        internal static string ToSerializedValue(this AutocompleteMode value)
        {
            switch (value)
            {
            case AutocompleteMode.OneTerm:
                return("oneTerm");

            case AutocompleteMode.TwoTerms:
                return("twoTerms");

            case AutocompleteMode.OneTermWithContext:
                return("oneTermWithContext");
            }
            return(null);
        }
Пример #9
0
    private void AutocompleteTag(string text)
    {
        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant>   variants     = new List <Variant>();

        if (MainForm.Settings != null)
        {
            foreach (string tag in MainForm.Ctags.GetTags())
            {
                Variant variant = new Variant();
                variant.CompletionText = tag;
                variant.DisplayText    = tag;
                variants.Add(variant);
            }
            autocomplete.Show(variants, text);
        }
    }
Пример #10
0
    private void AutocompletePath(string path)
    {
        if (path == null)
        {
            return;
        }
        path = path.Replace("/", "\\").Replace("\\\\", "\\");
        string dir   = ".";
        string name  = path;
        int    index = path.LastIndexOf("\\");

        if (index != -1)
        {
            dir  = path.Substring(0, index + 1);
            name = path.Substring(index + 1);
        }
        string[] dirs = null;
        try
        {
            dirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);
        }
        catch
        {
        }
        if (dirs == null || dirs.Length == 0)
        {
            return;
        }
        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant>   variants     = new List <Variant>();

        foreach (string file in dirs)
        {
            string  fileName = Path.GetFileName(file);
            Variant variant  = new Variant();
            variant.CompletionText = fileName + "\\";
            variant.DisplayText    = fileName + "\\";
            variants.Add(variant);
        }
        autocomplete.Show(variants, name);
    }
Пример #11
0
    private void Snippets_ShowAutocomplete(List <SnippetAtom> atoms, bool erase)
    {
        Snippets_CloseAutocomplete();
        snippetsAutocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant> variants = new List <Variant>();

        foreach (SnippetAtom atom in atoms)
        {
            Variant variant = new Variant();
            variant.Index          = atom.index;
            variant.CompletionText = atom.key;
            variant.DisplayText    = atom.GetCompletionText();
            variants.Add(variant);
        }
        if (erase)
        {
            snippetsAutocomplete.onDone = Snippets_OnAutocompleteDone_Erase;
        }
        else
        {
            snippetsAutocomplete.onDone = Snippets_OnAutocompleteDone;
        }
        snippetsAutocomplete.Show(variants, "");
    }
Пример #12
0
 public Handler(AutocompleteMode mode)
 {
     this.mode = mode;
 }
Пример #13
0
    private bool DoAutocomplete(Controller controller)
    {
        string text  = textBox.Controller.Lines[0].Text;
        Place  place = textBox.Controller.Lines.PlaceOf(textBox.Controller.LastSelection.caret);

        if (place.iChar < text.Length)
        {
            text = text.Substring(0, place.iChar);
        }
        if (!text.StartsWith("!") && !text.StartsWith("<") && !text.StartsWith(">") &&
            !StartsWithReplBra(text))
        {
            if (text.IndexOf(' ') == -1 && text.IndexOf('\t') == -1)
            {
                AutocompleteCommand(text);
                return(true);
            }
            int index0 = text.IndexOf(' ');
            int index1 = text.IndexOf('\t');
            if (index0 != -1 || index1 != -1)
            {
                int spaceIndex;
                if (index0 == -1)
                {
                    spaceIndex = index1;
                }
                else if (index1 == -1)
                {
                    spaceIndex = index0;
                }
                else
                {
                    spaceIndex = Math.Min(index0, index1);
                }
                if (text.IndexOf(' ', spaceIndex + 1) == -1 && text.IndexOf('\t', spaceIndex + 1) == -1)
                {
                    string command = text.Substring(0, spaceIndex);
                    string word    = text.Substring(spaceIndex + 1);
                    if (command == "reset")
                    {
                        AutocompleteProperty(word);
                        return(true);
                    }
                    if (command == "tag")
                    {
                        AutocompleteTag(word);
                        return(true);
                    }
                    if (MainForm.Settings != null)
                    {
                        Properties.Property property = MainForm.Settings[command];
                        if (property != null)
                        {
                            List <Variant> variants = property.GetAutocompleteVariants();
                            if (variants != null)
                            {
                                AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
                                autocomplete.Show(variants, word);
                                return(true);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if ((text.StartsWith("!{") ||
                 text.StartsWith("!^{") ||
                 text.StartsWith("<{") ||
                 text.StartsWith(">{") ||
                 text.StartsWith("<>{") ||
                 StartsWithReplBra(text)) &&
                !text.Contains("}"))
            {
                int prefixIndex;
                prefixIndex = text.LastIndexOf("s:");
                if (prefixIndex != -1 && text.IndexOf(";", prefixIndex) == -1)
                {
                    List <Variant> variants = new List <Variant>();
                    foreach (SyntaxFilesScanner.LanguageInfo info in MainForm.SyntaxFilesScanner.Infos)
                    {
                        Variant variant = new Variant();
                        variant.CompletionText = info.syntax;
                        variant.DisplayText    = info.syntax;
                        variants.Add(variant);
                    }
                    if (variants.Count > 0)
                    {
                        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
                        autocomplete.Show(variants, text.Substring(prefixIndex + 2));
                        return(true);
                    }
                }
                prefixIndex = text.LastIndexOf("e:");
                if (prefixIndex != -1 && text.IndexOf(";", prefixIndex) == -1)
                {
                    Properties.Property property = new Properties.EncodingProperty("", new EncodingPair(Encoding.UTF8, false));
                    List <Variant>      variants = property.GetAutocompleteVariants();
                    if (variants != null)
                    {
                        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
                        autocomplete.Show(variants, text.Substring(prefixIndex + 2));
                        return(true);
                    }
                }
            }
        }
        if (text.StartsWith("!!!!"))
        {
            text = text.Substring(4);
        }
        else if (text.StartsWith("!!!"))
        {
            text = text.Substring(3);
        }
        else if (text.StartsWith("!!"))
        {
            text = text.Substring(2);
        }
        else if (text.StartsWith("!^"))
        {
            text = text.Substring(2);
        }
        else if (text.StartsWith("!"))
        {
            text = text.Substring(1);
        }
        else if (text.StartsWith("<>"))
        {
            text = text.Substring(2);
        }
        else if (text.StartsWith("<") || text.StartsWith(">"))
        {
            text = text.Substring(1);
        }
        if (text.StartsWith("{"))
        {
            int ketIndex = text.IndexOf("}");
            if (ketIndex != -1)
            {
                text = text.Substring(ketIndex + 1);
            }
        }
        int quotesCount = 0;
        int quotesIndex = 0;

        while (true)
        {
            quotesIndex = text.IndexOf('"', quotesIndex);
            if (quotesIndex == -1)
            {
                break;
            }
            quotesIndex++;
            if (quotesIndex >= text.Length)
            {
                break;
            }
            quotesCount++;
        }
        string path  = "";
        int    index = text.Length;

        while (true)
        {
            if (index <= 0)
            {
                path = text;
                break;
            }
            index--;
            if (quotesCount % 2 == 0 && (text[index] == ' ' || text[index] == '\t' || text[index] == '"') ||
                quotesCount % 2 == 1 && text[index] == '"')
            {
                path = text.Substring(index + 1);
                break;
            }
        }
        AutocompletePath(textBox, path, GetFile);
        return(true);
    }
Пример #14
0
 public static string ToSerialString(this AutocompleteMode value) =>
 AutocompleteModeExtensions.ToSerialString(value);
Пример #15
0
 /// <summary>
 /// Sets the autocomplete mode.
 /// </summary>
 /// <param name="autocompleteMode">The desired autocomplete mode.</param>
 /// <returns>the updated builder.</returns>
 public IAutocompleteOptionsBuilder <TModel> WithMode(AutocompleteMode autocompleteMode)
 {
     this.Mode = autocompleteMode;
     return(this);
 }
 public static string ToSerialString(this AutocompleteMode value) => value switch
 {
Пример #17
0
    public static void AutocompletePath(MulticaretTextBox textBox, string path, Getter <string> getFile)
    {
        if (path == null)
        {
            return;
        }
        path = path.Replace("/", "\\").Replace("\\\\", "\\");
        string dir   = ".";
        string name  = path;
        int    index = path.LastIndexOf("\\");

        if (index != -1)
        {
            dir  = path.Substring(0, index + 1);
            name = path.Substring(index + 1);
        }
        if (getFile != null)
        {
            if (dir.Contains(RunShellCommand.FileDirVar))
            {
                string file = getFile();
                if (file != null)
                {
                    dir = dir.Replace(RunShellCommand.FileDirVar, Path.GetDirectoryName(file));
                }
            }
            if (dir.Contains(RunShellCommand.AppDataDirVar))
            {
                dir = dir.Replace(RunShellCommand.AppDataDirVar, AppPath.AppDataDir);
            }
        }
        string[] dirs  = null;
        string[] files = null;
        try
        {
            dirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);
        }
        catch
        {
        }
        try
        {
            files = Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly);
        }
        catch
        {
        }
        if ((files == null || files.Length == 0) && (dirs == null || dirs.Length == 0))
        {
            return;
        }
        AutocompleteMode autocomplete = new AutocompleteMode(textBox, AutocompleteMode.Mode.Raw);
        List <Variant>   variants     = new List <Variant>();

        if (dirs != null)
        {
            foreach (string file in dirs)
            {
                string  fileName = Path.GetFileName(file);
                Variant variant  = new Variant();
                variant.CompletionText = fileName + "\\";
                variant.DisplayText    = fileName + "\\";
                variants.Add(variant);
            }
        }
        if (files != null)
        {
            foreach (string file in files)
            {
                string  fileName = Path.GetFileName(file);
                Variant variant  = new Variant();
                variant.CompletionText = fileName;
                variant.DisplayText    = fileName;
                variants.Add(variant);
            }
        }
        autocomplete.Show(variants, name);
    }
Пример #18
0
 /// <summary>
 /// Sets the autocomplete mode.
 /// </summary>
 /// <param name="autocompleteMode">The desired autocomplete mode.</param>
 /// <returns>the updated builder.</returns>
 public IAutocompleteParametersBuilder <TModel> WithAutocompleteMode(AutocompleteMode autocompleteMode)
 {
     this.AutocompleteMode = autocompleteMode;
     return(this);
 }
Пример #19
0
 /// <summary>
 ///     If "on" browsers can store the form's input values, to auto-fill the form if the user returns to the page. If "off" browsers should not store this information.
 /// </summary>
 public static TBuilder Autocomplete <TBuilder>(this TBuilder instance,
                                                AutocompleteMode value) where TBuilder : IAutocompleteAttributeBuilder
 {
     return(instance.Attr("autocomplete", value.ConvertToString()));
 }