Snippet Manager

v1.8 now available!

  • (11 Pages)
  • +
  • « First
  • 8
  • 9
  • 10
  • 11

157 Replies - 29801 Views - Last Post: 02 March 2009 - 11:13 AM

#131 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 10 September 2008 - 01:52 PM

Awesome, thanks Psycho :^:

I've been looking for some decent icons :)
Was This Post Helpful? 0
  • +
  • -

#132 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 10 September 2008 - 03:37 PM

Did you manage to fix your paste problem?

Since there's no paste event, I've created my own paste function. It calls paste, and highlights everything that's been pasted (cuts down on time of highlighting everything)

For me, it's a little slow, but this works:
			public void Paste (System.Windows.Forms.ProgressBar progress)
			{ // this function will simulate "catching" the paste event
			  // use instead of "Paste"
			  	string temp = Clipboard.GetText();
			  	progress.Value = 0;
				int i = 0;
				int lines = 0;
				while (true)
				{
					i = temp.IndexOf(System.Environment.NewLine, i);
					if (i != -1)
					{
						lines++;
						i += System.Environment.NewLine.Length;
					}
					else break;
				}
				progress.Maximum = lines+1;
			    int beforePaste = this.Selectionstart;
			    this.Paste(); // after pasting, the caret will move to the end of the pasted text
			    try {
			    	LockWindowUpdate(this.Handle);
				  	int currentCaret = this.Selectionstart;
				  	this.Select (beforePaste,currentCaret);
				  	this.SelectionFont = this.DefaultFont;
				  	this.SelectionColor = this.Default;
				  	for (int x = this.GetCaretCoordinates().Y;
				  		 x <= this.GetLineFromCharIndex(currentCaret);
				  		 x++)
				  	{ 
				  		progress.Increment(1);
				  		this.ColouriseLine(this.GetLineFromCharIndex(x));
				  	} 
				  	this.Selectionstart = currentCaret;
			    } finally {LockWindowUpdate(IntPtr.Zero);}
			    progress.Increment(1); // just to fill the bar!
			}


ColouriseLine basically colourises the keywords on a given line index.
I added the progress bar ability because of how slow it is~ but like I said, it works ^_^

The only problem is that it only seems to work once~
Any ideas on why that could be?

Scrap that. It's because the RTB didn't have focus after the first call :wacko:
Was This Post Helpful? 0
  • +
  • -

#133 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 16 September 2008 - 05:13 AM

Moved back into developing the Snippet Manager yesterday.

I've added the syntax highlighting (still got a few tweaks, but it's working) and a splash screen (it's starting to take a while to load)

Holy crap, the last release has had 16 downloads!

<back to what I was saying>
The next release is due soon, I'm working towards v2.0 with complete syntax highlighting, auto indenting, etc~

:)
Was This Post Helpful? 0
  • +
  • -

#134 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 17 September 2008 - 03:09 AM

I set up a SourceForge for the Snippet Manager yesterday, and it got approved today ^_^

I've also added a form to create a new syntax file~ nice and simple interface. And there's a dropdown menu in the toolstrip to choose a language (the menu is populated at runtime, so when the user creates a new language, it automatically gets added to the list.

Next I'm gonna start working on making the program itself customisable~ stuff like "show splash on startup" and "turn clipboard recorder on/off" etc

:)

Here's a screenshot, taken from my SourceForge project:
https://sourceforge.net/dbimage.php?id=187498

The window to create a new highlighting language:
https://sourceforge.net/dbimage.php?id=187500

EDIT: Dammit. Forgot to show off the tabs in the screen shot. Oh well~
Was This Post Helpful? 0
  • +
  • -

#135 homemade-jam   User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: Snippet Manager

Posted 17 September 2008 - 10:48 AM

We're all impressed nonetheless :D Nice work ;)
Was This Post Helpful? 0
  • +
  • -

#136 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 17 September 2008 - 11:39 AM

Thanks, jam :^:

<Note while I remember>
Need to add an option for "case sensitive keywords" for stuff like assembly, where it isn't case sensitive. :)
</Note while I remember>
Was This Post Helpful? 0
  • +
  • -

#137 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5615
  • View blog
  • Posts: 14,693
  • Joined: 18-April 07

Re: Snippet Manager

Posted 17 September 2008 - 03:46 PM

All I have to say is.... awesome! Both of your guys' work is coming out totally kick ass. I have yet to try them but the screenies are sweet. I may give them a try when I get home later tonight. Maybe when we get going on sourceforge I can pitch in fixes or something in the future.

Of course when I am not being exploited by Chris and the powers that be on DIC! ;)

:^:
Was This Post Helpful? 0
  • +
  • -

#138 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5615
  • View blog
  • Posts: 14,693
  • Joined: 18-April 07

Re: Snippet Manager

Posted 17 September 2008 - 11:13 PM

So I downloaded a copy of your snippet manager gabehabe. Not a bad start. Takes a bit to get use to though but I am sure that will improve. Some suggestions could be...

1) Make the edit window dock to the right and bottom of the app window so when you expand the program, the edit window will also expand into a more "full screen" view.

2) I am not sure why it listed folders on my drive. I would think this would make more sense if it only listed folders which were snippet folders. Perhaps if you made the program create a snippet folder upon first time startup and then create all language folders in this snippet folder, it would be awesome. That way you could always look in this centralized snippet folder for any snippets and their subfolders.

3) I also deleted the language folder I created and had the program try to read the snippet I created in that folder and of course this caused the program to crash. So you might want to look into verifying that a folder/file always exists upon selection from the treeview.

4) I noticed the clipboard ring only updates when you put your cursor back into the edit window. What if the user doesn't want things from clipboard going to this ring automatically? You might want to give the user a choice as to whether or not things go directly to the clipboard ring. I only suggest this because if I was copying sensitive information and then switched to this program to do something else, I may have sensitive info appearing in my clipboard ring I didn't want there. I guess the bigger issue is to let the user have more control what is shown in the clipboard ring.

But awesome start. Looks great. :^:
Was This Post Helpful? 0
  • +
  • -

#139 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 18 September 2008 - 02:42 AM

Most of that's already fixed, it's been a while since I uploaded the latest release. It docks properly, and it records clipboard stuff from anywhere.

As for the snippets, that was only a temporary solution. Like you said, I'll put it all in one folder, most likely "snippets" or prefix each snippet folder with something to say "this folder contains snippets."
I'm also planning on making it possible to load custom directories.

Thanks for the feedback, I really appreciate it! :^:
Was This Post Helpful? 0
  • +
  • -

#140 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 19 September 2008 - 05:14 AM

I added a new feature last night, quick search. It's not fully functional yet, but it's a little animated dropdown thingy, like when you hit CTRL+F in Google Chrome. It doesn't look anywhere near as good, though. :(
Was This Post Helpful? 0
  • +
  • -

#141 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 20 September 2008 - 05:15 AM

New version! It's usable, but this is mostly for testing.

Syntax highlighting has gotten really screwy at the moment, so that will be fixed soon.

Other than that, it's changed a lot since the last release.

The splash screen is a bit crap, I just threw it together quickly. And it's a bit buggy, sometimes the snippet manager starts in the background.

Wow, that's a lot of bugs...

I'm yet to put all snippets in a snippet folder, but that will be done ASAP.

http://www.dreamincode.net/forums/index.php?act=Attach&type=post&id=8349

Here's the program:
Attached File  Snippet_Manager.zip (118.86K)
Number of downloads: 40


Future development:
Let's see...
Obviously, I'm going to fix all those nasty bugs. Syntax will be more customisable, including case sensitivity.
A slight expansion on Martyr2's idea~ rather than that snippets folder, I'm going to set it for workspaces.

Initial run will create a default workspace, but the user can create more.
These workspaces will be stored in a file, as a reference to decide which to load.

Save state:
Before exiting, it will ask if you want to save your state. If you do, it will restore any tabs you currently have open on the next startup (directories stored in a file)

It sounds like a lot of files, but I'm actually just gonna put it all in one file, SyntaxManager.config or something.

:)

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#142 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5615
  • View blog
  • Posts: 14,693
  • Joined: 18-April 07

Re: Snippet Manager

Posted 20 September 2008 - 06:00 PM

Are you going to make this an open source project? I figured that is why you launched sourceforge but thought I would ask. :)
Was This Post Helpful? 0
  • +
  • -

#143 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 21 September 2008 - 07:08 AM

Yeah, that's why I set up SourceForge.

I don't wanna upload anything until it's stable, which will hopefully be soon when I've got all those bugs fixed. Then I'll add a few new things, like intellisense, line numbering (again) and upload it.

I've fixed up the syntax highlighting, it's working again now.
Need to fix the block comment highlighting though~ it highlights when you type, but there's a few things to fix to highlight a chunk up until */ automatically (like when you put /* in the middle of your code, it automatically turns it to the comment colour)

Sounds like a lot, but it won't take too long. :)
Was This Post Helpful? 0
  • +
  • -

#144 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 22 September 2008 - 11:48 AM

Just fixed that horrible bug when you press a key when something is selected (it didn't delete it, which is what I was aiming for)
It does now.

hmmm... not too much left to do on syntax highlighting, I know it's taken a while, but I'm aiming to get it as good as the syntax highlighting in proper IDEs.
Line numbering and intellisense soon to come, I've put them in a seperate namespace, and I'll most likely set up another SourceForge project for it. (It's a namespace called CodeTools, so far it's only got syntax highlighting) I'll most likely compile it as a dll, too.


Currently working on:
-Bettering the syntax highlighting.
-File associations (Snippet Manager won't have compile options, but I'm planning on making an IDE for various languages after this)

:)

I got rid of the splash, it was annoying.
Was This Post Helpful? 0
  • +
  • -

#145 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 22 September 2008 - 04:22 PM

For those of you who are into C# development, you might find my syntax highlighting class quite interesting. It's pretty long, but I've gone for the "lengthy but cautious" approach. By the way, ignore that progressbar crap, that was just something I did when I was testing something. In the end, SyntaxBox will be completely independent, so those functions will be changed. :)

There are still some bugs, but I'm bored, and I figured posting it here would kill a few minutes.

/* 
 * Author: Danny Battison
 * Date: 30/08/2008
 */


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CodeTools
{
	/// <summary>
	/// Some useful tools for programming applications for programmers
	/// Contains a syntax highlighting rich text box
	/// TODO: Intellisense
	/// TODO: Line numbering
	/// </summary>
	
		public class SyntaxBox : RichTextBox
		{
			[DllImport("user32.dll")] // import lockwindow to remove flashing
			public static extern bool LockWindowUpdate (IntPtr hWndLock);
			
			List <string> keywords = new List<string>(); // the main keywords to highlight
			bool enablePreprocessor = false; // for something at the BEGINNING OF THE LINE only! (eg preprocessor in C++)
			bool blockComment = false; // use to see if colour should return to black after a new line
			int nestedComments = 0; // use to record how many nested comments there are
			bool lineCommented = false; // determines whether a line comment is currently being rendered
			bool quotation = false; // determines whether or not to colour a quote "this is a quote"
			bool number = false; // determines if a number is being highlighted
			public bool allowBlockComments = false; // determines if block comments are allowed
			// useful for times such as exiting a quote to determine whether the last " should be a start/end of a quote
			public string blockCommentStart; // the value for a block comment start
			public string blockCommentEnd; // the value for a block comment end
			public string lineComment; // the value for a line comment
			public string indents = String.Empty; // the amount of spaces to indent on each line
			public Color Comment; // the colour of comments
			public Color Quote; // the colour of quotes
			public Color Character; // the colour of an individual character
			public Color Default; // the default colour (most likely black)
			public Color Number; // default will be red
			public Font KeywordFont; // the font (bold?)
			public Color KeywordColour; // the colour of the keywords
			public new Font DefaultFont; // the default font of the SyntaxBox
			public SyntaxBox ()
			{
				this.ScrollBars = RichTextBoxScrollBars.Both;
				this.WordWrap = false;
				// assign some default values for the colours
				this.Font = new Font ("Courier New", 10);
				this.DefaultFont = new Font (this.SelectionFont, FontStyle.Regular);
				this.KeywordFont = new Font (this.SelectionFont, FontStyle.Bold);
				this.KeywordColour = Color.DarkBlue;
				this.Default = Color.Black;
				this.Quote = Color.Blue;
				this.Character = Color.DarkOrange;
				this.Number = Color.RoyalBlue;
				this.Comment = Color.Green;
				// assign an event handler, to determine when the colourise function should be called
				this.KeyDown += new KeyEventHandler(SyntaxBox_KeyDown);
				this.KeyUp += new KeyEventHandler(SyntaxBox_KeyUp);
			}

			void SyntaxBox_KeyUp(object sender, KeyEventArgs e)
			{ // apply the automatic indents when return is KeyUp
				this.SyntaxBox_EventHandler();
				try {
						LockWindowUpdate(this.Handle);
						if (e.KeyCode == Keys.Enter) // apply the indents
						{
							if (this.Text[this.Selectionstart-2] == '{')
								this.indents += "   ";
							else if (this.Text[this.Selectionstart-2] == '}')
							{
								if (this.Text[this.Selectionstart-3] == ' '
								  &&this.Text[this.Selectionstart-4] == ' '
								  &&this.Text[this.Selectionstart-5] == ' ')
									this.DeleteText (this.Selectionstart-5, 3);
								this.indents = this.indents.Remove (0,3);
							}
							this.AppendRtfToIndex(indents,this.Selectionstart);
						}
						if (this.SelectionColor == this.Comment && this.lineCommented
						  &&e.KeyCode == Keys.Enter)
						{
							this.lineCommented = false;
							this.SelectionColor = this.Default;
							this.SelectionFont = this.DefaultFont;
						}
						if (e.KeyCode == Keys.Space && this.SelectionColor != this.Comment)
						{
							this.SelectionColor = this.Default;
							this.SelectionFont = this.DefaultFont;
						}
					} catch (System.Exception t) {/* DO NOTHING */}
					finally {LockWindowUpdate(IntPtr.Zero);}
					if (e.KeyCode == Keys.Back)
					{
						//this.ColouriseLine(this.GetLineFromCharIndex(this.Selectionstart));
					}
			}
			
			void SyntaxBox_KeyDown(object sender, KeyEventArgs e)
			{ // call our event handler function if it isn't the navigation keys
				if (e.KeyCode != Keys.Up && e.KeyCode != Keys.Down
				  &&e.KeyCode != Keys.Left && e.KeyCode != Keys.Right
				  &&e.KeyCode != Keys.Control && e.KeyCode != Keys.Shift)
					this.SyntaxBox_EventHandler();
			}
			
			public void Paste (System.Windows.Forms.ProgressBar progress)
			{ // this function will simulate "catching" the paste event
			  // use instead of "Paste"
			  if (!Clipboard.ContainsText()) return; // can't do anything
			  	string temp = Clipboard.GetText();
			  	progress.Value = 0;
				progress.Maximum = this.Text.Length;
			    this.Paste(); // after pasting, the caret will move to the end of the pasted text
			    try {
			    	LockWindowUpdate(this.Handle);
				  	int currentCaret = this.Selectionstart;
				  	this.SelectAll();
				  	this.SelectionFont = this.DefaultFont;
				  	this.SelectionColor = this.Default;
				  	this.ColouriseAll(progress);
				  	this.Selectionstart = currentCaret;
			    } finally {LockWindowUpdate(IntPtr.Zero);}
			    progress.Increment(1); // just to fill the bar!
			    this.Focus();
			}
			
			void SyntaxBox_EventHandler ()
			{
				try { // use try to make sure it doesn't try to access something outside of the SyntaxBox (ie, the first character)
					if (this.SelectionLength == 0)
					{
						if (this.blockComment == false && this.lineCommented == false
						   && this.quotation == false && this.number == false)
						{ // change back to default
							if (this.SelectionColor != this.Comment)
							{
								this.SelectionColor = this.Default;
								this.SelectionFont = this.DefaultFont;
							}
						}
						this.ColouriseWord();
					}
				} catch (System.Exception t) {/* DO NOTHING */}
			}
			
			int GetLastSpace () // to minimise flashing, we will do this word for word
			{ // returns: the index of the beginning of the most recent word in the SyntaxBox
				int i = this.Selectionstart-1; // -1 to avoid recording the most recent space
				for (int j = i; j >= 0 ; j--)
					if (this.Text[j] == ' ' || this.Text[j] == '\n' || this.Text[j] == '(' || j == 0)
					{ // dumbass scope shit, need to assign j = i, then i = j
						i = j;
						break;
					}
				return i;
			}
			
			public void AddKeyword (string token)
			{
				// use '\n' in different places so that it does not just look for a space
				string token2 = '\n' + token; // prevents another bug
				this.keywords.Add(token);
				this.keywords.Add(token2);
			}
			
			public void AddKeywordsFromFile (string path)
			{
				string [] words = System.IO.File.ReadAllLines(path);
				for (int i = 0; i < words.Length; i++)
				{
					if (words[i] == "[ENABLE PREPROCESSOR]")
						this.enablePreprocessor = true;
					else if (words[i] == "[DISABLE PREPROCESSOR]")
						this.enablePreprocessor = false;
					else if (words[i] == "[ENABLE BLOCK COMMENTS]")
						this.allowBlockComments = true;
					else if (words[i] == "[DISABLE BLOCK COMMENTS]")
						this.allowBlockComments = false;
					else if (i == 2) this.lineComment = words[i];
					else this.AddKeyword(words[i]);
				}
			}
			
			public void ClearKeywords ()
			{
				this.keywords.Clear();
				this.lineComment = System.String.Empty;
			}
			
			public void AppendRtfToIndex (string text, int index)
			{ // pass the rich text box, the text to append, and the index to append from
				if (text == String.Empty) return; // nothing to do!
				if (index == this.Text.Length)
				{
					this.AppendText(text);
					return;
				}
				int currentCaret = this.Selectionstart + text.Length + 1;
				try {
					LockWindowUpdate(this.Handle); // lock the handle to remove flashing
					// select everything from the index to the end
					this.SelectAll();
					System.String temp = this.SelectedRtf;
					this.SelectedText = String.Empty;
					temp.Insert(index, text);
					this.Rtf = temp;
					this.Selectionstart = currentCaret;
				} finally {
					LockWindowUpdate(IntPtr.Zero);} // unlock the handle
			}
			
			public void AppendTextToIndex (string text, int index)
			{ // the text to append, and the index to start appending
			    // make sure the caret is still in the correct position after appending
			    // we add text.Length so that it will still be in the same place in relation
			    // to the words
			    int currentCaret = this.Selectionstart + text.Length;
			    try {
			    	LockWindowUpdate(this.Handle);
				    // select everything from the index to the end
				    this.Select (index, this.Text.Length - index); 
				    text += this.SelectedText; // add everything to what needs to be appended
				    this.SelectedText = String.Empty; // clear the selected text
				    this.AppendText(text); // append the string
				    this.Selectionstart = currentCaret; // reset the caret position
			    } finally {LockWindowUpdate(IntPtr.Zero);}
			    return; // return from the function
			}
			
			bool DeleteText (int start, int length)
			{ // pass the rich text box, the position to highlight from, and the length to highlight
			    int currentCaret = this.Selectionstart; // use to reset position
			    bool success = false; // the boolean to return
			    this.Select (start, length); // select the text
			    this.SelectedText = String.Empty; // set it to nothing
			    if (this.SelectedText != String.Empty) // if for any reason it could not be changed
			        success = false;
			    else success = true;
			    this.Selectionstart = currentCaret; // move the caret back to the current position
			    return success;
			}
			
			System.Drawing.Point GetCaretCoordinates ()
			{
				System.Drawing.Point p = new System.Drawing.Point();
				p.Y = (this.GetLineFromCharIndex(this.Selectionstart)) + 1;
				p.X = (this.Selectionstart - this.GetFirstCharIndexOfCurrentLine()) + 1;
				return p;
			}
			
			string wordToHighlight = String.Empty;
			bool KeywordMatch ()
			{
				try {
					int scan = GetLastSpace(); // find where to start scanning from
					this.wordToHighlight = String.Empty; // initialise to an empty string
					while (scan != this.Selectionstart)
					{ // update currentWord
						this.wordToHighlight += this.Text[scan];
						scan++;
					}
					// trim the brackets
					this.wordToHighlight = this.wordToHighlight.TrimEnd(')','-',';','[',']');
					foreach (string token in this.keywords)
						if (this.wordToHighlight.TrimStart(' ') == token.ToLower())
							return true;
					// otherwise, it doesn't exist
					return false;
				} catch (System.Exception t) {
					/* DO NOTHING */
					return false;
				}
				// warnings are so annoying (-_-/>)
			}
			
			bool checkNum ()
			{ // this function will check to see if a number is NOT part of a string. if it is, it will not be coloured
				if (this.Text[this.GetLastSpace()+1] <= '9' && this.Text[this.GetLastSpace()+1] >= '0')
					return true;
				else return false;
			}
			
			bool isComment ()
			{
				try {
					int currentCaret = this.Selectionstart;
					for (int i = this.lineComment.Length-1; i >= 0; i--)
					{
						if (this.Text[currentCaret-1] != this.lineComment[i])
							return false;
						currentCaret--;
					}
					return true; // the loop was completed!
				} catch (System.Exception t) {
					/* DO NOTHING */
					return false;
				}
			}
			
			public void ColouriseWord ()
			{
				try {
					int currentCaret = this.Selectionstart; // record where the caret is at current time
					
					// highlights the numbers
					if (this.checkNum() == true && this.SelectionColor != this.Comment
					  &&this.number == false)
					{
						this.number = true;
						try {
							LockWindowUpdate(this.Handle);
							this.Select (this.GetLastSpace(), this.Selectionstart-this.GetLastSpace());
							this.SelectionColor = this.Number;
							this.DeselectAll();
						} finally {LockWindowUpdate(IntPtr.Zero);}
					}
					// stops highlighting a number
					else if (this.checkNum() == false && this.SelectionColor == this.Number)
					{
						this.number = false;
						this.SelectionColor = this.Default;
						this.SelectionFont = this.DefaultFont;
					}									
					// highlights the word TODO inside a comment
					else if (this.SelectionColor == this.Comment
					  &&this.Text[this.Selectionstart-1] == 'O'
					  &&this.Text[this.Selectionstart-2] == 'D'
					  &&this.Text[this.Selectionstart-3] == 'O'
					  &&this.Text[this.Selectionstart-4] == 'T')
					{
						try {
							LockWindowUpdate(this.Handle);
							this.Selectionstart -= 4;
							this.Select(this.Selectionstart, 4);
							this.SelectionColor = Color.Red;
							this.SelectionFont = new Font (this.SelectionFont, FontStyle.Bold);
							this.DeselectAll();
							this.Selectionstart += 4;
							this.SelectionColor = Comment;
							this.SelectionFont = DefaultFont;
						} finally {LockWindowUpdate (IntPtr.Zero);}
					}
					  
					// starts highlighting quotations
					else if (this.Text[this.Selectionstart-1] == '"'
					       &&this.SelectionColor != this.Comment
					       &&this.SelectionColor != this.Number
					       &&this.SelectionColor != this.Character)
					{
						this.quotation = true;
						try {
							LockWindowUpdate(this.Handle);
							int stop = 1; // default length to highlight
							int x = this.Text.IndexOf(System.Environment.NewLine,this.Selectionstart);
							if (x == -1) x = this.Text.Length - this.Selectionstart;
							for (int i = this.Selectionstart; i < x; i++)
							{
								if (this.Text[i] == '"' && this.Text[i-1] != '\\')
								{
									stop = i;
									break;
								}
							}
							this.Selectionstart--;
							this.SelectionLength = stop;
							this.SelectionColor = this.Quote;
							this.DeselectAll();
							this.Selectionstart ++;
						} finally {LockWindowUpdate(IntPtr.Zero);}
					}
					// stops highlighting quotations
					else if ((this.Text[this.Selectionstart-1] == ' ' || this.Text[this.Selectionstart-1] == '\n'
					        ||this.Text[this.Selectionstart-1] == ';')
					        &&quotation == true && this.Text[this.Selectionstart-2] == '"'
					        &&this.Text[this.Selectionstart-3] != '\\') // check for \" because it's not the end of the quote
					{
						this.quotation = false; // exit quotation
						try {
							LockWindowUpdate (this.Handle);
							this.Selectionstart -= 1;
							this.Select (this.Selectionstart, 1);
							this.SelectionColor = this.Default;
							this.DeselectAll();
						} finally {LockWindowUpdate(IntPtr.Zero);}
					}
					// starts highlighting a block comment
					else if (this.Text[this.Selectionstart-1] == '*' && this.Text[this.Selectionstart-2] == '/'
					      && this.allowBlockComments == true && !this.lineCommented)
					{
						if (this.nestedComments == 0)
						{
							int count = 0; // count nested comments
							int length = 0; // determine how far to highlight
							for (int i = this.Selectionstart; i < this.Text.Length; i++)
							{
								try {
									if ((this.Text[i] == '*' && this.Text[i+1] == '/') || i == this.Text.Length)
									{
										if (count > 0)
											count--;
										else {
											length = i+1;
											break;
										}
									}
									if (this.Text[i] == '/' && this.Text[i+1] == '*')
										count ++;
								} catch (System.Exception t) {/* DO NOTHING */} 
							}
							try {
								LockWindowUpdate (this.Handle);
								this.Select(this.Selectionstart-2, length+2);
								this.SelectionColor = this.Comment;
								this.SelectionFont = this.DefaultFont;
								this.DeselectAll();
							} finally {LockWindowUpdate(IntPtr.Zero);}
						}
						else 
							this.nestedComments++;
					}
					// stops highlighting a block comment
					else if (this.Text[currentCaret-1] == '/'
					       &&this.Text[currentCaret-2] == '*'
					       &&this.allowBlockComments)
					{
						if (this.blockComment == false)
							return; // nothing to do
						if (this.nestedComments > 0)
							this.nestedComments--;
						else if (this.nestedComments == 0)
						{
							this.SelectionColor = this.Default;
							this.blockComment = false;
						}
					}
					// highlights a line comment
					else if (isComment() || (enablePreprocessor &&((this.Text[currentCaret-1] == '#'
									      && this.Text[currentCaret-2] == '\n')
									      ||(this.Text[0] == '#' && this.Selectionstart == 2))))
					{
						try {
							LockWindowUpdate(this.Handle);
							this.lineCommented = true;
							int x = this.GetCaretCoordinates().X - 1; // it's zero based
							int l = this.GetLineFromCharIndex(this.Selectionstart);
							this.Select (this.GetLastSpace(), this.Lines[l].Length-x+3);
							this.SelectionColor = this.Comment;
							this.SelectionFont = this.DefaultFont;
							this.DeselectAll();
						} finally {LockWindowUpdate(IntPtr.Zero);}
						
					}
					
					// highlights the keywords
					else if (KeywordMatch() == true
					       &&this.SelectionColor != Comment
					       &&this.SelectionColor != Quote
					       &&this.SelectionColor != Number)
					{
						try {
							LockWindowUpdate(this.Handle);
							this.Select (this.GetLastSpace(), wordToHighlight.Length);
							this.SelectionColor = this.KeywordColour;
							this.SelectionFont = this.KeywordFont;
							this.DeselectAll();
							this.wordToHighlight = String.Empty;
						} finally {LockWindowUpdate (IntPtr.Zero);}
					}
					// returns the word to black if it does not match
					else if (this.KeywordMatch() == false
					       &&this.SelectionColor != Comment
					       &&this.SelectionColor != Quote
					       &&this.SelectionColor != Number
					       &&!lineCommented
					       &&!blockComment)// the word does not match
					{
						try {
							LockWindowUpdate(this.Handle);
							this.Select (this.GetLastSpace(), this.Selectionstart - this.GetLastSpace());
							this.SelectionColor = this.Default;
							this.SelectionFont = this.DefaultFont;
							this.DeselectAll();
						} finally {LockWindowUpdate(IntPtr.Zero);}
					}
					this.Selectionstart = currentCaret;
				} catch (System.Exception t) {/* DO NOTHING */}
			}
			
			public void ColouriseLine (int line)
			{
				try {
					LockWindowUpdate(this.Handle);
					int currentCaret = this.Selectionstart;
					this.Selectionstart = this.GetFirstCharIndexFromLine(line)+1;
					this.SelectionLength = this.Text.IndexOf(System.Environment.NewLine, this.Selectionstart);
					this.SelectionColor = this.Default;
					this.SelectionFont = this.DefaultFont;
					this.DeselectAll();
					for (this.Selectionstart = this.GetFirstCharIndexFromLine(line);
					     this.Selectionstart < this.Text.IndexOf(System.Environment.NewLine, this.Selectionstart);
					     this.Selectionstart++)
					{
						if (this.Text[this.Selectionstart] == ' '
						  ||this.Selectionstart == this.Text.IndexOf(System.Environment.NewLine, this.Selectionstart)-1)
							this.SyntaxBox_EventHandler();
					}
				}
				finally {LockWindowUpdate(IntPtr.Zero);}
			}
			public void ColouriseAll(System.Windows.Forms.ProgressBar progress)
			{
				int currentCaret = this.Selectionstart;
				progress.Maximum = this.Lines.Length;
				for (this.Selectionstart = 0;
				     this.Selectionstart < this.Text.Length;
				     this.Selectionstart++)
				{
					progress.Increment (1);
					this.SyntaxBox_EventHandler();
				}
			}
		}
	}

Was This Post Helpful? 0
  • +
  • -

  • (11 Pages)
  • +
  • « First
  • 8
  • 9
  • 10
  • 11