Home > FlashDevelop > Snippet : Instantiate

Snippet : Instantiate

November 7th, 2010 Leave a comment Go to comments

One of my most used snippet is – instantiate.

To bind snippets to key-preses I use Macros.

Instantiating a class snippet could be simple one liner, if not for Vector data type. Vector has very unique format, and it requires special attention then instantiating. (I don’t use Array type anymore, so it’s very important for me to cover this case.)

I will present two different ways to instantiate stuff quickly.

1 – my old way of instantiating stuff

 

We need to create 2 snippets, I named them #instantiateLast and #instantiateSelected.

#instantiateLast :

$(CurWord) = new $(CurWord)($(EntryPoint));

#instantiateSelected :

$(SelText) = new $(SelText)($(EntryPoint));

 

Now in MENU >> Macros >> Edit Macros… we create 2 new macros :

instantiateLastWord [CTRL+ALT+1] :

InsertSnippet|#instantiateLast

 

instantiateSelected [SHIFT + CTRL+ALT+1] :

InsertSnippet|#instantiateSelected

 

(don’t forget to restart FD for shortcuts to start working.)

 

Use instantiateLastWord with non Vector classes keeping cursor over Class name, and then dealing with Vector – select the whole thing and use instantiateSelected.

2 – my current way of instantiating stuff

 

This method requires some instructions to use properly, but you will need only one macro for both Vector’s and non Vectors, and then you deal with Vector you will have to select less.

We will reuse #instantiateSelected snippet described above, and will create this macro for it:

instantiateSelectLast [CTRL+ALT+1]:

ScintillaCommand|WordLeftEndExtend
InsertSnippet|#instantiateSelected

You will have same functionality as before with non Vector classes, just use the macro keeping the cursor in the end of class name. With Vector is a bit tricky, you have to select everything except ”Vector”, and keep cursor in the end of this word. Best way to do it – back select to this point.

 

Have fun with this snippets.

 

Categories: FlashDevelop Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

MindScriptAct is Stephen Fry proof thanks to caching by WP Super Cache