public override void Initialize(int tabIndex)
        {
            editWidget = new MHTextEditWidget("", theme, pixelWidth: 320, multiLine: true, tabIndex: tabIndex, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = this.Name
            };
            editWidget.DrawFromHintedCache();
            editWidget.ActualTextEditWidget.EditComplete += (sender, e) =>
            {
                if (sender is TextEditWidget textEditWidget)
                {
                    this.SetValue(
                        textEditWidget.Text.Replace("\n", "\\n"),
                        userInitiated: true);
                }
            };

            editWidget.ActualTextEditWidget.TextChanged += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    editWidget.ActualTextEditWidget.Height = Math.Min(editWidget.ActualTextEditWidget.Printer.LocalBounds.Height, 500);
                });
            };

            this.Content = editWidget;
        }
Esempio n. 2
0
        public SurfacedEditorPage(IObject3D selectedItem)
        {
            this.WindowTitle = "MatterControl - " + "Editor Selector".Localize();
            this.HeaderText  = "Surfaced Editor".Localize();

            var tabControl = new SimpleTabs(theme, new GuiWidget())
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            tabControl.TabBar.BackgroundColor = theme.TabBarBackground;
            tabControl.TabBar.Padding         = 0;

            contentRow.AddChild(tabControl);
            contentRow.Padding = 0;

            var editContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Padding         = theme.DefaultContainerPadding,
                BackgroundColor = theme.ActiveTabColor
            };

            editWidget = new MHTextEditWidget("", multiLine: true)
            {
                HAnchor = HAnchor.Stretch,
                Name    = this.Name
            };
            editWidget.DrawFromHintedCache();

            editContainer.AddChild(editWidget);

            // add the tree view
            var treeView = new TreeView(theme)
            {
                Margin = new BorderDouble(left: 18),
            };

            treeView.AfterSelect += (s, e) =>
            {
                if (treeView.SelectedNode.Tag is IObject3D contextNode)
                {
                    editWidget.Text = "$." + string.Join(".", contextNode.AncestorsAndSelf().TakeWhile(o => !(o is ComponentObject3D)).Select(o => $"Children<{o.GetType().Name.ToString()}>").Reverse().ToArray());
                }
            };
            treeView.ScrollArea.ChildAdded += (s, e) =>
            {
                if (e is GuiWidgetEventArgs childEventArgs &&
                    childEventArgs.Child is TreeNode treeNode)
                {
                    treeNode.AlwaysExpandable = true;
                }
            };

            treeView.Click += (s, e) =>
            {
                if (treeView.IsDoubleClick(e))
                {
                    Console.WriteLine();
                }
            };

            treeView.ScrollArea.CloseAllChildren();

            var rootNode = Object3DTreeBuilder.BuildTree(selectedItem, theme);

            treeView.AddChild(rootNode);
            rootNode.TreeView = treeView;

            editContainer.AddChild(treeView);
            var dummyWidget = new GuiWidget()
            {
                BackgroundColor = Color.Red
            };

            var editTab = new ToolTab("Edit".Localize(), tabControl, editContainer, theme, hasClose: false)
            {
                Name = "Edit Tab"
            };

            tabControl.AddTab(editTab);

            var previewTab = new ToolTab("Preview".Localize(), tabControl, dummyWidget, theme, hasClose: false)
            {
                Name = "Preview Tab"
            };

            tabControl.AddTab(previewTab);

            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (tabControl.SelectedTabIndex == 1)
                {
                    // dummyWidget.Markdown = editWidget.Text;
                }
            };

            tabControl.SelectedTabIndex = 0;

            var saveButton = theme.CreateDialogButton("Save".Localize());

            saveButton.Click += (s, e) =>
            {
                this.ValueChanged?.Invoke(this, null);

                this.DialogWindow.CloseOnIdle();
            };
            this.AddPageAction(saveButton);
        }