📄 sharpdeveloptextareacontrol.cs
字号:
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
{
get {
return false;
}
}
// some other languages could support it
protected virtual bool SupportsRoundBracket
{
get {
return false;
}
}
protected bool HandleKeyPress(char ch)
{
string fileName = FileName;
if (codeCompletionWindow != null && !codeCompletionWindow.IsDisposed) {
codeCompletionWindow.ProcessKeyEvent(ch);
}
string ext = Path.GetExtension(fileName).ToLower();
bool isCSharpOrVBNet = ext == ".cs" || ext == ".vb";
bool isBoo = ext == ".boo"; // HACK: Boo wants CC, too...
switch (ch) {
case ' ':
//TextEditorProperties.AutoInsertTemplates
string word = GetWordBeforeCaret();
try {
if ((isCSharpOrVBNet||SupportsNew) && word.ToLower() == "new") {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
IParserService parserService = (IParserService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IParserService));
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, this.FileName, new CodeCompletionDataProvider(true, true), ch);
if (codeCompletionWindow != null)
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
return false;
}
} else {
if (word != null) {
CodeTemplateGroup templateGroup = CodeTemplateLoader.GetTemplateGroupPerFilename(FileName);
if (templateGroup != null) {
foreach (CodeTemplate template in templateGroup.Templates) {
if (template.Shortcut == word) {
if (word.Length > 0) {
int newCaretOffset = DeleteWordBeforeCaret();
//// set new position in text area
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
}
InsertTemplate(template);
return true;
}
}
}
}
}
} catch (Exception) {}
goto case '.';
case '<':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, fileName, new CommentCompletionDataProvider(), '<');
if (codeCompletionWindow != null)
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
} catch (Exception e) {
Console.WriteLine("EXCEPTION: " + e);
}
return false;
case '(':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
if (insightWindow == null || insightWindow.IsDisposed) {
insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this, fileName);
insightWindow.Closed += new EventHandler(CloseInsightWindow);
}
insightWindow.AddInsightDataProvider(new MethodInsightDataProvider());
insightWindow.ShowInsightWindow();
}
} catch (Exception e) {
Console.WriteLine("EXCEPTION: " + e);
}
return false;
case '[':
try {
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion) {
if (insightWindow == null || insightWindow.IsDisposed) {
insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this, fileName);
insightWindow.Closed += new EventHandler(CloseInsightWindow);
}
insightWindow.AddInsightDataProvider(new IndexerInsightDataProvider());
insightWindow.ShowInsightWindow();
}
} catch (Exception e) {
Console.WriteLine("EXCEPTION: " + e);
}
return false;
case '.':
try {
// TextAreaPainter.IHaveTheFocusLock = true;
if (((SharpDevelopTextEditorProperties)Document.TextEditorProperties).EnableCodeCompletion && (isCSharpOrVBNet||isBoo||SupportsDot)) {
codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(((Form)WorkbenchSingleton.Workbench), this, fileName, CreateCodeCompletionDataProvider(false), ch);
if (codeCompletionWindow != null)
codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
}
// TextAreaPainter.IHaveTheFocusLock = false;
} catch (Exception e) {
Console.WriteLine("EXCEPTION: " + e);
}
return false;
//// Alex: reparse file on ; - end of statement
// case '}':
// case ';':
// case ')': // reparse on closing bracket for foreach and for definitions
// PulseParser();
// return false;
//// Alex: end of mod
}
return false;
}
public string GetWordBeforeCaret()
{
int start = TextUtilities.FindPrevWordStart(Document, ActiveTextAreaControl.TextArea.Caret.Offset);
return Document.GetText(start, ActiveTextAreaControl.TextArea.Caret.Offset - start);
}
public int DeleteWordBeforeCaret()
{
int start = TextUtilities.FindPrevWordStart(Document, ActiveTextAreaControl.TextArea.Caret.Offset);
Document.Remove(start, ActiveTextAreaControl.TextArea.Caret.Offset - start);
return start;
}
/// <remarks>
/// This method inserts a code template at the current caret position
/// </remarks>
public void InsertTemplate(CodeTemplate template)
{
string selectedText = String.Empty;
if (base.ActiveTextAreaControl.TextArea.SelectionManager.HasSomethingSelected) {
selectedText = base.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText;
ActiveTextAreaControl.TextArea.Caret.Position = ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection[0].StartPosition;
base.ActiveTextAreaControl.TextArea.SelectionManager.RemoveSelectedText();
}
int newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
int finalCaretOffset = newCaretOffset;
int firstLine = Document.GetLineNumberForOffset(newCaretOffset);
// save old properties, these properties cause strange effects, when not
// be turned off (like insert curly braces or other formatting stuff)
bool save1 = TextEditorProperties.AutoInsertCurlyBracket;
IndentStyle save2 = TextEditorProperties.IndentStyle;
TextEditorProperties.AutoInsertCurlyBracket = false;
TextEditorProperties.IndentStyle = IndentStyle.Auto;
StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
string templateText = stringParserService.Parse(template.Text, new string[,] { { "Selection", selectedText } });
BeginUpdate();
for (int i =0; i < templateText.Length; ++i) {
switch (templateText[i]) {
case '|':
finalCaretOffset = newCaretOffset;
break;
case '\r':
break;
case '\t':
// new Tab().Execute(ActiveTextAreaControl.TextArea);
break;
case '\n':
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(newCaretOffset);
new Return().Execute(ActiveTextAreaControl.TextArea);
newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
break;
default:
ActiveTextAreaControl.TextArea.InsertChar(templateText[i]);
newCaretOffset = ActiveTextAreaControl.TextArea.Caret.Offset;
break;
}
}
int lastLine = Document.GetLineNumberForOffset(newCaretOffset);
EndUpdate();
Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, firstLine, lastLine));
Document.CommitUpdate();
ActiveTextAreaControl.TextArea.Caret.Position = Document.OffsetToPosition(finalCaretOffset);
TextEditorProperties.IndentStyle = IndentStyle.Smart;
Document.FormattingStrategy.IndentLines(ActiveTextAreaControl.TextArea, firstLine, lastLine);
// restore old property settings
TextEditorProperties.AutoInsertCurlyBracket = save1;
TextEditorProperties.IndentStyle = save2;
}
public void InitializeFormatter()
{
try {
IFormattingStrategy[] formater = (IFormattingStrategy[])(AddInTreeSingleton.AddInTree.GetTreeNode(formatingStrategyPath).BuildChildItems(this)).ToArray(typeof(IFormattingStrategy));
if (formater != null && formater.Length > 0) {
// formater[0].Document = Document;
Document.FormattingStrategy = formater[0];
}
} catch (TreePathNotFoundException) {
Console.WriteLine(formatingStrategyPath + " doesn't exists in the AddInTree");
}
}
public override string GetRangeDescription(int selectedItem, int itemCount)
{
StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
stringParserService.Properties["CurrentMethodNumber"] = selectedItem.ToString("##");
stringParserService.Properties["NumberOfTotalMethods"] = itemCount.ToString("##");
return stringParserService.Parse("${res:ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.InsightWindow.NumberOfText}");
}
// public override IDeclarationViewWindow CreateDeclarationViewWindow()
// {
// return new HtmlDeclarationViewWindow();
// }
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -