Exemplo n.º 1
0
        private static void PopulateHTMLElementList()
        {
            AutoCompleteService.Instance.ClearListboxItems();

            foreach (var element in HTMLElements)
            {
                var lItem = new AutoCompleteItem(element.Name, AutoCompleteItemType.Object);
                AutoCompleteService.Instance.AddItem(lItem);
            }

            _listState = AutoCompleteListState.Elements;
        }
Exemplo n.º 2
0
        private ListBoxItem CreateListBoxItem(AutoCompleteItem item)
        {
            ListBoxItem lbItem = new ListBoxItem();
            lbItem.Height = 21;
            lbItem.Tag = item.Name;

            // content
            StackPanel content = new StackPanel();
            content.Orientation = Orientation.Horizontal;
            lbItem.Content = content;

            // attach double-click handler (MouseButtonDown doesn't work with ListBoxItem)
            content.Background = new SolidColorBrush(Colors.Transparent); // it will only stretch if it has a background
            content.Width = 3000; // to cover all area
            content.Loaded += (sender, e) => DoubleClickHelper.Attach(sender, (s, me) => Select());

            if (Configuration.AutoCompleter.ObjectIcon != null && Configuration.AutoCompleter.FunctionIcon != null)
            {
                // icon
                Image icon = new Image();
                icon.Width = icon.Height = 12;
                icon.Margin = new Thickness(0, 0, 5, 0);
                icon.Source = new BitmapImage();

                content.Children.Add(icon);

                switch (item.Type)
                {
                    case AutoCompleteItemType.Object:
                        (icon.Source as BitmapImage).SetSource(Configuration.AutoCompleter.ObjectIcon);
                        break;

                    case AutoCompleteItemType.Function:
                        (icon.Source as BitmapImage).SetSource(Configuration.AutoCompleter.FunctionIcon);
                        break;
                }
            }

            // text
            TextBlock tb = new TextBlock();
            tb.Text = item.Name;
            tb.FontFamily = new FontFamily("Courier New");
            tb.FontWeight = FontWeights.Light;
            tb.Margin = new Thickness(0, 2, 0, 0);
            content.Children.Add(tb);

            if (item.Info != "")
            {
                // info
                TextBlock info = new TextBlock();
                info.Text = item.Info;
                info.FontFamily = new FontFamily("Courier New");
                info.FontWeight = FontWeights.Light;
                info.Foreground = new SolidColorBrush(Colors.LightGray);
                info.HorizontalAlignment = HorizontalAlignment.Right;
                info.Margin = new Thickness(5, 2, 0, 0);
                content.Children.Add(info);
            }

            // parameters (if applicable)
            if (item.Type == AutoCompleteItemType.Function)
            {
                string parameters = "";

                if (item.Parameters != null)
                    parameters = string.Join(", ", item.Parameters);

                TextBlock tbArgs = new TextBlock();
                tbArgs.Text = item.SurroundParamsWithParenthesis ? "(" + parameters + ")" : parameters;
                tbArgs.FontFamily = new FontFamily("Courier New");
                tbArgs.FontWeight = FontWeights.Light;
                tbArgs.Margin = new Thickness(0, 2, 0, 0);
                tbArgs.Foreground = new SolidColorBrush(Colors.Gray);
                content.Children.Add(tbArgs);
            }

            return lbItem;
        }
Exemplo n.º 3
0
        private static void AddHTMLAttributesToList(List<HTMLAttribute> attributes)
        {
            foreach (var attribute in attributes)
            {
                var lItem = new AutoCompleteItem(attribute.Name, AutoCompleteItemType.Function);
                lItem.SurroundParamsWithParenthesis = false;

                AutoCompleteService.Instance.AddItem(lItem);
            }
        }
Exemplo n.º 4
0
 public void AddItem(AutoCompleteItem item)
 {
     listBox.Items.Add(CreateListBoxItem(item));
 }