📄 sharpdeveloptextareacontrol.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.Windows.Forms;
using Reflector.UserInterface;
using ICSharpCode.Core.Services;
using ICSharpCode.Core.AddIns;
using ICSharpCode.Core.Properties;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.DefaultEditor.Actions;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Actions;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Gui.Components;
using ICSharpCode.TextEditor.Gui.InsightWindow;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using System.Threading;
namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
{
public class SharpDevelopTextAreaControl : TextEditorControl
{
readonly static string contextMenuPath = "/SharpDevelop/ViewContent/DefaultTextEditor/ContextMenu";
readonly static string editActionsPath = "/AddIns/DefaultTextEditor/EditActions";
readonly static string formatingStrategyPath = "/AddIns/DefaultTextEditor/Formater";
QuickClassBrowserPanel quickClassBrowserPanel = null;
ErrorDrawer errorDrawer;
public QuickClassBrowserPanel QuickClassBrowserPanel {
get {
return quickClassBrowserPanel;
}
}
public SharpDevelopTextAreaControl()
{
errorDrawer = new ErrorDrawer(this);
Document.FoldingManager.FoldingStrategy = new ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.ParserFoldingStrategy();
GenerateEditActions();
TextAreaDragDropHandler dragDropHandler = new TextAreaDragDropHandler();
TextEditorProperties = new SharpDevelopTextEditorProperties();
}
public virtual ICompletionDataProvider CreateCodeCompletionDataProvider(bool ctrlSpace)
{
//ivoko: please do not touch or discuss with me: we use another CCDP
return new CodeCompletionDataProvider(ctrlSpace, false);
}
protected override void InitializeTextAreaControl(TextAreaControl newControl)
{
base.InitializeTextAreaControl(newControl);
MenuService menuService = (MenuService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(MenuService));
newControl.ContextMenu = menuService.CreateContextMenu(this, contextMenuPath);
newControl.TextArea.KeyEventHandler += new ICSharpCode.TextEditor.KeyEventHandler(HandleKeyPress);
newControl.SelectionManager.SelectionChanged += new EventHandler(SelectionChanged);
newControl.Document.DocumentChanged += new DocumentEventHandler(DocumentChanged);
newControl.Caret.PositionChanged += new EventHandler(CaretPositionChanged);
newControl.TextArea.ClipboardHandler.CopyText += new CopyTextEventHandler(ClipboardHandlerCopyText);
// newControl.TextArea.IconBarMargin.Painted += new MarginPaintEventHandler(PaintIconBarBreakPoints);
// newControl.TextArea.IconBarMargin.MouseDown += new MarginMouseEventHandler(IconBarMouseDown);
}
void ClipboardHandlerCopyText(object sender, CopyTextEventArgs e)
{
ICSharpCode.SharpDevelop.Gui.Pads.SideBarView.PutInClipboardRing(e.Text);
}
public override void OptionsChanged()
{
base.OptionsChanged();
SharpDevelopTextEditorProperties sdtep = base.TextEditorProperties as SharpDevelopTextEditorProperties;
if (sdtep != null) {
if (!sdtep.ShowQuickClassBrowserPanel) {
RemoveQuickClassBrowserPanel();
} else {
ActivateQuickClassBrowserOnDemand();
}
}
}
// DISABLED (TAKEN OUT DEBUGGER)!
// void IconBarMouseDown(AbstractMargin iconBar, Point mousepos, MouseButtons mouseButtons)
// {
// int realline = iconBar.TextArea.TextView.GetLogicalLine(mousepos);
// if (realline >= 0 && realline < iconBar.TextArea.Document.TotalNumberOfLines) {
// DebuggerService debuggerService = (DebuggerService)ServiceManager.Services.GetService(typeof(DebuggerService));
// debuggerService.ToggleBreakpointAt(FileName, realline + 1, 0);
// iconBar.TextArea.Refresh(iconBar);
// }
// }
//
// void PaintIconBarBreakPoints(AbstractMargin iconBar, Graphics g, Rectangle rect)
// {
// DebuggerService debuggerService = (DebuggerService)ServiceManager.Services.GetService(typeof(DebuggerService));
// lock (debuggerService.Breakpoints) {
// foreach (THSBreakpoint breakpoint in debuggerService.Breakpoints) {
// try {
// if (Path.GetFullPath(breakpoint.FileName) == Path.GetFullPath(FileName)) {
// int lineNumber = iconBar.TextArea.Document.GetVisibleLine(breakpoint.Line - 1);
// int yPos = (int)(lineNumber * iconBar.TextArea.TextView.FontHeight) - iconBar.TextArea.VirtualTop.Y;
// if (yPos >= rect.Y && yPos <= rect.Bottom) {
// ((IconBarMargin)iconBar).DrawBreakpoint(g, yPos, breakpoint.IsEnabled);
// }
// }
// } catch (Exception) {}
// }
// }
// }
void CaretPositionChanged(object sender, EventArgs e)
{
IStatusBarService statusBarService = (IStatusBarService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IStatusBarService));
statusBarService.SetCaretPosition(ActiveTextAreaControl.TextArea.TextView.GetVisualColumn(ActiveTextAreaControl.Caret.Line, ActiveTextAreaControl.Caret.Column), ActiveTextAreaControl.Caret.Line, ActiveTextAreaControl.Caret.Column);
}
void DocumentChanged(object sender, DocumentEventArgs e)
{
((DefaultWorkbench)WorkbenchSingleton.Workbench).UpdateToolbars();
}
void SelectionChanged(object sender, EventArgs e)
{
((DefaultWorkbench)WorkbenchSingleton.Workbench).UpdateToolbars();
}
void GenerateEditActions()
{
try {
IEditAction[] actions = (IEditAction[])(AddInTreeSingleton.AddInTree.GetTreeNode(editActionsPath).BuildChildItems(this)).ToArray(typeof(IEditAction));
foreach (IEditAction action in actions) {
foreach (Keys key in action.Keys) {
editactions[key] = action;
}
}
} catch (TreePathNotFoundException) {
Console.WriteLine(editActionsPath + " doesn't exists in the AddInTree");
}
}
void RemoveQuickClassBrowserPanel()
{
if (quickClassBrowserPanel != null) {
Controls.Remove(quickClassBrowserPanel);
quickClassBrowserPanel.Dispose();
quickClassBrowserPanel = null;
textAreaPanel.BorderStyle = System.Windows.Forms.BorderStyle.None;
}
}
void ShowQuickClassBrowserPanel()
{
if (quickClassBrowserPanel == null) {
quickClassBrowserPanel = new QuickClassBrowserPanel(this);
Controls.Add(quickClassBrowserPanel);
textAreaPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
}
}
public void ActivateQuickClassBrowserOnDemand()
{
SharpDevelopTextEditorProperties sdtep = base.TextEditorProperties as SharpDevelopTextEditorProperties;
if (sdtep != null && sdtep.ShowQuickClassBrowserPanel && FileName != null) {
IParserService parserService = (IParserService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IParserService));
bool quickClassPanelActive = parserService.GetParser(FileName) != null;
if (quickClassPanelActive) {
ShowQuickClassBrowserPanel();
} else {
RemoveQuickClassBrowserPanel();
}
}
}
protected override void OnFileNameChanged(EventArgs e)
{
base.OnFileNameChanged(e);
ActivateQuickClassBrowserOnDemand();
}
//// Alex: routine for pulsing parser thread
// protected void PulseParser() {
// lock(DefaultParserService.ParserPulse) {
// Monitor.Pulse(DefaultParserService.ParserPulse);
// }
// }
//// ALex: end of mod
InsightWindow insightWindow = null;
internal CodeCompletionWindow codeCompletionWindow = null;
// some other languages could support it
protected virtual bool SupportsNew
{
get {
return false;
}
}
// some other languages could support it
protected virtual bool SupportsDot
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -