public SlicePresetsPage(PrinterConfig printer, PresetsContext presetsContext)
            : base("Close".Localize())
        {
            this.presetsContext    = presetsContext;
            this.printer           = printer;
            this.AlwaysOnTopOfMain = true;

            this.WindowTitle = "Slice Presets Editor".Localize();
            this.WindowSize  = new Vector2(640, 480);
            this.AnchorAll();

            this.headerRow.Visible  = false;
            this.contentRow.Padding = 0;

            contentRow.BackgroundColor = Color.Transparent;

            var inlineNameEdit = new InlineStringEdit(presetsContext.PersistenceLayer.Name, theme, presetsContext.LayerType.ToString() + " Name", boldFont: true);

            inlineNameEdit.ValueChanged += (s, e) =>
            {
                printer.Settings.SetValue(SettingsKey.layer_name, inlineNameEdit.Text, presetsContext.PersistenceLayer);
            };
            contentRow.AddChild(inlineNameEdit);

            var sliceSettingsWidget = CreateSliceSettingsWidget(printer, presetsContext.PersistenceLayer);

            contentRow.AddChild(sliceSettingsWidget);

            var duplicateButton = theme.CreateDialogButton("Duplicate".Localize());

            duplicateButton.Click += (s, e) =>
            {
                string sanitizedName  = numberMatch.Replace(inlineNameEdit.Text, "").Trim();
                string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));

                var clonedLayer = presetsContext.PersistenceLayer.Clone();
                clonedLayer.Name = newProfileName;
                presetsContext.PresetLayers.Add(clonedLayer);

                presetsContext.SetAsActive(clonedLayer.LayerID);
                presetsContext.PersistenceLayer = clonedLayer;

                sliceSettingsWidget.Close();
                sliceSettingsWidget = CreateSliceSettingsWidget(printer, clonedLayer);
                contentRow.AddChild(sliceSettingsWidget);

                inlineNameEdit.Text = newProfileName;
            };

            this.AddPageAction(duplicateButton);

            var deleteButton = theme.CreateDialogButton("Delete".Localize());

            deleteButton.Click += (s, e) =>
            {
                presetsContext.DeleteLayer();
                this.DialogWindow.Close();
            };
            this.AddPageAction(deleteButton);
        }
        private FlowLayoutWidget GetBottomRow(TextImageButtonFactory buttonFactory)
        {
            var container = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.ParentLeftRight,
                Margin  = new BorderDouble(top: 3)
            };

            Button duplicateButton = buttonFactory.Generate("Duplicate".Localize());

            duplicateButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    string sanitizedName  = numberMatch.Replace(presetNameInput.Text, "").Trim();
                    string newProfileName = GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));

                    var clonedLayer  = presetsContext.PersistenceLayer.Clone();
                    clonedLayer.Name = newProfileName;
                    presetsContext.PresetLayers.Add(clonedLayer);

                    presetsContext.SetAsActive(clonedLayer.LayerID);
                    presetsContext.PersistenceLayer = clonedLayer;

                    middleRow.CloseAllChildren();
                    middleRow.AddChild(CreateSliceSettingsWidget(clonedLayer));

                    presetNameInput.Text = newProfileName;
                });
            };

            Button deleteButton = buttonFactory.Generate("Delete".Localize());

            deleteButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    presetsContext.DeleteLayer();
                    this.Close();
                });
            };

            Button closeButton = buttonFactory.Generate("Close".Localize());

            closeButton.Click += (sender, e) =>
            {
                this.CloseOnIdle();
            };

            container.AddChild(duplicateButton);
            container.AddChild(deleteButton);
            container.AddChild(new HorizontalSpacer());
            container.AddChild(closeButton);

            return(container);
        }
Exemplo n.º 3
0
        private FlowLayoutWidget GetBottomRow(TextImageButtonFactory buttonFactory)
        {
            var container = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.ParentLeftRight,
                Margin  = new BorderDouble(top: 3)
            };

            Button duplicateButton = buttonFactory.Generate("Duplicate".Localize());

            duplicateButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    string sanitizedName  = numberMatch.Replace(presetNameInput.Text, "").Trim();
                    string newProfileName = GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault("layer_name")));

                    var clonedLayer  = presetsContext.PersistenceLayer.Clone();
                    clonedLayer.Name = newProfileName;
                    presetsContext.PresetLayers.Add(clonedLayer);

                    presetsContext.SetAsActive(clonedLayer.LayerID);
                    presetsContext.PersistenceLayer = clonedLayer;

                    middleRow.CloseAllChildren();
                    middleRow.AddChild(CreateSliceSettingsWidget(clonedLayer));

                    presetNameInput.Text = newProfileName;
                });
            };

            Button deleteButton = buttonFactory.Generate("Delete".Localize());

            deleteButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    presetsContext.DeleteLayer();
                    this.Close();
                });
            };

            Button closeButton = buttonFactory.Generate("Close".Localize());

            closeButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    if (initialPresetName != presetsContext.PersistenceLayer.Name)
                    {
                        // TODO: If we get to the point where we refresh rather than reload, we need
                        // to rebuild the target droplist to display the new name
                        ApplicationController.Instance.ReloadAdvancedControlsPanel();
                    }
                    this.Close();
                });
            };

            container.AddChild(duplicateButton);
            container.AddChild(deleteButton);
            container.AddChild(new HorizontalSpacer());
            container.AddChild(closeButton);

            return(container);
        }