Today, I’d like to talk a bit about the code editor which is used to create and view executable data. Notice that I used the verb ‘designing‘ instead of ‘writing‘ code in the title. There’s a very simple reason for this: N2D doesn’t yet define a syntax for textual input of code, instead, there is the code designer which provides a visual view on the raw assembly code (so there is no complex conversion required). The idea is that it will eventually (I hope sooner rather than later) be able to understand natural language, making a custom syntax not necessary. Because designing a good language, with accompanying parser can be tricky and time consuming, I opted to skip this step and instead rely on WPF for me to build a powerful designer with. This has sort of worked.
Before you get started with this post, might I suggest you to check the Echo words demo explanation for a more general introduction on how to use the code editor. This provides a good introduction for most of the general concepts. This post will deal with some more technical details. Because of the length, I decided to split it into 3 posts:
- editing techniques: that’s this post
- all the different code statements
- and: tips and tricks.
Editing techniques
Code editing is currently based on a drag drop paradigm in which you drag statements to the editor and drop them at the appropriate location.
- Drop locations are indicated using a gray, rounded border, containing the name of the drop target, like ‘Args’, ‘Children’,…
- To add statements at the bottom, simply drop them somewhere in the white space below or at the side.
- To insert items, drop them on the little black line above the statement. The previous statement will be moved down.
- When you drag an item and drop it somewhere else, it will be moved, except if the ’shift’ key is pressed, in which case the item will remain at it’s original position and will be copied to the drop target (no duplicate, but the same neuron is referenced. This is important!)
- You can also copy and paste items. During the copy process, the id’s of all the selected items are placed on the clipboard. A paste will get the id’s from the clipboard, transform them into neurons which are put in the selected place. You paste in drop targets, simply click in the drop target (there is no visual queue yet to indicate that the drop target is selected, this still needs some work) and paste. Note that copy-paste doesn’t yet work across multiple applications.
- If you press delete while an item is selected, it’s reference will be removed from the editor. If the underlying neuron is no longer referenced anywhere else, it is removed. All neurons that it references which are also no longer referenced are also removed (cascading delete). This is the most used deletion method in code editing. This means that when you delete a statement, all the parameter values that are no longer used, are also deleted. Or, if you delete a code block, all the statements that are no longer used anywhere else, are also deleted from the network.
- If you want more deletions options, use the ‘Delete special’ (ctrl+del) command. This shows a dialog which allows you to specify the deletion method you want:
- simply remove the reference, but always leave the neuron in the network
- Remove the reference and when no longer used, delete it (as with the normal delete)
- Always delete the neuron.Referenced neurons can be
- left alone: they are not deleted
- deleted when no longer referenced
- always deleted
- All neurons can have a ‘display title‘. When the designer finds one for a neuron, this is displayed when possible. You can easily change this name by pressing ‘F2′ or through the context menu of the selected item. This is very useful for variables and globals.
- Most statements have a little circle in the front of the image. This is a toggle button to enable/disable a breakpoint on the item. This is part of the debugger integration into the editor (more on that later).
- It’s also possible to change a statement from one type to another one through the context menu. A warning though about this command, you might loose data with this command, that can’t yet be undone (no proper undo support yet for this command).
- If you simply need to move a statement up or down, you can also use the context menu, which has a submenu for moving items around.