Пример #1
0
        public override void onActivated()
        {
            EditorGui    EditorGui    = "EditorGui";
            EWorldEditor EWorldEditor = "EWorldEditor";
            EditorTree   EditorTree   = "EditorTree";

            Creator.EWCreatorWindow      EWCreatorWindow     = "EWCreatorWindow";
            EditorGui.EditorGuiStatusBar EditorGuiStatusBar  = "EditorGuiStatusBar";
            ETransformSelection          ETransformSelection = "ETransformSelection";
            SimGroup MissionGroup = "MissionGroup";

            EditorGui.bringToFront("EWorldEditor");
            EWorldEditor.setVisible(true);

            EditorGui.menuBar.insert(EditorGui.worldMenu, EditorGui.menuBar["dynamicItemInsertPos"].AsInt());

            EWorldEditor.makeFirstResponder(true);
            EditorTree.open(MissionGroup, true);
            EWCreatorWindow.setNewObjectGroup(MissionGroup);

            EWorldEditor.syncGui();

            EditorGuiStatusBar.setSelectionObjectsByCount(EWorldEditor.getSelectionSize().AsString());

            // Should the Transform Selection window open?
            if (EWorldEditor["ETransformSelectionDisplayed"].AsBool())
            {
                ETransformSelection.setVisible(true);
            }

            base.onActivated();
        }
Пример #2
0
        public void Sections()
        {
            string content =
                @"# NAME1 -----
x <- 1


# NAME2 -----


";
            TextBufferMock textBuffer           = null;
            int            calls                = 0;
            OutlineRegionsChangedEventArgs args = null;

            textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            using (var tree = new EditorTree(textBuffer, _shell)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, _shell)) {
                        var rc1 = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc1);

                        rc1.Should().HaveCount(2);
                        rc1[0].DisplayText.Should().Be("# NAME1");
                        rc1[1].DisplayText.Should().Be("# NAME2");

                        rc1[0].Length.Should().Be(21);
                        rc1[1].Length.Should().Be(13);

                        ob.RegionsChanged += (s, e) => {
                            calls++;
                            args = e;
                        };

                        textBuffer.Insert(2, "A");
                        editorDocument.EditorTree.EnsureTreeReady();

                        // Wait for background/idle tasks to complete
                        var start = DateTime.Now;
                        while (calls == 0 && (DateTime.Now - start).TotalMilliseconds < 2000)
                        {
                            ((IIdleTimeSource)_shell).DoIdle();
                        }

                        calls.Should().Be(1);
                        args.Should().NotBeNull();
                        args.ChangedRange.Start.Should().Be(0);
                        args.ChangedRange.End.Should().Be(textBuffer.CurrentSnapshot.Length);
                        args.Regions.Should().HaveCount(2);

                        args.Regions[0].DisplayText.Should().Be("# ANAME1");
                        args.Regions[1].DisplayText.Should().Be("# NAME2");

                        args.Regions[0].Length.Should().Be(22);
                        args.Regions[1].Length.Should().Be(13);
                    }
                }
            }
        }
Пример #3
0
        public void EditorTree_InvalidateAll()
        {
            EditorTree tree = EditorTreeTest.MakeTree("if(true) x <- a + b");

            tree.Invalidate();
            tree.AstRoot.Children.Should().BeEmpty();
        }
Пример #4
0
        public async Task ParameterTest_ComputeCurrentParameter02()
        {
            await PackageIndexUtility.GetFunctionInfoAsync(FunctionIndex, "legend");

            REditorSettings.PartialArgumentNameMatch = true;

            ITextBuffer              textBuffer = new TextBufferMock("legend(bty=1, lt=3)", RContentTypeDefinition.ContentType);
            SignatureHelpSource      source     = new SignatureHelpSource(textBuffer, EditorShell);
            SignatureHelpSessionMock session    = new SignatureHelpSessionMock(textBuffer, 0);
            TextViewMock             textView   = session.TextView as TextViewMock;
            List <ISignature>        signatures = new List <ISignature>();

            using (var tree = new EditorTree(textBuffer, EditorShell)) {
                tree.Build();
                using (var document = new EditorDocumentMock(tree)) {
                    session.TrackingPoint = new TrackingPointMock(textBuffer, 7, PointTrackingMode.Positive, TrackingFidelityMode.Forward);

                    tree.TakeThreadOwnerShip();
                    await source.AugmentSignatureHelpSessionAsync(session, signatures, tree.AstRoot);

                    signatures.Should().ContainSingle();

                    textView.Caret = new TextCaretMock(textView, 8);
                    SignatureHelp sh    = signatures[0] as SignatureHelp;
                    int           index = sh.ComputeCurrentParameter(tree.TextSnapshot, tree.AstRoot, 8);
                    index.Should().Be(11);

                    textView.Caret = new TextCaretMock(textView, 15);
                    index          = sh.ComputeCurrentParameter(tree.TextSnapshot, tree.AstRoot, 15);
                    index.Should().Be(6);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Closes the document
        /// </summary>
        public virtual void Close()
        {
            if (IsClosed)
            {
                return;
            }

            IsClosed = true;
            _textDocumentFactoryService.TextDocumentDisposed -= OnTextDocumentDisposed;

            DocumentClosing?.Invoke(this, null);

            if (EditorTree != null)
            {
                _editorTree.Dispose(); // this will also remove event handlers
                _editorTree = null;
            }

            if (DocumentClosing != null)
            {
                foreach (EventHandler <EventArgs> eh in DocumentClosing.GetInvocationList())
                {
                    Debug.Fail(String.Format(CultureInfo.CurrentCulture, "There are still listeners in the EditorDocument.OnDocumentClosing event list: {0}", eh.Target));
                    DocumentClosing -= eh;
                }
            }

            ServiceManager.RemoveService <REditorDocument>(TextBuffer);
            TextBuffer = null;
        }
Пример #6
0
        public async Task ParameterTest_ComputeCurrentParameter02()
        {
            await FunctionIndex.GetPackageNameAsync("legend");

            _settings.PartialArgumentNameMatch.Returns(true);

            var textBuffer = new TextBufferMock("legend(bty=1, lt=3)", RContentTypeDefinition.ContentType);
            var eb         = textBuffer.ToEditorBuffer();
            var source     = new RSignatureHelpSource(textBuffer, Services);
            var session    = new SignatureHelpSessionMock(Services, textBuffer, 0);
            var textView   = session.TextView as TextViewMock;
            var signatures = new List <ISignature>();

            using (var tree = new EditorTree(eb, Services)) {
                tree.Build();
                using (var document = new EditorDocumentMock(tree)) {
                    session.TrackingPoint = new TrackingPointMock(textBuffer, 7, PointTrackingMode.Positive, TrackingFidelityMode.Forward);

                    tree.TakeThreadOwnerShip();
                    await source.AugmentSignatureHelpSessionAsync(session, signatures, tree.AstRoot);

                    signatures.Should().ContainSingle();

                    textView.Caret = new TextCaretMock(textView, 8);
                    var sh    = ((RSignatureHelp)signatures[0]).FunctionSignatureHelp;
                    var index = sh.SignatureInfo.ComputeCurrentParameter(tree.BufferSnapshot, tree.AstRoot, 8, _settings);
                    index.Should().Be(11);

                    textView.Caret = new TextCaretMock(textView, 15);
                    index          = sh.SignatureInfo.ComputeCurrentParameter(tree.BufferSnapshot, tree.AstRoot, 15, _settings);
                    index.Should().Be(6);
                }
            }
        }
Пример #7
0
        public void onUnSelect(SimObject obj)
        {
            EditorGui  EditorGui  = "EditorGui";
            Inspector  Inspector  = "Inspector";
            EditorTree EditorTree = "EditorTree";

            EditorGui.EditorGuiStatusBar EditorGuiStatusBar  = "EditorGuiStatusBar";
            ETransformSelection          ETransformSelection = "ETransformSelection";

            if (obj.isObject() && obj.isMethod("onEditorUnselect"))
            {
                obj.call("onEditorUnselect");
            }

            EditorGui.currentEditor.onObjectDeselected(obj);

            Inspector.removeInspect(obj);
            EditorTree.removeSelection(obj);

            // Inform the camera
            console.commandToServer("EditorOrbitCameraSelectChange", new string[] { getSelectionSize().AsString(), getSelectionCentroid().AsString() });

            EditorGuiStatusBar.setSelectionObjectsByCount(getSelectionSize().AsString());

            // Update the Transform Selection window

            ETransformSelection.onSelectionChanged();
        }
Пример #8
0
        public void onMultiSelect(SimSet set)
        {
            EditorTree EditorTree = "EditorTree";
            EditorGui  EditorGui  = "EditorGui";

            EditorGui.EditorGuiStatusBar EditorGuiStatusBar  = "EditorGuiStatusBar";
            ETransformSelection          ETransformSelection = "ETransformSelection";
            int count = set.getCount();
            int i     = 0;

            for (uint x = 0; x < set.getCount(); x++)
            {
                SimObject obj = set.getObject(x);
                if (obj.isMethod("onEditorSelect"))
                {
                    obj.call("onEditorSelect", count.AsString());
                }

                i++;

                EditorTree.addSelection(obj, i == count);
                EditorGui.currentEditor.onObjectSelected(obj);
            }
            // Inform the camera
            console.commandToServer("EditorOrbitCameraSelectChange", new string[] { count.AsString(), getSelectionCentroid().AsString() });
            EditorGuiStatusBar.setSelectionObjectsByCount(getSelectionSize().AsString());

            // Update the Transform Selection window, if it is
            // visible.

            if (ETransformSelection.isVisible())
            {
                ETransformSelection.onSelectionChanged();
            }
        }
Пример #9
0
        /// <summary>
        /// Closes the document
        /// </summary>
        public void Close()
        {
            if (IsClosed)
            {
                return;
            }

            IsClosed = true;
            Closing?.Invoke(this, null);

            EditorTree?.Dispose(); // this will also remove event handlers
            EditorTree = null;

            if (Closing != null)
            {
                foreach (var eh in Closing.GetInvocationList())
                {
                    var closingHandler = eh as EventHandler <EventArgs>;
                    if (closingHandler != null)
                    {
                        Debug.Fail(Invariant($"There are still listeners in the EditorDocument.OnDocumentClosing event list: {eh.Target}"));
                        Closing -= closingHandler;
                    }
                }
            }

            EditorBuffer?.Services?.RemoveService(this);
            EditorBuffer = null;
        }
Пример #10
0
        public static EditorTree ApplyTextChange(string expression, int start, int oldLength, int newLength, string newText)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            TextChange tc = new TextChange();

            tc.OldRange        = new TextRange(start, oldLength);
            tc.NewRange        = new TextRange(start, newLength);
            tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot);

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new Span(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new Span(start, oldLength));
            }

            return(tree);
        }
Пример #11
0
        public void TextChange_EditComment04()
        {
            string expression = "# comment\n a <- b + c";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 9, 1, 0, string.Empty);

            tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Structure);
        }
Пример #12
0
        public void TextChange_EditComment01(int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b # comment";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 12, oldLength, newLength, newText);

            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
Пример #13
0
        public void TextChange_EditWhitespaceTest(int start, int oldLength, int newLength, string newText, TextChangeType expected)
        {
            string expression = "x <- a + b";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, start, oldLength, newLength, newText);

            tree.PendingChanges.TextChangeType.Should().Be(expected);
        }
Пример #14
0
        public static EditorTree MakeTree(IServiceContainer services, string expression)
        {
            var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer();
            var tree       = new EditorTree(textBuffer, services);

            tree.Build();
            return(tree);
        }
Пример #15
0
        public void TextChange_CurlyBrace()
        {
            string expression = "if(true) {x <- 1} else ";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, expression.Length, 0, 1, "{");

            tree.IsDirty.Should().BeTrue();
            tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Structure);
        }
Пример #16
0
        public void EditorTree_InvalidateInRangeTest()
        {
            EditorTree tree = EditorTreeTest.MakeTree("if(true) x <- a + b");

            bool nodesChanged = false;
            bool result       = tree.InvalidateInRange(tree.AstRoot, new TextRange(4, 1), out nodesChanged);

            result.Should().BeTrue();
            nodesChanged.Should().BeTrue();
        }
Пример #17
0
        public static EditorTree MakeTree(ICoreShell coreShell, string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            var tree = new EditorTree(textBuffer, coreShell);

            tree.Build();

            return(tree);
        }
Пример #18
0
        public static EditorTree MakeTree(string expression)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            return(tree);
        }
Пример #19
0
        public void InvalidateAllInRange(string content, int start, int length)
        {
            EditorTree tree = EditorTreeTest.MakeTree(content);

            bool nodesChanged = tree.InvalidateInRange(new TextRange(start, length));

            nodesChanged.Should().BeTrue();

            tree.AstRoot.Children.Should().ContainSingle();
            tree.AstRoot.Children[0].Should().BeOfType <GlobalScope>();
            tree.AstRoot.Children[0].Children.Should().BeEmpty();
        }
Пример #20
0
        public void TextChange_EditComment05()
        {
            string expression = "#";

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 1, 0, 1, "a");

            tree.PendingChanges.TextChangeType.Should().Be(TextChangeType.Trivial);

            tree.AstRoot.Comments.Should().ContainSingle();
            var comment = tree.AstRoot.Comments[0];

            comment.Start.Should().Be(0);
            comment.Length.Should().Be(2);
        }
Пример #21
0
        private void txtEditorFilter_TextChanged(object sender, EventArgs e)
        {
            if (_activeSaveFile == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(txtEditorFilter.Text))
            {
                EditorTree.Nodes.Clear();
                foreach (var node in _activeSaveFile.Nodes)
                {
                    var treeNode = new NodeEntryTreeNode(node);
                    BuildVisualSubTree(treeNode, null);
                    EditorTree.Nodes.Add(treeNode);
                }

                return;
            }
            // Filter nodes. We also show parents if children contain the text.

            var filterString = txtEditorFilter.Text.ToLowerInvariant();

            List <NodeEntry> filteredNodes = new List <NodeEntry>();

            foreach (var node in _activeSaveFile.FlatNodes)
            {
                if (node.ToString().Contains(filterString))
                {
                    filteredNodes.Add(node);
                }
            }

            List <NodeEntryTreeNode> filteredTreeNodes = new List <NodeEntryTreeNode>();

            EditorTree.Nodes.Clear();
            foreach (var node in _activeSaveFile.Nodes)
            {
                var treeNode = new NodeEntryTreeNode(node);

                BuildVisualSubTree(treeNode, filterString);
                if (treeNode.Text.ToLowerInvariant().Contains(filterString) || treeNode.Nodes.Count > 0)
                {
                    EditorTree.Nodes.Add(treeNode);
                }
            }

            EditorTree.ExpandAll();
        }
Пример #22
0
        public REditorDocument(IEditorBuffer editorBuffer, IServiceContainer services, IExpressionTermFilter termFilter = null)
        {
            EditorBuffer = editorBuffer;
            _services    = services;

            EditorBuffer.Services.AddService(this);
            EditorBuffer.Closing += OnBufferClosing;

            var tree = new EditorTree(EditorBuffer, services, termFilter);

            tree.Build();
            EditorTree = tree;

            TreeValidator.FromEditorBuffer(EditorTree, services);
        }
Пример #23
0
        public static OutlineRegionCollection BuildOutlineRegions(IEditorShell editorShell, string content)
        {
            TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);

            using (var tree = new EditorTree(textBuffer, editorShell)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, editorShell)) {
                        OutlineRegionCollection rc = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc);
                        return(rc);
                    }
                }
            }
        }
Пример #24
0
        public static OutlineRegionCollection BuildOutlineRegions(string content)
        {
            TextBufferMock textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);

            using (EditorTree tree = new EditorTree(textBuffer)) {
                tree.Build();

                EditorDocumentMock      editorDocument = new EditorDocumentMock(tree);
                ROutlineRegionBuilder   ob             = new ROutlineRegionBuilder(editorDocument);
                OutlineRegionCollection rc             = new OutlineRegionCollection(0);
                ob.BuildRegions(rc);

                return(rc);
            }
        }
Пример #25
0
        public static OutlineRegionCollection BuildOutlineRegions(IServiceContainer services, string content)
        {
            var textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var eb         = textBuffer.ToEditorBuffer();

            using (var tree = new EditorTree(eb, services)) {
                tree.Build();
                using (var editorDocument = new EditorDocumentMock(tree)) {
                    using (var ob = new ROutlineRegionBuilder(editorDocument, services)) {
                        var rc = new OutlineRegionCollection(0);
                        ob.BuildRegions(rc);
                        return(rc);
                    }
                }
            }
        }
Пример #26
0
        public REditorDocument(IEditorBuffer editorBuffer, IServiceContainer services, bool isRepl)
        {
            EditorBuffer = editorBuffer;
            IsRepl       = isRepl;

            _services = services;

            EditorBuffer.Services.AddService(this);
            EditorBuffer.Closing += OnBufferClosing;

            var tree = new EditorTree(EditorBuffer, services);

            tree.Build();
            EditorTree = tree;

            _validator = new TreeValidator(EditorTree, services);
        }
Пример #27
0
        public void ProcessChange_EditExpression01()
        {
            string expression = "if(true) x <- 1";
            string expected1  =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [true]
            Variable  [true]
        TokenNode  [) [7...8)]
        SimpleScope  [9...15)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [11...13)]
                        Variable  [x]
                        TokenNode  [<- [11...13)]
                        NumericalValue  [1 [14...15)]
";

            ParserTest.VerifyParse(expected1, expression);

            EditorTree tree = EditorTreeTest.ApplyTextChange(expression, 3, 4, 5, "false");

            tree.IsDirty.Should().BeTrue();
            tree.ProcessChanges();

            string expected2 =
                @"GlobalScope  [Global]
    If  []
        TokenNode  [if [0...2)]
        TokenNode  [( [2...3)]
        Expression  [false]
            Variable  [false]
        TokenNode  [) [8...9)]
        SimpleScope  [10...16)
            ExpressionStatement  [x <- 1]
                Expression  [x <- 1]
                    TokenOperator  [<- [12...14)]
                        Variable  [x]
                        TokenNode  [<- [12...14)]
                        NumericalValue  [1 [15...16)]
";

            ParserTest.CompareTrees(expected2, tree.AstRoot);
        }
Пример #28
0
        public void onSelect(SimObject obj)
        {
            EditorTree EditorTree = "EditorTree";

            EditorTree.addSelection(obj, true);
            Util.setShadowVizLight(obj);
            if (obj.isObject() && obj.isMethod("onEditorSelect"))
            {
                obj.call("onEditorSelect", getSelectionSize().AsString());
            }


            EditorGui EditorGui = "EditorGui";

            EditorGui.currentEditor.onObjectSelected(obj);

            // Inform the camera

            console.commandToServer("EditorOrbitCameraSelectChange",
                                    new string[] { getSelectionSize().AsString(), getSelectionCentroid().AsString() });

            EditorGui.EditorGuiStatusBar EditorGuiStatusBar = "EditorGuiStatusBar";
            EditorGuiStatusBar.setSelectionObjectsByCount(getSelectionSize().AsString());

            // Update the materialEditorList

            iGlobal["$Tools::materialEditorList"] = obj.getId();

            // Used to help the Material Editor( the M.E doesn't utilize its own TS control )
            // so this dirty extension is used to fake it, just like the women I use to date...
            GuiWindowCollapseCtrl womanIUseToDate = "MaterialEditorPreviewWindow";
            GuiControl            theOtherTramp   = "MaterialEditorGui";

            if (womanIUseToDate.isVisible())
            {
                theOtherTramp.call("prepareActiveObject");
            }


            // Update the Transform Selection window

            ETransformSelection ETransformSelection = "ETransformSelection";

            ETransformSelection.onSelectionChanged();
        }
        public override void handleDelete()
        {
            EWorldEditor EWorldEditor = "EWorldEditor";
            EditorTree   EditorTree   = "EditorTree";

            // The tree handles deletion and notifies the
            // world editor to clear its selection.
            //
            // This is because non-SceneObject elements like
            // SimGroups also need to be destroyed.
            //
            // See EditorTree::onObjectDeleteCompleted().
            int selSize = EWorldEditor.getSelectionSize();

            if (selSize > 0)
            {
                EditorTree.deleteSelection();
            }
        }
Пример #30
0
        public REditorDocument(ITextBuffer textBuffer, ICoreShell shell)
        {
            _shell = shell;
            _textDocumentFactoryService = _shell.ExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            _textDocumentFactoryService.TextDocumentDisposed += OnTextDocumentDisposed;

            this.TextBuffer = textBuffer;
            IsClosed        = false;

            ServiceManager.AddService(this, TextBuffer, shell);

            _editorTree = new EditorTree(textBuffer, shell);
            if (REditorSettings.SyntaxCheckInRepl)
            {
                _validator = new TreeValidator(EditorTree, shell);
            }

            _editorTree.Build();
        }