mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-05 00:19:27 +03:00
Added ContentAdded and ContentRemoved events.
This commit is contained in:
parent
ba2997b872
commit
45bedfcbd7
@ -47,7 +47,6 @@
|
|||||||
|
|
||||||
public enum DarkDockArea
|
public enum DarkDockArea
|
||||||
{
|
{
|
||||||
None,
|
|
||||||
Document,
|
Document,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
|
@ -45,7 +45,7 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
[Category("Layout")]
|
[Category("Layout")]
|
||||||
[Description("Determines which area of the dock panel this content will dock to.")]
|
[Description("Determines which area of the dock panel this content will dock to.")]
|
||||||
[DefaultValue(DarkDockArea.None)]
|
[DefaultValue(DarkDockArea.Document)]
|
||||||
public DarkDockArea DockArea { get; set; }
|
public DarkDockArea DockArea { get; set; }
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
|
@ -233,7 +233,7 @@ namespace DarkUI.Docking
|
|||||||
{
|
{
|
||||||
// Check if previous iteration of loop met the difference
|
// Check if previous iteration of loop met the difference
|
||||||
if (differenceMadeUp >= difference)
|
if (differenceMadeUp >= difference)
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
if (tab.ClientRectangle.Width >= largest)
|
if (tab.ClientRectangle.Width >= largest)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,8 @@ namespace DarkUI.Docking
|
|||||||
#region Event Region
|
#region Event Region
|
||||||
|
|
||||||
public event EventHandler<DockContentEventArgs> ActiveContentChanged;
|
public event EventHandler<DockContentEventArgs> ActiveContentChanged;
|
||||||
|
public event EventHandler<DockContentEventArgs> ContentAdded;
|
||||||
|
public event EventHandler<DockContentEventArgs> ContentRemoved;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -111,14 +113,17 @@ namespace DarkUI.Docking
|
|||||||
if (_contents.Contains(dockContent))
|
if (_contents.Contains(dockContent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (dockContent.DockArea == DarkDockArea.None)
|
if (dockContent.DockArea != dockGroup.DockArea)
|
||||||
return;
|
throw new Exception($"Attempting to add '{dockContent.DockArea}' content to '{dockGroup.DockArea}' group.");
|
||||||
|
|
||||||
dockContent.DockPanel = this;
|
dockContent.DockPanel = this;
|
||||||
_contents.Add(dockContent);
|
_contents.Add(dockContent);
|
||||||
|
|
||||||
var region = _regions[dockContent.DockArea];
|
var region = _regions[dockContent.DockArea];
|
||||||
region.AddContent(dockContent, dockGroup);
|
region.AddContent(dockContent, dockGroup);
|
||||||
|
|
||||||
|
if (ContentAdded != null)
|
||||||
|
ContentAdded(this, new DockContentEventArgs(dockContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveContent(DarkDockContent dockContent)
|
public void RemoveContent(DarkDockContent dockContent)
|
||||||
@ -131,6 +136,14 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
var region = _regions[dockContent.DockArea];
|
var region = _regions[dockContent.DockArea];
|
||||||
region.RemoveContent(dockContent);
|
region.RemoveContent(dockContent);
|
||||||
|
|
||||||
|
if (ContentRemoved != null)
|
||||||
|
ContentRemoved(this, new DockContentEventArgs(dockContent));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsContent(DarkDockContent dockContent)
|
||||||
|
{
|
||||||
|
return _contents.Contains(dockContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateRegions()
|
private void CreateRegions()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using DarkUI.Forms;
|
using DarkUI.Forms;
|
||||||
using DarkUI.Win32;
|
using DarkUI.Win32;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Example
|
namespace Example
|
||||||
@ -10,6 +11,8 @@ namespace Example
|
|||||||
{
|
{
|
||||||
#region Field Region
|
#region Field Region
|
||||||
|
|
||||||
|
private List<DarkDockContent> _toolWindows = new List<DarkDockContent>();
|
||||||
|
|
||||||
private DockProject _dockProject;
|
private DockProject _dockProject;
|
||||||
private DockProperties _dockProperties;
|
private DockProperties _dockProperties;
|
||||||
private DockConsole _dockConsole;
|
private DockConsole _dockConsole;
|
||||||
@ -32,6 +35,9 @@ namespace Example
|
|||||||
// input before letting events pass through to the rest of the application.
|
// input before letting events pass through to the rest of the application.
|
||||||
Application.AddMessageFilter(DockPanel.MessageFilter);
|
Application.AddMessageFilter(DockPanel.MessageFilter);
|
||||||
|
|
||||||
|
// Hook in all the UI events manually for clarity.
|
||||||
|
HookEvents();
|
||||||
|
|
||||||
// Build the tool windows and add them to the dock panel
|
// Build the tool windows and add them to the dock panel
|
||||||
_dockProject = new DockProject();
|
_dockProject = new DockProject();
|
||||||
_dockProperties = new DockProperties();
|
_dockProperties = new DockProperties();
|
||||||
@ -39,26 +45,24 @@ namespace Example
|
|||||||
_dockLayers = new DockLayers();
|
_dockLayers = new DockLayers();
|
||||||
_dockHistory = new DockHistory();
|
_dockHistory = new DockHistory();
|
||||||
|
|
||||||
DockPanel.AddContent(_dockProject);
|
// Add the tool windows to a list
|
||||||
DockPanel.AddContent(_dockProperties);
|
_toolWindows.Add(_dockProject);
|
||||||
DockPanel.AddContent(_dockConsole);
|
_toolWindows.Add(_dockProperties);
|
||||||
DockPanel.AddContent(_dockLayers);
|
_toolWindows.Add(_dockConsole);
|
||||||
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
_toolWindows.Add(_dockLayers);
|
||||||
|
_toolWindows.Add(_dockHistory);
|
||||||
|
|
||||||
|
// Add the tool window list contents to the dock panel
|
||||||
|
foreach (var toolWindow in _toolWindows)
|
||||||
|
DockPanel.AddContent(toolWindow);
|
||||||
|
|
||||||
|
// Check window menu items which are contained in the dock panel
|
||||||
|
BuildWindowMenu();
|
||||||
|
|
||||||
// Add dummy documents to the main document area of the dock panel
|
// Add dummy documents to the main document area of the dock panel
|
||||||
DockPanel.AddContent(new DockDocument("Document 1"));
|
DockPanel.AddContent(new DockDocument("Document 1"));
|
||||||
DockPanel.AddContent(new DockDocument("Document 2"));
|
DockPanel.AddContent(new DockDocument("Document 2"));
|
||||||
DockPanel.AddContent(new DockDocument("Document 3"));
|
DockPanel.AddContent(new DockDocument("Document 3"));
|
||||||
|
|
||||||
// Show the tool windows as visible in the 'Window' menu
|
|
||||||
mnuProject.Checked = true;
|
|
||||||
mnuProperties.Checked = true;
|
|
||||||
mnuConsole.Checked = true;
|
|
||||||
mnuLayers.Checked = true;
|
|
||||||
mnuHistory.Checked = true;
|
|
||||||
|
|
||||||
// Hook in all the UI events manually for clarity.
|
|
||||||
HookEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -67,6 +71,9 @@ namespace Example
|
|||||||
|
|
||||||
private void HookEvents()
|
private void HookEvents()
|
||||||
{
|
{
|
||||||
|
DockPanel.ContentAdded += DockPanel_ContentAdded;
|
||||||
|
DockPanel.ContentRemoved += DockPanel_ContentRemoved;
|
||||||
|
|
||||||
mnuNewFile.Click += NewFile_Click;
|
mnuNewFile.Click += NewFile_Click;
|
||||||
mnuClose.Click += Close_Click;
|
mnuClose.Click += Close_Click;
|
||||||
|
|
||||||
@ -83,24 +90,39 @@ namespace Example
|
|||||||
mnuAbout.Click += About_Click;
|
mnuAbout.Click += About_Click;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleToolWindow(DarkToolWindow toolWindow, ToolStripMenuItem menuItem)
|
private void ToggleToolWindow(DarkToolWindow toolWindow)
|
||||||
{
|
{
|
||||||
if (toolWindow.DockPanel == null)
|
if (toolWindow.DockPanel == null)
|
||||||
{
|
|
||||||
DockPanel.AddContent(toolWindow);
|
DockPanel.AddContent(toolWindow);
|
||||||
menuItem.Checked = true;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
DockPanel.RemoveContent(toolWindow);
|
DockPanel.RemoveContent(toolWindow);
|
||||||
menuItem.Checked = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BuildWindowMenu()
|
||||||
|
{
|
||||||
|
mnuProject.Checked = DockPanel.ContainsContent(_dockProject);
|
||||||
|
mnuProperties.Checked = DockPanel.ContainsContent(_dockProperties);
|
||||||
|
mnuConsole.Checked = DockPanel.ContainsContent(_dockConsole);
|
||||||
|
mnuLayers.Checked = DockPanel.Contains(_dockLayers);
|
||||||
|
mnuHistory.Checked = DockPanel.Contains(_dockHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Event Handler Region
|
#region Event Handler Region
|
||||||
|
|
||||||
|
private void DockPanel_ContentAdded(object sender, DockContentEventArgs e)
|
||||||
|
{
|
||||||
|
if (_toolWindows.Contains(e.Content))
|
||||||
|
BuildWindowMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DockPanel_ContentRemoved(object sender, DockContentEventArgs e)
|
||||||
|
{
|
||||||
|
if (_toolWindows.Contains(e.Content))
|
||||||
|
BuildWindowMenu();
|
||||||
|
}
|
||||||
|
|
||||||
private void NewFile_Click(object sender, EventArgs e)
|
private void NewFile_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var newFile = new DockDocument("New document");
|
var newFile = new DockDocument("New document");
|
||||||
@ -120,27 +142,27 @@ namespace Example
|
|||||||
|
|
||||||
private void Project_Click(object sender, EventArgs e)
|
private void Project_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleToolWindow(_dockProject, mnuProject);
|
ToggleToolWindow(_dockProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Properties_Click(object sender, EventArgs e)
|
private void Properties_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleToolWindow(_dockProperties, mnuProperties);
|
ToggleToolWindow(_dockProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Console_Click(object sender, EventArgs e)
|
private void Console_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleToolWindow(_dockConsole, mnuConsole);
|
ToggleToolWindow(_dockConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Layers_Click(object sender, EventArgs e)
|
private void Layers_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleToolWindow(_dockLayers, mnuLayers);
|
ToggleToolWindow(_dockLayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void History_Click(object sender, EventArgs e)
|
private void History_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ToggleToolWindow(_dockHistory, mnuHistory);
|
ToggleToolWindow(_dockHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void About_Click(object sender, EventArgs e)
|
private void About_Click(object sender, EventArgs e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user