📄 sdiworkspacelayout.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 1425 $</version>
// </file>
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Windows.Forms;
using System.Reflection;
using ICSharpCode.Core;
using WeifenLuo.WinFormsUI;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// This is the a Workspace with a single document interface.
/// </summary>
public class SdiWorkbenchLayout : IWorkbenchLayout
{
DefaultWorkbench wbForm;
DockPanel dockPanel;
Dictionary<string, PadContentWrapper> contentHash = new Dictionary<string, PadContentWrapper>();
ToolStripContainer toolStripContainer;
AutoHideMenuStripContainer mainMenuContainer;
AutoHideStatusStripContainer statusStripContainer;
public IWorkbenchWindow ActiveWorkbenchwindow {
get {
if (dockPanel == null || dockPanel.ActiveDocument == null || dockPanel.ActiveDocument.IsDisposed) {
return null;
}
return dockPanel.ActiveDocument as IWorkbenchWindow;
}
}
// prevent setting ActiveContent to null when application loses focus (e.g. because of context menu popup)
DockContent lastActiveContent;
public object ActiveContent {
get {
DockContent activeContent;
if (dockPanel == null) {
activeContent = lastActiveContent;
} else {
activeContent = dockPanel.ActiveContent ?? lastActiveContent;
}
lastActiveContent = activeContent;
if (activeContent == null || activeContent.IsDisposed) {
return null;
}
if (activeContent is IWorkbenchWindow) {
return ((IWorkbenchWindow)activeContent).ActiveViewContent;
}
if (activeContent is PadContentWrapper) {
return ((PadContentWrapper)activeContent).PadContent;
}
return activeContent;
}
}
public void Attach(IWorkbench workbench)
{
wbForm = (DefaultWorkbench)workbench;
wbForm.SuspendLayout();
wbForm.Controls.Clear();
toolStripContainer = new ToolStripContainer();
toolStripContainer.SuspendLayout();
toolStripContainer.Dock = DockStyle.Fill;
dockPanel = new WeifenLuo.WinFormsUI.DockPanel();
toolStripContainer.ContentPanel.Controls.Add(this.dockPanel);
mainMenuContainer = new AutoHideMenuStripContainer(((DefaultWorkbench)wbForm).TopMenu);
mainMenuContainer.Dock = DockStyle.Top;
this.dockPanel.ActiveAutoHideContent = null;
this.dockPanel.Dock = System.Windows.Forms.DockStyle.Fill;
statusStripContainer = new AutoHideStatusStripContainer((StatusStrip)StatusBarService.Control);
statusStripContainer.Dock = DockStyle.Bottom;
toolStripContainer.ContentPanel.Controls.Add(mainMenuContainer);
toolStripContainer.ContentPanel.Controls.Add(statusStripContainer);
wbForm.Controls.Add(toolStripContainer);
// dock panel has to be added to the form before LoadLayoutConfiguration is called to fix SD2-463
LoadLayoutConfiguration();
ShowPads();
ShowViewContents();
RedrawAllComponents();
dockPanel.ActiveDocumentChanged += new EventHandler(ActiveMdiChanged);
dockPanel.ActiveContentChanged += new EventHandler(ActiveContentChanged);
ActiveMdiChanged(this, EventArgs.Empty);
toolStripContainer.ResumeLayout(false);
wbForm.ResumeLayout(false);
Properties fullscreenProperties = PropertyService.Get("ICSharpCode.SharpDevelop.Gui.FullscreenOptions", new Properties());
fullscreenProperties.PropertyChanged += TrackFullscreenPropertyChanges;
}
void TrackFullscreenPropertyChanges(object sender, PropertyChangedEventArgs e)
{
if (!Boolean.Equals(e.OldValue, e.NewValue) && wbForm.FullScreen) {
switch (e.Key) {
case "HideMainMenu":
case "ShowMainMenuOnMouseMove":
RedrawMainMenu();
break;
case "HideToolbars":
RedrawToolbars();
break;
//case "HideTabs":
//case "HideVerticalScrollbar":
//case "HideHorizontalScrollbar":
case "HideStatusBar":
case "ShowStatusBarOnMouseMove":
RedrawStatusBar();
break;
//case "HideWindowsTaskbar":
}
}
}
void ShowPads()
{
foreach (PadDescriptor content in WorkbenchSingleton.Workbench.PadContentCollection) {
if (!contentHash.ContainsKey(content.Class)) {
ShowPad(content);
}
}
// ShowPads could create new pads if new addins have been installed, so we
// need to call AllowInitialize here instead of in LoadLayoutConfiguration
foreach (PadContentWrapper content in contentHash.Values) {
content.AllowInitialize();
}
}
void ShowViewContents()
{
foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
ShowView(content);
}
}
void LoadLayoutConfiguration()
{
try {
if (File.Exists(LayoutConfiguration.CurrentLayoutFileName)) {
LoadDockPanelLayout(LayoutConfiguration.CurrentLayoutFileName);
} else {
LoadDefaultLayoutConfiguration();
}
} catch {
// ignore errors loading configuration
}
}
void LoadDefaultLayoutConfiguration()
{
if (File.Exists(LayoutConfiguration.CurrentLayoutTemplateFileName)) {
LoadDockPanelLayout(LayoutConfiguration.CurrentLayoutTemplateFileName);
}
}
void LoadDockPanelLayout(string fileName)
{
// LoadFromXml(fileName, ...) locks the file against simultanous read access
// -> we would loose the layout when starting two SharpDevelop instances
// at the same time => open stream with shared read access.
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) {
dockPanel.LoadFromXml(fs, new DeserializeDockContent(GetContent));
}
}
void ShowToolBars()
{
if (wbForm.ToolBars != null) {
ArrayList oldControls = new ArrayList();
foreach (Control ctl in toolStripContainer.ContentPanel.Controls) {
oldControls.Add(ctl);
}
toolStripContainer.ContentPanel.Controls.Clear();
toolStripContainer.ContentPanel.Controls.Add(oldControls[0] as Control);
foreach (ToolStrip toolBar in wbForm.ToolBars) {
if (!toolStripContainer.ContentPanel.Controls.Contains(toolBar)) {
toolStripContainer.ContentPanel.Controls.Add(toolBar);
}
}
for (int i = 1; i < oldControls.Count; i++) {
toolStripContainer.ContentPanel.Controls.Add(oldControls[i] as Control);
}
}
}
void HideToolBars()
{
if (wbForm.ToolBars != null) {
foreach (ToolStrip toolBar in wbForm.ToolBars) {
if (toolStripContainer.ContentPanel.Controls.Contains(toolBar)) {
toolStripContainer.ContentPanel.Controls.Remove(toolBar);
}
}
}
}
DockContent GetContent(string padTypeName)
{
foreach (PadDescriptor content in WorkbenchSingleton.Workbench.PadContentCollection) {
if (content.Class == padTypeName) {
return CreateContent(content);
}
}
return null;
}
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool LockWindowUpdate(IntPtr hWnd);
public void LoadConfiguration()
{
if (dockPanel != null) {
LockWindowUpdate(wbForm.Handle);
try {
IViewContent activeView = GetActiveView();
dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged);
DetachPadContents(true);
DetachViewContents(true);
dockPanel.ActiveDocumentChanged += new EventHandler(ActiveMdiChanged);
LoadLayoutConfiguration();
ShowPads();
ShowViewContents();
if (activeView != null && activeView.WorkbenchWindow != null) {
activeView.WorkbenchWindow.SelectWindow();
}
} finally {
LockWindowUpdate(IntPtr.Zero);
}
}
}
public void StoreConfiguration()
{
try {
if (dockPanel != null) {
LayoutConfiguration current = LayoutConfiguration.CurrentLayout;
if (current != null && !current.ReadOnly) {
string configPath = Path.Combine(PropertyService.ConfigDirectory, "layouts");
if (!Directory.Exists(configPath))
Directory.CreateDirectory(configPath);
dockPanel.SaveAsXml(Path.Combine(configPath, current.FileName));
}
}
} catch (Exception e) {
MessageService.ShowError(e);
}
}
void DetachPadContents(bool dispose)
{
foreach (PadContentWrapper padContentWrapper in contentHash.Values) {
padContentWrapper.allowInitialize = false;
}
foreach (PadDescriptor content in ((DefaultWorkbench)wbForm).PadContentCollection) {
try {
PadContentWrapper padContentWrapper = contentHash[content.Class];
padContentWrapper.DockPanel = null;
if (dispose) {
padContentWrapper.DetachContent();
padContentWrapper.Dispose();
}
} catch (Exception e) { MessageService.ShowError(e); }
}
if (dispose) {
contentHash.Clear();
}
}
void DetachViewContents(bool dispose)
{
foreach (IViewContent viewContent in WorkbenchSingleton.Workbench.ViewContentCollection) {
try {
SdiWorkspaceWindow f = (SdiWorkspaceWindow)viewContent.WorkbenchWindow;
f.DockPanel = null;
if (dispose) {
viewContent.WorkbenchWindow = null;
f.CloseEvent -= new EventHandler(CloseWindowEvent);
f.DetachContent();
f.Dispose();
}
} catch (Exception e) { MessageService.ShowError(e); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -