Autocomplete item for code snippets
Snippet can contain special char ^ for caret position.
Inheritance: AutocompleteItem
Esempio n. 1
0
        private void InitializeData(Object threadContext)
        {
            Stopwatch watch = Stopwatch.StartNew();

            _parser = new Parser();
            _store = new EvalStore();
            StringBuilder cmd = new StringBuilder();

            _attributes = new AttributeTable();
            _attributes.Load();
            statusStrip.Text = "Loading Attributes...";

            _facts = new FactTable();
            _facts.Load();
            statusStrip.Text = "Loading Facts...";

            _contexts = new ContextTable();
            _contexts.Load();
            statusStrip.Text = "Loading Contexts...";

            _resources = new ResourceTable();
            _resources.Load();
            statusStrip.Text = "Loading Resources...";

            watch.Stop();

            _popupMenu = new AutocompleteMenu(queryCode);
            _popupMenu.SearchPattern = @"[\w\.:=!<>]";
            _popupMenu.AllowTabKey = true;

            List<AutocompleteItem> items = new List<AutocompleteItem>();
            for (int i = 0; i < _facts.ColumnDefinitions.Count; i++) {
                items.Add(new AutocompleteItem(_facts.ColumnDefinitions[i].Name));
            }

            items.Add(new AutocompleteItem("select"));
            items.Add(new AutocompleteItem("where"));
            items.Add(new AutocompleteItem("order"));
            items.Add(new AutocompleteItem("group"));
            items.Add(new AutocompleteItem("by"));
            items.Add(new AutocompleteItem("limit"));
            items.Add(new AutocompleteItem("desc"));
            items.Add(new AutocompleteItem("asc"));
            items.Add(new AutocompleteItem("between"));

            for (int i=0; i<_resources.Cols; i++) {
                items.Add(new AutocompleteItem(_resources.ColumnDefinitions[i].Name));
            }

            items.Add(new AutocompleteItem("Context"));
            items.Add(new AutocompleteItem("value"));
            items.Add(new AutocompleteItem("time"));

            foreach (string func in _parser.GetFunctionNames()) {
                SnippetAutocompleteItem n = new SnippetAutocompleteItem(func + "(^)");
                n.ToolTipText = n.Text;
                n.ToolTipTitle = "";
                items.Add(n);
            }

            _popupMenu.Items.SetAutocompleteItems(items);
            queryCode.Language = FastColoredTextBoxNS.Language.SQL;

            _store.Enter();
            _store.Put<Element>("pi", new Element(3.131492653586));
            _store.Put<Element>("e", new Element(2.71828183));
            _store.Put<Table>(_facts.Name, _facts);
            _store.Put<Table>(_attributes.Name, _attributes);
            _store.Put<Table>(_contexts.Name, _contexts);
            _store.Put<Table>(_resources.Name, _resources);

            Trace.WriteLine("InitializeData              : " + watch.ElapsedMilliseconds + "ms");
            toolStrip1.Enabled = true;
            statusStrip.Text = "OK";
        }
Esempio n. 2
0
        /// <summary>
        /// Populates the code editor's auto complete menu, it runs through a series of loops
        /// assigning data to the individual AutocompleteItems.
        /// </summary>
        private void BuildAutocompleteMenu()
        {
            List<AutocompleteItem> items = new List<AutocompleteItem>();

            foreach (string item in autocompleteItems.StatementSnippets)
                items.Add(new SnippetAutocompleteItem(item) { ImageIndex = 1 });

            foreach (string item in autocompleteItems.DeclartionSnippets)
                items.Add(new SnippetAutocompleteItem(item) { ImageIndex = 1 });

            foreach (string item in autocompleteItems.Keywords)
                items.Add(new AutocompleteItem(item) { ImageIndex = 1 });

            foreach (string item in autocompleteItems.Constants)
                items.Add(new AutocompleteItem(item) { ImageIndex = 3 });

            foreach (RpgCodeExpress.RpgCode.Command command in rpgCodeReference.Items)
            {
                SnippetAutocompleteItem menuItem = new SnippetAutocompleteItem(command.Code);
                menuItem.ToolTipText = command.Description;
                menuItem.ToolTipTitle = command.Tooltip;
                menuItem.MenuText = command.Code.Substring(0, command.Code.Length - 3); // Add a "Name" to xml file.
                menuItem.ImageIndex = 0;
                items.Add(menuItem);
            }

            foreach (string definedClass in autocompleteItems.UserDefinedClasses)
                items.Add(new AutocompleteItem(definedClass) { ImageIndex = 5 });

            foreach (string method in autocompleteItems.UserDefinedMethods)
                items.Add(new SnippetAutocompleteItem(method) { ImageIndex = 0 });

            foreach (string global in autocompleteItems.UserDefinedGlobals)
                items.Add(new AutocompleteItem(global) { ImageIndex = 4 });

            foreach (string local in autocompleteItems.UserDefinedLocals)
                items.Add(new AutocompleteItem(local) { ImageIndex = 7 });

            foreach (string member in autocompleteItems.UserDefinedMembers)
                items.Add(new AutocompleteItem(member) { ImageIndex = 6 });

            // Sort them descending, alphabetically.
            items.Sort(delegate(AutocompleteItem item1, AutocompleteItem item2)
            {
                return item1.Text.CompareTo(item2.Text);
            });

            popupMenu.Items.SetAutocompleteItems(items);
        }