📄 sharptextareaclipboardhandler.cs
字号:
// SharpTextAreaClipboardHandler.cs
// Copyright (C) 2001 Mike Krueger
// Copyright (C) 2001 Andrea Paatz
//
// 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;
using System.Drawing;
using System.Windows.Forms;
namespace SharpDevelop.Gui.Edit.Text {
/// <summary>
/// The clipboard handler of the textarea.
/// </summary>
public class SharpTextAreaClipboardHandler : ISdClipboardHandable
{
TextAreaControl sharptextarea;
public SharpTextAreaClipboardHandler(TextAreaControl sharptextarea)
{
this.sharptextarea = sharptextarea;
}
public void Cut(object sender, EventArgs e)
{
if (sharptextarea.Selection.HasSomethingSelected && !sharptextarea.Buffer.ReadOnly) {
string str = sharptextarea.Buffer.Delete(sharptextarea.Selection.SelectionStart, sharptextarea.Selection.SelectionEnd);
sharptextarea.Caret.CaretPos = sharptextarea.Selection.RealStart;
sharptextarea.Selection.SetNoSelection();
sharptextarea.UpdateToEnd(sharptextarea.Caret.CaretPos.Y);
sharptextarea.Caret.SetUpDownPos();
// paste to clipboard
Clipboard.SetDataObject(new DataObject(DataFormats.Text, str));
}
}
public void Copy(object sender, EventArgs e)
{
Clipboard.SetDataObject(new DataObject(DataFormats.Text, sharptextarea.Buffer.GetText(sharptextarea.Selection.SelectionStart, sharptextarea.Selection.SelectionEnd)));
}
public void Paste(object sender, EventArgs e)
{
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Text)) {
string text = (string)data.GetData(DataFormats.Text);
if (!text.Equals("")) {
Delete(sender, e);
int y = sharptextarea.Caret.CaretPos.Y;
sharptextarea.Caret.CaretPos = sharptextarea.Buffer.Insert(sharptextarea.Caret.CaretPos, text);
if (y != sharptextarea.Caret.CaretPos.Y) {
sharptextarea.UpdateToEnd(y);
} else {
sharptextarea.UpdateLines(y, y);
}
}
}
}
public void Delete(object sender, EventArgs e)
{
if (sharptextarea.Selection.HasSomethingSelected && !sharptextarea.Buffer.ReadOnly) {
sharptextarea.Buffer.Delete(sharptextarea.Selection.SelectionStart,
sharptextarea.Selection.SelectionEnd);
sharptextarea.Caret.CaretPos = sharptextarea.Selection.RealStart;
sharptextarea.Selection.SetNoSelection();
sharptextarea.UpdateToEnd(sharptextarea.Caret.CaretPos.Y);
sharptextarea.Caret.SetUpDownPos();
}
}
public void SelectAll(object sender, EventArgs e)
{
Point start = new Point (0, 0);
Point end = new Point (sharptextarea.Buffer[sharptextarea.Buffer.Length -1].Text.Length, sharptextarea.Buffer.Length - 1);
if (start != sharptextarea.Selection.SelectionStart || end != sharptextarea.Selection.SelectionEnd) {
// sharptextarea.OldSelectionStart =
sharptextarea.Selection.SelectionStart = start;
// sharptextarea.OldSelectionEnd =
sharptextarea.Selection.SelectionEnd = end;
// sharptextarea.ScrollToCaret();
sharptextarea.Refresh();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -