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

📄 texteditordisplaybinding.cs

📁 全功能c#编译器
💻 CS
📖 第 1 页 / 共 2 页
字号:
		void OnFileChangedEvent(object sender, FileSystemEventArgs e)
		{
			lock (this) {
				if(e.ChangeType != WatcherChangeTypes.Deleted) {
					wasChangedExternally = true;
					if (((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Focused) {
						GotFocusEvent(this, EventArgs.Empty);
					}
				}
			}
		}

		// KSL End
	
		void TextAreaChangedEvent(object sender, DocumentEventArgs e)
		{
			IsDirty = true;
		}
		
		public override void RedrawContent()
		{
			textAreaControl.OptionsChanged();
			textAreaControl.Refresh();
		}
		
		public override void Dispose()
		{
			((Form)ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.Workbench).Activated -= new EventHandler(GotFocusEvent);
			textAreaControl.Dispose();
		}
		
		public override bool IsReadOnly {
			get {
				return textAreaControl.IsReadOnly;
			}
		}
		
		public override void Save(string fileName)
		{
			OnSaving(EventArgs.Empty);
			// KSL, Start new line
			if (watcher != null) {
				this.watcher.EnableRaisingEvents = false;
			}
			// KSL End
			
			textAreaControl.SaveFile(fileName);
			FileName  = fileName;
			TitleName = Path.GetFileName(fileName);
			IsDirty   = false;
			
			// KSL, Start new lines
			if (this.watcher != null) {
				this.watcher.EnableRaisingEvents = true;
			}
			// KSL End
			SetWatcher();
			OnSaved(new SaveEventArgs(true));
		}
		
		public override void Load(string fileName)
		{
			textAreaControl.IsReadOnly = (File.GetAttributes(fileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
			    
			textAreaControl.LoadFile(fileName);
			FileName  = fileName;
			TitleName = Path.GetFileName(fileName);
			IsDirty     = false;
			SetWatcher();
		}
		
		public IXmlConvertable CreateMemento()
		{
			DefaultProperties properties = new DefaultProperties();
			string[] bookMarks = new string[textAreaControl.Document.BookmarkManager.Marks.Count];
			for (int i = 0; i < bookMarks.Length; ++i) {
				bookMarks[i] = textAreaControl.Document.BookmarkManager.Marks[i].ToString();
			}
			properties.SetProperty("Bookmarks",   String.Join(",", bookMarks));
			properties.SetProperty("CaretOffset", textAreaControl.ActiveTextAreaControl.Caret.Offset);
			properties.SetProperty("VisibleLine", textAreaControl.ActiveTextAreaControl.TextArea.TextView.FirstVisibleLine);
			properties.SetProperty("HighlightingLanguage", textAreaControl.Document.HighlightingStrategy.Name);
			properties.SetProperty("Foldings", textAreaControl.Document.FoldingManager.SerializeToString());
			return properties;
		}
		
		public void SetMemento(IXmlConvertable memento)
		{
			IProperties properties = (IProperties)memento;
			string[] bookMarks = properties.GetProperty("Bookmarks").ToString().Split(',');
			foreach (string mark in bookMarks) {
				if (mark != null && mark.Length > 0) {
					textAreaControl.Document.BookmarkManager.Marks.Add(Int32.Parse(mark));
				}
			}
			
			textAreaControl.ActiveTextAreaControl.Caret.Position =  textAreaControl.Document.OffsetToPosition(Math.Min(textAreaControl.Document.TextLength, Math.Max(0, properties.GetProperty("CaretOffset", textAreaControl.ActiveTextAreaControl.Caret.Offset))));
//			textAreaControl.SetDesiredColumn();

			if (textAreaControl.Document.HighlightingStrategy.Name != properties.GetProperty("HighlightingLanguage", textAreaControl.Document.HighlightingStrategy.Name)) {
				IHighlightingStrategy highlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(properties.GetProperty("HighlightingLanguage", textAreaControl.Document.HighlightingStrategy.Name));
				if (highlightingStrategy != null) {
					textAreaControl.Document.HighlightingStrategy = highlightingStrategy;
				}
			}
			textAreaControl.ActiveTextAreaControl.TextArea.TextView.FirstVisibleLine = properties.GetProperty("VisibleLine", 0);
			
			textAreaControl.Document.FoldingManager.DeserializeFromString(properties.GetProperty("Foldings", ""));
//			// insane check for cursor position, may be required for document reload.
//			int lineNr = textAreaControl.Document.GetLineNumberForOffset(textAreaControl.Document.Caret.Offset);
//			LineSegment lineSegment = textAreaControl.Document.GetLineSegment(lineNr);
//			textAreaControl.Document.Caret.Offset = Math.Min(lineSegment.Offset + lineSegment.Length, textAreaControl.Document.Caret.Offset);
//			
//			textAreaControl.OptionsChanged();
//			textAreaControl.Refresh();
		}
		
		void CaretUpdate(object sender, EventArgs e)
		{
			CaretChanged(null, null);
			CaretModeChanged(null, null);
		}
		
		void CaretChanged(object sender, EventArgs e)
		{
			Point    pos       = textAreaControl.Document.OffsetToPosition(textAreaControl.ActiveTextAreaControl.Caret.Offset);
			LineSegment line   = textAreaControl.Document.GetLineSegment(pos.Y);
			IStatusBarService statusBarService = (IStatusBarService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IStatusBarService));
			statusBarService.SetCaretPosition(pos.X + 1, pos.Y + 1, textAreaControl.ActiveTextAreaControl.Caret.Offset - line.Offset + 1);
		}
		
		void CaretModeChanged(object sender, EventArgs e)
		{
			IStatusBarService statusBarService = (IStatusBarService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IStatusBarService));
			statusBarService.SetInsertMode(textAreaControl.ActiveTextAreaControl.Caret.CaretMode == CaretMode.InsertMode);
		}
				
		public override string FileName {
			set {
				if (Path.GetExtension(FileName) != Path.GetExtension(value)) {
					if (textAreaControl.Document.HighlightingStrategy != null) {
						textAreaControl.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(value);
						textAreaControl.Refresh();
					}
				}
				base.FileName  = value;
				base.TitleName = Path.GetFileName(value);
			}
		}
		public void JumpTo(int line, int column)
		{
			textAreaControl.ActiveTextAreaControl.JumpTo(line, column);
		}
		delegate void VoidDelegate(AbstractMargin margin);
		
		public void ForceFoldingUpdate(string language)
		{
			if (textAreaControl.TextEditorProperties.EnableFolding) {
				IParserService parserService = (IParserService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IParserService));
				string fileName = IsUntitled ? UntitledName : FileName;
				IParseInformation parseInfo;
				if (fileName == null || fileName.Length == 0) {
					if (language == "C#") {
						parseInfo = parserService.ParseFile("a.cs", textAreaControl.Document.TextContent, false);
					} else {
						parseInfo = parserService.ParseFile("a.vb", textAreaControl.Document.TextContent, false);
					}
				} else {
					parseInfo = parserService.GetParseInformation(fileName);
				}
				textAreaControl.Document.FoldingManager.UpdateFoldings(fileName, parseInfo);
//// Alex free parsings - not sure if better place is in UpdateFoldings asap
				parseInfo=null;
			}
		}
		
		public void ParseInformationUpdated(IParseInformation parseInfo)
		{
			if (textAreaControl.TextEditorProperties.EnableFolding) {
				textAreaControl.Document.FoldingManager.UpdateFoldings(TitleName, parseInfo);
//// Alex free parsings
				parseInfo=null;
				textAreaControl.ActiveTextAreaControl.TextArea.Invoke(new VoidDelegate(textAreaControl.ActiveTextAreaControl.TextArea.Refresh), new object[] { textAreaControl.ActiveTextAreaControl.TextArea.FoldMargin});
			}
		}
		

#region ICSharpCode.SharpDevelop.Gui.IClipboardHandler interface implementation
		public bool EnableCut {
			get {
				return textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCut;
			}
		}
		
		public bool EnableCopy {
			get {
				return textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableCopy;
			}
		}
		
		public bool EnablePaste {
			get {
				return textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnablePaste;
			}
		}
		
		public bool EnableDelete {
			get {
				return textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableDelete;
			}
		}
		
		public bool EnableSelectAll {
			get {
				return textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.EnableSelectAll;
			}
		}
		
		public void SelectAll(object sender, System.EventArgs e)
		{
			textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.SelectAll(sender, e);
		}
		
		public void Delete(object sender, System.EventArgs e)
		{
			textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Delete(sender, e);
		}
		
		public void Paste(object sender, System.EventArgs e)
		{
			textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Paste(sender, e);
		}
		
		public void Copy(object sender, System.EventArgs e)
		{
			textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Copy(sender, e);
		}
		
		public void Cut(object sender, System.EventArgs e)
		{
			textAreaControl.ActiveTextAreaControl.TextArea.ClipboardHandler.Cut(sender, e);
		}
#endregion
	}
}

⌨️ 快捷键说明

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