Writing Code With FDT

From FDT Documentation

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
-
One of FDT’s most notable features are the Smart Editor features. In this walkthrough we'll use the project created in the [[Basic AS3 Tutorial]].  
+
One of FDT’s most notable features are the Smart Editor features. In this walkthrough we'll use the project created in the [[Basic AS3 Tutorial]] as a base to explore FDT's code writing capabilities.  
Download the project [http://dl.dropbox.com/u/154189/fdt_wiki_files/as3_project.zip here] and learn about importing this project in the [[Sharing and Archiving Projects]] tutorial.  
Download the project [http://dl.dropbox.com/u/154189/fdt_wiki_files/as3_project.zip here] and learn about importing this project in the [[Sharing and Archiving Projects]] tutorial.  

Revision as of 12:06, 15 September 2010

One of FDT’s most notable features are the Smart Editor features. In this walkthrough we'll use the project created in the Basic AS3 Tutorial as a base to explore FDT's code writing capabilities.

Download the project here and learn about importing this project in the Sharing and Archiving Projects tutorial.

Below we’ll explore some of the most popular smart editor features, for a complete list see FDT’s Editor Features.


Advanced Code Completion (context and convention based) Default key binding: ctrl+space

Advanced code completion, also referred to as code hinting and content assist, is designed to help developers work fast. It provides context aware content completion while typing. Hitting the keystroke ctrl+space will active a pop up window that, based on the context of the cursor, will propose possible text choices to complete the current phrase. With the pop up window open, you can use the up and down arrows to navigate the options and then hit enter or return to have FDT complete the phrase. Code completion can be activated at anytime; however, the more of a phrase exists when code completion is activated - the fewer, and more accurate, options FDT will suggest.

Note- code completion can also create a constructor.

Also see changing the behaviour of code assist.

-video demo / screenshots of context aware completion QuickFixes Default key binding: cmd+1 / ctrl+1

Quick Fixes are designed to provide context aware code generation. Quick Fixes differ from Code Completion in that they are not designed to complete a code phrase. When Quick Fix is engaged, hitting cmd+1, FDT will analyze the context of the cursor and provide code generation options via a pop up window. Event Handler Generation When adding an event listener to an object, if FDT does not detect the event handler it will notify users with an error. Using a Quick Fix, FDT will suggest to ‘Create event listener....’ . When selected, FDT will generate the appropriate event handler method below.

-video demo / screenshots of event generation Reference Generation Quick fixes can auto generate references for you on demand. Method parameters, top level variables, field variables and local variables can be auto generated when FDT does not recognize a string of text.

-video demo / screenshots of reference generations Getter / Setter (Accessor / Mutator) Generation When a field variable exists FDT can auto generate getter & methods ( also refereed to as accessors and mutators). When your cursor is in the context of a field variable, activate Quickfix for available code generation options.

-video demo / screenshots of accessor / mutator generations

Note- Because variables and getters & setters exist within the same object, they must have different names. As such, FDT will analyze the name of the filed variable and generate methods that do not collide with the existing variable. Method Generation If a user makes a reference to a top level method or a method of an object that doesn’t exist, FDT can generate it for you. There are two main ways of implementing this QuickFix: Typing the name of the desired method follows with the calling parenthesis ‘()’. Typing a reference of an object and using typical dot syntax writing the name of the desired method followed with the calling parenthesis ‘()’.


When creating methods in the second fashion, FDT will jump to the target class and generate the method for you. Also, if parameters are included in the before the method is generated, FDT will automatically add those parameters to the method’s signature.

-video demo / screenshots of method generations Unimplemented Method Generation If a class implements particular interface and is missing the methods defined in the interface, FDT will flag it as an error and also provides a QuickFix to generate a class’s unimplemented methods.

-video demo / screenshots of generating a class’s unimplemented methods.

Class and Interface Generation FDT can invoke the New Actionscript Class wizard and the New ActionScript Interface wizard via QuickFix. This is useful when creating an object of a type that is yet undefined.

-video demo / screenshots of class and interface generation

Add Cast To Object Sometimes a variable ( reference ) is assigned via a method that will return an object of a different type. FDT will flag this as an error and using a QuickFix will add a cast to the method call.

Example: class Main extends Sprite { private var my_object : MovieClip;

public function Main() { my_object = make_new_object(); }

private function make_new_object() : DisplayObject { return new MovieClip(); } }

-video demo / screenshots of class and interface generation Namespace Generation

Code Templates Default key binding: ctrl+space

FDT’s template, also refereed to as code snippets, allow for quick generation of commonly used code. Although FDT ships with many templates pre-installed, users can edit existing templates, create new ones and even share templates with other FDT developers. Similar to Advanced Code Completion, code templates are activated by hitting the keystroke ctrl+space. When activated, begin typing the name of the template and then select it within the pop up windows that appears.

-video demo / screenshots of templates in action. Opening The Templates Editor To access FDT’s templates, open FDT’s Preferences window and navigate to FDT>Editor>Templates. Creating Templates With the Templates window open, click the New... button to begin creating your own template. With the New Template window open we see various fields to fill in: Name -The name of the template that will be searched when code completion is activated. Context - The language context that the template will be active within while editing a file in the Editor View. Description - A description of the template. This appears both within the content assist pop up window and within the New Templates window. Pattern - The text that will inserted when a user selects the template via the pop up window.


After setting the Name, Context and Description, fill in what text you wish to be inserted into your file when this template is selected. To enhance the functionality of templates users can add variables to their templates. Variables allow for more powerful and flexible templates by analyzing the context of the template when activated and adding text based on that context. FDT ships with a number of pre-defined variables which can be accessed by clicking the Insert Variable... button. Users can add their own their variables by using the syntax ‘${}’ and adding your own description between the braces.

Tip - When multiple instances of a custom variable exist, all instances of that variable will be simultaneously be updated.

-video demo / screenshots of templates in action. Editing Existing Templates With the Templates window open, choose a template to edit and click the Edit... button.. The Edit Template window will open and you can begin to edit the selected template. When finished, click OK to save the template. Importing and Exporting ( Sharing ) Templates Templates can be easily shared and even versioned via CVS. FDT templates are distributed via XML which FDT creates upon exporting and upon importing, will interpret the XML and add the templates to the Templates Editor. Exporting Templates With the Templates window open highlight the templates you wish to export, it can be just one or all of them. With your chosen templates selected, click the Export... button. FDT will then convert the templates to XML and then ask you where you would like to save the generated XML. Importing Templates With the Templates window open click the Import... button. FDT will then ask you to select the file which contains the templates you wish to add to your existing list of templates. Navigate to a valid .XML file and then click Open. If the provided template file is valid, FDT will add the templates to the available templates. If the templates valid is invaild, e.g. an error in the .XML syntax, FDT will notify with an error message. Organize Imports Default key binding: cmd+shift+o

During the course of writing code, either you will need to import an object into your class or unused imports will accumulate. Using Organize Imports will both remove unused import statements and add any import statements your code needs. Code Formatter Default key binding: cmd+shift+f / ctrl+shift+f

FDT allows you to define how your code is formatted. Whenever a user invokes FDT’s code formatter ( via keystroke ), FDT will readjust formatting such as indentation, white space, braces and blank lines.

To set your own formatting scheme, open FDT’s preferences window and navigate to FDT>Code Style>ActionScript Formatter. Here adjustments can be made to the how the Code Formatter behaves as well as see a preview of the how code will be adjusted when the Code Formatter is invoked. Project Specific Settings FDT also allows for project specific settings. This is helpful when working in a team environment and the team as set it’s own formatting standards.

Enable project specific formatting via the Project Properties Window. Open the window by right clicking on the target project and selecting “Properties”. Once here navigate to ActionScript Formatter and click on ‘Enable project specific settings’. When clicked, FDT’s ActionScript Formatter will appear. Navigation Shortcuts Jump To Declaration Default key binding: F3 While writing the code it is often necessary to change between different classes and other declarations. In order to expedite the work FDT defines some hot keys making it possible to go to declarations very quickly. The most important hot key is F3. If the cursor is placed on a literal - no matter, if it is a variable, a function or a class - using F3 makes the cursor jump directly to the declaration. If the cursor is placed on a literal and F4 is used, you get to the type declaration. In case of a variable it is the variable's type, in case of a function it is the type of a return value. F5 only works with functions that either overwrite other functions or that implement an interface. Here using F5 leads you to the overwritten method or the declaration within the interface respectively.


-screenshots Open Resource Default key binding: cmd+shift+r / ctrl+shift+r Another possibility to open a file is given by the "Open Resource" dialogue which opens when pressing CTRL+SHIFT+R. Enter the initials of the file to be opened and select the file. The wildcards * (any number of optional characters) and ? (one optional character) can also be used in order to search certain files.


-screenshots Quick Outline Default key binding: cmd+o / ctrl+o Withing the Editor View, invoking Quick Outline will have FDT open a pop up window that allows users to see a list of the methods, imports and attributes of the currently active class. There is a search field at the top to allow users to filter the pop up display and using the up and down arrows allows users to select a declaration and then hit enter or return to have FDT jump to that declaration.

-screenshots Open Type Default key binding: cmd+shift+t / ctrl+shift+t Open Type is similar to Jump To Declaration except it acts as more of a search of available source code from all open projects. This includes MXML files, Actionscript files, and SWCs. When invoked FDT will show all Types available sorted by project. Users can filter the results via the text input box on the top.

-screenshots Dependency View Default key binding: cmd+u / ctrl+u In order to understand quickly which class depends on others the "Quick Type Dependency" is useful. This opens via CTRL+U and shows a tree that explains the direct and indirect dependencies of the current file. Core classes are, however, not included. This way, it is possible to understand a program's structure more quickly and reduce, for example, the dependencies of classes amongst each other.

If you enter a letter in the entry field the view is being filtered and only elements starting with the according letter are shown. The wildcards * (any number of optional characters) and ? (one optional character) can also be used. Via the arrow keys elements can be selected and using return leads to the respective text passage.

-screenshots Reference and Declaration Search Default key binding: cmd+r / ctrl+r There are many occasions in which it is interesting to know where a method, a class or a variable is being used. Therefor, FDT offers a specialized search function. If the cursor is placed over the name of a class, a method or a variable, all references can be found quickly. These results are displayed in the "Search View". Double clicking or hitting return/enter on one of the entries leads directly to the source. FDT Search Default key binding: cmd+h / ctrl+h FDT search differs from Reference and Declaration Search in that when executed, the FDT Search Window will open and users can then can choose if you intend to search for references, declarations or both. Additionally, it can be defined if FDT should search in the workspace or only in the current project. The results are also displayed in the "Search View".

Get FDT5