Click here to Skip to main content
11,577,643 members (52,094 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

CodeDom Assistant

, 21 Sep 2007 81.1K 4.8K 76
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.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ScintillaNet
{
	public partial class SnippetChooser : UserControl
	{
		public SnippetChooser() 
		{
			InitializeComponent();
		}

		private string _snippetList = string.Empty;
		public string SnippetList
		{
			get
			{
				return _snippetList;
			}
			set
			{
				_snippetList = value;
			}
		}

		private Scintilla _scintilla;
		public Scintilla Scintilla
		{
			get
			{
				return _scintilla;
			}
			set
			{
				_scintilla = value;
			}
		}

		protected override void OnLeave(EventArgs e)
		{
			base.OnLostFocus(e);

			Hide();
		}

		protected override void OnVisibleChanged(EventArgs e)
		{
			base.OnVisibleChanged(e);

			txtSnippet.Text = string.Empty;
			setPosition();

			if (Visible)
			{
				txtSnippet.Focus();
				txtSnippet.AutoComplete.Show(0, _snippetList);
			}
			else
				Scintilla.Focus();
		}

		protected override void OnCreateControl()
		{
			setPosition();
			base.OnCreateControl();
			
			txtSnippet.Focus();
			txtSnippet.AutoComplete.Show(0, _snippetList);
		}
		
		public void setPosition()
		{
			if (!Visible)
				return;
			
			int pos = Scintilla.Caret.Position;
			int x = Scintilla.PointXFromPosition(pos);
			int y = Scintilla.PointYFromPosition(pos);

			this.Location = new Point(x, y);
		}


		private void SnippetChooser_Load(object sender, EventArgs e)
		{
			//	This Scintilla has a very limited command set. Its necessary becuase
			//	Scintilla's AutoComplete system is very sensitive when it comes to
			//	dismissing the window, almost anything will do it and there's really
			//	no practical way to prevent it.
			txtSnippet.Commands.RemoveAllBindings();

			txtSnippet.Commands.AddBinding(Keys.Delete, Keys.None, BindableCommand.Clear);
			txtSnippet.Commands.AddBinding(Keys.Back, Keys.None, BindableCommand.DeleteBack);
			txtSnippet.Commands.AddBinding('Z', Keys.Control, BindableCommand.Undo);
			txtSnippet.Commands.AddBinding('Y', Keys.Control, BindableCommand.Redo);
			txtSnippet.Commands.AddBinding('X', Keys.Control, BindableCommand.Cut);
			txtSnippet.Commands.AddBinding('C', Keys.Control, BindableCommand.Copy);
			txtSnippet.Commands.AddBinding('V', Keys.Control, BindableCommand.Paste);
			txtSnippet.Commands.AddBinding('A', Keys.Control, BindableCommand.SelectAll);

			txtSnippet.Commands.AddBinding(Keys.Down, Keys.None, BindableCommand.LineDown);
			txtSnippet.Commands.AddBinding(Keys.Up, Keys.None, BindableCommand.LineUp);

		}

		private void txtSnippet_KeyDown(object sender, KeyEventArgs e)
		{
			//	The built in Scintilla Command Bindings for left and right
			//	will automatically dismiss the AutoComplete Window, which
			//	we don't want. So instead we have to fake our own left and
			//	right functions
			switch (e.KeyCode)
			{
				case Keys.Right:
					txtSnippet.Caret.Goto(txtSnippet.Caret.Position + 1);
					break;
				case Keys.Left:
					txtSnippet.Caret.Goto(txtSnippet.Caret.Position - 1);
					break;
				case Keys.Enter:
				case Keys.Tab:
					if (txtSnippet.AutoComplete.SelectedIndex >= 0)
						txtSnippet.AutoComplete.Accept();					
					break;
				case Keys.Escape:
					Hide();
					break;
			}				
		}


		private void txtSnippet_AutoCompleteAccepted(object sender, AutoCompleteAcceptedEventArgs e)
		{
			string shortcut = txtSnippet.AutoComplete.SelectedText;
			Hide();
			Scintilla.Snippets.InsertSnippet(shortcut);
		}

		private void txtSnippet_DocumentChange(object sender, NativeScintillaEventArgs e)
		{
			////	If for any reason the window DOES manage to hide itself
			////	we merely reshow it.
			if (!txtSnippet.AutoComplete.IsActive && Visible)
			{
				int pos = Scintilla.Caret.Position;
				Scintilla.Caret.Goto(0);
				txtSnippet.AutoComplete.Show(0, _snippetList);
				Scintilla.Caret.Goto(pos);
			}
		}
	}
}

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

Share

About the Author

raygilbert
Web Developer
Australia Australia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 21 Sep 2007
Article Copyright 2007 by raygilbert
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid