Borland C++ 5.0 Scripts





Auto closing brackets

When opening bracket or brace is inserted in the source,
automaticaly place the corresponding closing bracket or brace next to it.



import IDE;
import editor;

declare kbd = IDE.KeyboardManager.GetKeyboard("Editor");

kbd.Assign("<(>","parens();");
kbd.Assign("<[>","brackets();");
kbd.Assign("<{>","braces();");

kbd.Assign("<\">","quotes1();");
kbd.Assign("<\'>","quotes2();");

kbd.Assign("<Ctrl-(>","editor.TopView.Position.InsertText(\"(\");");
kbd.Assign("<Ctrl-[>","editor.TopView.Position.InsertText(\"[\");");
kbd.Assign("<Ctrl-{>","editor.TopView.Position.InsertText(\"{\");");
kbd.Assign("<Ctrl-\">","editor.TopView.Position.InsertText(\"\\\"\");");

// For some strange reason, this does not work like the others ???
kbd.Assign("<Ctrl-\'>","editor.TopView.Position.InsertText(\"\\\'\");");

parens()
{
  declare pos = editor.TopView.Position;
  pos.InsertText("()");
  pos.MoveRelative(0,-1,true);
}

brackets()
{
  declare pos = editor.TopView.Position;
  pos.InsertText("[]");
  pos.MoveRelative(0,-1,true);
}

braces()
{
  declare pos = editor.TopView.Position;
  if (pos.Column == 1) {
    pos.InsertText("{\r\n\t\r\n}");
    pos.MoveRelative(-1,1,true);
  }
  else {
    pos.InsertText("{\r\n\r\n");
    pos.Align(1);
    pos.InsertText("}");
    pos.MoveRelative(-1,1,true);
  }
}

quotes1()
{
  declare pos = editor.TopView.Position;
  pos.InsertText("\"\"");
  pos.MoveRelative(0,-1,true);
}

quotes2()
{
  declare pos = editor.TopView.Position;
  pos.InsertText("\'\'");
  pos.MoveRelative(0,-1,true);
}

Download AutoBraces.zip



Cut, Copy and Paste in the editor context menu

Put Cut, Copy and Paste commands on the editor's context menu.

//////////////////////////////////////////////////////////////////////////////////////////////////

#define SEPARATOR1   "-BetterEditorMenu1"
#define UNDO      "Undo\tCtrl+Z"
#define UNDO_TIP    "Undo the previous editor action"
#define REDO      "Redo\tShift+Ctrl+Z"
#define REDO_TIP    "Redo the previously undone editor action"
#define SEPARATOR2  "-BetterEditorMenu2"
#define CUT        "Cut"
#define CUT_TIP    "Remove the selected text and put it in the Clipboard"
#define COPY      "Copy"
#define COPY_TIP    "Place a copy of the selected text in the Clipboard"
#define PASTE      "Paste\tCtrl+V"
#define PASTE_TIP    "Insert text from the Clipboard at the cursor position"
#define SELECT      "Select all"
#define SELECT_TIP  "Select the contents of this window"


//////////////////////////////////////////////////////////////////////////////////////////////////

import IDE;
import scriptEngine;

if (!scriptEngine.IsLoaded("menuhook")) scriptEngine.Load("menuhook");


//////////////////////////////////////////////////////////////////////////////////////////////////

CutCopyPaste()
  {
  assign_to_view_menu("Editor", SEPARATOR1);
  assign_to_view_menu("Editor", UNDO, "IDE.EditUndo()", UNDO_TIP);
  assign_to_view_menu("Editor", REDO, "IDE.EditRedo()", REDO_TIP);
  assign_to_view_menu("Editor", SEPARATOR2);
  assign_to_view_menu("Editor", CUT, "IDE.EditCut()", CUT_TIP);
  assign_to_view_menu("Editor", COPY, "IDE.EditCopy();", COPY_TIP);
  assign_to_view_menu("Editor", PASTE, "IDE.EditPaste()", PASTE_TIP);
  assign_to_view_menu("Editor", SELECT, "IDE.EditSelectAll()", SELECT_TIP);

  print "CutCopyPaste loaded, (C) Copyright 1998-99 Matt Arnold";
  }

~()
  {
  remove_view_menu_item("Editor", SEPARATOR1);
  remove_view_menu_item("Editor", UNDO);
  remove_view_menu_item("Editor", REDO);
  remove_view_menu_item("Editor", SEPARATOR2);
  remove_view_menu_item("Editor", CUT);
  remove_view_menu_item("Editor", COPY);
  remove_view_menu_item("Editor", PASTE);
  remove_view_menu_item("Editor", SELECT);
  }

Download CutCopyPaste.zip



Quick change editor font size

Quickly change the edit view font size using the F11 (make font smaller) and F12 (make font bigger) keys.

Note: The line import "User32" ...
and the whole block starting with class DialogHider and ending with declare DialogHider x;
is used to hide the options dialog, so the script works nicer.

   import IDE;
   import "User32" { void MoveWindow(int, int, int, int, int, int); }

   declare keyboard = IDE.KeyboardManager.GetKeyboard("Editor");
   keyboard.Assign("<F11>", "ResizeFont(\"{VK_UP}\");");
   keyboard.Assign("<F12>", "ResizeFont(\"{VK_DOWN}\");");

   ResizeFont(direction)
      {
      class DialogHider
         {
         DialogCreated(name, hDlg)
            {
            MoveWindow(hDlg, 0, 0, 0, 0, FALSE);
            pass(name, hDlg);
            }

         attach this:>DialogCreated to IDE:>DialogCreated;
         };
      IDE.RaiseDialogCreatedEvent  = TRUE;
      declare DialogHider x;
      IDE.KeyboardManager.SendKeys("%OE*{VK_HOME}{VK_DOWN}{VK_DOWN}" +
         "{VK_DOWN}{VK_DOWN}%s" + direction + "{VK_RETURN}");
      }

Download FontResize.zip



Header file sentry

This script puts a description at the beginnig of the current file, and if it is header, puts a sentry to prevent multiple inclusions.


import IDE;
import editor;

declare kbd = IDE.KeyboardManager.GetKeyboard("Editor");

// Choose a key combination
kbd.Assign("<F10>","add_sentry(\"Jogy\");");

add_sentry(user)
{
  // Validate current buffer.
  //
  if (!initialized(editor.TopView))
    return;

  declare curView = editor.TopView;

  declare sTmp = new String();

  sTmp.Text = curView.Buffer.FileName;
  sTmp.Lower();
  declare fileName = sTmp.Text;

  sTmp.Text = curView.Buffer.Extension;
  sTmp.Lower();
  declare fileExt = sTmp.SubString(1).Text;

  declare curTime = new TimeStamp();

  with (editor.TopView.Position) {
    declare curRow = .Row;
    declare curCol = .Column;

    .Move(1,1);
    .InsertText("/*------------------------------------------------------------------------------\n");
    if (fileExt == "cpp" || fileExt == "c")
      .InsertText("Module: ");
    else if (fileExt == "hpp" || fileExt == "h" || fileExt == "rh")
      .InsertText("Header: ");
    else
      .InsertText("File: ");

    .InsertText(fileName); .InsertText(".");
    .InsertText(fileExt); .InsertText("\n");
    .InsertText("Description: \n");
    .InsertText("Note: \n");
    .InsertText("Author: "); .InsertText(user); .InsertText("\n");
    .InsertText("Date created: "); .InsertText(curTime.Day);
    .InsertText(" "); .InsertText(curTime.MonthName());
    .InsertText(" "); .InsertText(curTime.Year);
    .InsertText("\n");
    .InsertText("Date last modified: "); .InsertText(curTime.Day);
    .InsertText(" "); .InsertText(curTime.MonthName());
    .InsertText(" "); .InsertText(curTime.Year);
    .InsertText("\n");
    .InsertText("------------------------------------------------------------------------------*/\n\n");

    if (fileExt == "hpp" || fileExt == "h" || fileExt == "rh") {
      .InsertText("#ifndef __"); .InsertText(fileName);
      .InsertText("_"); .InsertText(fileExt); .InsertText("__");
      .InsertText("  \t// Sentry\n");

      .InsertText("#define __"); .InsertText(fileName);
      .InsertText("_"); .InsertText(fileExt); .InsertText("__");
      .InsertText("\n\n");

      .Move(.LastRow, 1);
      .InsertText("#endif  \t// Sentry\n");
    }

    .Move(curRow, curCol);
  }
}

Download Sentry.zip





Convert text to C/C++ string statements

This script converts the selected plain text to a C/C++ string statement, and prefixes special symbols with '\' character. Example:

This is a text.
And this is a "text" with quotes.

will become

"This is a text.\n"
"And this is a \"text\" with quotes.\n"


//--------------------------------------------------------------------------
// Object Scripting
// Copyright (c) 2002 by Jogy
//
// MAKESTR.SPP: Make C/C++ string from the selected block.
//
// USE: Select a block and run script.
//--------------------------------------------------------------------------
print typeid(module());

//
// IDE imports.
//
import IDE;
import editor;

declare kbd = IDE.KeyboardManager.GetKeyboard("Editor");

// Choose a key combination
kbd.Assign("<Alt-3><'>","make_str();");

make_str()
{
  // Bail if no block.
  //
  if (!editor.TopView.IsValid) return;

  declare curView = editor.TopView;
  declare curBlk = curView.Block;
  declare curPos = curView.Position;

  curPos.Save();

  declare lastRow = curBlk.EndingRow;

  for (declare i = curBlk.StartingRow; i < lastRow; i++) {
    curPos.Move(i, 1);
    curPos.MoveEOL();
    while (curPos.Column > 1)
    {
      if (curPos.Character == '\"' || curPos.Character == '\'')
      {
        curPos.InsertText("\\");
      }

      curPos.MoveRelative(0, -1);
    }


    curPos.Move(i, 1);
    curPos.InsertText("\"");

    curPos.MoveEOL(i, 1);
    curPos.InsertText("\\n\"");
  }

  curPos.Restore();
}


Download MakeStr.zip






Back to home Back to main