📄 defaultworkbench.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Windows.Forms;
using System.ComponentModel;
using System.Xml;
using ICSharpCode.SharpDevelop.Internal.Project;
using ICSharpCode.Core.AddIns;
using ICSharpCode.Core.Properties;
using ICSharpCode.Core.Services;
using ICSharpCode.SharpDevelop.Gui.Components;
using ICSharpCode.SharpDevelop.Services;
using Reflector.UserInterface;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// This is the a Workspace with a multiple document interface.
/// </summary>
public class DefaultWorkbench : Form, IWorkbench
{
readonly static string mainMenuPath = "/SharpDevelop/Workbench/MainMenu";
readonly static string viewContentPath = "/SharpDevelop/Workbench/Views";
PadContentCollection viewContentCollection = new PadContentCollection();
ViewContentCollection workbenchContentCollection = new ViewContentCollection();
bool closeAll = false;
bool fullscreen;
FormWindowState defaultWindowState = FormWindowState.Normal;
Rectangle normalBounds = new Rectangle(0, 0, 640, 480);
IWorkbenchLayout layout = null;
protected static PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
public bool FullScreen {
get {
return fullscreen;
}
set {
fullscreen = value;
if (fullscreen) {
defaultWindowState = WindowState;
// - Hide window to prevet any further animations.
// - It fixes .NET Framework bug where the bounds of
// visible window are set incorectly too.
Visible = false;
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
Visible = true;
} else {
FormBorderStyle = FormBorderStyle.Sizable;
Bounds = normalBounds;
WindowState = defaultWindowState;
}
}
}
public string Title {
get {
return Text;
}
set {
Text = value;
}
}
EventHandler windowChangeEventHandler;
public IWorkbenchLayout WorkbenchLayout {
get {
return layout;
}
set {
if (layout != null) {
layout.ActiveWorkbenchWindowChanged -= windowChangeEventHandler;
layout.Detach();
}
value.Attach(this);
layout = value;
layout.ActiveWorkbenchWindowChanged += windowChangeEventHandler;
}
}
public PadContentCollection PadContentCollection {
get {
System.Diagnostics.Debug.Assert(viewContentCollection != null);
return viewContentCollection;
}
}
public ViewContentCollection ViewContentCollection {
get {
System.Diagnostics.Debug.Assert(workbenchContentCollection != null);
return workbenchContentCollection;
}
}
public IWorkbenchWindow ActiveWorkbenchWindow {
get {
if (layout == null) {
return null;
}
return layout.ActiveWorkbenchwindow;
}
}
public DefaultWorkbench()
{
ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
Text = resourceService.GetString("MainWindow.DialogName");
Icon = resourceService.GetIcon("Icons.SharpDevelopIcon");
windowChangeEventHandler = new EventHandler(OnActiveWindowChanged);
StartPosition = FormStartPosition.Manual;
AllowDrop = true;
}
public void InitializeWorkspace()
{
Menu = null;
// statusBarManager.Control.Dock = DockStyle.Bottom;
ActiveWorkbenchWindowChanged += new EventHandler(UpdateMenu);
MenuComplete += new EventHandler(SetStandardStatusBar);
SetStandardStatusBar(null, null);
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
IFileService fileService = (IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
projectService.CurrentProjectChanged += new ProjectEventHandler(SetProjectTitle);
projectService.CombineOpened += new CombineEventHandler(CombineOpened);
fileService.FileRemoved += new FileEventHandler(CheckRemovedFile);
fileService.FileRenamed += new FileEventHandler(CheckRenamedFile);
fileService.FileRemoved += new FileEventHandler(fileService.RecentOpen.FileRemoved);
fileService.FileRenamed += new FileEventHandler(fileService.RecentOpen.FileRenamed);
// TopMenu.Selected += new CommandHandler(OnTopMenuSelected);
// TopMenu.Deselected += new CommandHandler(OnTopMenuDeselected);
CreateMainMenu();
CreateToolBars();
}
public void CloseContent(IViewContent content)
{
if (propertyService.GetProperty("SharpDevelop.LoadDocumentProperties", true) && content is IMementoCapable) {
StoreMemento(content);
}
if (ViewContentCollection.Contains(content)) {
ViewContentCollection.Remove(content);
}
OnViewClosed(new ViewContentEventArgs(content));
content.Dispose();
content = null;
}
public void CloseAllViews()
{
try {
closeAll = true;
ViewContentCollection fullList = new ViewContentCollection(workbenchContentCollection);
foreach (IViewContent content in fullList) {
IWorkbenchWindow window = content.WorkbenchWindow;
window.CloseWindow(false);
}
} finally {
closeAll = false;
OnActiveWindowChanged(null, null);
}
}
public virtual void ShowView(IViewContent content)
{
System.Diagnostics.Debug.Assert(layout != null);
ViewContentCollection.Add(content);
if (propertyService.GetProperty("SharpDevelop.LoadDocumentProperties", true) && content is IMementoCapable) {
try {
IXmlConvertable memento = GetStoredMemento(content);
if (memento != null) {
((IMementoCapable)content).SetMemento(memento);
}
} catch (Exception e) {
Console.WriteLine("Can't get/set memento : " + e.ToString());
}
}
layout.ShowView(content);
content.WorkbenchWindow.SelectWindow();
OnViewOpened(new ViewContentEventArgs(content));
}
public virtual void ShowPad(IPadContent content)
{
PadContentCollection.Add(content);
if (layout != null) {
layout.ShowPad(content);
}
}
public void RedrawAllComponents()
{
UpdateMenu(null, null);
foreach (IViewContent content in workbenchContentCollection) {
content.RedrawContent();
if (content.WorkbenchWindow != null) {
content.WorkbenchWindow.RedrawContent();
}
}
foreach (IPadContent content in viewContentCollection) {
content.RedrawContent();
}
layout.RedrawAllComponents();
// statusBarManager.RedrawStatusbar();
}
public IXmlConvertable GetStoredMemento(IViewContent content)
{
if (content != null && content.FileName != null) {
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
string directory = propertyService.ConfigDirectory + "temp";
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.');
string fullFileName = directory + Path.DirectorySeparatorChar + fileName;
// check the file name length because it could be more than the maximum length of a file name
FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
if (fileUtilityService.IsValidFileName(fullFileName) && File.Exists(fullFileName)) {
IXmlConvertable prototype = ((IMementoCapable)content).CreateMemento();
XmlDocument doc = new XmlDocument();
doc.Load(fullFileName);
return (IXmlConvertable)prototype.FromXmlElement((XmlElement)doc.DocumentElement.ChildNodes[0]);
}
}
return null;
}
public void StoreMemento(IViewContent content)
{
if (content.FileName == null) {
return;
}
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
string directory = propertyService.ConfigDirectory + "temp";
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
XmlDocument doc = new XmlDocument();
doc.LoadXml("<?xml version=\"1.0\"?>\n<Mementoable/>");
XmlAttribute fileAttribute = doc.CreateAttribute("file");
fileAttribute.InnerText = content.FileName;
doc.DocumentElement.Attributes.Append(fileAttribute);
IXmlConvertable memento = ((IMementoCapable)content).CreateMemento();
doc.DocumentElement.AppendChild(memento.ToXmlElement(doc));
string fileName = content.FileName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.');
FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
// check the file name length because it could be more than the maximum length of a file name
string fullFileName = directory + Path.DirectorySeparatorChar + fileName;
if (fileUtilityService.IsValidFileName(fullFileName)) {
fileUtilityService.ObservedSave(new NamedFileOperationDelegate(doc.Save), fullFileName, FileErrorPolicy.ProvideAlternative);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -