示例#1
0
 public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     EditorContainer.AddNode(new Widget {
         Layout = new HBoxLayout(),
         Nodes  =
         {
             (editor         = editorParams.EditBoxFactory()),
             Spacer.HSpacer(4),
             (button         = new ThemedButton {
                 Text        = "...",
                 MinMaxWidth =                             20,
                 LayoutCell  = new LayoutCell(Alignment.Center)
             })
         }
     });
     editor.LayoutCell = new LayoutCell(Alignment.Center);
     editor.Editor.EditorParams.MaxLines = maxLines;
     editor.MinHeight += editor.TextWidget.FontHeight * (maxLines - 1);
     editor.Submitted += text => SetProperty(text);
     editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v);
     button.Clicked += () => {
         var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => {
             SetProperty(s);
         });
     };
 }
示例#2
0
        public AlertDialog(string text, params string[] buttons)
        {
            if (buttons.Length == 0)
            {
                buttons = new[] { "Ok" };
            }
            window = new Window(new WindowOptions {
                FixedSize = true,
                Title     = "Tangerine",
                Visible   = false,
                Style     = WindowStyle.Dialog
            });
            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                LayoutBasedWindowSize = true,
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 16
                },
                Nodes =
                {
                    new ThemedSimpleText(text)
                    {
                        Padding = new Thickness(4)
                    },
                    (buttonsPanel = new Widget{
                        Layout = new HBoxLayout{
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter, 1, 0),
                    })
                }
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            var cancelIndex = buttons.ToList().IndexOf("Cancel");

            if (cancelIndex >= 0)
            {
                result = cancelIndex;
                rootWidget.LateTasks.AddLoop(() => {
                    if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                    {
                        Close(cancelIndex);
                    }
                });
            }
            for (int i = 0; i < buttons.Length; i++)
            {
                var button = new ThemedButton {
                    Text = buttons[i]
                };
                int j = i;
                button.Clicked += () => Close(j);
                buttonsPanel.AddNode(button);
                if (i == 0)
                {
                    button.SetFocus();
                }
            }
        }
示例#3
0
        public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ThemedButton button;

            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.Editor.EditorParams.MaxLines = maxLines;
            editor.MinHeight += editor.TextWidget.FontHeight * (maxLines - 1);
            var first     = true;
            var submitted = false;
            var current   = CoalescedPropertyValue();

            editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value : ManyValuesText);
            button.Clicked += () => {
                var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => {
                    SetProperty(s);
                });
            };
            editor.Submitted += text => Submit();
            editor.AddChangeLateWatcher(() => editor.Text, text => {
                if (first)
                {
                    first = false;
                    return;
                }
                if (!editor.IsFocused())
                {
                    return;
                }
                if (submitted)
                {
                    Document.Current.History.Undo();
                }
                submitted = true;
                Submit();
            });
            editor.AddChangeLateWatcher(() => editor.IsFocused(), focused => {
                if (submitted)
                {
                    Document.Current.History.Undo();
                }
                if (!focused)
                {
                    submitted = false;
                }
            });
            ManageManyValuesOnFocusChange(editor, current);
        }
示例#4
0
            /// <summary>
            /// Creates basic UI elements, but lefts bundle list empty. To fill it, call <see cref="CreateBundlesList"/>
            /// </summary>
            public BundlePickerWidget(BundlePicker bundlePicker)
            {
                this.bundlePicker = bundlePicker;

                Layout = new VBoxLayout {
                    Spacing = 6
                };
                MaxWidth = 250f;

                checkboxes = new Dictionary <string, ThemedCheckBox>();
                lines      = new Dictionary <string, Widget>();
                scrollView = new ThemedScrollView();
                scrollView.CompoundPostPresenter.Add(new WidgetBoundsPresenter(Lime.Theme.Colors.ControlBorder));
                scrollView.Content.Layout = new VBoxLayout {
                    Spacing = 6
                };
                scrollView.Content.Padding = new Thickness(6);
                scrollView.CompoundPresenter.Add(new WidgetFlatFillPresenter(Color4.White));

                selectButton = new ThemedButton {
                    Text    = "Select all",
                    Clicked = SelectButtonClickHandler
                };

                refreshButton = new ThemedButton {
                    Text    = "Refresh",
                    Clicked = Refresh,
                };

                filter = new ThemedEditBox();
                filter.Tasks.Add(FilterBundlesTask);

                infoText = new ThemedSimpleText("Selected action uses all bundles.")
                {
                    Color        = Theme.Colors.BlackText,
                    MinMaxHeight = Theme.Metrics.DefaultEditBoxSize.Y,
                    Visible      = false,
                    VAlignment   = VAlignment.Center,
                };

                AddNode(filter);
                AddNode(infoText);
                AddNode(scrollView);

                var buttonLine = new Widget {
                    Layout = new HBoxLayout {
                        Spacing = 6
                    }
                };

                AddNode(buttonLine);
                buttonLine.AddNode(new Widget {
                    LayoutCell = new LayoutCell {
                        StretchX = float.MaxValue
                    }, MaxHeight = 0
                });
                buttonLine.AddNode(refreshButton);
                buttonLine.AddNode(selectButton);
                selectButton.Tasks.Add(UpdateTextOfSelectButtonTask());
            }
示例#5
0
 public SaveRulerDialog()
 {
     window = new Window(new WindowOptions {
         FixedSize = true,
         Title     = "Save Ruler",
         Visible   = false,
         Style     = WindowStyle.Dialog,
     });
     rootWidget = new ThemedInvalidableWindowWidget(window)
     {
         LayoutBasedWindowSize = true,
         Padding = new Thickness(8),
         Layout  = new VBoxLayout {
             Spacing = 16
         },
         Nodes =
         {
             new Widget {
                 Layout = new TableLayout{
                     ColCount    = 2,
                     RowCount    = 1,
                     Spacing     = 8,
                     ColDefaults =
                     {
                         new LayoutCell(Alignment.RightCenter, 0.5f, 0),
                         new LayoutCell(Alignment.LeftCenter,     1, 0)
                     }
                 },
                 Nodes =
                 {
                     new ThemedSimpleText("Enter ruler name"),
                     (EditBox = new ThemedEditBox()),
                 }
             },
             (buttonsPanel = new Widget{
                 Layout = new HBoxLayout{
                     Spacing = 8
                 },
                 LayoutCell = new LayoutCell(Alignment.RightCenter),
                 Nodes =
                 {
                     (okButton     = new ThemedButton("Ok")),
                     (cancelButton = new ThemedButton("Cancel")),
                 }
             })
         }
     };
     cancelButton.Clicked += window.Close;
     okButton.AddChangeWatcher(() => EditBox.Text, (text) => okButton.Enabled = !string.IsNullOrEmpty(text));
     okButton.Clicked += () => {
         result = EditBox.Text;
         window.Close();
     };
     rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
     EditBox.SetFocus();
 }
示例#6
0
        public static Widget ProduceStartPage(IEnumerable <string> recentProjects)
        {
            ThemedButton openButton = null;
            var          root       = new Frame {
                Layout = new LinearLayout(LayoutDirection.TopToBottom),
                Nodes  =
                {
                    (openButton = new ThemedButton("Open")
                    {
                        Clicked = () => FileChooser.ShowOpenCitrusProjectDialog(The.Workspace.Open, recentProjects.FirstOrDefault()),
                    })
                },
            };

            DecorateButton(openButton);
            foreach (var projectPath in recentProjects)
            {
                var   projectPathBound = projectPath;
                Frame f           = null;
                var   projectName = Path.GetFileNameWithoutExtension(projectPath);
                root.AddNode(
                    f = new Frame {
                    Layout = new LinearLayout(LayoutDirection.LeftToRight),
                    Nodes  =
                    {
                        (openButton = new ThemedButton($"{projectName}\n at \"{projectPathBound}\"")
                        {
                            Clicked = () => The.Workspace.Load(projectPathBound),
                        }),
                        new ThemedButton("X")
                        {
                            Clicked = () => {
                                The.Workspace.RemoveRecentProject(projectPathBound);
                                root.Nodes.Remove(f);
                            },
                        }
                    }
                }
                    );
                DecorateButton(openButton);
            }
            return(root);

            void DecorateButton(ThemedButton b)
            {
                b.MinSize = Vector2.Zero;
                b.MaxSize = Vector2.PositiveInfinity;
                var buttonText = (b["TextPresenter"] as SimpleText);

                buttonText.FontHeight   = 100;
                buttonText.OverflowMode = TextOverflowMode.Minify;
            }
        }
示例#7
0
        protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams)
        {
            ThemedButton button;

            this.allowedFileTypes = allowedFileTypes;
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell         = new LayoutCell(Alignment.Center);
            editor.Submitted         += text => SetComponent(text);
            button.Clicked           += OnSelectClicked;
            ExpandableContent.Padding = new Thickness(24, 10, 2, 2);
            var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix))
            {
                LabelWidth = 180
            });

            prefix.Prefix = GetLongestCommonPrefix(GetPaths());
            ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => {
                string oldPrefix = GetLongestCommonPrefix(GetPaths());
                if (oldPrefix == v)
                {
                    return;
                }
                SetPathPrefix(oldPrefix, v);
                prefix.Prefix = v.Trim('/');
            });
            ContainerWidget.AddChangeWatcher(() => ShowPrefix, show => {
                Expanded             = show && Expanded;
                ExpandButton.Visible = show;
            });
            var current = CoalescedPropertyValue();

            editor.AddChangeLateWatcher(current, v => editor.Text = ValueToStringConverter(v.Value) ?? "");
            ManageManyValuesOnFocusChange(editor, current);
        }
        private Widget CreateButtonsPanel()
        {
            var okButton = new ThemedButton {
                Text = "Ok"
            };
            var cancelButton = new ThemedButton {
                Text = "Cancel"
            };

            okButton.Clicked += () => {
                var value = "";
                foreach (var s in selected)
                {
                    value += $"{s},";
                }
                if (!string.IsNullOrEmpty(value))
                {
                    value = value.Trim(',');
                }
                onSave.Invoke(value);
                window.Close();
            };
            cancelButton.Clicked += () => {
                window.Close();
            };
            return(new Widget {
                Layout = new HBoxLayout {
                    Spacing = 8
                },
                LayoutCell = new LayoutCell {
                    StretchY = 0
                },
                Padding = new Thickness {
                    Top = 5
                },
                Nodes =
                {
                    new Widget {
                        MinMaxHeight = 0
                    },
                    okButton,
                    cancelButton
                },
            });
        }
        public static void Create()
        {
            var clear = new Subject <Unit>();

            Application.Desktop.CreateSingletonWindow(
                Observable.Return(true),
                dialog => new Window
            {
                Title   = Observable.Return("Console output"),
                Size    = Property.Create <Optional <Size <Points> > >(new Size <Points>(600, 600)).ToOptional(),
                Content = LogView.Create(InitializeConsoleRedirection(), color: Theme.DefaultText, clear: clear, darkTheme: Theme.IsDark)
                          .WithBackground(Theme.PanelBackground)
                          .WithOverlay(ThemedButton.Create(Command.Enabled(() => clear.OnNext(Unit.Default)), "Clear").DockTopRight()),
                Background = Theme.PanelBackground,
                Foreground = Theme.DefaultText,
                Border     = Separator.MediumStroke
            });
        }
示例#10
0
        public FileChooser()
        {
            Layout = new HBoxLayout {
                Spacing = 4
            };
            editor = new ThemedEditBox {
                LayoutCell = new LayoutCell(Alignment.Center)
            };
            AddNode(editor);
            var button = new ThemedButton {
                Text        = "...",
                MinMaxWidth = 20,
                LayoutCell  = new LayoutCell(Alignment.Center)
            };

            AddNode(button);
            editor.Submitted += ChooseFileByUser;
            button.Clicked   += ButtonClicked;
        }
示例#11
0
        public FileChooser()
        {
            Layout = new HBoxLayout {
                Spacing = 4
            };
            editor = new ThemedEditBox {
                LayoutCell = new LayoutCell(Alignment.Center)
            };
            AddNode(editor);
            var button = new ThemedButton {
                Text        = "...",
                MinMaxWidth = 20,
                LayoutCell  = new LayoutCell(Alignment.Center)
            };

            AddNode(button);
            editor.Submitted += ChooseFileByUser;
            button.Clicked   += () => ShowOpenCitrusProjectDialog(ChooseFileByUser, InitialDirectory);
        }
示例#12
0
 static IControl CreateButton(
     Command command,
     Brush hoverColor     = default(Brush),
     Command mouseEntered = default(Command),
     Command mouseExited  = default(Command))
 {
     return
         (Layout.StackFromTop(
              ThemedButton.Create(
                  command: command,
                  label: "Make class from selection",
                  icon: Icons.ExtractClass(command.IsEnabled),
                  tooltip: "Make class from selection",
                  hoverColor: hoverColor)
              .WithHeight(45)
              .OnMouse(
                  entered: mouseEntered,
                  exited: mouseExited),
              Separator.Shadow));
 }
示例#13
0
        public TriggerPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams)
        {
            if (EditorParams.Objects.Skip(1).Any())
            {
                EditorContainer.AddNode(CreateWarning("Edit of triggers isn't supported for multiple selection."));
                return;
            }
            node = (Node)editorParams.Objects.First();
            var button = new ThemedButton {
                Text        = "...",
                MinMaxWidth = 20,
                LayoutCell  = new LayoutCell(Alignment.Center)
            };
            var color = button.GlobalColor;

            EditorContainer.AddNode(editBox = editorParams.EditBoxFactory());
            EditorContainer.AddNode(Spacer.HSpacer(4));
            EditorContainer.AddNode(button);
            EditorContainer.AddNode(Spacer.HStretch());
            editBox.Submitted += text => {
                var newValue = FilterTriggers(text);
                editBox.Text = newValue;
                SetProperty(newValue);
            };
            button.Clicked += () => {
                var window = new TriggerSelectionDialog(
                    GetAvailableTriggers(),
                    new HashSet <string>(CurrentTriggers),
                    s => {
                    s = FilterTriggers(s);
                    SetProperty(s);
                    editBox.Text = s;
                }
                    );
            };
            editBox.AddChangeLateWatcher(CoalescedPropertyValue(), v => editBox.Text = v.Value);
            Invalidate();
        }
示例#14
0
        private Widget CreateKeyboardPane()
        {
            var hotkeyEditor = new HotkeyEditor();
            var pane         = new Widget {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };

            pane.Awoke += node => hotkeyEditor.SetFocus();

            var profileLabel = new ThemedSimpleText("Profile: ")
            {
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Right,
                LayoutCell = new LayoutCell(Alignment.RightCenter, 0)
            };
            var profilePicker = new ThemedDropDownList();

            profilePicker.TextWidget.Padding = new Thickness(3, 0);

            var exportButton = new ThemedButton("Export...");

            exportButton.Clicked = () => {
                var dlg = new FileDialog {
                    Mode            = FileDialogMode.Save,
                    InitialFileName = currentProfile.Name
                };
                if (dlg.RunModal())
                {
                    currentProfile.Save(dlg.FileName);
                }
            };
            var importButton = new ThemedButton("Import...");

            importButton.Clicked = () => {
                var dlg = new FileDialog {
                    Mode = FileDialogMode.Open
                };
                if (dlg.RunModal())
                {
                    string name = Path.GetFileName(dlg.FileName);
                    if (HotkeyRegistry.Profiles.Any(i => i.Name == name))
                    {
                        if (new AlertDialog($"Profile with name \"{name}\" already exists. Do you want to rewrite it?", "Yes", "Cancel").Show() != 0)
                        {
                            return;
                        }
                        else
                        {
                            profilePicker.Items.Remove(profilePicker.Items.First(i => i.Text == name));
                        }
                    }
                    var profile = HotkeyRegistry.CreateProfile(Path.GetFileName(dlg.FileName));
                    profile.Load(dlg.FileName);
                    profile.Save();
                    HotkeyRegistry.Profiles.Add(profile);
                    profilePicker.Items.Add(new CommonDropDownList.Item(profile.Name, profile));
                    profilePicker.Value = profile;
                }
            };
            var deleteButton = new ThemedButton("Delete");

            deleteButton.Clicked = () => {
                if (new AlertDialog($"Are you sure you want to delete profile \"{currentProfile.Name}\"?", "Yes", "Cancel").Show() == 0)
                {
                    currentProfile.Delete();
                    profilePicker.Items.Remove(profilePicker.Items.First(i => i.Value == currentProfile));
                    profilePicker.Index           = 0;
                    HotkeyRegistry.CurrentProfile = profilePicker.Value as HotkeyProfile;
                    foreach (var command in HotkeyRegistry.CurrentProfile.Commands)
                    {
                        command.Command.Shortcut = new Shortcut(Key.Unknown);
                    }
                }
            };

            var categoryLabel = new ThemedSimpleText("Commands: ")
            {
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Right,
                LayoutCell = new LayoutCell(Alignment.RightCenter, 0)
            };
            var categoryPicker = new ThemedDropDownList();

            categoryPicker.TextWidget.Padding = new Thickness(3, 0);

            var allShortcutsView = new ThemedScrollView();

            allShortcutsView.Content.Padding = contentPadding;
            allShortcutsView.Content.Layout  = new VBoxLayout {
                Spacing = 8
            };

            var selectedShortcutsView = new ThemedScrollView();

            selectedShortcutsView.Content.Padding = contentPadding;
            selectedShortcutsView.Content.Layout  = new VBoxLayout {
                Spacing = 4
            };

            hotkeyEditor.SelectedShortcutChanged = () => {
                selectedShortcutsView.Content.Nodes.Clear();
                var commands = hotkeyEditor.SelectedCommands.ToLookup(i => i.CategoryInfo);
                foreach (var category in commands)
                {
                    selectedShortcutsView.Content.AddNode(new ThemedSimpleText {
                        Text       = category.Key.Title,
                        VAlignment = VAlignment.Center,
                        Color      = Theme.Colors.GrayText
                    });
                    foreach (var command in category)
                    {
                        var shortcut = new ThemedSimpleText {
                            Text       = command.Shortcut.ToString(),
                            VAlignment = VAlignment.Center,
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 1)
                        };
                        var name = new ThemedSimpleText {
                            Text       = command.Title,
                            VAlignment = VAlignment.Center,
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 2)
                        };
                        var deleteShortcutButton = new ThemedTabCloseButton {
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 0),
                            Clicked    = () => {
                                command.Shortcut = new Shortcut();
                                hotkeyEditor.UpdateButtonCommands();
                                hotkeyEditor.UpdateShortcuts();
                            }
                        };
                        selectedShortcutsView.Content.AddNode(new Widget {
                            Layout = new TableLayout {
                                Spacing = 4, RowCount = 1, ColumnCount = 3
                            },
                            Nodes   = { shortcut, name, deleteShortcutButton },
                            Padding = new Thickness(15, 0)
                        });
                    }
                }
                selectedShortcutsView.ScrollPosition = allShortcutsView.MinScrollPosition;
            };

            var filterBox = new ThemedEditBox {
                MaxWidth = 200
            };

            filterBox.AddChangeWatcher(() => filterBox.Text, text => {
                UpdateAllShortcutsView(allShortcutsView, selectedShortcutsView, hotkeyEditor, text.ToLower());
                allShortcutsView.ScrollPosition = allShortcutsView.MinScrollPosition;
            });

            categoryPicker.Changed += args => {
                hotkeyEditor.Category = (args.Value as CommandCategoryInfo);
                hotkeyEditor.SetFocus();
                int index = -1;
                foreach (var node in allShortcutsView.Content.Nodes.SelectMany(i => i.Nodes))
                {
                    var button = node as ThemedExpandButton;
                    if (button == null)
                    {
                        continue;
                    }
                    index++;
                    if (index == args.Index)
                    {
                        if (!button.Expanded)
                        {
                            button.Clicked?.Invoke();
                        }
                        allShortcutsView.ScrollPosition = button.ParentWidget.Position.Y;
                        break;
                    }
                }
            };

            profilePicker.Changed += args => {
                var profile = args.Value as HotkeyProfile;
                if (profile != null)
                {
                    hotkeyEditor.Profile = profile;
                    filterBox.Text       = null;
                    UpdateAllShortcutsView(allShortcutsView, selectedShortcutsView, hotkeyEditor, filterBox.Text);
                    deleteButton.Enabled = profile.Name != HotkeyRegistry.DefaultProfileName && profilePicker.Items.Count > 1;
                    categoryPicker.Items.Clear();
                    foreach (var category in profile.Categories)
                    {
                        categoryPicker.Items.Add(new CommonDropDownList.Item(category.Title, category));
                    }
                    categoryPicker.Value = null;
                    categoryPicker.Value = profile.Categories.First();
                    currentProfile       = profile;
                }
            };
            UpdateProfiles(profilePicker);

            HotkeyRegistry.Reseted = () => UpdateProfiles(profilePicker);

            pane.AddNode(new Widget {
                Layout = new TableLayout {
                    Spacing = 4, RowCount = 2, ColumnCount = 3
                },
                Nodes =
                {
                    profileLabel,  profilePicker,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 4
                        },
                        Nodes = { exportButton,importButton, deleteButton               }
                    },
                    categoryLabel, categoryPicker
                },
                LayoutCell = new LayoutCell {
                    StretchY = 0
                }
            });

            pane.AddNode(hotkeyEditor);
            pane.AddNode(new Widget {
                Layout = new HBoxLayout {
                    Spacing = 12
                },
                Nodes =
                {
                    new Widget              {
                        Layout = new VBoxLayout{
                            Spacing = 4
                        },
                        Nodes =
                        {
                            new Widget      {
                                Layout = new HBoxLayout{
                                    Spacing = 8
                                },
                                Nodes =
                                {
                                    new ThemedSimpleText("Search: ")
                                    {
                                        VAlignment = VAlignment.Center,
                                        LayoutCell = new LayoutCell(Alignment.LeftCenter, 0)
                                    },
                                    filterBox
                                },
                                LayoutCell = new LayoutCell{
                                    StretchY = 0
                                }
                            },
                            new ThemedFrame {
                                Nodes  =    { allShortcutsView      },
                                Layout = new VBoxLayout()
                            }
                        }
                    },
                    new Widget              {
                        Layout = new VBoxLayout{
                            Spacing = 4
                        },
                        Nodes =
                        {
                            new ThemedSimpleText("Selected commands:")
                            {
                                LayoutCell = new LayoutCell{
                                    StretchY = 0
                                }
                            },
                            new ThemedFrame {
                                Nodes  =    { selectedShortcutsView },
                                Layout = new VBoxLayout()
                            }
                        }
                    }
                }
            });

            return(pane);
        }
示例#15
0
        private Widget CreateThemeEditor()
        {
            var pane = new Widget {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };
            var themeEditor = new ColorThemeEditor()
            {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };
            bool firstCall = true;

            pane.AddChangeWatcher(() => themeEditor.Version, _ => {
                if (firstCall)
                {
                    firstCall = false;
                    return;
                }
                themeChanged = true;
                themeEdited  = true;
            });
            var darkIcons      = CreateDarkIconsSwitch(pane);
            var loadDarkButton = new ThemedButton("Dark preset")
            {
                Clicked = () => {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Dark;
                    AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateDarkTheme();
                    AppUserPreferences.Instance.ColorTheme     = ColorTheme.CreateDarkTheme();
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var loadLightButton = new ThemedButton("Light preset")
            {
                Clicked = () => {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Light;
                    AppUserPreferences.Instance.LimeColorTheme = Theme.ColorTheme.CreateLightTheme();
                    AppUserPreferences.Instance.ColorTheme     = ColorTheme.CreateLightTheme();
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var saveButton = new ThemedButton("Save theme")
            {
                Clicked = () => {
                    var dlg = new FileDialog {
                        AllowedFileTypes = new string[] { "theme" },
                        Mode             = FileDialogMode.Save
                    };
                    if (dlg.RunModal())
                    {
                        string path       = dlg.FileName;
                        var    serializer = new Yuzu.Json.JsonSerializer();
                        try {
                            var limeTheme = AppUserPreferences.Instance.LimeColorTheme;
                            var theme     = AppUserPreferences.Instance.ColorTheme;
                            using (var fileStream = new FileStream(path, FileMode.OpenOrCreate)) {
                                serializer.ToStream(new List <object> {
                                    limeTheme, theme
                                }, fileStream);
                            }
                        } catch (System.Exception e) {
                            AlertDialog.Show(e.Message);
                        }
                    }
                }
            };
            var loadButton = new ThemedButton("Load theme")
            {
                Clicked = () => {
                    var dlg = new FileDialog {
                        AllowedFileTypes = new string[] { "theme" },
                        Mode             = FileDialogMode.Open
                    };
                    if (dlg.RunModal())
                    {
                        string path         = dlg.FileName;
                        var    deserializer = new Yuzu.Json.JsonDeserializer();
                        try {
                            using (var fs = new FileStream(path, FileMode.OpenOrCreate)) {
                                var read = deserializer.FromStream(new List <object>(), fs) as List <object>;
                                AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Custom;
                                AppUserPreferences.Instance.LimeColorTheme = (Theme.ColorTheme)read[0];
                                AppUserPreferences.Instance.ColorTheme     = (ColorTheme)read[1];
                            }
                        } catch (System.Exception e) {
                            AlertDialog.Show(e.Message);
                        }
                    }
                    themeEditor.Rebuild();
                    themeChanged = true;
                }
            };
            var buttons = new Widget {
                Layout = new HBoxLayout {
                    Spacing = 4
                },
                Nodes = { loadDarkButton, loadLightButton, saveButton, loadButton }
            };

            pane.AddNode(buttons);
            pane.AddNode(themeEditor);
            return(pane);
        }
示例#16
0
        public Result Show(Marker marker, bool canDelete)
        {
            Widget             buttonsPanel;
            Button             deleteButton;
            Button             okButton;
            Button             cancelButton;
            DropDownList       actionSelector;
            EditBox            markerIdEditor;
            ThemedDropDownList jumpToSelector;
            Result             result;
            var window = new Window(new WindowOptions {
                FixedSize = true, Title = "Marker properties", Visible = false, Style = WindowStyle.Dialog
            });

            jumpToSelector = new ThemedDropDownList();
            foreach (var m in Document.Current.Container.Markers)
            {
                jumpToSelector.Items.Add(new ThemedDropDownList.Item(m.Id, m));
            }
            jumpToSelector.Text = marker.JumpTo;
            var rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                LayoutBasedWindowSize = true,
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 16
                },
                Nodes =
                {
                    new Widget  {
                        Layout = new TableLayout{
                            ColCount    = 2,
                            RowCount    = 3,
                            Spacing     = 8,
                            ColDefaults =
                            {
                                new LayoutCell(Alignment.RightCenter, 0.5f, 0),
                                new LayoutCell(Alignment.LeftCenter,     1, 0)
                            }
                        },
                        Nodes =
                        {
                            new ThemedSimpleText("Marker Id"),
                            (markerIdEditor = new ThemedEditBox{
                                Text = marker.Id,                   MinSize= Theme.Metrics.DefaultEditBoxSize * new Vector2(2, 1)
                            }),
                            new ThemedSimpleText("Action"),
                            (actionSelector = new ThemedDropDownList{
                                Items =
                                {
                                    new DropDownList.Item("Play",    MarkerAction.Play),
                                    new DropDownList.Item("Jump",    MarkerAction.Jump),
                                    new DropDownList.Item("Stop",    MarkerAction.Stop),
                                    new DropDownList.Item("Destroy", MarkerAction.Destroy),
                                },
                                Value = marker.Action
                            }),
                            new ThemedSimpleText("Jump to"),
                            jumpToSelector,
                        }
                    },
                    (buttonsPanel = new Widget{
                        Layout = new HBoxLayout{
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Nodes =
                        {
                            (okButton     = new ThemedButton("Ok")),
                            (cancelButton = new ThemedButton("Cancel")),
                        }
                    })
                }
            };

            if (canDelete)
            {
                deleteButton = new ThemedButton("Delete");
                buttonsPanel.AddNode(deleteButton);
                deleteButton.Clicked += () => {
                    result = Result.Delete;
                    window.Close();
                };
            }
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.Add(new KeyPressHandler(Key.Escape,
                                                         (input, key) => {
                input.ConsumeKey(key);
                window.Close();
            }));
            okButton.Clicked += () => {
                result = Result.Ok;
                window.Close();
            };
            cancelButton.Clicked += window.Close;
            okButton.SetFocus();
            result = Result.Cancel;
            window.ShowModal();
            if (result == Result.Ok)
            {
                marker.Id     = markerIdEditor.Text;
                marker.Action = (MarkerAction)actionSelector.Value;
                marker.JumpTo = jumpToSelector.Text;
            }
            return(result);
        }
示例#17
0
        public SaveRulerDialog(Ruler ruler)
        {
            ThemedButton cancelButton;
            ThemedButton okButton;
            CheckBox     checkBox;
            EditBox      editBox;

            window = new Window(new WindowOptions {
                Title   = "Save Ruler",
                Visible = false,
                Style   = WindowStyle.Dialog,
            });
            WindowWidget rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                LayoutBasedWindowSize = true,
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 16
                },
                Nodes =
                {
                    new Widget {
                        Layout = new TableLayout{
                            ColumnCount    = 2,
                            RowCount       = 2,
                            Spacing        = 8,
                            ColumnDefaults =
                            {
                                new DefaultLayoutCell(Alignment.RightCenter, 0.5f, 0),
                                new DefaultLayoutCell(Alignment.LeftCenter,     1, 0)
                            }
                        },
                        Nodes =
                        {
                            new ThemedSimpleText("Ruler name"),
                            (editBox = new ThemedEditBox{
                                MinWidth = 150
                            }),
                            new ThemedSimpleText("Anchor to root"),
                            (checkBox = new ThemedCheckBox())
                        }
                    },
                    new Widget {
                        Layout = new HBoxLayout{
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Nodes      =
                        {
                            (okButton     = new ThemedButton("Ok")),
                            (cancelButton = new ThemedButton("Cancel")),
                        }
                    }
                }
            };

            cancelButton.Clicked += window.Close;
            okButton.AddChangeWatcher(() => editBox.Text, (text) => okButton.Enabled = !string.IsNullOrEmpty(text));
            okButton.Clicked += () => {
                ruler.Name         = editBox.Text;
                ruler.AnchorToRoot = checkBox.Checked;
                result             = true;
                window.Close();
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            editBox.SetFocus();
        }
示例#18
0
        public ManageRulersDialog()
        {
            Button cancelButton;
            Button okButton;
            var    window = new Window(new WindowOptions {
                Title      = "Manage Rulers",
                Style      = WindowStyle.Dialog,
                ClientSize = new Vector2(300, 200),
                Visible    = false
            });
            var collection = new ObservableCollection <Ruler>(ProjectUserPreferences.Instance.Rulers);
            var lines      = new List <RulerLine>();
            ThemedScrollView container;
            WindowWidget     rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    (container            = new ThemedScrollView {
                        Padding           = new Thickness        {
                            Right         =           10
                        },
                    }),
                    new Widget {
                        Padding           = new Thickness        {
                            Top           =            10
                        },
                        Layout            = new HBoxLayout       {
                            Spacing       =        8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Nodes      =
                        {
                            (okButton     = new ThemedButton     {
                                Text      = "Ok"
                            }),
                            (cancelButton = new ThemedButton     {
                                Text      = "Cancel"
                            }),
                        }
                    }
                }
            };

            container.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>(
                                                w => {
                if (w.Parent == null)
                {
                    return;
                }
                var listView = (ThemedScrollView)w;
                w.PrepareRendererState();
                var i     = (int)(listView.ScrollPosition / RowHeight);
                var start = 0f;
                while (true)
                {
                    float height;
                    if (start == 0f)
                    {
                        height = RowHeight - listView.ScrollPosition % RowHeight;
                    }
                    else
                    {
                        height = start + RowHeight <= w.Size.Y ? RowHeight : w.Size.Y - start;
                    }
                    var color = i % 2 == 0
                                                ? ColorTheme.Current.Inspector.StripeBackground2
                                                : ColorTheme.Current.Inspector.StripeBackground1;
                    Renderer.DrawRect(new Vector2(0, start), new Vector2(w.Size.X, start + height), color);
                    start += height;
                    i++;
                    if (start >= w.Size.Y)
                    {
                        break;
                    }
                }
            }));
            container.Content.Layout = new VBoxLayout {
                Spacing = 4
            };
            var list = new Widget {
                Layout = new VBoxLayout(),
            };

            container.Content.AddNode(list);
            list.Components.Add(new WidgetFactoryComponent <Ruler>(ruler => new RulerRowView(ruler,
                                                                                             // Delete button clicked
                                                                                             () => {
                collection.Remove(ruler);
                container.ScrollPosition = container.ScrollPosition > RowHeight ? container.ScrollPosition - RowHeight : 0;
            },
                                                                                             // Edit button clicked
                                                                                             () => {
                if (ruler.AnchorToRoot)
                {
                    var size = Document.Current.Container.AsWidget.Size / 2;
                    foreach (var line in ruler.Lines)
                    {
                        line.Value += (line.RulerOrientation == RulerOrientation.Horizontal ? size.Y : size.X);
                    }
                }
                collection.Remove(ruler);
                lines.AddRange(ruler.Lines);
            }), collection));
            okButton.Clicked += () => {
                var temp = ProjectUserPreferences.Instance.Rulers.ToList();
                foreach (var ruler in temp.Except(collection))
                {
                    ProjectUserPreferences.Instance.Rulers.Remove(ruler);
                }
                ProjectUserPreferences.Instance.ActiveRuler.Lines.AddRange(lines);
                if (!ProjectUserPreferences.Instance.RulerVisible && lines.Count != 0)
                {
                    (SceneViewCommands.ToggleDisplayRuler as Command)?.Issue();
                }
                Core.UserPreferences.Instance.Save();
                Application.InvalidateWindows();
                window.Close();
            };
            cancelButton.Clicked += () => window.Close();
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();
            window.ShowModal();
        }
示例#19
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();
                    }
                }
            });
        }