⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homeendkeys.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
// HomeEndKeys.cs 
// Copyright (C) 2000 Mike Krueger
// Copyright (C) 2000 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;

using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Actions;

namespace SharpDevelop.Actions.Edit {
	
	public class Home : ISdEditAction
	{
		public virtual void Execute(ISdEditActionExecutor executor)
		{
			Point pos = executor.TextArea.Caret.CaretPos;
			for (pos.X = 0; pos.X < executor.TextArea.Buffer[pos.Y].Text.Length; ++pos.X)
				if (!Char.IsWhiteSpace(executor.TextArea.Buffer[pos.Y].Text[pos.X])) 
					break;
			
			if (pos.X == executor.TextArea.Caret.CaretPos.X)
				pos.X = 0;
			
			executor.TextArea.Caret.CaretPos = pos;
			executor.TextArea.Caret.SetUpDownPos();
		}
		
	}
	
	public class End : ISdEditAction
	{
		public virtual void Execute(ISdEditActionExecutor executor)
		{
			Point pos = executor.TextArea.Caret.CaretPos;
			pos.X = executor.TextArea.Buffer[pos.Y].Text.Length;
			executor.TextArea.Caret.CaretPos = pos;
			executor.TextArea.Caret.SetUpDownPos();
		}
	}
	
	public class ShiftHome : Home
	{
		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 ShiftEnd : End
	{
		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 MoveToStart : ISdEditAction
	{
		public virtual void Execute(ISdEditActionExecutor executor)
		{
			executor.TextArea.Caret.CaretPos = new Point(0, executor.TextArea.Caret.GetFirstValidPosGreater(-1));
			executor.TextArea.Caret.SetUpDownPos();
		}
	}
	
	public class MoveToEnd : ISdEditAction
	{
		public virtual void Execute(ISdEditActionExecutor executor)
		{
			executor.TextArea.Caret.CaretPos = new Point(executor.TextArea.Buffer[executor.TextArea.Buffer.Length - 1].Text.Length, executor.TextArea.Caret.GetFirstValidPosLower(executor.TextArea.Buffer.Length));
			executor.TextArea.Caret.SetUpDownPos();
		}
	}
	
	public class ShiftMoveToStart : MoveToStart
	{
		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 ShiftMoveToEnd : MoveToEnd
	{
		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);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -