Example #1
0
        private void CreateTabBarWidget(Splitter container, TabBarPlacement placement, float stretch, int insertAt)
        {
            var tabbedWidget = new TabbedWidget()
            {
                LayoutCell = new LayoutCell {
                    StretchY = 0
                },
                AllowReordering = true
            };

            tabbedWidget.FocusScope = new KeyboardFocusScope(tabbedWidget);
            var rootWidget = AddTitle(tabbedWidget, out ThemedTabCloseButton closeButton, out ThemedSimpleText titleLabel);

            foreach (var panelPlacement in placement.Placements)
            {
                var panel = Model.Panels.First(pan => pan.Id == panelPlacement.Id);
                panel.ContentWidget.Unlink();
                if (panelPlacement.Hidden)
                {
                    continue;
                }
                var tab = new ThemedTab {
                    Text     = panel.Id,
                    Closable = true,
                };
                tab.Closing += () => {
                    Model.FindPanelPlacement(panel.Id).Hidden = true;
                    Refresh();
                };
                tabbedWidget.AddTab(tab, new Widget {
                    Id         = $"DockPanel<{panel.Id}>",
                    LayoutCell = new LayoutCell(),
                    Layout     = new VBoxLayout(),
                    Padding    = new Thickness(0, 1),
                    Nodes      = { panel.ContentWidget }
                }, true);
                CreateDragBehaviour(panelPlacement, tab, panel.ContentWidget);
            }
            tabbedWidget.ActiveTabIndex    = 0;
            tabbedWidget.TabBar.OnReorder += args => {
                var item = placement.Placements[args.OldIndex];
                placement.RemovePlacement(item);
                placement.Placements.Insert(args.NewIndex, item);
                tabbedWidget.ActivateTab(args.NewIndex);
            };
            titleLabel.AddChangeWatcher(
                () => ((Tab)tabbedWidget.TabBar.Nodes[tabbedWidget.ActiveTabIndex]).Text,
                title => titleLabel.Text = title
                );
            closeButton.Clicked += () => {
                foreach (var panelPlacement in placement.Placements)
                {
                    panelPlacement.Hidden = true;
                }
                Refresh();
            };
            CreateDragBehaviour(placement, rootWidget.Nodes[0].AsWidget, rootWidget);
            container.Nodes.Insert(insertAt, rootWidget);
            container.Stretches.Insert(insertAt, stretch);
        }
Example #2
0
        private void CreateTabBarWidget(Splitter container, TabBarPlacement placement, float stretch, bool requestTitle)
        {
            var tabbedWidget = new TabbedWidget {
                TabBar          = new PanelTabBar(),
                AllowReordering = true,
                BarPlacement    = TabbedWidget.TabBarPlacement.Bottom,
                PostPresenter   = new SyncDelegatePresenter <TabbedWidget>(w => {
                    w.PrepareRendererState();
                    var activeTab = (Tab)w.TabBar.Nodes[w.ActiveTabIndex];
                    var color     = ColorTheme.Current.Docking.TabOutline;
                    var a         = activeTab.CalcPositionInSpaceOf(w);
                    var start     = a * Vector2.Down;
                    var b         = a + Vector2.Down * activeTab.ContentHeight;
                    var c         = b + activeTab.ContentWidth * Vector2.Right;
                    var d         = c - Vector2.Down * activeTab.ContentHeight;
                    var end       = start + w.Size * Vector2.Right;
                    Renderer.DrawLine(start, a + Vector2.Right * 0.5f, color);
                    Renderer.DrawLine(a, b, color);
                    Renderer.DrawLine(b + new Vector2(-0.5f, -0.5f), c + new Vector2(0.5f, -0.5f), color);
                    Renderer.DrawLine(c, d, color);
                    Renderer.DrawLine(d + Vector2.Left * 0.5f, end, color);
                })
            };
            Widget rootWidget = tabbedWidget;

            tabbedWidget.FocusScope           = new KeyboardFocusScope(tabbedWidget);
            tabbedWidget.TabBar.OnReordering += args => placement.Placements.Move(args.IndexFrom, args.IndexTo);
            if (requestTitle)
            {
                rootWidget = WrapWithTitle(tabbedWidget, out var closeButton, out var titleLabel);
                titleLabel.AddChangeWatcher(
                    () => ((Tab)tabbedWidget.TabBar.Nodes[tabbedWidget.ActiveTabIndex]).Text,
                    title => titleLabel.Text = title
                    );
                closeButton.Clicked += () => {
                    placement.Placements.Where(p => !p.Hidden).ElementAt(tabbedWidget.ActiveTabIndex).Hidden = true;
                    Refresh();
                };
                CreateDragBehaviour(placement, rootWidget.Nodes[0].AsWidget, rootWidget);
            }
            foreach (var panelPlacement in placement.Placements)
            {
                var panel = Model.Panels.First(pan => pan.Id == panelPlacement.Id);
                panel.ContentWidget.Unlink();
                if (panelPlacement.Hidden)
                {
                    continue;
                }
                var tab = new PanelTab {
                    Text     = panel.Id,
                    Closable = false,
                };
                tab.Closing += () => {
                    Model.FindPanelPlacement(panel.Id).Hidden = true;
                    Refresh();
                };
                tabbedWidget.AddTab(tab, new Widget {
                    Id         = $"DockPanel<{panel.Id}>",
                    LayoutCell = new LayoutCell(),
                    Layout     = new VBoxLayout(),
                    Padding    = new Thickness(0, 1),
                    Nodes      = { panel.ContentWidget }
                }, true);
                CreateDragBehaviour(panelPlacement, tab, panel.ContentWidget);
                panel.PanelWidget = rootWidget;
            }
            tabbedWidget.ActiveTabIndex = 0;
            container.Nodes.Add(rootWidget);
            container.Stretches.Add(stretch);
        }
Example #3
0
        public PreferencesDialog()
        {
            window = new Window(new WindowOptions {
                ClientSize           = new Vector2(800, 600),
                FixedSize            = false,
                Title                = "Preferences",
                MinimumDecoratedSize = new Vector2(400, 300),
                Visible              = false
            });
            Frame = new ThemedFrame {
                Padding    = new Thickness(8),
                LayoutCell = new LayoutCell {
                    StretchY = float.MaxValue
                },
                Layout = new StackLayout(),
            };
            Content = new TabbedWidget();
            Content.AddTab("General", CreateGeneralPane(), true);
            Content.AddTab("Appearance", CreateColorsPane());
            Content.AddTab("Theme", CreateThemePane());
            Content.AddTab("Keyboard shortcuts", CreateKeyboardPane());
            Content.AddTab("Toolbar", toolbarModelEditor = new ToolbarModelEditor());

            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    Content,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.LeftCenter),
                        Padding    = new Thickness {
                            Top = 5
                        },
                        Nodes =
                        {
                            (resetButton     = new ThemedButton {
                                Text         = "Reset To Defaults", MinMaxWidth    = 150f
                            }),
                            new Widget {
                                MinMaxHeight =        0
                            },
                            (okButton        = new ThemedButton {
                                Text         = "Ok"
                            }),
                            (cancelButton    = new ThemedButton {
                                Text         = "Cancel"
                            }),
                        }
                    }
                }
            };
            HotkeyRegistry.CurrentProfile.Save();
            okButton.Clicked += () => {
                saved = true;
                SaveAfterEdit();
                window.Close();
                VisualHintsPanel.Refresh();
                Core.UserPreferences.Instance.Save();
                if (themeChanged)
                {
                    AlertDialog.Show("Color theme changes will be applied after Tangerine restart.");
                }
            };
            resetButton.Clicked += () => {
                if (new AlertDialog($"Are you sure you want to reset to defaults?", "Yes", "Cancel").Show() == 0)
                {
                    ResetToDefaults();
                }
            };
            cancelButton.Clicked += () => {
                window.Close();
                Core.UserPreferences.Instance.Load();
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    Core.UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();

            window.Closed += () => {
                if (saved)
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Save();
                    }
                    HotkeyRegistry.CurrentProfile = currentProfile;
                }
                else
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Load();
                    }
                    HotkeyRegistry.CurrentProfile = HotkeyRegistry.CurrentProfile;
                }
            };

            foreach (var command in HotkeyRegistry.CurrentProfile.Commands)
            {
                command.Command.Shortcut = new Shortcut(Key.Unknown);
            }
            window.ShowModal();
        }
Example #4
0
        public PreferencesDialog()
        {
            theme  = AppUserPreferences.Instance.Theme;
            window = new Window(new WindowOptions {
                ClientSize           = new Vector2(600, 400),
                FixedSize            = false,
                Title                = "Preferences",
                MinimumDecoratedSize = new Vector2(400, 300)
            });
            Frame = new ThemedFrame {
                Padding    = new Thickness(8),
                LayoutCell = new LayoutCell {
                    StretchY = float.MaxValue
                },
                Layout = new StackLayout(),
            };
            Content = new TabbedWidget();
            Content.AddTab("General", CreateGeneralPane(), true);
            Content.AddTab("Appearance", CreateColorsPane());

            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    Content,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.LeftCenter),
                        Nodes      =
                        {
                            (resetButton     = new ThemedButton {
                                Text         = "Reset To Defaults", MinMaxWidth    = 150f
                            }),
                            new Widget {
                                MinMaxHeight =        0
                            },
                            (okButton        = new ThemedButton {
                                Text         = "Ok"
                            }),
                            (cancelButton    = new ThemedButton {
                                Text         = "Cancel"
                            }),
                        }
                    }
                }
            };
            okButton.Clicked += () => {
                window.Close();
                if (theme != AppUserPreferences.Instance.Theme)
                {
                    AlertDialog.Show("The color theme change will take effect next time you run Tangerine.");
                }
                Core.UserPreferences.Instance.Save();
            };
            resetButton.Clicked += () => {
                if (new AlertDialog($"Are you sure you want to reset to defaults?", "Yes", "Cancel").Show() == 0)
                {
                    ResetToDefaults();
                }
            };
            cancelButton.Clicked += () => {
                window.Close();
                Core.UserPreferences.Instance.Load();
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    Core.UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();
        }
Example #5
0
        public static void ShowFor(Model3D source)
        {
            // Do not show others attachment dialogs if one is already present
            if (history != null)
            {
                return;
            }
            history = new DocumentHistory();
            Button cancelButton;
            var    attachment = new Model3DAttachmentParser().Parse(source.ContentsPath) ?? new Model3DAttachment {
                ScaleFactor = 1
            };
            var window = new Window(new WindowOptions {
                ClientSize           = new Vector2(700, 400),
                FixedSize            = false,
                Title                = "Attachment3D",
                MinimumDecoratedSize = new Vector2(500, 300),
            });
            var content = new TabbedWidget();

            content.AddTab("General", CreateGeneralPane(attachment), true);
            content.AddTab("Material Effects", CreateMaterialEffectsPane(attachment));
            content.AddTab("Components", CreateComponentsPane(attachment));
            content.AddTab("Mesh Options", CreateMeshOptionsPane(attachment));
            content.AddTab("Animations", CreateAnimationsPane(attachment));
            Button       okButton;
            WindowWidget rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    content,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Padding    = new Thickness {
                            Top = 5
                        },
                        Nodes =
                        {
                            (okButton     = new ThemedButton {
                                Text      = "Ok"
                            }),
                            (cancelButton = new ThemedButton {
                                Text      = "Cancel"
                            }),
                        }
                    }
                }
            };

            cancelButton.Clicked += () => {
                window.Close();
                history = null;
                UserPreferences.Instance.Load();
            };
            okButton.Clicked += () => {
                try {
                    CheckErrors(attachment, source);
                    window.Close();
                    history = null;
                    // Since attachment dialog not present as modal window, document can be rolled back with "undo"
                    // operation to the state when source isn't presented or source content path isn't set.
                    // So check it out before saving.
                    if (source.DescendantOf(Document.Current.RootNode) && source.ContentsPath != null)
                    {
                        Model3DAttachmentParser.Save(attachment, System.IO.Path.Combine(Project.Current.AssetsDirectory, source.ContentsPath));
                    }
                } catch (Lime.Exception e) {
                    new AlertDialog(e.Message).Show();
                }
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    UserPreferences.Instance.Load();
                }
            });
            rootWidget.Tasks.AddLoop(() => {
                if (!Command.Undo.IsConsumed())
                {
                    Command.Undo.Enabled = history.CanUndo();
                    if (Command.Undo.WasIssued())
                    {
                        Command.Undo.Consume();
                        history.Undo();
                    }
                }
                if (!Command.Redo.IsConsumed())
                {
                    Command.Redo.Enabled = history.CanRedo();
                    if (Command.Redo.WasIssued())
                    {
                        Command.Redo.Consume();
                        history.Redo();
                    }
                }
            });
        }