BIITSoft Forum Index BIITSoft
Community forum for BIIT Software Systems users
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Introduction to PowerEditor Scripting

 
Post new topic   Reply to topic    BIITSoft Forum Index -> Power Editor
View previous topic :: View next topic  
Author Message
SClemens
Site Admin


Joined: 13 Jun 2005
Posts: 143

PostPosted: Fri Jan 04, 2008 4:56 pm    Post subject: Introduction to PowerEditor Scripting Reply with quote

Hi,

PowerEditor includes a powerful built-in scripting language to automate many editing tasks easily. If you have used eScript in CMS Encore Pro then the concepts are quite similar although PowerEditor has a different set of editor related functions. Also the scripting language is very similar to Delphi and Pascal so those familiar with those should feel right at home Smile

Okay how to get started...

1. Open up PowerEditor.

2. From the main menu, select "Scripting" and then "Setup...", this will open up the Scripting Setup dialog box.

3. Select "User Scripts" item in the tree (and attached to it are all the user-defined scripts, PowerEditor comes with a few already set up, but you can change these, or easily add your own).

PS The "Main Script" tree item is a special PowerEditor maintained one with lots of useful built-in scripts, but shouldn't be changed, but you can copy any useful code from there for use in your own scripts.

4. When selected on the "User Scripts" tree item, then click the "Add" button on the toolbar, this will create a new basic script called "MenuUser1".

5. Feel free to change the name in the edit box, but it must start with "MenuUser" (this is so PowerEditor knows it's a user-defined script). Also don't use spaces or any non-alphanumeric characters in the name.
For example change the name to: MenuUserMyFirstScript

6. For "Must have text selection?" keep it checked (default) if this script must only run if there is currently text selected in the current open editor file.

7. Give the script a "Caption:" (this caption will be displayed in the Scripting menu), example: My &First Script
The "&" character above precedes the accelerator key you wish to use on the menu (which is "F" in this case) - but this is optional. Also try to have each item with a unique accelerator key (if used).

8. For "Shortcut:" type in the shortcut keys you wish to use to invoke this script via the editor, default is "None" but you can set it most Ctrl/Shift/Alt key combinations, example: Ctrl+Shift+A
Note: Each script should have a unique shortcut or leave it to "None".

9. You can also fill in the Description in the "Descrip.:" field (optional)

10. For "Allowed for File Extensions:" fill in the editor file extensions (";" semi-colon delimited) which this script is applicable to (leave blank to allow script to run on all files). Example: .c;.cpp;.pas;.htm;.html

11. Now to type the actual script...
Code:
if (copy(text, 1, 1) = '[') and (copy(text, length(text), 1) = ']') then
  text := copy(text, 2, length(text) - 2)
else
  text := '[' + text + ']';

This is a very simple script that simply takes the current selected editor text and surrounds it with "[" and "]" and if it already has it, then removes it.
PS You can press Ctrl+Space and Ctrl+Shift+Space in the scripting editor for Code Completion and Code Parameters.

12. After having entered the script, now click off that script in the tree onto the preceding script (or any other user script, but do not click on the "User Scripts" item). You will now be prompted that the script has now yet been saved, and if you wish to Save now? Select "Yes" button, the script will now been saved (if there are no errors - otherwise go back to the script and fix them) - the saving process combines all the other user scripts into the combined User Scripts source file.

13. Now click the "Close" button on the Setup Scripting dialog.

14. Now from the PowerEditor main menu, select Scripting, then User Scripts, and then the new script or scripts you just created should now be listed there which you can now invoke anytime to run your custom script or via pressing the shortcut key (if you have assigned any to your script).


Obviously this is just the bare beginning of what's possible with PowerEditor's Scripting capabilities, but a nice starting point for those new to scripting.

Enjoy...

Regards
_________________
Steve Clemens

CMS Encore Pro - The easy way to build and maintain your website.
http://www.biitsoft.com/products/cmsencorepro/index.htm
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    BIITSoft Forum Index -> Power Editor All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group