Exemplo n.º 1
0
    private Variant GetPropertyVariant(Properties.Property property)
    {
        Variant variant = new Variant();

        variant.CompletionText = property.name;
        variant.DisplayText    = property.name + " <new value>";
        return(variant);
    }
Exemplo n.º 2
0
 public void ParametersToTemp(Dictionary <string, SValue> settingsData)
 {
     settingsData.Clear();
     for (int i = 0; i < properties.Count; i++)
     {
         Properties.Property property = properties[i];
         if (property.AllowTemp)
         {
             settingsData[property.name] = property.GetTemp();
         }
     }
 }
Exemplo n.º 3
0
 public void ParametersFromTemp(Dictionary <string, SValue> settingsData)
 {
     for (int i = 0; i < properties.Count; i++)
     {
         Properties.Property property = properties[i];
         if (property.AllowTemp && !property.initedByConfig)
         {
             SValue value = settingsData.ContainsKey(property.name) ? settingsData[property.name] : SValue.None;
             property.SetTemp(value);
         }
     }
 }
Exemplo n.º 4
0
    public string GetHelpText()
    {
        StringBuilder builder = new StringBuilder();

        builder.AppendLine("# Settings properties");
        builder.AppendLine();
        builder.AppendLine("- First col legend: C - loads from config on start, T - from temp settings, [EMPTY] - only from config");
        builder.AppendLine("- Store here in config:           xml: <item name=\"name\" value=\"value\"/>");
        builder.AppendLine("- Make it store in temp settings: xml: <item name=\"name\"/>");
        builder.AppendLine("- [:<filter>] using example:      xml: <item name=\"name:*.cs;*.txt\" value=\"value for cs/txt file\"/>");
        builder.AppendLine("- Set property by command dialog: name value (autocomplete supported by `Tab` or `Ctrl+Space`)");
        builder.AppendLine("- Clear if several nodes allowed: xml: <item name=\"name\" value=\"\"/>");
        builder.AppendLine();
        TextTable table = new TextTable().SetMaxColWidth(33);

        Properties.AddHeadTo(table);
        table.AddLine();
        bool first = true;

        Properties.Property prev = null;
        foreach (Properties.Property property in properties)
        {
            if (!first)
            {
                table.NewRow();
            }
            first = false;
            if (prev != null && prev.Type != property.Type)
            {
                if (prev.GetHelpTypeText(table))
                {
                    table.NewRow();
                }
            }
            property.GetHelpText(this, table);
            prev = property;
        }
        builder.Append(table);
        builder.AppendLine();
        builder.Append(EncodingPair.GetEncodingsText());
        return(builder.ToString());
    }
Exemplo n.º 5
0
    public void Parse(XmlDocument document, StringBuilder errors, bool isLocal)
    {
        XmlNode root = null;

        foreach (XmlNode node in document.ChildNodes)
        {
            if (node is XmlElement && node.Name == "config")
            {
                root = node;
                break;
            }
        }
        if (root != null)
        {
            bool wasUnknownName = false;
            foreach (XmlNode node in root.ChildNodes)
            {
                XmlElement element = node as XmlElement;
                if (element != null && element.Name == "item")
                {
                    string name    = element.GetAttribute("name");
                    string keyName = Properties.NameOfName(name);
                    Properties.Property property = settings[keyName];
                    if (property != null)
                    {
                        if (element.HasAttribute("value"))
                        {
                            string value = element.GetAttribute("value");
                            if (isLocal && (property.constraints & Properties.Constraints.NotForLocal) != 0)
                            {
                                errors.Append("Disallowed in local config: name=" + keyName + " (to prevent unexpected behaviour on directory switching)");
                            }
                            else
                            {
                                property.initedByConfig = true;
                                string error = property.SetText(value, Properties.SubvalueOfName(name));
                                if (!string.IsNullOrEmpty(error))
                                {
                                    errors.AppendLine(error);
                                }
                            }
                        }
                        else
                        {
                            if (property != null)
                            {
                                if (property.AllowTemp)
                                {
                                    property.initedByConfig = false;
                                }
                                else
                                {
                                    errors.Append("Saving name=" + keyName + " in temp isn't allowed, need value");
                                }
                            }
                        }
                    }
                    else
                    {
                        errors.AppendLine("Unknown name=" + keyName);
                        wasUnknownName = true;
                    }
                }
            }
            if (wasUnknownName)
            {
                errors.AppendLine("(if no errors before upgrade, please, remove this names from configs by F2 and Ctrl+F2)");
            }
        }
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
0
 private void Add(Properties.Property property)
 {
     propertyByName[property.name] = property;
     properties.Add(property);
 }