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

📄 edit.cs

📁 c#精彩编程百例(源代码)
💻 CS
📖 第 1 页 / 共 2 页
字号:
// Edit.cs
// Copyright (C) 2000 Mike Krueger
//
// 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 Microsoft.Win32;
using System;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Xml;
using System.Reflection;
using System.Text;

using SharpDevelop.Actions;
using SharpDevelop.Gui;
using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Gui.Dialogs;
using SharpDevelop.Gui.Window;
using SharpDevelop.Tool.Data;
using SharpDevelop.Internal.Project;
using SharpDevelop.Internal.Messages;
using SharpDevelop.Internal.Text;

namespace SharpDevelop.Actions.Menu {
	
	public class UndoAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null && window.ISdEditable.UndoStack != null) {
				if (window.HasTextArea)
					window.TextArea.Buffer.BeginUpdate();
				window.ISdEditable.UndoStack.Undo();
				if (window.HasTextArea) {
					window.TextArea.Caret.CheckCaretPos();
					window.TextArea.Buffer.EndUpdate();
				}
				
			}
		}
	}
	
	public class RedoAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null && window.ISdEditable.UndoStack != null) {
				if (window.HasTextArea)
					window.TextArea.Buffer.BeginUpdate();
				window.ISdEditable.UndoStack.Redo();
				if (window.HasTextArea) {
					window.TextArea.Caret.CheckCaretPos();
					window.TextArea.Buffer.EndUpdate();
				}
			}
		}
	}
		
	public class CutAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null)
				window.ISdEditable.ClipboardHandler.Cut(null, null);
		}
	}
	
	public class CopyAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null)
				window.ISdEditable.ClipboardHandler.Copy(null, null);
		}
	}
	
	public class PasteAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null)
				window.ISdEditable.ClipboardHandler.Paste(null, null);
		}
	}
		
	public class DeleteAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null)
				window.ISdEditable.ClipboardHandler.Delete(null, null);
		}
	}
	
	public class SelectAllAction : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.ISdEditable != null)
				window.ISdEditable.ClipboardHandler.SelectAll(null, null);
		}
	}
	
	public class WordCount : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		public void Execute(ISdPluginExecutor executor)
		{
			WordCountDialog wcd = new WordCountDialog(executor.Main);
			wcd.Owner = executor.Main;
			wcd.ShowDialog();
			wcd.Dispose();
		}
	}
	
	////////////// Format sub menu
	
	public class RemoveLeadingWS : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		void Convert(TextAreaControl textarea, int y1, int y2) 
		{
			int           redocounter = 0; // must count how many Delete operations occur
			Point         p1 = new Point();
			Point         p2 = new Point();
			for (int i = y1; i < y2; ++i) {
				p1.Y = p2.Y = i;
				for (int x = 0; x < textarea.Buffer[i].Text.Length && Char.IsWhiteSpace(textarea.Buffer[i].Text[x]); ++x) {
					p1.X = x;
					p2.X = x + 1;
					textarea.Buffer.Delete(p1, p2);
					++redocounter;                  // count deletes
					--x;                            // length changed
				}
			}
			textarea.Caret.CheckCaretPos();                       // current cursor position may be invalid
			textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
			textarea.UpdateLines(y1, y2);
		}
		
		public void Execute(ISdPluginExecutor executor)
		{
			if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
				return;
			
			TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
			textarea.Buffer.BeginUpdate();
			if (textarea.Selection.HasSomethingSelected) {
				int y = textarea.Selection.RealEnd.Y + 1;
				if (textarea.Selection.RealEnd.X == 0)
					--y;
				Convert(textarea, textarea.Selection.RealStart.Y, y);
			} else
				Convert(textarea, 0, textarea.Buffer.Length);
			textarea.Buffer.EndUpdate();
		}
	}
	
	public class RemoveTrailingWS : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		void Convert(TextAreaControl textarea, int y1, int y2) 
		{
			int           redocounter = 0; // must count how many Delete operations occur
			Point         p1 = new Point();
			Point         p2 = new Point();
			for (int i = y1; i < y2; ++i) {
				int x = textarea.Buffer[i].Text.Length - 1;
				p1.Y = p2.Y = i;
				while (x >= 0 && Char.IsWhiteSpace(textarea.Buffer[i].Text[x])) {
					p1.X = x;
					p2.X = x + 1;
					textarea.Buffer.Delete(p1, p2);
					++redocounter;                  // count deletes
					--x;                            // length changed
				}
			}
			textarea.Caret.CheckCaretPos();                       // current cursor position may be invalid
			textarea.Buffer.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes)
			textarea.UpdateLines(y1, y2);
		}
		public void Execute(ISdPluginExecutor executor)
		{
			if (executor.Main.ActiveContentWindow == null || !executor.Main.ActiveContentWindow.HasTextArea)
				return;
			
			TextAreaControl textarea = executor.Main.ActiveContentWindow.TextArea;
			textarea.Buffer.BeginUpdate();
			if (textarea.Selection.HasSomethingSelected) {
				int y = textarea.Selection.RealEnd.Y + 1;
				if (textarea.Selection.RealEnd.X == 0)
					--y;
				Convert(textarea, textarea.Selection.RealStart.Y, y);
			} else
				Convert(textarea, 0, textarea.Buffer.Length);
			textarea.Buffer.EndUpdate();
		}
	}
	
	
	public class ToUpperCase : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		void Convert(TextAreaControl textarea, Point from, Point to)
		{
			string what = textarea.Buffer.Delete(from, to).ToUpper();
			textarea.Buffer.Insert(from, what);
			textarea.UndoStack.UndoLast(2);
			textarea.UpdateLines(from.Y, to.Y);
		}
		
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.HasTextArea) {
				TextAreaControl textarea = window.TextArea;
				
				textarea.Buffer.BeginUpdate();
				if (textarea.Selection.HasSomethingSelected) {
					Convert(textarea, textarea.Selection.RealStart, textarea.Selection.RealEnd);
				} else
					if (textarea.Caret.CaretPos.X < textarea.Buffer[textarea.Caret.CaretPos.Y].Text.Length) // cursor at line end ?
						Convert(textarea, textarea.Caret.CaretPos, new Point(textarea.Caret.CaretPos.X + 1, textarea.Caret.CaretPos.Y));
				textarea.Buffer.EndUpdate();
			}
		}
	}
	public class ToLowerCase : ISdPlugin
	{
		public ISdMessageHandler MessageHandler {
			get {
				return null;
			}
		}
		void Convert(TextAreaControl textarea, Point from, Point to)
		{
			string what = textarea.Buffer.Delete(from, to).ToLower();
			textarea.Buffer.Insert(from, what);
			textarea.UndoStack.UndoLast(2);
			textarea.UpdateLines(from.Y, to.Y);
		}
		
		public void Execute(ISdPluginExecutor executor)
		{
			ContentWindow window = executor.Main.ActiveContentWindow;
			if (window != null && window.HasTextArea) {
				TextAreaControl textarea = window.TextArea;
				
				if (textarea.Selection.HasSomethingSelected) {
					Convert(textarea, textarea.Selection.RealStart, textarea.Selection.RealEnd);
				} else
					if (textarea.Caret.CaretPos.X < textarea.Buffer[textarea.Caret.CaretPos.Y].Text.Length) // cursor at line end ?
						Convert(textarea, textarea.Caret.CaretPos, new Point(textarea.Caret.CaretPos.X + 1, textarea.Caret.CaretPos.Y));
			}
		}

⌨️ 快捷键说明

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