Ejemplo n.º 1
0
        private List <MemberTreeNode> GetInheritedMembers(ClassModel classModel)
        {
            List <MemberTreeNode> memberNodes = new List <MemberTreeNode>();

            // Add members from our super class as long as it is not null, Object, Void, or haXe Dynamic
            while (classModel != null &&
                   classModel.Name != "Object" &&
                   classModel != ClassModel.VoidClass &&
                   (!classModel.InFile.haXe || classModel.Type != "Dynamic"))
            {
                MemberList members = classModel.Members;

                foreach (MemberModel member in members)
                {
                    MemberTreeNode node = GetMemberTreeNode(member, classModel);

                    if (node != null)
                    {
                        memberNodes.Add(node);
                    }
                }

                // Follow the inheritence chain down
                classModel = classModel.Extends;
            }

            return(memberNodes);
        }
Ejemplo n.º 2
0
        private void NavigateToMemberTreeNode(MemberTreeNode node)
        {
            if (node is InheritedMemberTreeNode)
            {
                InheritedMemberTreeNode inheritedNode = (InheritedMemberTreeNode)node;
                FileModel model = ModelsExplorer.Instance.OpenFile(inheritedNode.ClassModel.InFile.FileName);

                if (!(node is InheritedClassTreeNode))
                {
                    // We have to update the Tag to reflect the line number the member starts on
                    inheritedNode.Tag = GetInheritedMemberTag(model, inheritedNode.Model.Name);
                }
            }
            else if (node is ImportTreeNode)
            {
                ImportTreeNode importNode  = (ImportTreeNode)node;
                ClassModel     importModel = (ClassModel)importNode.Model;
                if (!importModel.IsVoid() && importModel.InFile != null)
                {
                    ModelsExplorer.Instance.OpenFile(importModel.InFile.FileName);
                }
            }

            // Navigate to node location
            ASContext.Context.OnSelectOutlineNode(node);

            // If navigating to an inherited class or member, we need to reset our combobox
            if (node is InheritedMemberTreeNode || node is ImportTreeNode)
            {
                ResetDropDowns();
            }
        }
Ejemplo n.º 3
0
        private void UpdateMemberDropDown()
        {
            MemberTreeNode currentMemberNode = memberComboBox.SelectedItem as MemberTreeNode;
            MemberTreeNode selectedNode      = null;

            // get the line the caret is on
            int line = _document.SciControl.LineFromPosition(_document.SciControl.CurrentPos);

            foreach (MemberTreeNode memberNode in memberComboBox.Items)
            {
                // if the member is in this code file and the caret is within the lines of the member,
                // then select it
                if (!(memberNode is InheritedMemberTreeNode) &&
                    (line >= memberNode.Model.LineFrom && line <= memberNode.Model.LineTo))
                {
                    selectedNode = memberNode;
                    break;
                }
            }

            if (_lastSelectedClassNode != selectedNode ||
                memberComboBox.SelectedItem != selectedNode)
            {
                // Update the combobox with the new selected node
                _lastSelectedMemberNode     = selectedNode;
                memberComboBox.SelectedItem = selectedNode;
            }
        }
Ejemplo n.º 4
0
        private void BuildImportDropDown()
        {
            importComboBox.Items.Clear();

            if (ASContext.Context.CurrentModel != null && _settings.ShowImportedClasses)
            {
                List <MemberTreeNode> importNodes = new List <MemberTreeNode>();

                // Add all the imported classes from this file
                foreach (MemberModel importModel in ASContext.Context.CurrentModel.Imports)
                {
                    // ignore package imports
                    if (!importModel.Type.EndsWith(".*"))
                    {
                        ClassModel classModel = ASContext.Context.ResolveType(importModel.Type, ASContext.Context.CurrentModel);
                        if (!classModel.IsVoid() && classModel.InFile != null)
                        {
                            MemberTreeNode node = GetClassTreeNode(classModel, false, true);
                            importNodes.Add(node);
                        }
                    }
                }

                // Apply member sort
                if (_memberSort != null)
                {
                    importNodes.Sort(_memberSort);
                }

                importComboBox.Items.AddRange(importNodes.ToArray());
            }
        }
Ejemplo n.º 5
0
        private void BuildMemberDropDown()
        {
            memberComboBox.BeginUpdate();

            memberComboBox.Items.Clear();

            MemberList    members       = null;
            ClassTreeNode classTreeNode = classComboBox.SelectedItem as ClassTreeNode;
            ClassModel    classModel    = null;

            if (ASContext.Context.CurrentModel != null)
            {
                List <MemberTreeNode> memberNodes = new List <MemberTreeNode>();

                if (classTreeNode == null)
                {
                    // The caret is not within a class, so add the global members
                    members = ASContext.Context.CurrentModel.Members;
                }
                else
                {
                    // The caret is within a class, so add the classes members
                    classModel = (ClassModel)classTreeNode.Model;
                    members    = classModel.Members;
                }

                // Add the local members
                foreach (MemberModel member in members)
                {
                    MemberTreeNode node = GetMemberTreeNode(member, null);

                    if (node != null)
                    {
                        memberNodes.Add(node);
                    }
                }

                // Add inherited members if applicable
                if (_settings.ShowInheritedMembers && classModel != null)
                {
                    memberNodes.AddRange(GetInheritedMembers(classModel.Extends));
                }

                // Apply member sort
                if (_memberSort != null)
                {
                    memberNodes.Sort(_memberSort);
                }

                memberComboBox.Items.AddRange(memberNodes.ToArray());
            }

            // Select the member that contains the caret
            UpdateMemberDropDown();

            memberComboBox.EndUpdate();
        }
Ejemplo n.º 6
0
        private void BuildClassDropDown()
        {
            classComboBox.BeginUpdate();

            classComboBox.Items.Clear();

            if (ASContext.Context.CurrentModel != null)
            {
                List <MemberTreeNode> classNodes = new List <MemberTreeNode>();
                List <string>         classNames = new List <string>();

                // Add all the classes from this file
                foreach (ClassModel classModel in ASContext.Context.CurrentModel.Classes)
                {
                    MemberTreeNode node = GetClassTreeNode(classModel, false, false);
                    classNodes.Add(node);

                    if (_settings.ShowSuperClasses)
                    {
                        // While extended class is not null, Object, Void, or haXe Dynamic
                        var extendClassModel = classModel.Extends;
                        while (extendClassModel != null &&
                               extendClassModel.Name != "Object" &&
                               extendClassModel != ClassModel.VoidClass &&
                               (!extendClassModel.InFile.haXe || extendClassModel.Type != "Dynamic"))
                        {
                            // Have we already added this class? Multiple classes could extend the same base.
                            if (classNames.Contains(extendClassModel.QualifiedName))
                            {
                                break;
                            }
                            classNames.Add(extendClassModel.QualifiedName);

                            node = GetClassTreeNode(extendClassModel, true, false);
                            classNodes.Add(node);

                            extendClassModel = extendClassModel.Extends;
                        }
                    }
                }

                // Apply member sort
                if (_memberSort != null)
                {
                    classNodes.Sort(_memberSort);
                }

                classComboBox.Items.AddRange(classNodes.ToArray());
            }

            // Select the class that contains the caret
            UpdateClassDropDown();

            classComboBox.EndUpdate();
        }
Ejemplo n.º 7
0
        private MemberTreeNode GetMemberTreeNode(MemberModel memberModel, ClassModel classModel)
        {
            MemberTreeNode node       = null;
            int            imageIndex = PluginUI.GetIcon(memberModel.Flags, memberModel.Access);

            if (imageIndex != 0)
            {
                node = classModel == null ? new MemberTreeNode(memberModel, imageIndex, _settings.LabelPropertiesLikeFunctions) :
                       new InheritedMemberTreeNode(classModel, memberModel, imageIndex, _settings.LabelPropertiesLikeFunctions);
            }

            return(node);
        }
Ejemplo n.º 8
0
        private bool NodeStartsWith(MemberTreeNode node, string searchKey)
        {
            string searchString;

            // If node navigates to a class then ignore the package name
            if (node is ClassTreeNode || node is ImportTreeNode || node is InheritedClassTreeNode)
            {
                searchString = _settings.IgnoreUnderscore ? node.Model.Name.TrimStart('_') : node.Model.Name;
            }
            else
            {
                searchString = _settings.IgnoreUnderscore ? node.Label.TrimStart('_') : node.Label;
            }

            return(searchString.StartsWith(searchKey, StringComparison.CurrentCultureIgnoreCase));
        }
Ejemplo n.º 9
0
        private void UpdateClassDropDown()
        {
            MemberTreeNode selectedNode       = null;
            bool           singleClassContext = false;

            // Check to see if there is only one class in this file
            if (ASContext.Context.CurrentModel != null)
            {
                if (ASContext.Context.CurrentModel.Classes.Count == 1 &&
                    ASContext.Context.CurrentModel.Members.Count == 0)
                {
                    singleClassContext = true;
                }
            }

            // get the line the caret is on
            int line = _document.SciControl.LineFromPosition(_document.SciControl.CurrentPos);

            foreach (MemberTreeNode classNode in classComboBox.Items)
            {
                // if the caret is within the lines of the class, then select it
                if (!(classNode is InheritedClassTreeNode) &&
                    (singleClassContext ||
                     (line >= classNode.Model.LineFrom && line <= classNode.Model.LineTo)))
                {
                    selectedNode = classNode;
                    break;
                }
            }

            if (_lastSelectedClassNode != selectedNode ||
                classComboBox.SelectedItem != selectedNode)
            {
                // Update the combobox with the new selected node
                _lastSelectedClassNode     = selectedNode;
                classComboBox.SelectedItem = selectedNode;

                // Update the members to match the new class
                BuildMemberDropDown();
            }
        }
Ejemplo n.º 10
0
        private void comboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            // Update ForeColor and BackColor if a theme overrides the defaults
            ComboBox comboBox = sender as ComboBox;

            if (PluginBase.MainForm.GetThemeValue("ToolStripComboBoxControl.ForeColor") != null)
            {
                var foreColor = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.ForeColor");
                if (comboBox.ForeColor != foreColor)
                {
                    comboBox.ForeColor = foreColor;
                }
            }

            if (PluginBase.MainForm.GetThemeValue("ToolStripComboBoxControl.BackColor") != null)
            {
                var backColor = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.BackColor");
                if (comboBox.BackColor != backColor)
                {
                    comboBox.BackColor = backColor;
                }
            }

            // If we drawing an item that exists
            if (e.Index > -1)
            {
                MemberTreeNode node = comboBox.Items[e.Index] as MemberTreeNode;

                int imageWidth  = _icons.ImageSize.Width;
                int imageHeight = _icons.ImageSize.Height;

                // Clear the old background
                if ((e.State & DrawItemState.ComboBoxEdit) == 0)
                {
                    e.Graphics.FillRectangle(new SolidBrush(comboBox.BackColor), e.Bounds.Left + imageWidth, e.Bounds.Top, e.Bounds.Width - imageWidth, e.Bounds.Height);
                }

                // Draw the item image
                e.Graphics.DrawImage(_icons.Images[node.ImageIndex], new Rectangle(e.Bounds.Left, e.Bounds.Top, imageWidth, imageHeight));

                // Is this item being hovered over?
                if ((e.State & DrawItemState.Focus) != 0 ||
                    (e.State & DrawItemState.Selected) != 0)
                {
                    // Draw a selection box and label in the selection text color
                    e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), e.Bounds.Left + imageWidth, e.Bounds.Top, e.Bounds.Width - imageWidth - 1, e.Bounds.Height - 1);
                    e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), e.Bounds.Left + imageWidth, e.Bounds.Top, e.Bounds.Width - imageWidth - 1, e.Bounds.Height - 1);

                    e.Graphics.DrawString(node.Label, comboBox.Font, new SolidBrush(SystemColors.HighlightText), new Point(e.Bounds.Left + imageWidth + 1, e.Bounds.Top));
                }
                // Is this item disabled?
                else if ((e.State & DrawItemState.Disabled) != 0)
                {
                    // Draw the label in the disabled text color
                    e.Graphics.DrawString(node.Label, comboBox.Font, new SolidBrush(SystemColors.GrayText), new Point(e.Bounds.Left + imageWidth + 1, e.Bounds.Top));
                }
                // Is this item inherited?
                else if (node is InheritedMemberTreeNode)
                {
                    // Draw the label in the disabled text color
                    e.Graphics.DrawString(node.Label, comboBox.Font, new SolidBrush(Color.Gray), new Point(e.Bounds.Left + imageWidth + 1, e.Bounds.Top));
                }
                else
                {
                    // Draw the label in the foreground color
                    e.Graphics.DrawString(node.Label, comboBox.Font, new SolidBrush(comboBox.ForeColor), new Point(e.Bounds.Left + imageWidth + 1, e.Bounds.Top));
                }
            }
        }
Ejemplo n.º 11
0
 static bool NodeStartsWith(MemberTreeNode node, string searchKey)
 {
     return GetNodeSearchString(node).StartsWith(searchKey, StringComparison.CurrentCultureIgnoreCase);
 }
Ejemplo n.º 12
0
 static bool NodeContains(MemberTreeNode node, string searchKey)
 {
     // Using IndexOf instead of Contains so that the IgnoreCase can be included
     return GetNodeSearchString(node).IndexOf(searchKey, 0, StringComparison.CurrentCultureIgnoreCase) != -1;
 }
Ejemplo n.º 13
0
        static string GetNodeSearchString(MemberTreeNode node)
        {
            // If node navigates to a class then ignore the package name
            if (node is ClassTreeNode || node is ImportTreeNode || node is InheritedClassTreeNode)
                return Settings.IgnoreUnderscore ? node.Model.Name.TrimStart('_') : node.Model.Name;

            return Settings.IgnoreUnderscore ? node.Label.TrimStart('_') : node.Label;
        }