mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-23 12:11:32 +03:00
Added tab areas to dock groups
This commit is contained in:
parent
c39af6c190
commit
4de889ae6e
@ -108,6 +108,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Docking\Items\DarkDockSplitter.cs" />
|
||||
<Compile Include="Docking\Items\DarkDockTab.cs" />
|
||||
<Compile Include="Docking\Items\DarkDockTabArea.cs" />
|
||||
<Compile Include="Extensions\BitmapExtensions.cs" />
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Forms\DarkDialog.cs">
|
||||
|
@ -1,6 +1,8 @@
|
||||
using DarkUI.Config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DarkUI.Docking
|
||||
@ -12,6 +14,8 @@ namespace DarkUI.Docking
|
||||
|
||||
private List<DarkDockContent> _contents;
|
||||
|
||||
private DarkDockTabArea _tabArea;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Property Region
|
||||
@ -41,6 +45,8 @@ namespace DarkUI.Docking
|
||||
DockArea = dockRegion.DockArea;
|
||||
|
||||
Order = order;
|
||||
|
||||
_tabArea = new DarkDockTabArea(DockArea);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -57,6 +63,14 @@ namespace DarkUI.Docking
|
||||
|
||||
if (VisibleContent == null)
|
||||
VisibleContent = dockContent;
|
||||
|
||||
var menuItem = new ToolStripMenuItem(dockContent.DockText);
|
||||
menuItem.Tag = dockContent;
|
||||
menuItem.Click += TabMenuItem_Select;
|
||||
menuItem.Image = dockContent.Icon;
|
||||
_tabArea.TabMenu.Items.Add(menuItem);
|
||||
|
||||
UpdateTabArea();
|
||||
}
|
||||
|
||||
public void RemoveContent(DarkDockContent dockContent)
|
||||
@ -74,6 +88,115 @@ namespace DarkUI.Docking
|
||||
foreach (var content in _contents)
|
||||
VisibleContent = content;
|
||||
}
|
||||
|
||||
ToolStripMenuItem itemToRemove = null;
|
||||
foreach (ToolStripMenuItem item in _tabArea.TabMenu.Items)
|
||||
{
|
||||
var menuContent = item.Tag as DarkDockContent;
|
||||
if (menuContent == null)
|
||||
continue;
|
||||
|
||||
if (menuContent == dockContent)
|
||||
itemToRemove = item;
|
||||
}
|
||||
|
||||
if (itemToRemove != null)
|
||||
{
|
||||
itemToRemove.Click -= TabMenuItem_Select;
|
||||
_tabArea.TabMenu.Items.Remove(itemToRemove);
|
||||
}
|
||||
|
||||
UpdateTabArea();
|
||||
}
|
||||
|
||||
private void UpdateTabArea()
|
||||
{
|
||||
if (DockArea == DarkDockArea.Document)
|
||||
_tabArea.Visible = (_contents.Count > 0);
|
||||
else
|
||||
_tabArea.Visible = (_contents.Count > 1);
|
||||
|
||||
var size = 0;
|
||||
|
||||
switch (DockArea)
|
||||
{
|
||||
case DarkDockArea.Document:
|
||||
size = _tabArea.Visible ? Consts.DocumentTabAreaSize : 0;
|
||||
Padding = new Padding(0, size, 0, 0);
|
||||
_tabArea.Area = new Rectangle(Padding.Left, 0, ClientRectangle.Width - Padding.Horizontal, size);
|
||||
break;
|
||||
case DarkDockArea.Left:
|
||||
case DarkDockArea.Right:
|
||||
size = _tabArea.Visible ? Consts.ToolWindowTabAreaSize : 0;
|
||||
Padding = new Padding(0, 0, 0, size);
|
||||
_tabArea.Area = new Rectangle(Padding.Left, ClientRectangle.Height - size, ClientRectangle.Width - Padding.Horizontal, size);
|
||||
break;
|
||||
case DarkDockArea.Bottom:
|
||||
size = _tabArea.Visible ? Consts.ToolWindowTabAreaSize : 0;
|
||||
Padding = new Padding(1, 0, 0, size);
|
||||
_tabArea.Area = new Rectangle(Padding.Left, ClientRectangle.Height - size, ClientRectangle.Width - Padding.Horizontal, size);
|
||||
break;
|
||||
}
|
||||
|
||||
BuildTabs();
|
||||
}
|
||||
|
||||
private void BuildTabs()
|
||||
{
|
||||
if (!_tabArea.Visible)
|
||||
return;
|
||||
|
||||
SuspendLayout();
|
||||
|
||||
|
||||
|
||||
ResumeLayout();
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handler Region
|
||||
|
||||
private void TabMenuItem_Select(object sender, EventArgs e)
|
||||
{
|
||||
var menuItem = sender as ToolStripMenuItem;
|
||||
if (menuItem == null)
|
||||
return;
|
||||
|
||||
var content = menuItem.Tag as DarkDockContent;
|
||||
if (content == null)
|
||||
return;
|
||||
|
||||
DockPanel.ActiveContent = content;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Render Region
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
var g = e.Graphics;
|
||||
|
||||
using (var b = new SolidBrush(Colors.GreyBackground))
|
||||
{
|
||||
g.FillRectangle(b, ClientRectangle);
|
||||
}
|
||||
|
||||
if (!_tabArea.Visible)
|
||||
return;
|
||||
|
||||
using (var b = new SolidBrush(Colors.MediumBackground))
|
||||
{
|
||||
g.FillRectangle(b, _tabArea.Area);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
// Absorb event
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -83,6 +83,11 @@ namespace DarkUI.Docking
|
||||
#region Method Region
|
||||
|
||||
public void AddContent(DarkDockContent dockContent)
|
||||
{
|
||||
AddContent(dockContent, null);
|
||||
}
|
||||
|
||||
public void AddContent(DarkDockContent dockContent, DarkDockGroup dockGroup)
|
||||
{
|
||||
if (_contents.Contains(dockContent))
|
||||
return;
|
||||
@ -94,7 +99,7 @@ namespace DarkUI.Docking
|
||||
_contents.Add(dockContent);
|
||||
|
||||
var region = _regions[dockContent.DockArea];
|
||||
region.AddContent(dockContent);
|
||||
region.AddContent(dockContent, dockGroup);
|
||||
}
|
||||
|
||||
public void RemoveContent(DarkDockContent dockContent)
|
||||
|
@ -1,5 +1,4 @@
|
||||
using DarkUI.Config;
|
||||
using DarkUI.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -46,12 +45,12 @@ namespace DarkUI.Docking
|
||||
|
||||
#region Method Region
|
||||
|
||||
public void AddContent(DarkDockContent dockContent)
|
||||
internal void AddContent(DarkDockContent dockContent)
|
||||
{
|
||||
AddContent(dockContent, null);
|
||||
}
|
||||
|
||||
public void AddContent(DarkDockContent dockContent, DarkDockGroup dockGroup)
|
||||
internal void AddContent(DarkDockContent dockContent, DarkDockGroup dockGroup)
|
||||
{
|
||||
// If no existing group is specified then create a new one
|
||||
if (dockGroup == null)
|
||||
@ -73,7 +72,7 @@ namespace DarkUI.Docking
|
||||
PositionGroups();
|
||||
}
|
||||
|
||||
public void RemoveContent(DarkDockContent dockContent)
|
||||
internal void RemoveContent(DarkDockContent dockContent)
|
||||
{
|
||||
dockContent.DockRegion = null;
|
||||
|
||||
|
41
DarkUI/Docking/Items/DarkDockTabArea.cs
Normal file
41
DarkUI/Docking/Items/DarkDockTabArea.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using DarkUI.Config;
|
||||
using DarkUI.Controls;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DarkUI.Docking
|
||||
{
|
||||
public class DarkDockTabArea
|
||||
{
|
||||
#region Field Region
|
||||
|
||||
private Dictionary<DarkDockContent, DarkDockTab> _tabs = new Dictionary<DarkDockContent, DarkDockTab>();
|
||||
|
||||
private DarkContextMenu _tabMenu = new DarkContextMenu();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Property Region
|
||||
|
||||
public DarkDockArea DockArea { get; private set; }
|
||||
|
||||
public Rectangle Area { get; set; }
|
||||
|
||||
public int Offset { get; set; }
|
||||
|
||||
public bool Visible { get; set; }
|
||||
|
||||
public DarkContextMenu TabMenu { get { return _tabMenu; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor Region
|
||||
|
||||
public DarkDockTabArea(DarkDockArea dockArea)
|
||||
{
|
||||
DockArea = dockArea;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ namespace Example
|
||||
DockPanel.AddContent(_dockProperties);
|
||||
DockPanel.AddContent(_dockConsole);
|
||||
DockPanel.AddContent(_dockLayers);
|
||||
DockPanel.AddContent(_dockHistory);
|
||||
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
||||
|
||||
// Add dummy documents to the main document area of the dock panel
|
||||
DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
|
||||
|
Loading…
x
Reference in New Issue
Block a user