Example #1
0
        void OutlineTreeIconFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            var    pixRenderer = (CellRendererPixbuf)cell;
            object o           = model.GetValue(iter, 0);

            if (o is DNode)
            {
                var icon = DCompletionData.GetNodeIcon(o as DNode);
                if (icon != (Core.IconId)null)
                {
                    pixRenderer.Pixbuf = ImageService.GetPixbuf(icon.Name, IconSize.Menu);
                }
            }
            else if (o is D_Parser.Dom.Statements.StatementContainingStatement)
            {
                pixRenderer.Pixbuf = ImageService.GetPixbuf("gtk-add", IconSize.Menu);
            }
        }
Example #2
0
        void _updateTypeLookupDataTh(object p)
        {
            while (true)
            {
                typeLookupUpdateSignal.WaitOne();
                while (typeLookupUpdateSignal.WaitOne(100));

                var ed = (IEditorData)p;
                // SyntaxTree, curBlock, CaretLocation
                var ast = ed.SyntaxTree;
                var caret = ed.CaretLocation;
                var curBlock = lastSelectedBlock;
                try
                {
                    #region Update the type & member selectors
                    isUpdatingLookupDropdowns = true; // Temporarily disable SelectionChanged event handling

                    // First fill the Types-Dropdown
                    var types = new List<DCompletionData>();
                    ICompletionData selectedItem = null;
                    var l1 = new List<INode> { ast };
                    var l2 = new List<INode>();

                    while (l1.Count > 0)
                    {
                        foreach (var n in l1)
                        {
                            // Show all type declarations of the current module
                            if (n is DClassLike || n is DEnum)
                            {
                                var completionData = new DCompletionData(n);
                                if (caret >= n.Location && caret <= n.EndLocation)
                                {
                                    selectedItem = completionData;
                                    curBlock = n as IBlockNode;
                                }
                                types.Add(completionData);
                            }

                            if (n is IBlockNode)
                            {
                                var ch = ((IBlockNode)n).Children;
                                if (ch.Count != 0)
                                    l2.AddRange(ch);
                            }
                        }

                        l1.Clear();
                        l1.AddRange(l2);
                        l2.Clear();
                    }

                    if (selectedItem == null && ast != null)
                        curBlock = ast;

                    // For better usability, pre-sort items
                    try
                    {
                        types.Sort();
                    }
                    catch { }

                    Dispatcher.Invoke(new Action(() =>
                    {
                        lookup_Types.ItemsSource = types;
                        lookup_Types.SelectedItem = selectedItem;
                    }));

                    if (curBlock is IBlockNode)
                    {
                        selectedItem = null;
                        // Fill the Members-Dropdown
                        var members = new List<DCompletionData>();

                        // Search a parent class to show all this one's members and to select that member where the caret currently is located
                        var watchedParent = curBlock as IBlockNode;

                        while (watchedParent != null && !(watchedParent is DClassLike || watchedParent is DEnum || watchedParent is DModule))
                            watchedParent = watchedParent.Parent as IBlockNode;

                        if (watchedParent != null)
                            lock (watchedParent)
                                foreach (var n in watchedParent)
                                {
                                    if (n == null)
                                        continue;

                                    var cData = new DCompletionData(n);
                                    if (selectedItem == null && cData.Node != null && caret >= cData.Node.Location && caret < cData.Node.EndLocation)
                                        selectedItem = cData;
                                    members.Add(cData);
                                }

                        try
                        {
                            members.Sort();
                        }
                        catch { }

                        Dispatcher.Invoke(new Action(() =>
                        {
                            lookup_Members.ItemsSource = members;
                            lookup_Members.SelectedItem = selectedItem;
                        }));
                    }
                    else
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            lookup_Members.ItemsSource = null;
                            lookup_Members.SelectedItem = null;
                        }));
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Parser);
                }
                isUpdatingLookupDropdowns = false;
            }
        }
Example #3
0
 void _insertTypeDataInternal(IBlockNode Parent, ref DCompletionData selectedItem, List<DCompletionData> types)
 {
     if (Parent != null)
         foreach (var n in Parent)
         {
             var completionData = new DCompletionData(n);
             if (selectedItem == null && CaretLocation >= n.Location && CaretLocation <= n.EndLocation)
                 selectedItem = completionData;
             types.Add(completionData);
         }
 }
        private void UpdatePath(object sender, Mono.TextEditor.DocumentLocationEventArgs e)
        {
            var ast = Document.ParsedDocument as ParsedDModule;

            if (ast == null)
            {
                return;
            }

            var SyntaxTree = ast.DDom;

            if (SyntaxTree == null)
            {
                return;
            }

            // Resolve the hovered piece of code
            var        loc          = new CodeLocation(Document.Editor.Caret.Location.Column, Document.Editor.Caret.Location.Line);
            IStatement stmt         = null;
            var        currentblock = DResolver.SearchBlockAt(SyntaxTree, loc, out stmt) as IBlockNode;

            //could be an enum value, which is not IBlockNode
            if (currentblock is DEnum)
            {
                foreach (INode nd in (currentblock as DEnum).Children)
                {
                    if ((nd is DEnumValue) &&
                        ((nd.Location <= loc) && (nd.EndLocation >= loc)))
                    {
                        currentblock = nd as IBlockNode;
                        break;
                    }
                }
            }

            List <PathEntry> result = new List <PathEntry>();
            INode            node   = currentblock;

            while ((node != null) && ((node is IBlockNode) || (node is DEnumValue)))
            {
                PathEntry entry;

                var icon = DCompletionData.GetNodeIcon(node as DNode);

                entry          = new PathEntry(icon.IsNull?null: ImageService.GetPixbuf(icon.Name, IconSize.Menu), node.Name + DParameterDataProvider.GetNodeParamString(node));
                entry.Position = EntryPosition.Left;
                entry.Tag      = node;
                //do not include the module in the path bar
                if ((node.Parent != null) && !((node is DNode) && (node as DNode).IsAnonymous))
                {
                    result.Insert(0, entry);
                }
                node = node.Parent;
            }

            if (!((currentblock is DMethod) || (currentblock is DEnumValue)))
            {
                PathEntry noSelection = new PathEntry(GettextCatalog.GetString("No Selection"))
                {
                    Tag = new NoSelectionCustomNode(currentblock)
                };
                result.Add(noSelection);
            }

            var prev = CurrentPath;

            CurrentPath = result.ToArray();
            OnPathChanged(new DocumentPathChangedEventArgs(prev));
        }
Example #5
0
        public Gdk.Pixbuf GetIcon(int n)
        {
            var icon = DCompletionData.GetNodeIcon(memberList[n] as DNode);

            return(ImageService.GetPixbuf(icon.Name, IconSize.Menu));
        }
Example #6
0
        /// <summary>
        /// If different code block was selected, 
        /// update the list of items that are available in the current scope
        /// </summary>
        public void UpdateTypeLookupData()
        {
            try
            {
                // Update highlit bracket offsets
                if (DSettings.Instance.EnableMatchingBracketHighlighting)
                    CurrentlyHighlitBrackets = DBracketSearcher.SearchBrackets(Editor.Document, Editor.CaretOffset, Editor.TextArea.Caret.Location);
                else
                    CurrentlyHighlitBrackets = null;

                if (SyntaxTree == null)
                {
                    lookup_Members.ItemsSource = lookup_Types.ItemsSource = null;
                    return;
                }

                var curBlock = DResolver.SearchBlockAt(SyntaxTree, CaretLocation, out lastSelectedStatement);

                if (curBlock == null)
                    curBlock = SyntaxTree;

                if (typeLookupUpdateOperation != null && typeLookupUpdateOperation.Status != DispatcherOperationStatus.Completed)
                    typeLookupUpdateOperation.Abort();

                lastSelectedBlock = curBlock;

                typeLookupUpdateOperation = Dispatcher.BeginInvoke(new Action(() =>
                {
                    try
                    {
                        #region Update the type & member selectors
                        isUpdatingLookupDropdowns = true; // Temporarily disable SelectionChanged event handling

                        // First fill the Types-Dropdown
                        var types = new List<DCompletionData>();
                        ICompletionData selectedItem = null;
                        var l1 = new List<INode> { SyntaxTree };
                        var l2 = new List<INode>();

                        while (l1.Count > 0)
                        {
                            foreach (var n in l1)
                            {
                                // Show all type declarations of the current module
                                if (n is DClassLike || n is DEnum)
                                {
                                    var completionData = new DCompletionData(n);
                                    if (CaretLocation >= n.Location && CaretLocation <= n.EndLocation)
                                    {
                                        selectedItem = completionData;
                                        curBlock = n as IBlockNode;
                                    }
                                    types.Add(completionData);
                                }

                                if (n is IBlockNode)
                                {
                                    var ch = (n as IBlockNode).Children;
                                    if (ch != null)
                                        l2.AddRange(ch);
                                }
                            }

                            l1.Clear();
                            l1.AddRange(l2);
                            l2.Clear();
                        }

                        if (selectedItem == null && SyntaxTree != null)
                            curBlock = SyntaxTree;

                        // For better usability, pre-sort items
                        try
                        {
                            types.Sort();
                        }
                        catch { }

                        lookup_Types.ItemsSource = types;
                        lookup_Types.SelectedItem = selectedItem;

                        if (curBlock is IBlockNode)
                        {
                            selectedItem = null;
                            // Fill the Members-Dropdown
                            var members = new List<DCompletionData>();

                            // Search a parent class to show all this one's members and to select that member where the caret currently is located
                            var watchedParent = curBlock as IBlockNode;

                            while (watchedParent != null && !(watchedParent is DClassLike || watchedParent is DEnum || watchedParent is IAbstractSyntaxTree))
                                watchedParent = watchedParent.Parent as IBlockNode;

                            if (watchedParent != null)
                                lock(watchedParent)
                                    foreach (var n in watchedParent)
                                    {
                                        if (n == null)
                                            continue;

                                        var cData = new DCompletionData(n);
                                        if (selectedItem == null && cData.Node!=null && CaretLocation >= cData.Node.Location && CaretLocation < cData.Node.EndLocation)
                                            selectedItem = cData;
                                        members.Add(cData);
                                    }

                            try
                            {
                                members.Sort();
                            }
                            catch { }

                            lookup_Members.ItemsSource = members;
                            lookup_Members.SelectedItem = selectedItem;
                        }
                        else
                        {
                            lookup_Members.ItemsSource = null;
                            lookup_Members.SelectedItem = null;
                        }

                        isUpdatingLookupDropdowns = false;
                        #endregion
                    }
                    catch (Exception ex) { ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Parser); }
                }), DispatcherPriority.Background);
            }
            catch (Exception ex) { ErrorLogger.Log(ex, ErrorType.Error, ErrorOrigin.Parser); }
        }