Active Comments

The idea of Active Comments is to make comments alive and give old fashioned comments new meaning and look.
From now on, you can assign mouse event on your comments and 'tell' your comments what to do on each one. For example, on left mouse click, open some web address in your browser, on mouse over show some picture and on mouse double click open some file.

Let suppose we are writing a example for a GSM/GPSR module which is connected to EasyPIC6 and we would like to provide a photo of our hardware (jumpers, cables, etc.). within the example.
Also, it would be also nice to put some documentation about chip we are using and a GSM module extra board. Now we can have all those things defined in one single comment using Active Comment Editor.

New Active Comment

When you start Active Comment Editor for the first time (from the View menu, from editor's pop-up menu, or by pressing Ctrl + Alt + P) you will get an empty editor :

Active Comments Editor

By clicking the New button you are prompted to enter a name for the comment :

New Active Comment

You can notice that when you start typing a name, properties pane is automatically displayed so you can edit properties if you wish. A Comment will be is created when you click Save button.

Properties are consisted of two major categories - Attributes and Events.

Attributes can be :

There are four predefined event types you can apply to an Active Comment :

  1. OnLeftClick + Alt
  2. OnRightClick
  3. OnDoubleClick
  4. OnMouseOver

First three event types can have one of the following three actions :

  1. OpenUrl - Opens entered URL in default Web browser.
  2. OpenFile - Opens a file within a default program associated with the file extension (defined by Windows).
  3. None - Does nothing.

Fourth event, OnMouseOver, has only 2 actions :

  1. PreviewImage - Shows image when cursor is moved over a comment.
  2. None - Does nothing.

Attributes are tightly bounded with events. For example, you can not have OnLeftClick + Alt -> OpenFile if there is no file attribute set, or if there is no file added to project. Same behavior applies to image attribute.

Let's start editing our Active Comment by entering some valid web address in the URL field :

Entering Web Address

For every Active Comment a XML file will be created, containing all valid information regarding the Active Comment - attributes, events, etc. and it is automatically added to Project manager after saving it :

Images Attributes And Events

You can see the contents of the created XML file by expanding Active Comment Editor :

Editing XML file

As we mentioned above you can add image or file which are already included in project. If the the desired image or file aren't added, you can do it directly from here by clicking the Add Image To Project or Add Image To Project button.

Next file dialog will be opened :

Adding Image To Project Dialog

There, you should select the desired image to be added. In our example, Easy_GSM_GPRS.jpg image will be added.

Selected picture is automatically added to the drop down list of the Image field in Active Comment Editor :

Image Field

Now, when image has been selected, we can assign an event for it. For example, OnMouseOver will be used for PreviewImage action, and OnLeftClick + Alt will be assigned to OpenUrl action :

Images Attributes And Events

Now we can save our changes to Active Comment by clicking the Save button.

  Note : Setting file attributes is same as for image, so it won't be explained separately.

Once we have finished creating our active comment, we can notice that it has been added to source file on current caret position with ac: prefix 'telling' IDE that it is active comment :

Active Comment In Code Editor

Now let's try it. If you LeftClick+Alt on it, URL in default Web browser will be opened. If you hover the mouse over it, you will see an Image preview:

Image Preview

There is another way to add an active comment to an active project. You can do it simply by typing a comment in old fashion way, except with ac: prefix. So it would look like this :

Active Comment In Code Editor

Notice that when you stop typing, Add Comment To Project button will show. By clicking on it, you will open Active Comment Editor and comment name will be already set, so you need only to adjust attributes and settings.
After saving you can always edit your active comment by Active Comment Editor, and switch between comments directly from editor.

If you remove a file from the Project Manager or add an Active Comment File which contains information about the file which is no longer in project, and hover the mouse over the comment, you will be prompted to either add file to project or remove event definition from Active Comment for this file :

File Linked Missing

If you remove active comment file from the Project Manager, you'll receive this message:

Missing File

Click on Yes button you'll prompted for an active comment file :

Open Active Comment File

If you click No, comment will be removed from the source code.

Renaming Active Comment

When you click on rename button, you will be prompted to enter new name :

Rename Active Comment

Now click again Rename button. Now you have renamed your Active Comment in such a way that its filename, source code name are changed :

Rename Active Comment

Deleting Active Comment

Deleting active comment works similar like renaming it. By clicking on delete button, you will remove an active comment from both code and Project Manager.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code