Scripts in UltraEdit32 v.14


    There are programmers who use such a tool as UltraEdit32 .
    In no case do I advertise this product, I just decided to share information about some of its features.
    This article discusses scripting capabilities for UltraEdit v.14.


    To automate routine tasks, UltraEdit has two tools:
    • Macros - used to record sequences of calls to menu functions, button presses, and other committed actions for their subsequent repetition.
      Created are created in automatic macro recording mode when each action is taken into account.
      They are written in the form of Basic - a similar language in the form of sequences of actions.
    • Scripts - designed to create more flexible automation scripts that are difficult to implement with macros.
      Created in the same text editor, conventional programming.
      They are written in the form of JavaScript (v.1.7.) Scripts, which is good news.

    So, first a few general points, and then a few examples that I myself constantly use.

    Scripting



    Creating scripts is very simple, in the “ Scripting ” menu there is a tab “ Scripts ... ” with which you can easily and easily manage all available scripts. Also, when you select “ Script list ”, a window with a list of scripts becomes available, which can be attached in a convenient place, for example, as in the second figure, in the lower left corner.


    You can familiarize yourself with the script management tools on the site in more detail , but not in Russian.

    Scripts are stored in regular .js files and are connected automatically when the program starts.
    It should be understood that scripts are not sets of functions, and when called, everyone works from start to finish.

    To use the specific properties of the document, one more has been added to standard JavaScript objects: UltraEdit , which is the main interface to the current workspace.

    Key Useful Properties and Methods of the UltraEdit Object


    • activeDocument - oddly enough, provides access to the currently active document.
      An example :
      UltraEdit.activeDocument.write('Hello Habr');

      Appends the text 'Hello Habr' to the position of the current cursor.

    • activeDocument.selection - provides access to the current selected text.
      An example :
      var str = UltraEdit.activeDocument.selection;
      str = str.replace(/Word/g, "Habr");
      UltraEdit.outputWindow.showWindow(true);
      UltraEdit.outputWindow.write(str);

      Replaces all Word words with Habr in the selected text and displays the result in the information output window.

    • activeDocument.selection.copy () / cut () / paste () - I think I do not need special comments.

    • activeDocument.key () - allows you to simulate keystrokes during script execution.
      An example :
      UltraEdit.activeDocument.key("HOME");
      UltraEdit.activeDocument.startSelect();
      UltraEdit.activeDocument.key("END");
      UltraEdit.messageBox(UltraEdit.activeDocument.selection);

      Select the entire current line and show it in the alert.

    • messageBox - a method, a replacement for the usual alert ().

    • Array document [] - unlike activeDocument provides the ability to access any of the currently open tabs by index.
      An example :
      UltraEdit.document[1].write('Hello second tab');

      Will add the text 'Hello second tab' to the cursor position in the text on the second tab.
      Note, document.length accordingly contains the number of open tabs.

    • getString is a method of entering information into a script.
      Example:
      var str = UltraEdit.getString("Введи символ разделитель",1);

      It displays a text input window and places the result in the str variable .

    • outputWindow - Another interesting object that allows you to work not with text, but with an additional information output window, designed to display current information and logs.
      An example :
      UltraEdit.outputWindow.showWindow(true);
      UltraEdit.outputWindow.write("Test outputWindow");

      It will open an output window if it does not show and displays the text in it: 'Test outputWindow '.

    • newFile - a method that creates a new, empty tab.
      An example :
      UltraEdit.newFile();


    In my opinion, the most interesting properties and methods were examined.
    A full description of all the methods is in the help for the program, and also on the site you can find some good examples of scripts.

    And now some simple scripts that I prefer to always keep handy


    Replacing all double quotes in the selected text fragment with single ones:
    UltraEdit.activeDocument.mode = 1;//Признак того, что надо работать с выделением
    UltraEdit.activeDocument.findReplace.selectText = true;
    UltraEdit.activeDocument.findReplace.replaceAll = true;
    UltraEdit.activeDocument.findReplace.replace("\"", "'");


    Commenting out selected text:
    UltraEdit.activeDocument.cut();
    UltraEdit.activeDocument.write("/*");
    UltraEdit.activeDocument.paste();
    UltraEdit.activeDocument.write("*/");

    I did it through the clipboard, because it's easier, but you need to remember that it overwrites the current buffer.

    As antonym to the previous script, uncommenting the selected text:
    UltraEdit.activeDocument.mode = 1;//Признак того, что надо работать с выделением
    UltraEdit.activeDocument.findReplace.selectText = true;
    UltraEdit.activeDocument.findReplace.replaceAll = true;
    UltraEdit.activeDocument.findReplace.replace("/*", "");
    UltraEdit.activeDocument.findReplace.replace("*/", "");

    * Source code was highlighted with Source Code Highlighter.



    Of course, there are much more possibilities, but I use these scripts most often.

    Pavel Osipov
    06/17/2009.

    Also popular now: