Beispiel #1
0
            public override INode HandleMultipleResults(INode[] matches)
            {
                var dlg = new ListSelectionDialog();

                var l = new List<string>();
                int j = 0;
                foreach (var n in matches)
                    l.Add("(" + (++j).ToString() + ") " + n.ToString()); // Bug: To make items unique (which is needed for the listbox to run properly), it's needed to add some kind of an identifier to the beginning of the string
                dlg.List.ItemsSource = l;

                dlg.List.SelectedIndex = 0;

                if (dlg.ShowDialog().Value)
                    return matches[dlg.List.SelectedIndex];
                return null;
            }
Beispiel #2
0
        void ContextMenu_GotoDefinition_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                if (SyntaxTree == null)
                    return;

                var ctxt = ResolutionContext.Create(ParseCache, null, lastSelectedBlock, lastSelectedStatement);
                ctxt.ContextIndependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

                var rr = DResolver.ResolveType(this, ctxt, DResolver.AstReparseOptions.AlsoParseBeyondCaret | DResolver.AstReparseOptions.OnlyAssumeIdentifierList);

                AbstractType res = null;
                // If there are multiple types, show a list of those items
                if (rr != null && rr.Length > 1)
                {
                    var dlg = new ListSelectionDialog();

                    var l = new List<string>();
                    int j = 0;
                    foreach (var i in rr)
                        l.Add("(" + (++j).ToString() + ") " + i.ToString()); // Bug: To make items unique (which is needed for the listbox to run properly), it's needed to add some kind of an identifier to the beginning of the string
                    dlg.List.ItemsSource = l;

                    dlg.List.SelectedIndex = 0;

                    if (dlg.ShowDialog().Value)
                    {
                        res = rr[dlg.List.SelectedIndex];
                    }
                }
                else if (rr.Length == 1)
                    res = rr[0];
                else
                {
                    MessageBox.Show("No symbol found!");
                    return;
                }

                INode n = null;

                if (res is DSymbol)
                    n = ((DSymbol)res).Definition;
                else
                {
                    MessageBox.Show("Select valid symbol!");
                    return;
                }

                var mod = n.NodeRoot as DModule;
                if (mod == null)
                    return;
                CoreManager.Instance.OpenFile(mod.FileName, n.Location.Line, n.Location.Column);
            }
            catch { }
        }
        void ContextMenu_AddImportStatement_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                if (SyntaxTree == null)
                    return;

                var rr = DResolver.ResolveType(this,
                    new ResolverContextStack(ParseCache, new ResolverContext {
                        ScopedBlock = lastSelectedBlock,
                        ScopedStatement=lastSelectedStatement
                    }) { ContextIndependentOptions = ResolutionOptions.ReturnMethodReferencesOnly },
                    DResolver.AstReparseOptions.OnlyAssumeIdentifierList | DResolver.AstReparseOptions.AlsoParseBeyondCaret);

                AbstractType res = null;
                // If there are multiple types, show a list of those items
                if (rr != null && rr.Length > 1)
                {
                    var dlg = new ListSelectionDialog();

                    var l = new List<string>();
                    int j = 0;
                    foreach (var i in rr)
                        l.Add("(" + (++j).ToString() + ") " + i.ToString()); // Bug: To make items unique (which is needed for the listbox to run properly), it's needed to add some kind of an identifier to the beginning of the string
                    dlg.List.ItemsSource = l;

                    dlg.List.SelectedIndex = 0;

                    if (dlg.ShowDialog().Value)
                    {
                        res = rr[dlg.List.SelectedIndex];
                    }
                }
                else if (rr.Length == 1)
                    res = rr[0];
                else
                {
                    MessageBox.Show("No symbol found!");
                    return;
                }

                var n = DResolver.GetResultMember(res);

                if (n == null)
                {
                    MessageBox.Show("Select valid symbol!");
                    return;
                }

                var mod = n.NodeRoot as DModule;
                if (mod == null)
                    return;

                if (mod == SyntaxTree)
                {
                    MessageBox.Show("Symbol is part of the current module. No import required!");
                    return;
                }

                bool alreadyAdded= false;

                foreach(var sstmt in mod.StaticStatements)
                    if (sstmt is ImportStatement)
                    {
                        var impStmt=(ImportStatement)sstmt;

                        foreach (var imp in impStmt.Imports)
                            if (imp.ModuleIdentifier.ToString() == mod.ModuleName)
                            {
                                alreadyAdded = true;
                                break;
                            }

                        if (impStmt.ImportBinding != null && impStmt.ImportBinding.Module.ModuleIdentifier.ToString() == mod.ModuleName)
                            alreadyAdded = true;

                        if (alreadyAdded)
                            break;
                    }

                if (alreadyAdded)
                {
                    MessageBox.Show("Module " + mod.ModuleName + " already imported!");
                    return;
                }

                var loc = DParser.FindLastImportStatementEndLocation(Editor.Text);
                Editor.Document.BeginUpdate();
                Editor.Document.Insert(Editor.Document.GetOffset(loc.Line + 1, 0), "import " + mod.ModuleName + ";\r\n");
                KeysTyped = true;
                Editor.Document.EndUpdate();
            }
            catch { }
        }