📄 misckeys.cs
字号:
// MiscKeys.cs
// Copyright (C) 2000 Mike Krueger
// Copyright (C) 2000 Andrea Paatz
// Copyright (C) 2000 Jeppe Cramon
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System.Drawing;
using System.Windows.Forms;
using System;
using SharpDevelop.Tool.Data;
using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Gui.Edit.Text.TemplateCompletion;
using SharpDevelop.Actions;
using SharpDevelop.Internal.Text;
namespace SharpDevelop.Actions.Edit {
public class Tab : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
if (executor.TextArea.Selection.HasSomethingSelected) {
int min = executor.TextArea.Selection.RealStart.Y;
int max = executor.TextArea.Selection.RealEnd.Y;
if (executor.TextArea.Selection.RealEnd.X == 0)
--max;
for (int i = min; i <= max; ++i)
executor.TextArea.Buffer.Insert(new Point(0, i), "\t");
executor.TextArea.Buffer.UndoStack.UndoLast(max - min + 1);
executor.TextArea.UpdateLines(min, max);
} else {
executor.TextArea.ClipboardHandler.Delete(null, null);
bool overwritten = false;
if (!executor.TextArea.Caret.InsertMode && executor.TextArea.Caret.CaretPos.X < executor.TextArea.Buffer[executor.TextArea.Caret.CaretPos.Y].Text.Length) {
executor.TextArea.Buffer.Delete(executor.TextArea.Caret.CaretPos, new Point(executor.TextArea.Caret.CaretPos.X + 1, executor.TextArea.Caret.CaretPos.Y));
overwritten = true;
}
Point pos = executor.TextArea.Buffer.Insert(executor.TextArea.Caret.CaretPos, "\t");
executor.TextArea.Caret.CaretPos = pos;
executor.TextArea.Caret.SetUpDownPos();
executor.TextArea.UpdateLines(pos.Y, pos.Y);
if (overwritten)
executor.TextArea.UndoStack.UndoLast(2);
}
}
}
public class ShiftTab : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
if (executor.TextArea.Selection.HasSomethingSelected) {
int min = executor.TextArea.Selection.RealStart.Y;
int max = executor.TextArea.Selection.RealEnd.Y;
if (executor.TextArea.Selection.RealEnd.X == 0)
--max;
for (int i = min; i <= max; ++i)
if (executor.TextArea.Buffer[i].Text.Length > 0 && executor.TextArea.Buffer[i].Text[0] == '\t') {
executor.TextArea.Buffer.Delete(new Point(0, i), new Point(1, i));
}
executor.TextArea.Buffer.UndoStack.UndoLast(max - min + 1);
executor.TextArea.UpdateLines(min, max);
} else {
Point pos = executor.TextArea.Caret.CaretPos;
Point opos = pos;
pos.X = Math.Max(0, pos.X - executor.TextArea.Options.TabIndent);
executor.TextArea.Caret.CaretPos = pos;
executor.TextArea.Caret.SetUpDownPos();
}
}
}
public class Backspace : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
Point pos = executor.TextArea.Selection.RealStart;
int min = pos.Y;
if (executor.TextArea.Selection.HasSomethingSelected) {
executor.TextArea.ClipboardHandler.Delete(null, null);
return;
}
pos = executor.TextArea.Caret.CaretPos;
if (pos.X > 0) {
--pos.X;
executor.TextArea.Buffer.Delete(pos, new Point(pos.X + 1, pos.Y));
executor.TextArea.UpdateLines(pos.Y, pos.Y);
executor.TextArea.Caret.CaretPos = pos;
}
else
if (pos.Y > 0) {
pos = new Point(executor.TextArea.Buffer[pos.Y - 1].Text.Length, pos.Y - 1);
executor.TextArea.Buffer.Delete(pos, new Point(0, pos.Y + 1));
executor.TextArea.UpdateToEnd(pos.Y);
executor.TextArea.Caret.CaretPos = pos;
}
executor.TextArea.Caret.SetUpDownPos();
}
}
public class Delete : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
if (executor.TextArea.Selection.HasSomethingSelected) {
executor.TextArea.ClipboardHandler.Delete(null, null);
return;
}
Point pos = executor.TextArea.Caret.CaretPos;
if (pos.X < executor.TextArea.Buffer[pos.Y].Text.Length) {
executor.TextArea.Buffer.Delete(pos, new Point(pos.X + 1, pos.Y));
executor.TextArea.UpdateLines(pos.Y, pos.Y);
} else
if (pos.Y < executor.TextArea.Buffer.Length - 1) {
executor.TextArea.Buffer.Delete(pos, new Point(0, pos.Y + 1));
executor.TextArea.UpdateToEnd(pos.Y);
}
}
}
public class Cut : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.ClipboardHandler.Cut(null, null);
}
}
public class Copy : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.ClipboardHandler.Copy(null, null);
}
}
public class Paste : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.ClipboardHandler.Paste(null, null);
}
}
public class ToggleEditMode : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.Caret.InsertMode = !executor.TextArea.Caret.InsertMode;
executor.TextArea.Caret.CaretPos = executor.TextArea.Caret.CaretPos;
}
}
public class Return : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
executor.TextArea.ClipboardHandler.Delete(null, null);
Point pos = executor.TextArea.Buffer.Insert(executor.TextArea.Caret.CaretPos, "\n");
pos.X = Indent.IndentLine(executor.TextArea.Buffer, pos.Y, executor.TextArea.Options.IndentStyle);
if (executor.TextArea.Options.AutoInsertCurlyBracket &&
executor.TextArea.Caret.CaretPos.X - 1 > 0 &&
executor.TextArea.Buffer[executor.TextArea.Caret.CaretPos.Y].Text.Length > 0 &&
executor.TextArea.Buffer[executor.TextArea.Caret.CaretPos.Y].Text[executor.TextArea.Caret.CaretPos.X - 1] == '{') {
executor.TextArea.Buffer.Insert(pos, "\n}");
Indent.IndentLine(executor.TextArea.Buffer, pos.Y + 1, executor.TextArea.Options.IndentStyle);
Indent.IndentLine(executor.TextArea.Buffer, pos.Y + 2, executor.TextArea.Options.IndentStyle);
}
executor.TextArea.Caret.CaretPos = pos;
executor.TextArea.UpdateToEnd(pos.Y - 1);
executor.TextArea.Caret.SetUpDownPos();
}
}
public class IndentSelection : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
if (executor.TextArea.Selection.HasSomethingSelected) {
int y1 = executor.TextArea.Selection.RealStart.Y;
int y2 = executor.TextArea.Selection.RealEnd.Y;
Indent.IndentLines(executor.TextArea.Buffer, y1, y2, executor.TextArea.Options.IndentStyle);
executor.TextArea.Refresh(); // TODO : LineUpdate
}
}
}
public class TextAreaOptions : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
new SharpDevelop.Gui.Dialogs.OptionsDialog("Buffer Options", executor.TextArea.Options).ShowDialog();
executor.TextArea.Refresh();
}
}
public class ToggleComment : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
int y1 = executor.TextArea.Selection.RealStart.Y;
int y2 = executor.TextArea.Selection.RealEnd.Y;
if (!executor.TextArea.Selection.HasSomethingSelected)
y1 = y2 = executor.TextArea.Caret.CaretPos.Y;
if (y2 - y1 > 0) {
if (executor.TextArea.Selection.SelectionEnd.X == 0 && executor.TextArea.Selection.SelectionEnd.Y == y2)
--y2;
if (executor.TextArea.Selection.SelectionStart.X == 0 && executor.TextArea.Selection.SelectionStart.Y == y2)
--y2;
}
for (int i = y1; i <= y2; ++i) {
if (executor.TextArea.Buffer[i].Text.Length > 1 && executor.TextArea.Buffer[i].Text[0] == '/' && executor.TextArea.Buffer[i].Text[1] == '/')
executor.TextArea.Buffer.Delete(new Point(0, i), new Point(2, i));
else
executor.TextArea.Buffer.Insert(new Point(0, i), "//");
}
executor.TextArea.UpdateLines(y1, y2);
}
}
public class MovePageDown : ISdEditAction
{
public virtual void Execute(ISdEditActionExecutor executor)
{
Point pos = executor.TextArea.Caret.CaretPos;
if (pos.Y < executor.TextArea.Buffer.Length - executor.TextArea.lastVisibleLine) {
pos.Y = executor.TextArea.Caret.GetFirstValidPosGreater(pos.Y + executor.TextArea.lastVisibleLine);
pos.X = executor.TextArea.Caret.UpDownPos;
executor.TextArea.Caret.CaretPos = pos;
}else{
pos.Y = executor.TextArea.Caret.GetFirstValidPosLower(executor.TextArea.Buffer.Length);
pos.X = executor.TextArea.Caret.UpDownPos;
executor.TextArea.Caret.CaretPos = pos;
}
}
}
public class MovePageUp : ISdEditAction
{
public virtual void Execute(ISdEditActionExecutor executor)
{
Point pos = executor.TextArea.Caret.CaretPos;
if (pos.Y > executor.TextArea.lastVisibleLine){
pos.Y = executor.TextArea.Caret.GetFirstValidPosLower(pos.Y - executor.TextArea.lastVisibleLine);
pos.X = executor.TextArea.Caret.UpDownPos;
executor.TextArea.Caret.CaretPos = pos;
} else {
pos.Y = executor.TextArea.Caret.GetFirstValidPosGreater(-1);
executor.TextArea.Caret.CaretPos = pos;
}
}
}
public class ShiftMovePageUp : MovePageUp
{
public override void Execute(ISdEditActionExecutor executor)
{
Point oldpos = executor.TextArea.Caret.CaretPos;
executor.TextArea.ClearSelectionMove = false;
base.Execute(executor);
executor.TextArea.ClearSelectionMove = true;
executor.TextArea.Selection.SetSelectionEnd(oldpos, executor.TextArea.Caret.CaretPos);
}
}
public class ShiftMovePageDown : MovePageDown
{
public override void Execute(ISdEditActionExecutor executor)
{
Point oldpos = executor.TextArea.Caret.CaretPos;
executor.TextArea.ClearSelectionMove = false;
base.Execute(executor);
executor.TextArea.ClearSelectionMove = true;
executor.TextArea.Selection.SetSelectionEnd(oldpos, executor.TextArea.Caret.CaretPos);
}
}
public class TemplateCompletion : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
Point dpos = new Point(0, 0); // TODO : Correct Position
dpos.X = (int)(executor.TextArea.Caret.CaretPos.X * executor.TextArea.TextAreaPainter.FontWidth);
dpos.Y = (int)(executor.TextArea.Caret.CaretPos.Y * executor.TextArea.TextAreaPainter.FontHeight);
dpos.Y += 120;
// dpos.X += window.main.DesktopLocation.X;
// dpos.Y += window.main.DesktopLocation.X;
// dpos.X += executor.TextArea.DesktopLocation.X;
// dpos.Y += executor.TextArea.DesktopLocation.Y;
string word = executor.TextArea.GetWordBeforeCaret();
TemplateCompletionWindow scw = new TemplateCompletionWindow(word, dpos);
if (scw.Value != null) {
executor.TextArea.InsertTemplate(scw.Value);
}
}
}
public class Undo : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
if (executor.TextArea.Buffer.ReadOnly)
return;
executor.TextArea.Selection.SetNoSelection(); // JC: Is this correct, it actually ought to
// // undo selection if the selection was the last action ?
executor.TextArea.Caret.CheckCaretPos();
}
}
public class Fold : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.Buffer.Foldings.FoldPos(executor.TextArea.Caret.CaretPos);
executor.TextArea.Refresh();
}
}
public class UnFold : ISdEditAction
{
public void Execute(ISdEditActionExecutor executor)
{
executor.TextArea.Buffer.Foldings.UnFold(executor.TextArea.Caret.CaretPos.Y + 1);
executor.TextArea.Refresh();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -