Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

CodeDom Assistant

, 21 Sep 2007
Generating CodeDom Code By Parsing C# or VB
codedomassistant_demo.zip
CodeDomAssistant_Demo
CodeDomAssistant.exe
ICSharpCode.NRefactory.dll
RemoteLoader.dll
SciLexer.dll
ScintillaNet.dll
codedomassistant_src.zip
sln.CodeDomAssistant
CodeDomAssistant
bin
Debug
SciLexer.dll
Properties
Settings.settings
NRefactory
NRefactoryASTGenerator
AST
Project
Configuration
Resources
ICSharpCode.NRefactory.snk
Src
Ast
General
Lexer
BuildKeywords.pl
CSharp
Special
VBNet
Parser
CSharp
cs.ATG
Frames
Parser.frame
Scanner.frame
SharpCoco.exe
VBNet
VBNET.ATG
PrettyPrinter
CSharp
VBNet
Visitors
Test
General
Lexer
CSharp
VBNet
Output
CodeDOM
CSharp
VBNet
Parser
Expressions
GlobalScope
Statements
TypeLevel
RemoteLoader
Properties
ScintillaNET
Configuration
Builtin
LexerKeywordListNames
LexerStyleNames
FindReplace
Printing
Properties
Resources
DeleteHS.png
GoToNextMessage - Copy.png
GoToNextMessage.png
GoToPreviousMessage.png
LineColorHS.png
Thumbs.db
ScintillaNET.csproj.vspscc
Snippets
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace ScintillaNet
{
	[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
	public class CaretInfo : ScintillaHelperBase
	{
		protected internal CaretInfo(Scintilla scintilla) : base(scintilla) 
		{
			BlinkRate = SystemInformation.CaretBlinkTime;
			Width = SystemInformation.CaretWidth;
		}

		protected internal bool ShouldSerialize()
		{
			return ShouldSerializeBlinkRate() ||
					ShouldSerializeColor() ||
					ShouldSerializeCurrentLineBackgroundColor() ||
					ShouldSerializeWidth() ||
					ShouldSerializeHighlightCurrentLine() ||
					ShouldSerializeCurrentLineBackgroundAlpha() ||
					ShouldSerializeStyle() ||
					ShouldSerializeIsSticky();
		}

		public void EnsureVisible()
		{
			NativeScintilla.ScrollCaret();
		}

		public override string ToString()
		{
			return ShouldSerialize() ? base.ToString() : string.Empty;
		}

		public void ChooseCaretX()
		{
			NativeScintilla.ChooseCaretX();
		}

		#region Width

		public int Width
		{
			get
			{
				return NativeScintilla.GetCaretWidth();
			}
			set
			{
				NativeScintilla.SetCaretWidth(value);
			}
		}

		private bool ShouldSerializeWidth()
		{
			return Width != SystemInformation.CaretWidth;
		}

		private void ResetWidth()
		{
			Width = SystemInformation.CaretWidth;
		}
		#endregion

		#region	CaretStyle
		public CaretStyle Style
		{
			get
			{
				return (CaretStyle)NativeScintilla.GetCaretStyle();
			}
			set
			{
				NativeScintilla.SetCaretStyle((int)value);
			}
		}

		private bool ShouldSerializeStyle()
		{
			return Style != CaretStyle.Line;
		}

		private void ResetStyle()
		{
			Style = CaretStyle.Line;
		}
		#endregion

		#region Color

		public Color Color
		{
			get
			{
				if (Scintilla.ColorBag.ContainsKey("Caret.Color"))
					return Scintilla.ColorBag["Caret.Color"];

				Color c = Utilities.RgbToColor(NativeScintilla.GetCaretFore());
				
				if (c == Color.FromArgb(0,0,0))
					return Color.Black;

				return c;
			}
			set
			{
				if (value == Color)
					return;

				if (value.IsKnownColor)
				{
					if (Color == Color.Black)
						Scintilla.ColorBag.Remove("Caret.Color");
					else
						Scintilla.ColorBag["Caret.Color"] = value;
				}

				NativeScintilla.SetCaretFore(Utilities.ColorToRgb(value));
			}
		}

		private bool ShouldSerializeColor()
		{
			return Color != Color.Black;
		}

		private void ResetColor()
		{
			Color = Color.Black;
		}
		#endregion Color

		#region CurrentLineBackgroundColor


		public Color CurrentLineBackgroundColor
		{
			get
			{
				if (Scintilla.ColorBag.ContainsKey("Caret.CurrentLineBackgroundColor"))
					return Scintilla.ColorBag["Caret.CurrentLineBackgroundColor"];

				Color c = Utilities.RgbToColor(NativeScintilla.GetCaretLineBack());

				if (c.ToArgb() == Color.Yellow.ToArgb())
					return Color.Yellow;

				return c;
			}
			set
			{
				

				if (value == Color)
					return;

				if (value.IsKnownColor)
				{
					if (Color == Color.Yellow)
						Scintilla.ColorBag.Remove("Caret.CurrentLineBackgroundColor");
					else
						Scintilla.ColorBag["Caret.CurrentLineBackgroundColor"] = value;
				}

				NativeScintilla.SetCaretLineBack(Utilities.ColorToRgb(value));
			}
		}

		private bool ShouldSerializeCurrentLineBackgroundColor()
		{
			return CurrentLineBackgroundColor != Color.Yellow;
		}

		private void ResetCurrentLineBackgroundColor()
		{
			CurrentLineBackgroundColor = Color.Yellow;
		}
		#endregion

		#region HighlightCurrentLine
		
		public bool HighlightCurrentLine
		{
			get
			{
				return NativeScintilla.GetCaretLineVisible();
			}
			set
			{
				NativeScintilla.SetCaretLineVisible(value);
			}
		}

		private bool ShouldSerializeHighlightCurrentLine()
		{
			return HighlightCurrentLine;
		}

		private void ResetHighlightCurrentLine()
		{
			HighlightCurrentLine = false;
		}
		#endregion

		#region CurrentLineBackgroundAlpha

		public int CurrentLineBackgroundAlpha
		{
			get
			{
				return NativeScintilla.GetCaretLineBackAlpha();
			}
			set
			{
				NativeScintilla.SetCaretLineBackAlpha(value);
			}
		}

		private bool ShouldSerializeCurrentLineBackgroundAlpha()
		{
			return CurrentLineBackgroundAlpha != 256;
		}

		private void ResetCurrentLineBackgroundAlpha()
		{
			CurrentLineBackgroundAlpha = 256;
		}

		#endregion

		#region BlinkRate

		public int BlinkRate
		{
			get
			{
				return NativeScintilla.GetCaretPeriod();
			}
			set
			{
				NativeScintilla.SetCaretPeriod(value);
			}
		}

		private bool ShouldSerializeBlinkRate()
		{
			return BlinkRate != SystemInformation.CaretBlinkTime;
		}

		private void ResetBlinkRate()
		{
			BlinkRate = SystemInformation.CaretBlinkTime;
		}
		#endregion

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public int Position
		{
			get
			{
				return NativeScintilla.GetCurrentPos();
			}
			set
			{
				NativeScintilla.SetCurrentPos(value);
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public int Anchor
		{
			get
			{
				return NativeScintilla.GetAnchor();
			}
			set
			{
				NativeScintilla.SetAnchor(value);
			}
		}


		#region IsSticky
		public bool IsSticky
		{
			get
			{
				return NativeScintilla.GetCaretSticky();
			}
			set
			{
				NativeScintilla.SetCaretSticky(value);
			}
		}

		private bool ShouldSerializeIsSticky()
		{
			return IsSticky;
		}

		private void ResetIsSticky()
		{
			IsSticky = false;
		} 
		#endregion

		
		public void Goto(int position)
		{
			NativeScintilla.GotoPos(position);
		}



		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public int LineNumber
		{
			get
			{
				return NativeScintilla.LineFromPosition(NativeScintilla.GetCurrentPos());
			}
			set
			{
				NativeScintilla.GotoLine(value);
			}
		}

		public void BringIntoView()
		{
			NativeScintilla.MoveCaretInsideView();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

raygilbert
Web Developer
Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 21 Sep 2007
Article Copyright 2007 by raygilbert
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid