Customizing & Extending Video Highlights

  • Using History to replay actions
  • Creating Commands or Macros
  • Automating design tasks using Extensions and Macros
  • Assigning macros to a keystroke
  • Inserting server-side code using Server Behaviors and Snippets

Evaluate Visual Studio

Introduction

When repetitive tasks used in an application can be automated programmatically, it is often called a macro. With software development it is very handy to be able to create macros and other forms of automation so that the tasks of creating the code are simplified. Other timesavers include libraries of code people have written that can be leveraged to create custom behavior in your application. In this video we’ll examine these time saving features.

Dreamweaver Section

In Dreamweaver as you make changes to the design surface, the History panel is populated with a list of each change. You can reposition the slider at the left of the panel enact various levels of "Undo" and "Redo". The History panel also provides means to replay steps that were performed. Once recorded in the list, highlight the specific steps that you would like to replay, and the "Replay" button will re-enact them. Some steps, although recorded, cannot be replayed, and are shown with a red X. When desired steps are highlighted you can use the "Save" icon in the lower right portion of the History panel this saves the repeatable steps into a command, which is like a simple macro. Once recorded the command appears on the "Commands" window for replay at any time that you wish. These commands can also be enhanced with programmatic code. They are stored in files which look like standard HTML, but include JavaScript sections that hold the commands that interact with the Dreamweaver object model. Here is an example freeware script called "All of Them" that searches through the html to find all instances of whatever tag the cursor is placed on. To use this kind of macro it must be placed in the "Commands" folder, found in the Configuration folder where Dreamweaver is installed on the system. This is a good time to test out this special command. Here is a sample HTML file that includes three <input> elements. After selecting one, the "All of them" command can be run from the Commands menu. It has found all three <input> elements from the document, and allows them to be selected.

Similar to how commands are built, you can also modify Inspectors, which are these editing surfaces in the Properties panel. Also Objects, which are found on the Insert menu. Aside from Commands and Objects, Macromedia also allows you to extend the interface with the use of Macromedia Extensions. These .MXP files extend what the interface is able to perform. Extensions can perform tasks like reformatting tables, connecting to back-end databases, and helping to write scripts for browsers.

A final way that the environment can be extended is when you want to write server—side code. By referencing the Application panel, and then the Server Behaviors tab, you can use the "plus" button to include Server Behaviors in your code. By selecting the last option, "Get more sever behaviors", it takes you to the Dreamweaver Exchange Web site. And from here you can evaluate free and paid solutions that extend the server-side logic that is available to your code. We will further discuss the use of Server Behaviors in an upcoming video.

These features of commands, macros, extensions, and server behaviors enhance the development experience in Dreamweaver.

Visual Studio 2005 Section

Visual Studio offers many tools and the power to accomplish almost every task, but you may require a finer level of control. For example, you may want to automate a task or a series of tasks that you perform regularly. Or you may have designed tools that you want to use in the Visual Studio integrated development environment.

To get started with this kind of automation, let’s see how to build a simple macro that automatically types a piece of text.

To record a macro, press SHIFT+CTRL+R. You’ll see a macro tool bar popup with 3 icons, for pause, stop, and cancel macro recording. At this point, menu selections and keyboard input are being recorded as programmatic elements. Individual mouse movement such as clicking to focus on a different part of the document are not captured. When you’re done recording the macro steps, click the "Stop" button in the Macro Recorder. To see the results of the recording, open the macro explorer from the View menu / other windows / macro explorer, or by using the shortcut key Alt+F8. You can then rename the macro to whatever name you wish, thereby preserving it. To execute this macro, you can simply double-click it. More conveniently, macros can be assigned to a keyboard shortcut by referencing Tools / Options / Environment / Keyboard, which we’ll look at in just a moment.

Back in Macro Explorer if you reference the context menu on the macro and click "Edit", you will be taken to a separate IDE called Visual Studio Macros. From Here you can edit the behavior of the macro, even including the programming logic. This is possible because the macro is really recorded as programmatic code. To see this in action, let’s add commands that will open a Web browser and search the Internet for whatever term is currently highlighted in the text. The DTE object referenced in the code allows you to access the Visual Studio environment, Its name stands for "Development Tools Extensibility". From this object we can obtain any selected text in the active window.

If we go back to Tools / Options / Environment / Keyboard, we can define a hotkey for this macro. We can wire the macro to respond to the CTRL-ALT-F key combination. Now from a section of code we are curious about, we can use this key sequence to very easily search the topic online.

Macros are the easiest way to extend the Visual Studio integrated development environment. Not only do they provide a productivity boost by allowing you to record several actions in the IDE and play them back as a single command, they also allow you to learn the Visual Studio Automation models as you edit a recorded macro.

For most developers, macros are sufficient for programming against the Visual Studio Automation model. But in some cases you will want to integrate a tool right into the development environment. This can be accomplished with Add-ins. Menu options, panels, and more can be merged in to appear as if they were built-in to Visual Studio.

Another feature new for 2005 in Visual Studio is Code Snippets. These can only be used in Code-Behind files, and allow you to add common blocks of programmatic code easily. By referencing the context menu and then "Insert Snippet", here is an sample snippet under Networking that uses a modem to dial a phone number. Snippets work like templates in that the green shaded areas of text indicate where text should be changed. In this case we will select COM4, 9600 baud, and an appropriate telephone number.

Code Snippets are also available for keywords, that are activated as you type. For example, in this class file if we create a new string property by typing "prop" and then pressing tab, the code snippet will automatically fill in the field, and property set and get methods with sample data. Now pressing the tab key again will move your cursor to the next shaded area. Notice that as you change the field name to "_TestString", the field names in the set and get methods are updated automatically. Now press tab again, and change the property name to TestString and press enter. The code snippet is now done, and your cursor moves to below the code block.

You can manage the collection of Snippets from the Code Snippet Manager, available on the Tools menu. These snippets are simple files with a .snippet extension, are individual to each user, being stored with each user’s profile under Documents and Settings.

Conclusion

This concludes our comparison of Dreamweaver and Visual Studio 2005 related to customizing and extending.