Restore ChromeTab plus button for new parts

This commit is contained in:
John Lewin 2018-10-15 17:14:33 -07:00
parent 58743e9105
commit d8d8c1309e
5 changed files with 76 additions and 3 deletions

View file

@ -64,8 +64,9 @@ namespace MatterHackers.MatterControl
public double TabButtonHeight => 30 * GuiWidget.DeviceScale;
public double MenuGutterWidth => 35 * GuiWidget.DeviceScale;
private double microButtonHeight => 20 * GuiWidget.DeviceScale;
public double MicroButtonHeight => 20 * GuiWidget.DeviceScale;
private double microButtonWidth => 30 * GuiWidget.DeviceScale;
private readonly int defaultScrollBarWidth = 120;
/// <summary>
@ -254,7 +255,7 @@ namespace MatterHackers.MatterControl
HoverColor = this.AccentMimimalOverlay,
Margin = new BorderDouble(right: 1),
HAnchor = HAnchor.Absolute,
Height = this.microButtonHeight,
Height = this.MicroButtonHeight,
Width = this.microButtonWidth
};

View file

@ -28,7 +28,9 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.CustomWidgets;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
@ -56,4 +58,30 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnDraw(graphics2D);
}
}
public class NewTabButton : GuiWidget
{
private ThemeConfig theme;
public NewTabButton(ImageBuffer imageBuffer, ThemeConfig theme)
{
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Center;
this.theme = theme;
IconButton = new IconButton(imageBuffer, theme)
{
HAnchor = HAnchor.Left,
Height = theme.MicroButtonHeight,
Width = theme.MicroButtonHeight,
Name = "Create New",
};
this.AddChild(IconButton);
}
public ITab LastTab { get; set; }
public IconButton IconButton { get; }
}
}

View file

@ -49,6 +49,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private ChromeTab libraryTab;
private ChromeTab storeTab;
private int partCount = 0;
public PartPreviewContent(ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
@ -70,6 +72,33 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Border = new BorderDouble(left: 1),
};
tabControl.PlusClicked += (s, e) =>
{
UiThread.RunOnIdle(async () =>
{
var partHistory = ApplicationController.Instance.Library.PartHistory;
var workspace = new BedConfig(partHistory);
await workspace.LoadContent(
new EditContext()
{
ContentStore = ApplicationController.Instance.Library.PartHistory,
SourceItem = partHistory.NewPlatingItem()
});
ApplicationController.Instance.Workspaces.Add(workspace);
var partID = partCount;
var newTab = this.CreatePartTab(
"New Design".Localize() + (partCount == 0 ? "" : $" ({partCount++})"), workspace, theme);
tabControl.ActiveTab = newTab;
partCount++;
});
};
tabControl.ActiveTabChanged += (s, e) =>
{
if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage)

View file

@ -32,6 +32,7 @@ using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
@ -225,6 +226,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private GuiWidget leadingTabAdornment;
public event EventHandler PlusClicked;
public ChromeTabs(GuiWidget rightAnchorItem, ThemeConfig theme)
: base(theme, rightAnchorItem)
{
@ -243,10 +246,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
tabTrailer = new TabTrailer(this, theme)
{
VAnchor = VAnchor.Bottom,
MinimumSize = new Vector2(16, theme.TabButtonHeight),
MinimumSize = new Vector2(8, theme.TabButtonHeight),
};
this.TabBar.ActionArea.AddChild(tabTrailer);
var plusTabButton = new NewTabButton(AggContext.StaticData.LoadIcon("fa-plus_12.png", theme.InvertIcons), theme)
{
Height = 20,
};
plusTabButton.IconButton.Click += (s, e) =>
{
this.PlusClicked?.Invoke(this, null);
};
this.TabBar.ActionArea.AddChild(plusTabButton);
}
public override void AddTab(GuiWidget tabWidget, int tabIndex = -1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B