📄 sdiworkspacelayout.cs
字号:
}
}
public void Detach()
{
StoreConfiguration();
dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged);
DetachPadContents(true);
DetachViewContents(true);
try {
if (dockPanel != null) {
dockPanel.Dispose();
dockPanel = null;
}
} catch (Exception e) {
MessageService.ShowError(e);
}
if (contentHash != null) {
contentHash.Clear();
}
wbForm.Controls.Clear();
}
class PadContentWrapper : DockContent
{
PadDescriptor padDescriptor;
bool isInitialized = false;
internal bool allowInitialize = false;
public IPadContent PadContent {
get {
return padDescriptor.PadContent;
}
}
public PadContentWrapper(PadDescriptor padDescriptor)
{
if (padDescriptor == null)
throw new ArgumentNullException("padDescriptor");
this.padDescriptor = padDescriptor;
this.DockableAreas = ((((WeifenLuo.WinFormsUI.DockAreas.Float | WeifenLuo.WinFormsUI.DockAreas.DockLeft) |
WeifenLuo.WinFormsUI.DockAreas.DockRight) |
WeifenLuo.WinFormsUI.DockAreas.DockTop) |
WeifenLuo.WinFormsUI.DockAreas.DockBottom);
HideOnClose = true;
}
public void DetachContent()
{
Controls.Clear();
padDescriptor = null;
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (Visible && Width > 0)
ActivateContent();
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (Visible && Width > 0)
ActivateContent();
}
/// <summary>
/// Enables initializing the content. This is used to prevent initializing all view
/// contents when the layout configuration is changed.
/// </summary>
public void AllowInitialize()
{
allowInitialize = true;
if (Visible && Width > 0)
ActivateContent();
}
void ActivateContent()
{
if (!allowInitialize)
return;
if (!isInitialized) {
isInitialized = true;
IPadContent content = padDescriptor.PadContent;
if (content == null)
return;
Control control = content.Control;
control.Dock = DockStyle.Fill;
Controls.Add(control);
}
}
protected override string GetPersistString()
{
return padDescriptor.Class;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing) {
if (padDescriptor != null) {
padDescriptor.Dispose();
padDescriptor = null;
}
}
}
}
PadContentWrapper CreateContent(PadDescriptor content)
{
if (contentHash.ContainsKey(content.Class)) {
return contentHash[content.Class];
}
Properties properties = (Properties)PropertyService.Get("Workspace.ViewMementos", new Properties());
PadContentWrapper newContent = new PadContentWrapper(content);
if (!string.IsNullOrEmpty(content.Icon)) {
newContent.Icon = IconService.GetIcon(content.Icon);
}
newContent.Text = StringParser.Parse(content.Title);
contentHash[content.Class] = newContent;
return newContent;
}
public void ShowPad(PadDescriptor content)
{
if (content == null) {
return;
}
if (!contentHash.ContainsKey(content.Class)) {
DockContent newContent = CreateContent(content);
newContent.Show(dockPanel);
} else {
contentHash[content.Class].Show();
}
}
public bool IsVisible(PadDescriptor padContent)
{
if (padContent != null && contentHash.ContainsKey(padContent.Class)) {
return !contentHash[padContent.Class].IsHidden;
}
return false;
}
public void HidePad(PadDescriptor padContent)
{
if (padContent != null && contentHash.ContainsKey(padContent.Class)) {
contentHash[padContent.Class].Hide();
}
}
public void ActivatePad(PadDescriptor padContent)
{
if (padContent != null && contentHash.ContainsKey(padContent.Class)) {
//contentHash[padContent.Class].ActivateContent();
contentHash[padContent.Class].Show();
}
}
public void ActivatePad(string fullyQualifiedTypeName)
{
//contentHash[fullyQualifiedTypeName].ActivateContent();
contentHash[fullyQualifiedTypeName].Show();
}
public void RedrawAllComponents()
{
// redraw correct pad content names (language changed).
foreach (PadDescriptor padDescriptor in ((IWorkbench)wbForm).PadContentCollection) {
DockContent c = contentHash[padDescriptor.Class];
if (c != null) {
c.Text = StringParser.Parse(padDescriptor.Title);
}
}
RedrawMainMenu();
RedrawToolbars();
RedrawStatusBar();
}
void RedrawMainMenu()
{
Properties fullscreenProperties = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.FullscreenOptions", new Properties());
bool hideInFullscreen = fullscreenProperties.Get("HideMainMenu", false);
bool showOnMouseMove = fullscreenProperties.Get("ShowMainMenuOnMouseMove", true);
mainMenuContainer.AutoHide = wbForm.FullScreen && hideInFullscreen;
mainMenuContainer.ShowOnMouseDown = true;
mainMenuContainer.ShowOnMouseMove = showOnMouseMove;
}
void RedrawToolbars()
{
Properties fullscreenProperties = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.FullscreenOptions", new Properties());
bool hideInFullscreen = fullscreenProperties.Get("HideToolbars", true);
bool toolBarVisible = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.ToolBarVisible", true);
if (toolBarVisible) {
if (wbForm.FullScreen && hideInFullscreen) {
HideToolBars();
} else {
ShowToolBars();
}
} else {
HideToolBars();
}
}
void RedrawStatusBar()
{
Properties fullscreenProperties = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.FullscreenOptions", new Properties());
bool hideInFullscreen = fullscreenProperties.Get("HideStatusBar", true);
bool showOnMouseMove = fullscreenProperties.Get("ShowStatusBarOnMouseMove", true);
bool statusBarVisible = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.StatusBarVisible", true);
statusStripContainer.AutoHide = wbForm.FullScreen && hideInFullscreen;
statusStripContainer.ShowOnMouseDown = true;
statusStripContainer.ShowOnMouseMove = showOnMouseMove;
statusStripContainer.Visible = statusBarVisible;
}
public void CloseWindowEvent(object sender, EventArgs e)
{
SdiWorkspaceWindow f = (SdiWorkspaceWindow)sender;
f.CloseEvent -= CloseWindowEvent;
if (f.ViewContent != null) {
((IWorkbench)wbForm).CloseContent(f.ViewContent);
if (f == oldSelectedWindow) {
oldSelectedWindow = null;
}
ActiveMdiChanged(this, null);
}
}
public IWorkbenchWindow ShowView(IViewContent content)
{
if (content.WorkbenchWindow is SdiWorkspaceWindow) {
SdiWorkspaceWindow oldSdiWindow = (SdiWorkspaceWindow)content.WorkbenchWindow;
if (!oldSdiWindow.IsDisposed) {
oldSdiWindow.Show(dockPanel);
return oldSdiWindow;
}
}
if (!content.Control.Visible) {
content.Control.Visible = true;
}
content.Control.Dock = DockStyle.Fill;
SdiWorkspaceWindow sdiWorkspaceWindow = new SdiWorkspaceWindow(content);
sdiWorkspaceWindow.CloseEvent += new EventHandler(CloseWindowEvent);
if (dockPanel != null) {
sdiWorkspaceWindow.Show(dockPanel);
}
return sdiWorkspaceWindow;
}
void ActiveMdiChanged(object sender, EventArgs e)
{
OnActiveWorkbenchWindowChanged(e);
}
void ActiveContentChanged(object sender, EventArgs e)
{
OnActiveWorkbenchWindowChanged(e);
}
static IViewContent GetActiveView()
{
IWorkbenchWindow activeWindow = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;
if (activeWindow != null) {
return activeWindow.ViewContent;
}
return null;
}
IWorkbenchWindow oldSelectedWindow = null;
public virtual void OnActiveWorkbenchWindowChanged(EventArgs e)
{
IWorkbenchWindow newWindow = this.ActiveWorkbenchwindow;
if (newWindow == null || newWindow.ViewContent != null) {
if (ActiveWorkbenchWindowChanged != null) {
ActiveWorkbenchWindowChanged(this, e);
}
//if (newWindow == null)
// LoggingService.Debug("window change to null");
//else
// LoggingService.Debug("window change to " + newWindow);
} else {
//LoggingService.Debug("ignore window change to disposed window");
}
if (oldSelectedWindow != null) {
oldSelectedWindow.OnWindowDeselected(EventArgs.Empty);
}
oldSelectedWindow = newWindow;
if (oldSelectedWindow != null && oldSelectedWindow.ActiveViewContent != null && oldSelectedWindow.ActiveViewContent.Control != null) {
oldSelectedWindow.OnWindowSelected(EventArgs.Empty);
oldSelectedWindow.ActiveViewContent.SwitchedTo();
}
}
public event EventHandler ActiveWorkbenchWindowChanged;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -