AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scripts collection
Goto page Previous  1, 2, 3 ... 15, 16, 17, 18  Next
 
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Visitor7



Joined: 03 Jun 2012
Posts: 88

PostPosted: Sat Jun 16, 2012 9:14 pm    Post subject: Reply with quote

Cycling between specified font settings.

cpFontSwitch.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=18482#18482
// cpFontSwitch.js    ver.1.6    2012-07-19
// Cycling between specified font settings.
// Usage: Call("Scripts::Main", 1, "cpFontSwitch.js", `m [n1] [t1] [s1] [ [n2] [t2] [s2] [n3] [t3] [s3]  ...]`)
//    m - options mask, integer 1...7:
//      0x001 (1)  -  process font name
//      0x010 (2)  -  process font type
//      0x100 (4)  -  process font size
//    n - font name, in quotes
//    t - font type:
//      1 - normal
//      2 - bold
//      3 - italic
//      4 - bold italic
//    s - font size
// Examples:
//     Call("Scripts::Main", 1, "cpFontSwitch.js", `2 1 2 3`)
//        Switch font between normal/bold/italic.
//     Call("Scripts::Main", 1, "cpFontSwitch.js", `6 1 10 2 12`)
//        Switch between normal font(size 10) and bold font(size 12).
//     Call("Scripts::Main", 1, "cpFontSwitch.js", `7 "MS Sans Serif" 1 8 "Courier New" 2 10`)
//        Switch between normal "MS Sans Serif"(size 8) and bold "Courier New"(size 10).
//     Call("Scripts::Main", 1, "cpFontSwitch.js", `5 "MS Sans Serif" 8 "Courier New" 10 "Arial" 9`)
//        Switch between "MS Sans Serif"(size 8), "Courier New"(size 10) and "Arial"(size 9).

var hMainWnd = AkelPad.GetMainWnd();
var hWndEdit = AkelPad.GetEditWnd();
var lpLogFont;
var pFontName = "";
var nWeight;
var bItalic;
var nFontType;
var nFontSize;
var i;
var oMask;
var rowLen;
var colLen;

if (hMainWnd && hWndEdit && IsIntRng(0, 0, 1, 7) && (lpLogFont = AkelPad.MemAlloc(92 /*sizeof(LOGFONTW)*/)))      ///////////////////
{
   AkelPad.SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, hWndEdit, lpLogFont);
   pFontName = AkelPad.MemRead(lpLogFont + 28 /*offsetof(LOGFONTW, lfFaceName)*/, 1 /*DT_UNICODE*/);
   nWeight = AkelPad.MemRead(lpLogFont + 16 /*offsetof(LOGFONTW, lfWeight)*/, 3 /*DT_DWORD*/);
   bItalic = AkelPad.MemRead(lpLogFont + 20 /*offsetof(LOGFONTW, lfItalic)*/, 5 /*DT_BYTE*/);
   nFontSize = AkelPad.SendMessage(hWndEdit, 3188 /*AEM_GETCHARSIZE*/, 3 /*AECS_POINTSIZE*/, 0);
   AkelPad.MemFree(lpLogFont);
   if (pFontName && nWeight && nFontSize)                                       ///////////////////
   {
      if (nWeight < 600)                                 ////
         nFontType = 1;
       else
         nFontType = 2;
      if (bItalic)
         nFontType += 2;
      oMask = WScript.Arguments(0);                        ////
      i = oMask;
      for (colLen=0; i!=0; ++colLen)
         i &= ~(-i);
      rowLen = (WScript.Arguments.Length - 1) / colLen;
      if (IsIntRng(1, rowLen, 1))
      {
         for (i; i < rowLen; ++i)                              ////
         {
            if  (((!(1 & oMask)) || ((1 & oMask) && (pFontName == WScript.Arguments(i * colLen + 1)))) && ((!(2 & oMask)) || ((2 & oMask) && (nFontType == WScript.Arguments(i * colLen + 1 + (1 & oMask))))) && ((!(4 & oMask)) || ((4 & oMask) && (nFontSize == WScript.Arguments(i * colLen + 1 + (1 & oMask) + ((2 & oMask) >> 1))))))
               break;
         }
         if (++i >= rowLen) i=0;
         if (1 & oMask)    pFontName = WScript.Arguments(i * colLen + 1);      ////
         if (2 & oMask)    nFontType = WScript.Arguments(i * colLen + 1 + (1 & oMask));
         if (4 & oMask)    nFontSize = WScript.Arguments(i * colLen + 1 + (1 & oMask) + ((2 & oMask) >> 1));
         if (isNaN(pFontName) && IsIntRng(1, nFontType, 1, 4) && IsIntRng(1, nFontSize, 0))
         {
            AkelPad.Font(pFontName, nFontType, nFontSize);
         }
      }
   }
}

function IsIntRng(aMod, aNum, aFrom, aTo)   //aMod: 0 - aNum is script argument namber, 1 - aNum is namber
{
   var aValue;
   if (aMod&1)
      aValue = aNum;
   else if (WScript.Arguments.length > aNum)
      aValue = +WScript.Arguments(aNum);
   if ((Math.floor(aValue) == aValue) && (aValue >= aFrom) && ((aTo === undefined) || (aValue <= aTo)))
      return true;
   return false;
}


Last edited by Visitor7 on Thu Jul 19, 2012 2:18 pm; edited 9 times in total
Back to top
View user's profile Send private message
Visitor7



Joined: 03 Jun 2012
Posts: 88

PostPosted: Mon Jun 25, 2012 12:50 am    Post subject: Reply with quote

Advanced Undo/Redo manipulation.

UndoMax.js lite
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=18578#18578
// UndoMax.js      v1.3 lite      2012-06-27
// Undo all changes made after document opening:
//         Call("Scripts::Main", 1, "UndoMax.js")
//     or Call("Scripts::Main", 1, "UndoMax.js", "0")
// Undo all changes made since the last save. The same result would Reopen (F5), but need confirmation:
//         Call("Scripts::Main", 1, "UndoMax.js", "1")
// Redo all changes:
//         Call("Scripts::Main", 1, "UndoMax.js", "2")
//
// Advanced usage:  Call("Scripts::Main", 1, "UndoMax.js", "[s[ l]]")
//    s - settings, integer 1...7:
//        b001 (1)  -  undo mode         (0 - after opening, 1 - last/no save)
//        b010 (2)  -  undo/redo switch   (0 - undo, 1 - redo)
//        b100 (4)  -  report            (0 - do nothing, 1 - show the number of actions performed upon script completion)
//    l - limit, specified number of undo/redo actions.
// Examples:
//    Call("Scripts::Main", 1, "UndoMax.js", "0 10")
//        Try to repeat undo 10 times.
//    Call("Scripts::Main", 1, "UndoMax.js", "6 7")
//        Try to repeat redo 7 times with report.
//    Call("Scripts::Main", 1, "UndoMax.js", "1 15")
//        Try to repeat undo 15 times within the last save.
//    Call("Scripts::Main", 1, "UndoMax.js", "4")
//        Undo all with report.

var hMainWnd=AkelPad.GetMainWnd();
var hWndEdit = AkelPad.GetEditWnd();
var oSys = AkelPad.SystemFunction();
var uSettings = 0;
var limit = Number.MAX_VALUE;
var aNamber;
var aReport = "";

if (hMainWnd && hWndEdit)
{
  if(WScript.Arguments.length > 0)
    uSettings = WScript.Arguments(0);
  if(WScript.Arguments.length > 1)
    limit = WScript.Arguments(1);
  aNamber = (uSettings&2)?uniRedo(limit):uniUndo((uSettings&1), limit);
  aReport += (uSettings&2)?"Redo":"Undo";
  aReport += " actions: " + aNamber;
  if (uSettings&4)
    AkelPad.MessageBox(hMainWnd, aReport, "UndoMax.js", 64 /*MB_OK, MB_ICONINFORMATION*/);
}

function uniUndo(mod, lim)
{
  var n = 0;
  if (((!(mod&1)) && AkelPad.SendMessage(hWndEdit, 3075 /*AEM_CANUNDO*/, 0, 0)) || (AkelPad.SendMessage(hWndEdit, 3086 /*AEM_GETMODIFY*/, 0, 0) && (mod&1)))
  {
    SetRedraw(hWndEdit, false);
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, true);
    while (AkelPad.SendMessage(hWndEdit, 3075 /*AEM_CANUNDO*/, 0, 0))
    {
      if ( (!AkelPad.SendMessage(hWndEdit, 3086 /*AEM_GETMODIFY*/, 0, 0) && (mod&1)) || (n >= lim) )
        break;
      AkelPad.SendMessage(hWndEdit, 3077 /*AEM_UNDO*/, 0, 0);
      ++n;
    }
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, false);
    SetRedraw(hWndEdit, true);
  }
  return n;
}

function uniRedo(lim)
{
  var n = 0;
  if (AkelPad.SendMessage(hWndEdit, 3076 /*AEM_CANREDO*/, 0, 0))
  {
    SetRedraw(hWndEdit, false);
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, true);
    while (AkelPad.SendMessage(hWndEdit, 3076 /*AEM_CANREDO*/, 0, 0))
    {
      if (n >= lim)
        break;
      AkelPad.SendMessage(hWndEdit, 3078 /*AEM_REDO*/, 0, 0);
      ++n;
    }
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, false);
    SetRedraw(hWndEdit, true);
  }
  return n;
}

function SetRedraw(hWnd, bRedraw)
{
   AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
   if (bRedraw) oSys.Call("user32::InvalidateRect", hWnd, 0, true);
}


UndoMax.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=18575#18575
// UndoMax.js      v1.3      2012-06-27      (En/Ru)
// Advanced Undo/Redo manipulation.
//
// Usage:  Call("Scripts::Main", 1, "UndoMax.js", "[s[ l[ p]]]")
//    s - settings, integer 0...31, default 0:
//        b00001 (1)  -   undo mode         (0 - after opening, 1 - last/no save)
//        b00010 (2)  -   undo/redo switch      (0 - undo, 1 - redo)
//        b00100 (4)  -   report            (0 - do nothing, 1 - show the number of actions performed upon script completion)
//        b01000 (8)  -   prompt            (0 - do nothing, 1 - request command arguments at startup)
//        b10000 (16) -  shiftkeys         (0 - enable, 1 - disable. use to avoid conflict if you call the script through hot key combination with shift)
//        The report and the prompt can also be activated by shift keys holding in moment of script startup(or by pressing during a pause after startup):
//        Report - left shift key.  Prompt - right shift key.
//    l - limit, specified number of undo/redo actions. Default 0 - maximum actions.
//    p - waiting time of shift pressing after startup, in milliseconds, default 0. Use when calling the script through hot key combination and want to use the shift keys.
// Examples:
//    Call("Scripts::Main", 1, "UndoMax.js", "0")  or  Call("Scripts::Main", 1, "UndoMax.js")
//         Undo all changes made after document opening.
//    Call("Scripts::Main", 1, "UndoMax.js", "1")
//         Undo all changes made since the last save. The same result would Reopen (F5), but need confirmation.
//    Call("Scripts::Main", 1, "UndoMax.js", "2")
//         Redo all changes.
//    Call("Scripts::Main", 1, "UndoMax.js", "1 10")
//         Try to repeat undo 10 times within the last saved.
//    Call("Scripts::Main", 1, "UndoMax.js", "6 7")
//         Try to repeat redo 7 times with report.
//    Call("Scripts::Main", 1, "UndoMax.js", "4")
//         Undo all changes made after document opening with report.
//    Call("Scripts::Main", 1, "UndoMax.js", "28")
//        Prompt with report.
//    Call("Scripts::Main", 1, "UndoMax.js", "1 0 250")
//        Undo all(last save) with a pause 250 ms, for example, to assign hot key combination Alt+U to be able to use the shift keys .

var hMainWnd=AkelPad.GetMainWnd();
var hWndEdit = AkelPad.GetEditWnd();
var oSys = AkelPad.SystemFunction();
var uSettings = 0;
var limit = 0;
var aNamber;
var aReport = "";
var rKey = 0;
var pKey = 0;
var usPause = 0;

if (hMainWnd && hWndEdit)
{
  if(WScript.Arguments.length > 0)
     uSettings = WScript.Arguments(0);
  if(WScript.Arguments.length > 1)
     limit = WScript.Arguments(1);
  if(WScript.Arguments.length > 2)
     usPause = WScript.Arguments(2);
  WScript.Sleep(usPause);
  if (!(uSettings&16))
     {
      pKey = oSys.Call("user32::GetAsyncKeyState", 161/*VK_RSHIFT*/);
      rKey = oSys.Call("user32::GetAsyncKeyState", 160/*VK_LSHIFT*/);
     }
  if ((uSettings&8) || (pKey<0))
    {
     var cpResult = AkelPad.InputBox(hMainWnd, "UndoMax.js", GetLangString(0) + (uSettings&3) + " " + limit + ")", "")
     if (cpResult)
        {
         var arrResult = cpResult.split(' ');
         if (arrResult[0])   uSettings = ((uSettings&4) | arrResult[0]);
         if (arrResult[1])   limit = arrResult[1];
         else limit = 0;
        }
     else if (cpResult === undefined)
         WScript.Quit();
    }
  if (limit == 0) limit = Number.MAX_VALUE;
  aNamber = (uSettings&2)?uniRedo(limit):uniUndo((uSettings&1), limit);
  if ((uSettings&4) || (rKey<0))
    {
     aReport += (uSettings&2)?"Redo":"Undo";
     aReport += GetLangString(1) + aNamber;
     AkelPad.MessageBox(hMainWnd, aReport, "UndoMax.js", 64 /*MB_OK, MB_ICONINFORMATION*/);
    }
}

function uniUndo(mod, lim)
{
  var n = 0;
  if (((!(mod&1)) && AkelPad.SendMessage(hWndEdit, 3075 /*AEM_CANUNDO*/, 0, 0)) || (AkelPad.SendMessage(hWndEdit, 3086 /*AEM_GETMODIFY*/, 0, 0) && (mod&1)))
  {
    SetRedraw(hWndEdit, false);
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, true);
    while (AkelPad.SendMessage(hWndEdit, 3075 /*AEM_CANUNDO*/, 0, 0))
    {
      if ( (!AkelPad.SendMessage(hWndEdit, 3086 /*AEM_GETMODIFY*/, 0, 0) && (mod&1)) || (n >= lim) )
        break;
      AkelPad.SendMessage(hWndEdit, 3077 /*AEM_UNDO*/, 0, 0);
      ++n;
    }
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, false);
    SetRedraw(hWndEdit, true);
  }
  return n;
}

function uniRedo(lim)
{
  var n = 0;
  if (AkelPad.SendMessage(hWndEdit, 3076 /*AEM_CANREDO*/, 0, 0))
  {
    SetRedraw(hWndEdit, false);
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, true);
    while (AkelPad.SendMessage(hWndEdit, 3076 /*AEM_CANREDO*/, 0, 0))
    {
      if (n >= lim)
        break;
      AkelPad.SendMessage(hWndEdit, 3078 /*AEM_REDO*/, 0, 0);
      ++n;
    }
    AkelPad.SendMessage(hWndEdit, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, false);
    SetRedraw(hWndEdit, true);
  }
  return n;
}

function SetRedraw(hWnd, bRedraw)
{
   AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
   if (bRedraw) oSys.Call("user32::InvalidateRect", hWnd, 0, true);
}

function GetLangString(nStringID)
{
  var nLangID=AkelPad.GetLangId(1 /*LANGID_PRIMARY*/);
  if (nLangID == 0x19) //LANG_RUSSIAN
  {
    if (nStringID == 0)
      return "\u0412\u0432\u0435\u0434\u0438\u0442\u0435\u0020\u043D\u043E\u0432\u044B\u0435\u0020\u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B\u003A\u0020\u0053\u0020\u005B\u004C\u005D\u000D\u000A\u0053\u0020\u002D\u0020\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u0020\u0028\u0030\u0020\u002D\u0020\u0075\u006E\u0064\u006F\u003B\u0020\u0031\u0020\u002D\u0020\u0075\u006E\u0064\u006F\u0020\u0434\u043E\u0020\u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F\u003B\u0020\u0032\u0020\u002D\u0020\u0072\u0065\u0064\u006F\u0029\u000D\u000A\u004C\u0020\u002D\u0020\u043A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E\u0020\u043F\u043E\u0432\u0442\u043E\u0440\u043E\u0432\u0020\u0028\u043C\u0430\u043A\u0441\u0438\u043C\u0443\u043C\u0020\u0435\u0441\u043B\u0438\u0020\u043D\u0435\u0020\u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E\u0029\u000D\u000A\u0028\u004F\u004B\u0020\u002D\u0020\u0442\u0435\u043A\u0443\u0449\u0438\u0435\u002E\u0020\u0043\u0061\u006E\u0063\u0065\u006C\u0020\u002D\u0020\u0432\u044B\u0445\u043E\u0434\u002E\u0020\u0422\u0435\u043A\u0443\u0449\u0438\u0435\u003A\u0020";
    if (nStringID == 1)
      return "\u0020\u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u043E\u003A\u0020";
  }
  else
  {
    if (nStringID == 0)
      return "Enter new script arguments: A [N]\nA - action (0 - undo; 1 - undo last save; 2 - redo)\nN - reiteration number (maximum if not specified)\n(OK - current, Cancel - exit. Current: ";
    if (nStringID == 1)
      return " actions: ";
  }
  return "";
}
Back to top
View user's profile Send private message
Visitor7



Joined: 03 Jun 2012
Posts: 88

PostPosted: Wed Jul 04, 2012 10:03 am    Post subject: Reply with quote

Hide tabbar if one tab.

AutohideTab.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=18632#18632
// AutohideTab.js    ver.2.8    2012-07-19
// Hide tabbar if one tab.
//    Opens files in the current tab if the Alt key holded or the left mouse button pressed.
//    Can open files in the current tab by default, by pressing Alt or LMB in a new tab.
// Usage: Call ("Scripts::Main", 1, "AutohideTab.js"[, "s [p]"])
//    Second call closes the script.
//    s - settings flags, integer 0...15, default 1:
//       b0001 (1) - open files in current tab by default, in new tab if holded Alt.
//       b0010 (2) - don`t restore tabbar on exit.
//       b0100 (4) - if no tabbar on start, then show it at the bottom.
//       b1000 (8) - force tabbar on exit.
//    p - delay time of file opening in milliseconds, default 100:
//       Scripts checks on hold the left mouse button. To give you time to press it after Drag`n`Drop, pause is needed.
//       Example: Call ("Scripts::Main", 1, "AutohideTab.js", "3 120")
// Autorun (in AkelPad.ini or Registry):
//    Add following to "CmdLineBegin": /Call ("Scripts::Main", 1, "AutohideTab.js"[, "s[ p]"])
//
// Скрывает панель вкладок если вкладка одна.
//    Открывает файл в текущей вкладке если удержана клавиша Alt или нажата левая кнопка мыши.
//    Может по умолчанию открывать файлы в текущей вкладке, а по Alt или LMB - в новой.
// Запуск: Call("Scripts::Main", 1, "AutohideTab.js"[, "s[ p]"])
//    Повторный вызов закрывает скрипт.
//    s - флаги установок, целое от 0 до 15, по умолчанию 1:
//       b0001  (1)  -  открывать файлы в текущей вкладке по умолчанию, а если удержана Alt - в новой.
//       b0010  (2)  -  не возвращать состояние строки вкладок при выходе из программы.
//       b0100  (4)  -  если строка вкладок отсутствует в момент запуска скрипта, то показывать ее внизу.
//       b1000  (8)  -  принудительно включать строку вкладок при выходе из программы.
//    p - время задержки открытия файла в миллисекундах, по умолчанию 100:
//       Cкрипт проверяет на удержание левую клавишу мыши, но чтобы вы успели ее нажать после
//       Drag`n`Drop, нужна пауза.
//       Например: Call("Scripts::Main", 1, "AutohideTab.js", "3 120")
// Автозапуск(в AkelPad.ini или реестре):
//    Добавить в строку "CmdLineBegin" следующее: /Call("Scripts::Main", 1, "AutohideTab.js"[, "s[ p]"])

var hMainWnd = AkelPad.GetMainWnd();
var oSys=AkelPad.SystemFunction();
var pClassName="AkelPad::Scripts::" + WScript.ScriptName + "::" + oSys.Call("kernel32::GetCurrentProcessId");
var hInstanceDLL = AkelPad.GetInstanceDll();
var hWnd;
var options = 1;
var pauseOpen = 100;
var tabState;
var tabBottom = false;
var keyAlt;
var mouseLB;
var framesMany;
var framesManyPrev = 2;

if (hMainWnd && AkelPad.IsMDI())
{
   if (AkelPad.WindowRegisterClass(pClassName))
   {
      hWnd = oSys.Call("user32::CreateWindowEx" + _TCHAR, 0, pClassName, 0, 0x80000000/*WS_POPUP*/, 0,0,0,0, hMainWnd, 0, hInstanceDLL, WindowCallback);
      if (hWnd)
      {
         if (AkelPad.WindowSubClass(hMainWnd, AkelPadCallBack,/*AKDN_*/ 1036 /*EDIT_ONFINISH*/, 1035 /*EDIT_ONSTART*/, 1077 /*OPENDOCUMENT_START*/))
         {
             AkelPad.ScriptNoMutex();
             AkelPad.WindowGetMessage();
             AkelPad.WindowUnsubClass(hMainWnd);
         }
         else
            AkelPad.SendMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
      }
      AkelPad.WindowUnregisterClass(pClassName);
   }
   else if (hWnd = oSys.Call("user32::FindWindowEx" + _TCHAR, 0, 0, pClassName, 0))
      AkelPad.SendMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
}

function AkelPadCallBack(hwnd,umsg,wparam,lparam)
{
   if (umsg == 1077 /*AKDN_OPENDOCUMENT_START*/)
   {
      keyAlt = oSys.Call("user32::GetAsyncKeyState", 18 /*VK_MENU*/);
      WScript.Sleep(pauseOpen);
      mouseLB = oSys.Call("user32::GetAsyncKeyState", 1 /*VK_LBUTTON*/);
      if ( (((keyAlt < 0) || (mouseLB < 0)) && (!(options & 1))) || (((keyAlt >= 0) && (mouseLB >= 0)) && (options & 1)) )
          AkelPad.Command(4324 /*IDM_WINDOW_FILECLOSE*/);
   }
   else if (umsg == 1035 /*AKDN_EDIT_ONSTART*/)
      OneTabHide(1);
   else if (umsg == 1036 /*AKDN_EDIT_ONFINISH*/)
      OneTabHide(0);
   return 0;
}

function WindowCallback(hwnd, umsg, wparam,lparam)
{
   if (umsg == 1 /*WM_CREATE*/)
   {
      options = GetArg(0, options, 0, 15);
      pauseOpen = GetArg(1, pauseOpen, 0);
      tabState = AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 157 /*MI_TABoptionsMDI*/, 0);
      if ( (tabState & 4) || ((options & 4)&&(tabState & 1)) )
         tabBottom = true;
      OneTabHide(0);
   }
   else if (umsg == 16 /*WM_CLOSE*/)
   {
      if (((options&8) && (tabBottom)) || ((!(options&2)) && (tabState&4)))
         AkelPad.Command(4302 /*IDM_WINDOW_TABVIEW_BOTTOM*/);
      else if ((!(options&2)) && (tabState&1) && (!(options&8)))
         AkelPad.Command(4303 /*IDM_WINDOW_TABVIEW_NONE*/);
      else if ((!(options&2)) || (options&8))
         AkelPad.Command(4301 /*IDM_WINDOW_TABVIEW_TOP*/);
      oSys.Call("user32::DestroyWindow", hwnd);
   }
   else if (umsg == 2 /*WM_DESTROY*/)
      oSys.Call("user32::PostQuitMessage", 0);
   return 0;
}

function OneTabHide(shift)
{
   framesMany = ((AkelPad.SendMessage(hMainWnd, 1291 /*AKD_FRAMESTATS*/, 0 /*FWS_COUNTALL*/, 0) + shift) > 1)?true:false;
   if (framesMany != framesManyPrev)
   {
      framesManyPrev = framesMany;
      if (framesMany)
      {
         if (tabBottom)    AkelPad.Command(4302 /*IDM_WINDOW_TABVIEW_BOTTOM*/);
         else        AkelPad.Command(4301 /*IDM_WINDOW_TABVIEW_TOP*/);
      }
      else      AkelPad.Command(4303 /*IDM_WINDOW_TABVIEW_NONE*/);
   }
}

function GetArg(aNum, aDef, aFrom, aTo)
{
   if (WScript.Arguments.length > aNum)
   {
      var aValue = +WScript.Arguments(aNum);
      if ((Math.floor(aValue) == aValue) && (aValue >= aFrom) && ((aTo === undefined) || (aValue <= aTo)))
         return aValue;
   }
   return aDef;
}
Back to top
View user's profile Send private message
F. Phoenix



Joined: 24 Dec 2011
Posts: 124

PostPosted: Sat Aug 18, 2012 10:12 am    Post subject: Reply with quote

Remaked Vlad's SpacesToTabs script: now it converts only leading spaces and takes more options.

IndentsToTabs.js
Code:

/* [Ru] Скрипт для преобразования пробелов в начале строки в табуляцию.
// Параметры:
//    /w — переопределить число пробелов в 1 табуляции (формат: /w=число)
//    /s — не подтверждать количество пробелов (по умолчанию перед заменой вылезает диалог)
//    /r — обработка лишних пробелов: /r- — удаление, /r+ — замена на табуляцию (по умолчанию скрипт их не трогает)
*/
/* [En] Convert leading spaces to tabulation.
// Arguments:
//    /w — set tab width (default is AkelPad's settings; format: /w=number)
//    /s — don't show input box before process
//    /r — residual spaces: /r- — remove, /r+ — make tab (default is ignore)
*/
// Version: F.Phoenix, 2012-08-18a (based on VladSh's SpacesToTabs 2.0)
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=19164#19164

var CAPTION_AP = "AkelPad -> " + WScript.ScriptName;
var hWndEdit = AkelPad.GetEditWnd();
if (hWndEdit)
{
   // Getting selected text
   var bTextSelected = true;
   var pSelText = AkelPad.GetSelText();
   if (!pSelText)
   {
      pSelText = AkelPad.GetTextRange(0, -1);
      bTextSelected = false;
   }
   if (!pSelText) WScript.Quit();
   
   // Settings
   var nOptWidth = 0, bOptSilent = false, nOptResidual = 0;
   for (var i = 0; i < WScript.Arguments.length; i++)
   {
      var arg = WScript.Arguments(i);
      if (arg == "/s") bOptSilent = true;
      else if (arg.search(/^\/w=\d+$/) != -1) nOptWidth = arg.substr(3);
      else if (arg.search(/^\/r[\+\-]$/) != -1) nOptResidual = arg.substr(2) + 1;
   }
   var nTabStop = (nOptWidth > 0 ? nOptWidth : AkelPad.SendMessage(hWndEdit, 3239 /*AEM_GETTABSTOP*/ , 0, 0));
   if (!bOptSilent)
   {
      var bRu = (AkelPad.GetLangId(1 /*LANGID_PRIMARY*/) == 0x19);
      nTabStop = AkelPad.InputBox(hWndEdit, CAPTION_AP, (bRu ? "Введите количество пробелов в одном символе табуляции"
                                                             : "Enter the number of spaces in one tab character"), nTabStop);
      if (isNaN(nTabStop)) //not isNumber
      {
         if (nTabStop) AkelPad.MessageBox(hWndEdit, (bRu ? "Введено нечисловое значение, операция отменена..."
                                                         : "Non-numeric value entered, the operation is canceled..."),
                                          CAPTION_AP, 48 /*MB_ICONEXCLAMATION*/ ); //press Cancel
         WScript.Quit();
      }
   }
   
   // Changing text (common part)
   pSelText = pSelText.replace(/^\s+/mg, Replacer);
   if(!bTextSelected) AkelPad.SetSel(0, -1);
   AkelPad.ReplaceSel(pSelText);
}

function Replacer(str)
{
   var nMin = (nOptResidual == 0 ? nTabStop : 1);
   for (var nSpaceCount = nTabStop; nSpaceCount >= nMin; nSpaceCount--)
   {
      var rxSpaces = new RegExp(' {' + nSpaceCount + '}', "g");
      str = str.replace(rxSpaces, (nSpaceCount == nTabStop || nOptResidual == "+1" ? "\t" : ""));
   }
   return str;
}


(Download)
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1598

PostPosted: Mon Sep 17, 2012 9:18 am    Post subject: Reply with quote

forgetAboutTab.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=19810#19810
// http://infocatcher.ucoz.net/js/akelpad_scripts/forgetAboutTab.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/forgetAboutTab.js

// (c) Infocatcher 2012, 2014
// version 0.1.0.1 - 2014-04-20

// Close current tab and remove information about it from recent files

// Dependencies:
//   DeleteRecentFile.js
//   http://akelpad.sourceforge.net/forum/viewtopic.php?p=10810#10810

// Arguments:
//   -file='%f'     - file to forget (or don't specify to use current)
//   -confirm=true  - show confirmation dialog

// Usage in ContextMenu plugin:
//   -"Forget about this tab" Call("Scripts::Main", 1, "forgetAboutTab.js") Icon("%a\AkelFiles\Plugs\RecentFiles.dll", 5)
//   -"Забыть об этой вкладке" Call("Scripts::Main", 1, "forgetAboutTab.js") Icon("%a\AkelFiles\Plugs\RecentFiles.dll", 5)

var file = AkelPad.GetArgValue("file", "") || AkelPad.GetEditFile(0);
var ask  = AkelPad.GetArgValue("confirm", true);
if(file && (!ask || confirm())) {
   WScript.Sleep(50);
   AkelPad.Command(4318 /*IDM_WINDOW_FRAMECLOSE*/);
   //WScript.Sleep(50);
   AkelPad.Call("Scripts::Main", 1, "DeleteRecentFile.js", file);
}

function confirm() {
   return AkelPad.MessageBox(
      AkelPad.GetMainWnd(),
      getConfirmText(),
      WScript.ScriptName,
      33 /*MB_OKCANCEL|MB_ICONQUESTION*/
   ) == 1 /*IDOK*/;
}
function getConfirmText() {
   switch(AkelPad.GetLangId(1 /*LANGID_PRIMARY*/)) {
      case 0x19: /*ru*/ return "Забыть об этой вкладке?";
      default:   /*en*/ return "Forget about this tab?";
   }
}
<download | mirror | development version>
Close current tab and remove information about it from recent files.
Dependencies: DeleteRecentFile.js


Last edited by Infocatcher on Sun Apr 20, 2014 5:20 pm; edited 2 times in total
Back to top
View user's profile Send private message
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5293

PostPosted: Tue Sep 18, 2012 6:06 pm    Post subject: Reply with quote

Draw tables with pseudographic symbols. Screenshot



DrawLine.js

Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=19835#19835
// Version v1.2
//
//
//// Draw tables with pseudographic symbols.
//// Lines are drawn with Arrow + Shift/Ctrl/Alt key.
//// Second script call will turn off drawing.
//
// Arguments:
// -DoubleLine=true  -Draw with double line (default is false).
// -Shift=true       -Lines are drawn with Arrow + Shift key (default is true).
// -Ctrl=true        -Lines are drawn with Arrow + Ctrl key (default is false).
// -Alt=true         -Lines are drawn with Arrow + Alt key (default is false).
//
// Examples:
// -"Draw lines" Call("Scripts::Main", 1, "DrawLine.js", `-DoubleLine=true -Shift=false -Ctrl=true`)


//Arguments
var bDoubleLine=AkelPad.GetArgValue("DoubleLine", false);
var bShift=AkelPad.GetArgValue("Shift", true);
var bCtrl=AkelPad.GetArgValue("Ctrl", false);
var bAlt=AkelPad.GetArgValue("Alt", false);

//Variables
var hMainWnd=AkelPad.GetMainWnd();
var oSys=AkelPad.SystemFunction();
var hSubClass;
var hScript;
var lpCaretIndex;
var lpLeftIndex;
var lpUpIndex;
var lpRightIndex;
var lpDownIndex;
var nCaretChar;
var nCharInLine;
var nLeftChar;
var nRightChar;
var nUpChar;
var nDownChar;
var nInsertChar;
var dwOptions;
var dwExOptions;
var bMove;
var bInit;
var lpCharsConnect;
var lpLeftConnect;
var lpUpConnect;
var lpRightConnect;
var lpDownConnect;

if (!bShift && !bCtrl && !bAlt)
{
  AkelPad.MessageBox(hMainWnd, GetLangString(0), WScript.ScriptName, 48 /*MB_ICONEXCLAMATION*/);
  WScript.Quit();
}

if (bDoubleLine)
{
  lpCharsConnect=[9574, 9552, 9559, 9580, 9571, 9577, 9565, 9568, 9553, 9562, 9556];
  lpLeftConnect=[9574, 9552, 9559, 9580, 9571, 9577, 9565];
  lpUpConnect=[9568, 9580, 9571, 9553, 9562, 9577, 9565];
  lpRightConnect=[9556, 9552, 9574, 9568, 9580, 9562, 9577];
  lpDownConnect=[9556, 9574, 9559, 9553, 9568, 9580, 9571];
}
else
{
  lpCharsConnect=[9516, 9472, 9488, 9532, 9508, 9524, 9496, 9500, 9474, 9492, 9484];
  lpLeftConnect=[9516, 9472, 9488, 9532, 9508, 9524, 9496];
  lpUpConnect=[9500, 9532, 9508, 9474, 9492, 9524, 9496];
  lpRightConnect=[9484, 9472, 9516, 9500, 9532, 9492, 9524];
  lpDownConnect=[9484, 9516, 9488, 9474, 9500, 9532, 9508];
}

if ((hScript=AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/)) && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
{
  //Script is running, second call close it.
  AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
}
else
{
  lpCaretIndex=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/);
  lpLeftIndex=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/);
  lpUpIndex=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/);
  lpRightIndex=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/);
  lpDownIndex=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/);

  if (hSubClass=AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 256 /*WM_KEYDOWN*/))
  {
    //Allow other scripts running.
    AkelPad.ScriptNoMutex();

    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }
  AkelPad.MemFree(lpCaretIndex);
  AkelPad.MemFree(lpLeftIndex);
  AkelPad.MemFree(lpUpIndex);
  AkelPad.MemFree(lpRightIndex);
  AkelPad.MemFree(lpDownIndex);
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 256 /*WM_KEYDOWN*/)
  {
    if (wParam == 0x25 /*VK_LEFT*/ ||
        wParam == 0x26 /*VK_UP*/ ||
        wParam == 0x27 /*VK_RIGHT*/ ||
        wParam == 0x28 /*VK_DOWN*/)
    {
      if ((!bShift || (oSys.Call("user32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000)) &&
          (!bCtrl || (oSys.Call("user32::GetKeyState", 0x11 /*VK_CONTROL*/) & 0x8000)) &&
          (!bAlt || (oSys.Call("user32::GetKeyState", 0x12 /*VK_MENU*/) & 0x8000)))
      {
        dwExOptions=AkelPad.SendMessage(hWnd, 3233 /*AEM_EXGETOPTIONS*/, 0, 0)
        if (!(dwExOptions & 0x4 /*AECOE_OVERTYPE*/))
        {
          AkelPad.SendMessage(hWnd, 3379 /*AEM_LOCKUPDATE*/, 0x2 /*AELU_CARET*/, 1);
          AkelPad.SendMessage(hWnd, 3234 /*AEM_EXSETOPTIONS*/, 2 /*AECOOP_OR*/, 0x4 /*AECOE_OVERTYPE*/);
        }
        dwOptions=AkelPad.SendMessage(hWnd, 3227 /*AEM_GETOPTIONS*/, 0, 0);
        if (!(dwOptions & 0x200 /*AECO_CARETOUTEDGE*/))
          AkelPad.SendMessage(hWnd, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x200 /*AECO_CARETOUTEDGE*/);
        bInit=true;

        for (;;)
        {
          nLeftChar=0;
          nRightChar=0;
          nUpChar=0;
          nDownChar=0;
          bMove=false;

          AkelPad.SendMessage(hWnd, 3130 /*AEM_GETINDEX*/, 5 /*AEGI_CARETCHAR*/, lpCaretIndex);
          nCaretChar=AkelPad.SendMessage(hWnd, 3046 /*AEM_CHARAT*/, lpCaretIndex, 0);
          nCharInLine=AkelPad.MemRead(lpCaretIndex + (_X64?16:8) /*offsetof(AECHARINDEX, nCharInLine)*/, 3 /*DT_DWORD*/);

          oSys.Call("kernel32::RtlMoveMemory", lpLeftIndex, lpCaretIndex, _X64?24:12 /*sizeof(AECHARINDEX)*/);
          if (AkelPad.SendMessage(hWnd, 3130 /*AEM_GETINDEX*/, 21 /*AEGI_PREVCHARINLINE*/, lpLeftIndex))
            nLeftChar=AkelPad.SendMessage(hWnd, 3046 /*AEM_CHARAT*/, lpLeftIndex, 0);

          oSys.Call("kernel32::RtlMoveMemory", lpRightIndex, lpCaretIndex, _X64?24:12 /*sizeof(AECHARINDEX)*/);
          if (AkelPad.SendMessage(hWnd, 3130 /*AEM_GETINDEX*/, 20 /*AEGI_NEXTCHARINLINE*/, lpRightIndex))
            nRightChar=AkelPad.SendMessage(hWnd, 3046 /*AEM_CHARAT*/, lpRightIndex, 0);

          oSys.Call("kernel32::RtlMoveMemory", lpUpIndex, lpCaretIndex, _X64?24:12 /*sizeof(AECHARINDEX)*/);
          if (AkelPad.SendMessage(hWnd, 3130 /*AEM_GETINDEX*/, 25 /*AEGI_PREVLINE*/, lpUpIndex))
          {
            AkelPad.MemCopy(lpUpIndex + (_X64?16:8) /*offsetof(AECHARINDEX, nCharInLine)*/, nCharInLine, 3 /*DT_DWORD*/);
            nUpChar=AkelPad.SendMessage(hWnd, 3046 /*AEM_CHARAT*/, lpUpIndex, 0);
          }

          oSys.Call("kernel32::RtlMoveMemory", lpDownIndex, lpCaretIndex, _X64?24:12 /*sizeof(AECHARINDEX)*/);
          if (AkelPad.SendMessage(hWnd, 3130 /*AEM_GETINDEX*/, 24 /*AEGI_NEXTLINE*/, lpDownIndex))
          {
            AkelPad.MemCopy(lpDownIndex + (_X64?16:8) /*offsetof(AECHARINDEX, nCharInLine)*/, nCharInLine, 3 /*DT_DWORD*/);
            nDownChar=AkelPad.SendMessage(hWnd, 3046 /*AEM_CHARAT*/, lpDownIndex, 0);
          }

          if (wParam == 0x25 /*VK_LEFT*/)
          {
            if (InArray(nDownChar, lpUpConnect) && InArray(nUpChar, lpDownConnect) && InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[3];
            else if (InArray(nDownChar, lpUpConnect) && InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[0];
            else if (InArray(nUpChar, lpDownConnect) && InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[5];
            else if (InArray(nDownChar, lpUpConnect) && InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[4];
            else if (InArray(nDownChar, lpUpConnect))
              nInsertChar=lpCharsConnect[2];
            else if (InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[6];
            else
              nInsertChar=lpCharsConnect[1];
            if (nCaretChar == nInsertChar)
            {
              if (bInit)
              {
                nInsertChar=lpCharsConnect[1];
                bMove=true;
              }
              else break;
            }
            if (bMove) AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x25 /*VK_LEFT*/, 0);
            AkelPad.SendMessage(hWnd, 3045 /*AEM_INSERTCHAR*/, nInsertChar, 0);
            AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x25 /*VK_LEFT*/, 0);
          }
          else if (wParam == 0x26 /*VK_UP*/)
          {
            if (InArray(nLeftChar, lpRightConnect) && InArray(nRightChar, lpLeftConnect) && InArray(nDownChar, lpUpConnect))
              nInsertChar=lpCharsConnect[3];
            else if (InArray(nLeftChar, lpRightConnect) && InArray(nDownChar, lpUpConnect))
              nInsertChar=lpCharsConnect[4];
            else if (InArray(nRightChar, lpLeftConnect) && InArray(nDownChar, lpUpConnect))
              nInsertChar=lpCharsConnect[7];
            else if (InArray(nLeftChar, lpRightConnect) && InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[5];
            else if (InArray(nLeftChar, lpRightConnect))
              nInsertChar=lpCharsConnect[6];
            else if (InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[9];
            else
              nInsertChar=lpCharsConnect[8];
            if (nCaretChar == nInsertChar)
            {
              if (bInit)
              {
                nInsertChar=lpCharsConnect[8];
                bMove=true;
              }
              else break;
            }
            if (bMove) AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x26 /*VK_UP*/, 0);
            AkelPad.SendMessage(hWnd, 3045 /*AEM_INSERTCHAR*/, nInsertChar, 0);
            AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x25 /*VK_LEFT*/, 0);
          }
          else if (wParam == 0x27 /*VK_RIGHT*/)
          {
            if (InArray(nDownChar, lpUpConnect) && InArray(nUpChar, lpDownConnect) && InArray(nLeftChar, lpRightConnect))
              nInsertChar=lpCharsConnect[3];
            else if (InArray(nDownChar, lpUpConnect) && InArray(nLeftChar, lpRightConnect))
              nInsertChar=lpCharsConnect[0];
            else if (InArray(nUpChar, lpDownConnect) && InArray(nLeftChar, lpRightConnect))
              nInsertChar=lpCharsConnect[5];
            else if (InArray(nDownChar, lpUpConnect) && InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[7];
            else if (InArray(nDownChar, lpUpConnect))
              nInsertChar=lpCharsConnect[10];
            else if (InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[9];
            else
              nInsertChar=lpCharsConnect[1];

            if (nCaretChar == nInsertChar)
            {
              if (bInit)
              {
                nInsertChar=lpCharsConnect[1];
                bMove=true;
              }
              else break;
            }
            if (bMove) AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x27 /*VK_RIGHT*/, 0);
            AkelPad.SendMessage(hWnd, 3045 /*AEM_INSERTCHAR*/, nInsertChar, 0);
            AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x25 /*VK_LEFT*/, 0);
          }
          else if (wParam == 0x28 /*VK_DOWN*/)
          {
            if (InArray(nLeftChar, lpRightConnect) && InArray(nRightChar, lpLeftConnect) && InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[3];
            else if (InArray(nLeftChar, lpRightConnect) && InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[4];
            else if (InArray(nRightChar, lpLeftConnect) && InArray(nUpChar, lpDownConnect))
              nInsertChar=lpCharsConnect[7];
            else if (InArray(nLeftChar, lpRightConnect) && InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[0];
            else if (InArray(nLeftChar, lpRightConnect))
              nInsertChar=lpCharsConnect[2];
            else if (InArray(nRightChar, lpLeftConnect))
              nInsertChar=lpCharsConnect[10];
            else
              nInsertChar=lpCharsConnect[8];
            if (nCaretChar == nInsertChar)
            {
              if (bInit)
              {
                nInsertChar=lpCharsConnect[8];
                bMove=true;
              }
              else break;
            }
            if (bMove)
            {
              if (!nDownChar) AppendText("\n");
              AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x28 /*VK_DOWN*/, 0);
            }
            AkelPad.SendMessage(hWnd, 3045 /*AEM_INSERTCHAR*/, nInsertChar, 0);
            AkelPad.SendMessage(hWnd, 3044 /*AEM_KEYDOWN*/, 0x25 /*VK_LEFT*/, 0);
          }
          if (bInit && bMove)
            bInit=false;
          else
            break;
        }
        if (!(dwOptions & 0x200 /*AECO_CARETOUTEDGE*/))
          AkelPad.SendMessage(hWnd, 3228 /*AEM_SETOPTIONS*/, 4 /*AECOOP_XOR*/, 0x200 /*AECO_CARETOUTEDGE*/);
        if (!(dwExOptions & 0x4 /*AECOE_OVERTYPE*/))
        {
          AkelPad.SendMessage(hWnd, 3234 /*AEM_EXSETOPTIONS*/, 4 /*AECOOP_XOR*/, 0x4 /*AECOE_OVERTYPE*/);
          AkelPad.SendMessage(hWnd, 3379 /*AEM_LOCKUPDATE*/, 0x2 /*AELU_CARET*/, false);
          AkelPad.SendMessage(hWnd, 3377 /*AEM_UPDATECARET*/, 0, 0);
        }
        AkelPad.WindowNoNextProc(hSubClass);
        return 0;
      }
    }
  }
}

function InArray(nItem, lpArray)
{
  var i;

  for (i=0; i < lpArray.length; ++i)
  {
    if (lpArray[i] == nItem)
      return true;
  }
  return false;
}

function AppendText(pText)
{
  var lpAppend;

  if (lpAppend=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AEAPPENDTEXTW)*/))
  {
    AkelPad.MemCopy(lpAppend /*offsetof(AEAPPENDTEXTW, pText)*/, AkelPad.MemStrPtr(pText), 2 /*DT_QWORD*/);
    AkelPad.MemCopy(lpAppend + (_X64?8:4) /*offsetof(AEAPPENDTEXTW, dwTextLen)*/, pText.length, 2 /*DT_QWORD*/);
    AkelPad.MemCopy(lpAppend + (_X64?16:8) /*offsetof(AEAPPENDTEXTW, nNewLine)*/, 1 /*AELB_ASINPUT*/, 3 /*DT_DWORD*/);
    AkelPad.SendMessage(AkelPad.GetEditWnd(), 3028 /*AEM_APPENDTEXTW*/, 0, lpAppend);
    AkelPad.MemFree(lpAppend);
  }
}

function SetRedraw(hWnd, bRedraw)
{
  AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
  if (bRedraw) oSys.Call("user32::InvalidateRect", hWnd, 0, true);
}

function GetLangString(nStringID)
{
  var nLangID=AkelPad.GetLangId(1 /*LANGID_PRIMARY*/);

  if (nLangID == 0x19) //LANG_RUSSIAN
  {
    if (nStringID == 0)
      return "\x0425\x043E\x0442\x044F\x0020\x0431\x044B\x0020\x043E\x0434\x0438\x043D\x0020\x0438\x0437\x0020\x043C\x043E\x0434\x0438\x0444\x0438\x043A\x0430\x0442\x043E\x0440\x043E\x0432 Ctrl, Shift, Alt \x0434\x043E\x043B\x0436\x0435\x043D\x0020\x0431\x044B\x0442\x044C\x0020\x0432\x043A\x043B\x044E\x0447\x0435\x043D\x002E";
  }
  else
  {
    if (nStringID == 0)
      return "At least one of the modifiers Ctrl, Shift, Alt must be enabled.";
  }
  return "";
}



Last edited by Instructor on Wed Feb 19, 2014 11:49 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
VladSh



Joined: 29 Nov 2006
Posts: 2602
Location: Киев, Русь

PostPosted: Fri Oct 19, 2012 10:36 pm    Post subject: Reply with quote

Отчёты писал и пришлось подсчитывать количество доков в xml, родился маленький, но полезный скриптец по подсчёту суммы чисел в выделенном тексте:

SumNumbers.js

Code:
/// The sum of all the numbers contained in the selected text
//  Сумма всех чисел, содержащихся в выделенном тексте
//  http://akelpad.sourceforge.net/forum/viewtopic.php?p=20177#20177
//  Version: 1.1 (2012.10.20)
// 
//  Examples:
//  -"По всему тексту" Call("Scripts::Main", 1, "SumNumbers.js")
//  -"Только между xml-тэгами" Call("Scripts::Main", 1, "SumNumbers.js", `-qStart="<" -qEnd=">"`)

var str = AkelPad.GetSelText();
if (str) {
   if (WScript.Arguments.length == 2) {
      var qStart = AkelPad.GetArgValue("qStart", "");
      var qEnd = AkelPad.GetArgValue("qEnd", "");
      str = str.replace(new RegExp("[^" + qStart + qEnd + "]*[" + qEnd + "]", "g"), "");
   }
   
   var arr = str.match(/\d+/g);
   if (arr) {
      var sResult = arr[0];
      var nResult = parseInt(sResult);
      for (i = 1; i < arr.length; i++) {
         sResult += " + " + arr[i];
         nResult += parseInt(arr[i]);
      }
      AkelPad.Call("Log::Output", 5, sResult + " = " + nResult + "\n", -1, 1);
   }
}
Back to top
View user's profile Send private message Visit poster's website
DV



Joined: 16 Nov 2006
Posts: 830
Location: Kyiv, Ukraine

PostPosted: Sat Oct 20, 2012 4:56 pm    Post subject: Reply with quote

KeySubst.js
Code:
/*****************************************************************************
 *  KeySubst.js  v.0.9                                                       *
 *  (C) DV, May-June 2011, Oct 2012                                          *
 *  Thanks to: Instructor, FeyFre                                            *
 *****************************************************************************/
/*  Examples:
     -"En->Ru,Ru->En" Call("Scripts::Main", 1, "KeySubst.js", `-to=rus,eng`)
     -"En->Uk,Uk->En" Call("Scripts::Main", 1, "KeySubst.js", `-to=ukr,eng`)
     -"En->Ru,Uk->Ru" Call("Scripts::Main", 1, "KeySubst.js", `-to=rus,rus`)
     -"En->Uk,Ru->Uk" Call("Scripts::Main", 1, "KeySubst.js", `-to=ukr,ukr`)
     -"En->En,Uk->Ru" Call("Scripts::Main", 1, "KeySubst.js", `-to=eng,rus`)
     -"En->En,Ru->Uk" Call("Scripts::Main", 1, "KeySubst.js", `-to=eng,ukr`)
    To deactivate the script, use Ctrl+~ (VK_CONTROL+VK_OEM_3).
 *****************************************************************************/

var alph = [
 /* eng=0 */ [ "`1234567890-=\\qwertyuiop[]asdfghjkl;\'zxcvbnm,./`",
               "~!@#$%^&*()_+|QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?~",
               // special key combinations...
               "\u0055",
               "\u0055" ],
 /* rus=1 */ [ "ё1234567890-=\\йцукенгшщзхъфывапролджэячсмитьбю.ё",
               "Ё!\"№;%:?*()_+/ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,Ё",
               // special key combinations...
               "\u0055",
               "\u0055" ],
 /* ukr=2 */ [ "\'1234567890-=\\йцукенгшщзхїфівапролджєячсмитьбю.ё",
               "\'!\"№;%:?*()_+/ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,Ё",
               // special key combinations...
               "ґ",
               "Ґ" ]
]; // Note: trailing 'ё' is needed for Ukrainian because of ` to ' hack.

var eng = 0;
var rus = 1;
var ukr = 2;

var default_langTo1 = rus; // rus: En->Ru
var default_langTo2 = eng; // eng: Ru->En,Uk->En
var langTo1 = -1;
var langTo2 = -1;
var argLangTo = getScriptArg("-to").toLowerCase().split(",");
if (argLangTo.length > 0)
{
  langTo1 = getLang(argLangTo[0]);
  if (argLangTo.length > 1)
  {
    langTo2 = getLang(argLangTo[1]);
  }
}
var hWndMain = AkelPad.GetMainWnd();
var hWndEdit = AkelPad.GetEditWnd();
var oSys = AkelPad.SystemFunction();

AkelPad.ScriptNoMutex();

var mutexName = "KeySubst_js_" + hWndMain;
var hMutex;
if (hMutex = oSys.Call("kernel32::CreateMutex" + _TCHAR, 0, 1, mutexName))
{
  if (oSys.GetLastError() == 183 /*ERROR_ALREADY_EXISTS*/)
  {
    oSys.Call("kernel32::CloseHandle", hMutex);
    oSys.Call("user32::SendMessage" + _TCHAR, hWndEdit, 0x0100 /*WM_KEYDOWN*/, 0xC0, 0);
    WScript.Quit();
  }
}

var hEditSubClass;
if (hEditSubClass = AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback))
{
  //Message loop
  AkelPad.WindowGetMessage();

  AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  oSys.Call("kernel32::CloseHandle", hMutex);
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 0x0102 /*WM_CHAR*/)
  {
    var ch = convertSymbolCode(hWnd, wParam, 0);
    if (ch != 0)
    {
      AkelPad.WindowNextProc(hEditSubClass, hWnd, uMsg, ch, lParam);
      AkelPad.SendMessage(hWnd, 3377 /*AEM_UPDATECARET*/, 0, 0);
      AkelPad.WindowNoNextProc(hEditSubClass);
      return 1; // processed
    }
  }
  else if ( (uMsg == 0x0100 /*WM_KEYDOWN*/) ||
            (uMsg == 0x0104 /*WM_SYSKEYDOWN*/) )
  {
    var nCtrlState = oSys.Call("user32::GetKeyState", 0x11 /*VK_CONTROL: Ctrl*/);
    var nAltState = oSys.Call("user32::GetKeyState", 0x12 /*VK_MENU: Alt*/)
    var nAltGrState = oSys.Call("user32::GetKeyState", 0xA5 /*VK_RMENU: AltGr*/)

    if (wParam == 0xC0 /*VK_OEM_3: (`~)*/)
    {
      if ((lParam == 0) || ((nCtrlState & 0x80) && !(nAltState & 0x80)))
      {
        //Exit message loop
        oSys.Call("user32::PostQuitMessage", 0);
        return 1; // processed
      }
    }

    var nSet = 0;
    if (((nCtrlState & 0x80) && (nAltState & 0x80)) ||
        (nAltGrState & 0x80))
    {
      nSet = 1;
    }
    // check special key combinations...
    if (nSet != 0)
    {
      var ch = convertSymbolCode(hWnd, wParam, nSet);
      if (ch != 0)
      {
        oSys.Call("user32::PostMessage" + _TCHAR, hWnd, 0x0102 /*WM_CHAR*/, ch, lParam);
        return 1; // processed
      }
    }
  }
  return 0;
}

function convertSymbolCode(hWnd, wParam, nSet)
{
  var nLangId = getEditLangId(hWnd);
  var nLangFrom = eng;
  var nLangTo = (langTo1 == -1) ? default_langTo1 : langTo1;
  if (nLangId == 1049) /* rus */
  {
    nLangFrom = rus;
    nLangTo = (langTo2 == -1) ? default_langTo2 : langTo2;
  }
  else if (nLangId == 1058) /* ukr */
  {
    nLangFrom = ukr;
    nLangTo = (langTo2 == -1) ? default_langTo2 : langTo2;
  }

  if (nLangTo != nLangFrom)
  {
    if (nSet == 0)
    {
      // characters
      var nCase = 0;
      var ch = String.fromCharCode(wParam);
      var i = alph[nLangFrom][nCase].indexOf(ch);
      if (i < 0)
      {
        nCase = 1;
        i = alph[nLangFrom][nCase].indexOf(ch);
      }
      if (i >= 0)
      {
        if (i < alph[nLangTo][nCase].length)
        {
          ch = alph[nLangTo][nCase].charCodeAt(i);
          return ch;
        }
      }
    }
    else
    {
      // codes
      var nShiftState = oSys.Call("user32::GetKeyState", 0x10 /*VK_SHIFT: Shift*/);
      var nCase = (nShiftState & 0x80) ? (2*nSet + 1) : (2*nSet);
      var i;
      for (i = 0; i < alph[nLangFrom][nCase].length; i++)
      {
        if (alph[nLangFrom][nCase].charCodeAt(i) == wParam)
        {
          var ch = alph[nLangTo][nCase].charCodeAt(i);
          if (ch != wParam)
            return ch;
        }
      }
    }
  }
  return 0;
}

function getEditLangId(hEdit)
{
  var nEditThreadId = oSys.Call("user32::GetWindowThreadProcessId", hEdit, 0);
  var nLang = oSys.Call("user32::GetKeyboardLayout", nEditThreadId);
  return (nLang & 0xFFFF);
}

function getLang(s)
{
  var lang = -1;
  if (s == "eng")
    lang = eng;
  else if (s == "rus")
    lang = rus;
  else if (s == "ukr")
    lang = ukr;
  return lang;
}

function getScriptArg(argName)
{
  var s = "";
  argName = argName.toLowerCase();
  for (var n = 0; n < WScript.Arguments.length; n++)
  {
    var t = WScript.Arguments(n);
    var a = t.split("=");
    if (a[0].toLowerCase() == argName)
    {
      s = a[1];
      break;
    }
  }
  return s;
}

Скрипт, который подменяет нажатые клавиши.
* Этот скрипт нужно сохранить как юникодный файл ( в кодировке UTF-16 LE или UTF-8 ) !
В представленном функционале подмена нажатых клавиш имитирует использование русской или украинской раскладки клавиатуры во время работы с английской раскладкой. И наоборот: при работе с русской раскладкой клавиатуры имитируется английская.
Подмена нажатых клавиш не зависит от установленных языков (кроме английского) и работает даже в том случае, если в системе в принципе не установлена ни русская, ни украинская раскладка клавиатуры.
Соответственно, скрипт можно дополнить для поддержки других раскладок.
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1325
Location: Poland

PostPosted: Sat Oct 27, 2012 9:59 pm    Post subject: Reply with quote

Search files by name/content and replace content - part 1.
Part 2 - in the next post.
Required to include: BrowseForFolder_function.js and FileAndStream_functions.js
All in one: KDJ.zip

FindReplaceFiles.js

Code:
// FindReplaceFiles.js - ver. 2014-07-03 (x86/x64)
//
// Search files by name/content and replace content.
//
// Usage:
// Call("Scripts::Main", 1, "FindReplaceFiles.js")
// Required to include: BrowseForFolder_function.js, FileAndStream_functions.js
//
// Keys and mouse:
// Alt+F       - focus to Files list
// Ctrl+A      - select all items on files list
// Ctrl+C      - copy selected items from files list
// Del         - remove selected items from files list (don't delete the files)
// F4          - open all selected files for editing
// DblClick    - open selected file for editing and select the found text (or close file if is currently edited)
// Ctrl+Enter
// Shift+Enter - open focused file for editing and select the found text (or close file if is currently edited)
// F1          - help for regular expressions or wildcards
// Alt+Del     - remove item from history list (Directory, Name of file, Text in file)

var oSys     = AkelPad.SystemFunction();
var hInstDLL = AkelPad.GetInstanceDll();
var sClass   = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstDLL;
var hDlg;

if (hDlg = oSys.Call("User32::FindWindowExW", 0, 0, sClass, 0))
{
  if (! oSys.Call("User32::IsWindowVisible", hDlg))
    oSys.Call("User32::ShowWindow", hDlg, 8 /*SW_SHOWNA*/);
  if (oSys.Call("User32::IsIconic", hDlg))
    oSys.Call("User32::ShowWindow", hDlg, 9 /*SW_RESTORE*/);

  oSys.Call("User32::SetForegroundWindow", hDlg);
  WScript.Quit();
}

if (! (AkelPad.Include("BrowseForFolder_function.js") && AkelPad.Include("FileAndStream_functions.js")))
  WScript.Quit();

var Scale =
{
  Init: function()
  {
    var hDC = oSys.Call("User32::GetDC", hMainWnd);
    this.ScaleX = oSys.Call("Gdi32::GetDeviceCaps", hDC, 88 /*LOGPIXELSX*/);
    this.ScaleY = oSys.Call("Gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/);
    oSys.Call("User32::ReleaseDC", hMainWnd, hDC);
    //Align to 16 pixel
    this.ScaleX += (16 - this.ScaleX % 16) % 16;
    this.ScaleY += (16 - this.ScaleY % 16) % 16;
  },
  X:  function(n) {return oSys.Call("Kernel32::MulDiv", n, this.ScaleX, 96);},
  Y:  function(n) {return oSys.Call("Kernel32::MulDiv", n, this.ScaleY, 96);},
  UX: function(n) {return oSys.Call("Kernel32::MulDiv", n, 96, this.ScaleX);},
  UY: function(n) {return oSys.Call("Kernel32::MulDiv", n, 96, this.ScaleY);}
}
Scale.Init();

var DT_UNICODE = 1;
var DT_QWORD   = 2;
var DT_DWORD   = 3;
var DT_WORD    = 4;

var hMainWnd   = AkelPad.GetMainWnd();
var nBkColorRE = 0xA0FFFF;
var hBrush     = oSys.Call("Gdi32::CreateSolidBrush", nBkColorRE);
var nMaxLenCBE = 15;
var nMaxLenCBL = 27;
var nBufSize   = 1024;
var lpBuffer   = AkelPad.MemAlloc(nBufSize);
var lpLVITEM   = AkelPad.MemAlloc(_X64 ? 72 : 60); //sizeof(LVITEM)
var hParent;
var hFocus;
var bCloseCBL;
var bCloseDlg;

AkelPad.MemCopy(lpLVITEM, 0x0001 /*LVIF_TEXT*/, DT_DWORD); //mask
AkelPad.MemCopy(lpLVITEM + (_X64 ? 24 : 20), lpBuffer, DT_QWORD); //pszText
AkelPad.MemCopy(lpLVITEM + (_X64 ? 32 : 24), nBufSize, DT_DWORD); //cchTextMax

var nWndMinW = Scale.X(480);
var nWndMinH = Scale.Y(488);
var oWndPos  = {"X": 240, "Y": 140, "W": nWndMinW, "H": nWndMinH, "Max": 0};

var bSeparateWnd    = 0;
var bKeepFiles      = 1;
var bPathShow       = 1;
var nPathLen        = 0;
var bSortDesc       = 0;
var nDirLevel       = -1;
var bNameRE         = 0;
var bNotName        = 0;
var bInFiles        = 1;
var bInStreams      = 0;
var bSkipReadOnly   = 0;
var bSkipHidden     = 0;
var bSkipSystem     = 0;
var bContentRE      = 0;
var bMatchCase      = 0;
var bMultiline      = 0;
var bNotContain     = 0;
var bSkipBinary     = 1;
var bSkipLarger     = 1;
var nMaxFileSize    = 0;
var sDir            = "";
var sName           = "";
var sContent        = "";
var sReplace        = "";
var sLastContent    = "";
var bLastContentRE  = 0;
var bLastMatchCase  = 0;
var bLastMultiline  = 0;
var bLastNotContain = 0;
var bAfterReplace   = 0;
var aDirs           = [];
var aNames          = [];
var aContents       = [];
var aReplace        = [];
var aFiles          = [];
var aFilesSel       = [0];
var nFilesFoc       = 0;

ReadIni();

var aDlg         = [];
var IDDIRG       = 2000;
var IDDIRCB      = 2001;
var IDCURRENTB   = 2002;
var IDBROWSEB    = 2003;
var IDDIRLEVELS  = 2004;
var IDDIRLEVELCB = 2005;
var IDNAMEG      = 2006;
var IDNAMECB     = 2007;
var IDHELP1B     = 2008;
var IDNAMERE     = 2009;
var IDNOTNAME    = 2010;
var IDINFILES    = 2011;
var IDINSTREAMS  = 2012;
var IDCONTENTG   = 2013;
var IDCONTENTCB  = 2014;
var IDHELP2B     = 2015;
var IDMATCHCASE  = 2016;
var IDCONTENTRE  = 2017;
var IDMULTILINE  = 2018;
var IDNOTCONTAIN = 2019;
var IDSKIPBINARY = 2020;
var IDSKIPLARGER = 2021;
var IDMAXSIZEE   = 2022;
var IDREPLACES   = 2023;
var IDREPLACECB  = 2024;
var IDHELP3B     = 2025;
var IDSKIPG      = 2026;
var IDREADONLY   = 2027;
var IDHIDDEN     = 2028;
var IDSYSTEM     = 2029;
var IDSEARCHB    = 2030;
var IDREPLACEB   = 2031;
var IDEDITB      = 2032;
var IDCOPYB      = 2033;
var IDCLEARB     = 2034;
var IDSETTINGSB  = 2035;
var IDCLOSEB     = 2036;
var IDFILELV     = 2037;
var IDSTATUS     = 2038;

//0x50000000 - WS_VISIBLE|WS_CHILD
//0x50000002 - WS_VISIBLE|WS_CHILD|SS_RIGHT
//0x50000007 - WS_VISIBLE|WS_CHILD|BS_GROUPBOX
//0x50000100 - WS_VISIBLE|WS_CHILD|SBARS_SIZEGRIP
//0x50010000 - WS_VISIBLE|WS_CHILD|WS_TABSTOP
//0x50010042 - WS_VISIBLE|WS_CHILD|WS_TABSTOP|CBS_AUTOHSCROLL|CBS_DROPDOWN
//0x50010003 - WS_VISIBLE|WS_CHILD|WS_TABSTOP|CBS_DROPDOWNLIST
//0x50010003 - WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_AUTOCHECKBOX
//0x50012002 - WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_NUMBER|ES_RIGHT
//0x50810009 - WS_VISIBLE|WS_CHILD|WS_BORDER|WS_TABSTOP|LVS_SHOWSELALWAYS|LVS_REPORT

aDlg[IDDIRG      ]={Class: "BUTTON",             Style: 0x50000007, Text: sTxtDir};
aDlg[IDDIRCB     ]={Class: "COMBOBOX",           Style: 0x50210042};
aDlg[IDCURRENTB  ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtCurrent};
aDlg[IDBROWSEB   ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtBrowse};
aDlg[IDDIRLEVELS ]={Class: "STATIC",             Style: 0x50000002, Text: sTxtSubDirs};
aDlg[IDDIRLEVELCB]={Class: "COMBOBOX",           Style: 0x50010003};
aDlg[IDNAMEG     ]={Class: "BUTTON",             Style: 0x50000007, Text: sTxtFileName};
aDlg[IDNAMECB    ]={Class: "COMBOBOX",           Style: 0x50210042, Sel1: 0, Sel2: -1};
aDlg[IDHELP1B    ]={Class: "BUTTON",             Style: 0x50010000, Text: "?"};
aDlg[IDNAMERE    ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtRegExp};
aDlg[IDNOTNAME   ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtNotName};
aDlg[IDINFILES   ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtFiles};
aDlg[IDINSTREAMS ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtStreams};
aDlg[IDCONTENTG  ]={Class: "BUTTON",             Style: 0x50000007, Text: sTxtTextInFile};
aDlg[IDCONTENTCB ]={Class: "COMBOBOX",           Style: 0x50210042, Sel1: 0, Sel2: -1};
aDlg[IDHELP2B    ]={Class: "BUTTON",             Style: 0x50010000, Text: "?"};
aDlg[IDMATCHCASE ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtMatchCase};
aDlg[IDCONTENTRE ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtRegExp};
aDlg[IDMULTILINE ]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtMultiline};
aDlg[IDNOTCONTAIN]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtNotContain};
aDlg[IDSKIPBINARY]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtSkipBinary};
aDlg[IDSKIPLARGER]={Class: "BUTTON",             Style: 0x50010003, Text: sTxtSkipLarger};
aDlg[IDMAXSIZEE  ]={Class: "EDIT",               Style: 0x50012002, ExStyle: 0x200};
aDlg[IDREPLACES  ]={Class: "STATIC",             Style: 0x50000000, Text: sTxtReplaceWith};
aDlg[IDREPLACECB ]={Class: "COMBOBOX",           Style: 0x50210042, Sel1: 0, Sel2: -1};
aDlg[IDHELP3B    ]={Class: "BUTTON",             Style: 0x50010000, Text: "?"};
aDlg[IDSKIPG     ]={Class: "BUTTON",             Style: 0x50000007, Text: sTxtSkip};
aDlg[IDREADONLY  ]={Class: "BUTTON",             Style: 0x50010003, Text: "Read-only"};
aDlg[IDHIDDEN    ]={Class: "BUTTON",             Style: 0x50010003, Text: "Hidden"};
aDlg[IDSYSTEM    ]={Class: "BUTTON",             Style: 0x50010003, Text: "System"};
aDlg[IDSEARCHB   ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtSearch};
aDlg[IDREPLACEB  ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtReplace};
aDlg[IDEDITB     ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtEdit};
aDlg[IDCOPYB     ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtCopyList};
aDlg[IDCLEARB    ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtClearList};
aDlg[IDSETTINGSB ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtSettings};
aDlg[IDCLOSEB    ]={Class: "BUTTON",             Style: 0x50010000, Text: sTxtClose};
aDlg[IDFILELV    ]={Class: "SysListView32",      Style: 0x50810009};
aDlg[IDSTATUS    ]={Class: "msctls_statusbar32", Style: 0x50000100};

AkelPad.ScriptNoMutex();
AkelPad.WindowRegisterClass(sClass);

while (! bCloseDlg)
{
  bCloseDlg = true;
  hParent   = bSeparateWnd ? 0 : hMainWnd;
  oWndPos.W = Math.max(Scale.X(oWndPos.W), nWndMinW);
  oWndPos.H = Math.max(Scale.Y(oWndPos.H), nWndMinH);
  aDlg[IDMAXSIZEE].Text = (nMaxFileSize > 0) ? nMaxFileSize.toString() : "";

  hDlg = oSys.Call("User32::CreateWindowExW",
         0,               //dwExStyle
         sClass,          //lpClassName
         sTxtScriptName,  //lpWindowName
         0x80CF0000,      //dwStyle=WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SIZEBOX
         oWndPos.X,       //x
         oWndPos.Y,       //y
         oWndPos.W,       //nWidth
         oWndPos.H,       //nHeight
         hParent,         //hWndParent
         0,               //hMenu
         hInstDLL,        //hInstance
         DialogCallback); //Script function callback. To use it class must be registered by WindowRegisterClass.

  oSys.Call("User32::ShowWindow", hDlg, oWndPos.Max ? 3 /*SW_MAXIMIZE*/ : 1 /*SW_SHOWNORMAL*/);
  AkelPad.WindowGetMessage();
}

AkelPad.WindowUnregisterClass(sClass);
AkelPad.MemFree(lpBuffer);
AkelPad.MemFree(lpLVITEM);
oSys.Call("Gdi32::DeleteObject", hBrush);
oSys.Call("User32::SetForegroundWindow", hMainWnd);

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  var i;

  if (uMsg == 1) //WM_CREATE
  {
    var hGuiFont = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);

    for (i = 2000; i < aDlg.length; ++i)
    {
      aDlg[i].HWND = oSys.Call("User32::CreateWindowExW",
        aDlg[i].ExStyle, //dwExStyle
        aDlg[i].Class,   //lpClassName
        aDlg[i].Text,    //lpWindowName
        aDlg[i].Style,   //dwStyle
        0, 0, 0, 0,      //x, y, nWidth, nHeight
        hWnd,            //hWndParent
        i,               //ID
        hInstDLL,        //hInstance
        0);              //lpParam

      AkelPad.SendMessage(aDlg[i].HWND, 48 /*WM_SETFONT*/, hGuiFont, true);
    }

    for (i = IDNAMERE; i <= IDINSTREAMS; ++i)
      aDlg[i].W = GetTextWidth(aDlg[i].Text.replace("&", ""), hWnd, hGuiFont) + Scale.X(18);
    for (i = IDMATCHCASE; i <= IDSKIPLARGER; ++i)
      aDlg[i].W = GetTextWidth(aDlg[i].Text.replace("&", ""), hWnd, hGuiFont) + Scale.X(18);

    //Get handles to edit/list in ComboBoxes IDNAMECB, IDCONTENTCB and IDREPLACECB
    AkelPad.MemCopy(lpBuffer, _X64 ? 64 : 52 /*sizeof(COMBOBOXINFO)*/, DT_DWORD);
    oSys.Call("User32::GetComboBoxInfo", aDlg[IDNAMECB].HWND, lpBuffer);
    aDlg[IDNAMECB].HWNDEdit = AkelPad.MemRead(lpBuffer + (_X64 ? 48 : 44) /*hwndItem*/, DT_QWORD);
    aDlg[IDNAMECB].HWNDList = AkelPad.MemRead(lpBuffer + (_X64 ? 56 : 48) /*hwndList*/, DT_QWORD);
    oSys.Call("User32::GetComboBoxInfo", aDlg[IDCONTENTCB].HWND, lpBuffer);
    aDlg[IDCONTENTCB].HWNDEdit = AkelPad.MemRead(lpBuffer + (_X64 ? 48 : 44) /*hwndItem*/, DT_QWORD);
    aDlg[IDCONTENTCB].HWNDList = AkelPad.MemRead(lpBuffer + (_X64 ? 56 : 48) /*hwndList*/, DT_QWORD);
    oSys.Call("User32::GetComboBoxInfo", aDlg[IDREPLACECB].HWND, lpBuffer);
    aDlg[IDREPLACECB].HWNDEdit = AkelPad.MemRead(lpBuffer + (_X64 ? 48 : 44) /*hwndItem*/, DT_QWORD);
    aDlg[IDREPLACECB].HWNDList = AkelPad.MemRead(lpBuffer + (_X64 ? 56 : 48) /*hwndList*/, DT_QWORD);

    AkelPad.SendMessage(aDlg[IDNAMERE    ].HWND, 0x00F1 /*BM_SETCHECK*/, bNameRE, 0);
    AkelPad.SendMessage(aDlg[IDNOTNAME   ].HWND, 0x00F1 /*BM_SETCHECK*/, bNotName, 0);
    AkelPad.SendMessage(aDlg[IDINFILES   ].HWND, 0x00F1 /*BM_SETCHECK*/, bInFiles, 0);
    AkelPad.SendMessage(aDlg[IDINSTREAMS ].HWND, 0x00F1 /*BM_SETCHECK*/, bInStreams, 0);
    AkelPad.SendMessage(aDlg[IDMATCHCASE ].HWND, 0x00F1 /*BM_SETCHECK*/, bMatchCase, 0);
    AkelPad.SendMessage(aDlg[IDCONTENTRE ].HWND, 0x00F1 /*BM_SETCHECK*/, bContentRE, 0);
    AkelPad.SendMessage(aDlg[IDMULTILINE ].HWND, 0x00F1 /*BM_SETCHECK*/, bMultiline, 0);
    AkelPad.SendMessage(aDlg[IDNOTCONTAIN].HWND, 0x00F1 /*BM_SETCHECK*/, bNotContain, 0);
    AkelPad.SendMessage(aDlg[IDSKIPBINARY].HWND, 0x00F1 /*BM_SETCHECK*/, bSkipBinary, 0);
    AkelPad.SendMessage(aDlg[IDSKIPLARGER].HWND, 0x00F1 /*BM_SETCHECK*/, bSkipLarger, 0);
    AkelPad.SendMessage(aDlg[IDREADONLY  ].HWND, 0x00F1 /*BM_SETCHECK*/, bSkipReadOnly, 0);
    AkelPad.SendMessage(aDlg[IDHIDDEN    ].HWND, 0x00F1 /*BM_SETCHECK*/, bSkipHidden, 0);
    AkelPad.SendMessage(aDlg[IDSYSTEM    ].HWND, 0x00F1 /*BM_SETCHECK*/, bSkipSystem, 0);

    AkelPad.SendMessage(aDlg[IDDIRCB    ].HWND, 0x0141 /*CB_LIMITTEXT*/, 256, 0);
    AkelPad.SendMessage(aDlg[IDNAMECB   ].HWND, 0x0141 /*CB_LIMITTEXT*/, 256, 0);
    AkelPad.SendMessage(aDlg[IDCONTENTCB].HWND, 0x0141 /*CB_LIMITTEXT*/, 256, 0);
    AkelPad.SendMessage(aDlg[IDREPLACECB].HWND, 0x0141 /*CB_LIMITTEXT*/, 256, 0);
    AkelPad.SendMessage(aDlg[IDDIRCB    ].HWND, 0x0155 /*CB_SETEXTENDEDUI*/, 1, 0);
    AkelPad.SendMessage(aDlg[IDNAMECB   ].HWND, 0x0155 /*CB_SETEXTENDEDUI*/, 1, 0);
    AkelPad.SendMessage(aDlg[IDCONTENTCB].HWND, 0x0155 /*CB_SETEXTENDEDUI*/, 1, 0);
    AkelPad.SendMessage(aDlg[IDREPLACECB].HWND, 0x0155 /*CB_SETEXTENDEDUI*/, 1, 0);

    SetWindowText(aDlg[IDDIRCB].HWND, sDir);
    FillCB();
    SetPartsSB();

    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1036 /*LVM_SETEXTENDEDLISTVIEWSTYLE*/, 0x0020 /*LVS_EX_FULLROWSELECT*/, 0x0020);
    SetColumnLV();
    SetHeaderLV();

    oSys.Call("User32::PostMessageW", hWnd, 0x8000 /*WM_APP*/, 0, 0);

    hFocus = aDlg[IDDIRCB].HWND;
  }

  else if (uMsg == 0x8000 /*WM_APP*/)
  {
    SetWindowText(aDlg[IDNAMECB].HWND, sName);
    SetWindowText(aDlg[IDCONTENTCB].HWND, sContent);
    SetWindowText(aDlg[IDREPLACECB].HWND, sReplace);
    EnableButtons();
    oSys.Call("User32::UpdateWindow", hWnd);
    SetTextSB(-2);
    FillLV();
    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, nFilesFoc, false);
  }

  else if (uMsg == 0x8001 /*WM_APP+1*/)
    oSys.Call("User32::SetFocus", wParam);

  else if ((uMsg == 6 /*WM_ACTIVATE*/) && (! wParam))
    hFocus = oSys.Call("User32::GetFocus");

  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("User32::SetFocus", hFocus);

  else if (uMsg == 36) //WM_GETMINMAXINFO
  {
    AkelPad.MemCopy(lParam + 24, nWndMinW, DT_DWORD); //ptMinTrackSize_x
    AkelPad.MemCopy(lParam + 28, nWndMinH, DT_DWORD); //ptMinTrackSize_y
  }

  else if (uMsg == 3) //WM_MOVE
  {
    if (! (oSys.Call("User32::IsZoomed", hWnd) || oSys.Call("User32::IsIconic", hWnd)))
      GetWindowPos(hWnd, oWndPos);
  }

  else if (uMsg == 5) //WM_SIZE
  {
    if (wParam == 0 /*SIZE_RESTORED*/)
      GetWindowPos(hWnd, oWndPos);

    ResizeDlg(LoWord(lParam), HiWord(lParam));
  }

  else if (uMsg == 0x0133) //WM_CTLCOLOREDIT
  {
    if ((lParam == aDlg[IDNAMECB].HWNDEdit) || (lParam == aDlg[IDCONTENTCB].HWNDEdit) || (lParam == aDlg[IDREPLACECB].HWNDEdit))
    {
      if (((lParam == aDlg[IDNAMECB].HWNDEdit) && (bNameRE)) || (((lParam == aDlg[IDCONTENTCB].HWNDEdit) || (lParam == aDlg[IDREPLACECB].HWNDEdit)) && (bContentRE)))
      {
        oSys.Call("Gdi32::SetBkColor", wParam, nBkColorRE);
        return hBrush;
      }
      else
      {
        oSys.Call("Gdi32::SetBkColor", wParam, oSys.Call("User32::GetSysColor", 5 /*COLOR_WINDOW*/));
        return oSys.Call("User32::GetSysColorBrush", 5 /*COLOR_WINDOW*/);
      }
    }
  }

  else if (uMsg == 0x0134) //WM_CTLCOLORLISTBOX
  {
    if ((lParam == aDlg[IDNAMECB].HWNDList) || (lParam == aDlg[IDCONTENTCB].HWNDList) || (lParam == aDlg[IDREPLACECB].HWNDList))
    {
      if (((lParam == aDlg[IDNAMECB].HWNDList) && (bNameRE)) || (((lParam == aDlg[IDCONTENTCB].HWNDList) || (lParam == aDlg[IDREPLACECB].HWNDList)) && (bContentRE)))
      {
        oSys.Call("Gdi32::SetBkColor", wParam, nBkColorRE);
        return hBrush;
      }
      else
      {
        oSys.Call("Gdi32::SetBkColor", wParam, oSys.Call("User32::GetSysColor", 5 /*COLOR_WINDOW*/));
        return oSys.Call("User32::GetSysColorBrush", 5 /*COLOR_WINDOW*/);
      }
    }
  }

  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 0x0D /*VK_RETURN*/)
    {
      hFocus = oSys.Call("User32::GetFocus");
      if (Ctrl() || Shift())
      {
        if (hFocus == aDlg[IDFILELV].HWND)
          OpenOrCloseFile(1);
      }
      else
      {
        if (hFocus == aDlg[IDFILELV].HWND)
          oSys.Call("User32::PostMessageW", hWnd, 273 /*WM_COMMAND*/, IDEDITB, 0);
        else if (IsCloseCB() &&
                 (hFocus != aDlg[IDCURRENTB].HWND) && (hFocus != aDlg[IDBROWSEB].HWND) && (hFocus != aDlg[IDHELP1B   ].HWND) && (hFocus != aDlg[IDHELP2B  ].HWND) &&
                 (hFocus != aDlg[IDHELP3B  ].HWND) && (hFocus != aDlg[IDSEARCHB].HWND) && (hFocus != aDlg[IDEDITB    ].HWND) && (hFocus != aDlg[IDREPLACEB].HWND) &&
                 (hFocus != aDlg[IDCOPYB   ].HWND) && (hFocus != aDlg[IDCLEARB ].HWND) && (hFocus != aDlg[IDSETTINGSB].HWND))
          oSys.Call("User32::PostMessageW", hWnd, 273 /*WM_COMMAND*/, IDSEARCHB, 0);
      }
    }
    else if (wParam == 0x70 /*VK_F1*/)
    {
      if ((! Ctrl()) && (! Shift()))
      {
        hFocus = oSys.Call("User32::GetFocus");
        if (hFocus == aDlg[IDNAMECB].HWNDEdit)
        {
          oSys.Call("User32::SetFocus", aDlg[IDHELP1B].HWND);
          Help(IDHELP1B, 1);
        }
        else if ((hFocus == aDlg[IDCONTENTCB].HWNDEdit) && bContentRE)
        {
          oSys.Call("User32::SetFocus", aDlg[IDHELP2B].HWND);
          Help(IDHELP2B, 1);
        }
        else if ((hFocus == aDlg[IDREPLACECB].HWNDEdit) && bContentRE)
        {
          oSys.Call("User32::SetFocus", aDlg[IDHELP3B].HWND);
          Help(IDHELP3B, 1);
        }
      }
    }
    else if (wParam == 0x73 /*VK_F4*/)
    {
      if ((! Ctrl()) && (! Shift()))
        oSys.Call("User32::PostMessageW", hWnd, 273 /*WM_COMMAND*/, IDEDITB, 0);
    }
    else if (wParam == 0x1B /*VK_ESCAPE*/)
    {
      if (IsCloseCB())
        oSys.Call("User32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
    }
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if ((! Ctrl()) && (! Shift()))
    {
      if (wParam == 0x46 /*F key*/)
          oSys.Call("User32::SetFocus", aDlg[IDFILELV].HWND);
      else if (wParam == 0x2E /*VK_DELETE*/)
      {
        if (AkelPad.SendMessage(aDlg[IDDIRCB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0))
          DeleteItemCB(aDlg[IDDIRCB].HWND, aDirs);
        else if (AkelPad.SendMessage(aDlg[IDNAMECB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0))
          DeleteItemCB(aDlg[IDNAMECB].HWND, aNames);
        else if (AkelPad.SendMessage(aDlg[IDCONTENTCB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0))
          DeleteItemCB(aDlg[IDCONTENTCB].HWND, aContents);
        else if (AkelPad.SendMessage(aDlg[IDREPLACECB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0))
          DeleteItemCB(aDlg[IDREPLACECB].HWND, aReplace);
      }
    }
  }

  else if ((uMsg == 0x004E /*WM_NOTIFY*/) && (wParam == IDFILELV))
  {
    switch (AkelPad.MemRead(lParam + (_X64 ? 16 : 8) /*code*/, DT_DWORD))
    {
      case -101 : //LVN_ITEMCHANGED
        if (AkelPad.MemRead(lParam + (_X64 ? 32 : 20) /*uNewState*/, DT_DWORD) & 0x1 /*LVIS_FOCUSED*/)
          SetTextSB(AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, DT_DWORD));
        break;

      case -3 : //NM_DBLCLK
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, DT_DWORD) > -1)
        {
          OpenOrCloseFile(1);
          break;
        }
      case -2 : //NM_CLICK
      case -5 : //NM_RCLICK
      case -6 : //NM_RDBLCLK
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, DT_DWORD) == -1)
          SetSelLV(GetCurFocLV());
        break;

      case -155 : //LVN_KEYDOWN
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*wVKey*/, DT_WORD) == 0x2E /*VK_DELETE*/)
        {
          if ((! Ctrl()) && (! Shift()) && (! Alt()))
            RemoveFromList();
        }
        else if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12), DT_WORD) == 0x41 /*A key*/)
        {
          if (Ctrl() && (! Shift()) && (! Alt()))
            SetSelAllLV();
        }
        else if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12), DT_WORD) == 0x43 /*C key*/)
        {
          if (Ctrl() && (! Shift()) && (! Alt()))
            CopySelected();
        }
        break;

      case -108 : //LVN_COLUMNCLICK
        bSortDesc = ! bSortDesc;
        nFilesFoc = aFiles.length - GetCurFocLV() - 1;

        GetSelArrayLV();
        aFiles.reverse();
        aFilesSel.reverse();

        for (i = 0; i < aFilesSel.length; ++i)
          aFilesSel[i] = aFiles.length - aFilesSel[i] - 1;

        SetHeaderLV();
        FillLV();
    }
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    var nLowParam = LoWord(wParam);
    var nHiwParam = HiWord(wParam);
    bCloseCBL = 1;

    if (nLowParam == IDDIRLEVELCB)
    {
      if (nHiwParam == 1 /*CBN_SELCHANGE*/)
      {
        nDirLevel = AkelPad.SendMessage(aDlg[IDDIRLEVELCB].HWND, 0x0147 /*CB_GETCURSEL*/, 0, 0);
        if (nDirLevel == (AkelPad.SendMessage(aDlg[IDDIRLEVELCB].HWND, 0x0146 /*CB_GETCOUNT*/, 0, 0) - 1))
          nDirLevel = -1;
      }
      else if (nHiwParam == 8 /*CBN_CLOSEUP*/)
        bCloseCBL = 0;
    }
    else if ((nLowParam == IDNAMECB) || (nLowParam == IDCONTENTCB) || (nLowParam == IDREPLACECB))
    {
      if (nHiwParam == 3 /*CBN_SETFOCUS*/)
        AkelPad.SendMessage(aDlg[nLowParam].HWNDEdit, 177 /*EM_SETSEL*/, aDlg[nLowParam].Sel1, aDlg[nLowParam].Sel2);
      else if (nHiwParam == 10 /*CBN_SELENDCANCEL*/)
      {
        aDlg[nLowParam].Sel1 = LoWord(AkelPad.SendMessage(lParam, 0x0140 /*CB_GETEDITSEL*/, 0, 0));
        aDlg[nLowParam].Sel2 = HiWord(AkelPad.SendMessage(lParam, 0x0140 /*CB_GETEDITSEL*/, 0, 0));
      }
      EnableButtons();
    }
    else if (nLowParam == IDCURRENTB)
      CurrentDir();
    else if (nLowParam == IDBROWSEB)
      BrowseDirs();
    else if ((nLowParam == IDHELP1B) || (nLowParam == IDHELP2B) || (nLowParam == IDHELP3B))
      Help(nLowParam);
    else if (nLowParam == IDNAMERE)
    {
      bNameRE = ! bNameRE;
      oSys.Call("User32::InvalidateRect", aDlg[IDNAMECB].HWNDEdit, 0, true);
    }
    else if (nLowParam == IDNOTNAME)
      bNotName = ! bNotName;
    else if (nLowParam == IDINFILES)
    {
      bInFiles = ! bInFiles;
      if (! bInFiles)
      {
        bInStreams = true;
        AkelPad.SendMessage(aDlg[IDINSTREAMS].HWND, 0x00F1 /*BM_SETCHECK*/, bInStreams, 0);
      }
    }
    else if (nLowParam == IDINSTREAMS)
    {
      bInStreams = ! bInStreams;
      if (! bInStreams)
      {
        bInFiles = true;
        AkelPad.SendMessage(aDlg[IDINFILES].HWND, 0x00F1 /*BM_SETCHECK*/, bInFiles, 0);
      }
    }
    else if (nLowParam == IDMATCHCASE)
      bMatchCase = ! bMatchCase;
    else if (nLowParam == IDCONTENTRE)
    {
      bContentRE = ! bContentRE;
      EnableButtons();
      oSys.Call("User32::InvalidateRect", aDlg[IDCONTENTCB].HWNDEdit, 0, true);
      oSys.Call("User32::InvalidateRect", aDlg[IDREPLACECB].HWNDEdit, 0, true);
    }
    else if (nLowParam == IDMULTILINE)
      bMultiline = ! bMultiline;
    else if (nLowParam == IDNOTCONTAIN)
    {
      bNotContain = ! bNotContain;
      EnableButtons();
    }
    else if (nLowParam == IDSKIPBINARY)
      bSkipBinary = ! bSkipBinary;
    else if (nLowParam == IDSKIPLARGER)
    {
      bSkipLarger = ! bSkipLarger;
      EnableButtons();
    }
    else if (nLowParam == IDMAXSIZEE)
    {
      if (nHiwParam == 0x0300 /*EN_CHANGE*/)
      {
        nMaxFileSize = parseInt(GetWindowText(lParam), 10);
        if ((! isFinite(nMaxFileSize)) || (nMaxFileSize <= 0))
        {
          nMaxFileSize = 0;
          SetWindowText(lParam, "");
        }
      }
    }
    else if (nLowParam == IDREADONLY)
      bSkipReadOnly = ! bSkipReadOnly;
    else if (nLowParam == IDHIDDEN)
      bSkipHidden = ! bSkipHidden;
    else if (nLowParam == IDSYSTEM)
      bSkipSystem = ! bSkipSystem;
    else if ((nLowParam == IDSEARCHB) || (nLowParam == IDREPLACEB))
      SearchFiles(nLowParam == IDREPLACEB);
    else if (nLowParam == IDEDITB)
      OpenFiles();
    else if (nLowParam == IDCOPYB)
      CopyList();
    else if (nLowParam == IDCLEARB)
      ClearList();
    else if (nLowParam == IDSETTINGSB)
      Settings();
    else if (nLowParam == IDCLOSEB)
      oSys.Call("User32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 16) //WM_CLOSE
  {
    WriteIni();
    oSys.Call("User32::DestroyWindow", hWnd); //Destroy dialog
  }

  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("User32::PostQuitMessage", 0); //Exit message loop

  else
  {
    var nID = oSys.Call("User32::GetDlgCtrlID", oSys.Call("User32::GetFocus"));
    if (nID == IDFILELV)
      nID = IDEDITB;
    else if ((nID != IDCURRENTB) && (nID != IDBROWSEB) && (nID != IDHELP1B) && (nID != IDHELP2B) && (nID != IDHELP3B) && (nID < IDSEARCHB))
      nID = IDSEARCHB;
    oSys.Call("User32::DefDlgProcW", hWnd, 1025 /*DM_SETDEFID*/, nID, 0);
  }

  return 0;
}

function LoWord(nParam)
{
  return (nParam & 0xFFFF);
}

function HiWord(nParam)
{
  return ((nParam >> 16) & 0xFFFF);
}

function MkLong(nLoWord, nHiWord)
{
  return (nLoWord & 0xFFFF) | (nHiWord << 16);
}

function Ctrl()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x11 /*VK_CONTROL*/) & 0x8000);
}

function Shift()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000);
}

function Alt()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x12 /*VK_MENU*/) & 0x8000);
}

function GetWindowPos(hWnd, oRect)
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)

  oSys.Call("User32::GetWindowRect", hWnd, lpRect);

  oRect.X = AkelPad.MemRead(lpRect,      DT_DWORD);
  oRect.Y = AkelPad.MemRead(lpRect +  4, DT_DWORD);
  oRect.W = AkelPad.MemRead(lpRect +  8, DT_DWORD) - oRect.X;
  oRect.H = AkelPad.MemRead(lpRect + 12, DT_DWORD) - oRect.Y;

  AkelPad.MemFree(lpRect);
}

function GetWindowText(hWnd)
{
  oSys.Call("User32::GetWindowTextW", hWnd, lpBuffer, nBufSize / 2);
  return AkelPad.MemRead(lpBuffer, DT_UNICODE);
}

function SetWindowText(hWnd, sText)
{
  oSys.Call("User32::SetWindowTextW", hWnd, sText);
}

function GetTextWidth(sText, hWnd, hFont)
{
  var hDC    = oSys.Call("User32::GetDC", hWnd);
  var lpSize = AkelPad.MemAlloc(8);
  var nWidth;

  oSys.Call("Gdi32::SelectObject", hDC, hFont);
  oSys.Call("Gdi32::SetMapMode", hDC, 1 /*MM_TEXT*/);
  oSys.Call("Gdi32::GetTextExtentPoint32W", hDC, sText, sText.length, lpSize);

  nWidth = AkelPad.MemRead(lpSize, DT_DWORD);

  oSys.Call("User32::ReleaseDC", hWnd, hDC);
  AkelPad.MemFree(lpSize);
  return nWidth;
}

function ResizeDlg(nW, nH)
{
  var nFlags = 0x14; //SWP_NOACTIVATE|SWP_NOZORDER
  var nW5    = Scale.X(5);
  var nW10   = Scale.X(10);
  var nW20   = Scale.X(20);
  var nW73   = Scale.X(73);
  var nW80   = Scale.X(80);
  var nW160  = Scale.X(160);
  var nH13   = Scale.Y(13);
  var nH16   = Scale.Y(16);
  var nH21   = Scale.Y(21);
  var i;

  oSys.Call("User32::SetWindowPos",
    aDlg[IDDIRG].HWND, 0,
    nW5,
    Scale.Y(5),
    nW - nW80 - nW10 - 2 * nW5,
    Scale.Y(70),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDDIRCB].HWND, 0,
    2 * nW5,
    Scale.Y(25),
    nW - nW80 - nW10 - 4 * nW5,
    1,
    nFlags);
  for (i = IDCURRENTB; i <= IDBROWSEB; ++i)
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      2 * nW5 + (i - IDCURRENTB) * (nW80 + nW5),
      Scale.Y(49),
      nW80,
      nH21,
      nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDDIRLEVELS].HWND, 0,
    nW - Scale.X(115) - 2 - nW73 - nW80 - nW10 - 2 * nW5,
    Scale.Y(54),
    Scale.X(115),
    nH13,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDDIRLEVELCB].HWND, 0,
    nW - nW73 - nW80 - nW10 - 2 * nW5,
    Scale.Y(49),
    nW73,
    1,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDNAMEG].HWND, 0,
    nW5,
    Scale.Y(80),
    nW - nW80 - nW10 - 2 * nW5,
    Scale.Y(85),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDNAMECB].HWND, 0,
    2 * nW5,
    Scale.Y(100),
    nW - nW80 - nW20 - nW10 - 4 * nW5,
    1,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDHELP1B].HWND, 0,
    nW - nW80 - nW20 - nW10 - 2 * nW5,
    Scale.Y(100),
    nW20,
    nH21,
    nFlags);
  for (i = IDNAMERE; i <= IDINSTREAMS; ++i)
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      2 * nW5 + Math.floor((i - IDNAMERE) / 2) * nW160,
      Scale.Y(125 + ((i - IDNAMERE) % 2) * 20),
      aDlg[i].W,
      nH16,
      nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDCONTENTG].HWND, 0,
    nW5,
    Scale.Y(170),
    nW - nW80 - nW10 - 2 * nW5,
    Scale.Y(146),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDCONTENTCB].HWND, 0,
    2 * nW5,
    Scale.Y(190),
    nW - nW80 - nW20 - nW10 - 4 * nW5,
    1,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDHELP2B].HWND, 0,
    nW - nW80 - nW20 - nW10 - 2 * nW5,
    Scale.Y(190),
    nW20,
    nH21,
    nFlags);
  for (i = IDMATCHCASE; i <= IDSKIPLARGER; ++i)
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      2 * nW5 + Math.floor((i - IDMATCHCASE) / 3) * nW160,
      Scale.Y(215 + ((i - IDMATCHCASE) % 3) * 20),
      aDlg[i].W,
      nH16,
      nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDMAXSIZEE].HWND, 0,
    2 * nW5 + nW160 + aDlg[IDSKIPLARGER].W,
    Scale.Y(253),
    Scale.X(60),
    Scale.Y(20),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDREPLACES].HWND, 0,
    2 * nW5,
    Scale.Y(275),
    nW160,
    nH13,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDREPLACECB].HWND, 0,
    2 * nW5,
    Scale.Y(290),
    nW - nW80 - nW20 - nW10 - 4 * nW5,
    1,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDHELP3B].HWND, 0,
    nW - nW80 - nW20 - nW10 - 2 * nW5,
    Scale.Y(290),
    nW20,
    nH21,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDSKIPG].HWND, 0,
    nW - nW80 - nW5,
    Scale.Y(35),
    nW80,
    Scale.Y(80),
    nFlags);
  for (i = IDREADONLY; i <= IDSYSTEM; ++i)
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      nW - nW80,
      Scale.Y(55 + (i - IDREADONLY) * 20),
      nW73,
      nH16,
      nFlags);
  for (i = IDSEARCHB; i <= IDCLOSEB; ++i)
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      nW - nW80 - nW5,
      Scale.Y(152 + (i - IDSEARCHB) * 24),
      nW80,
      nH21,
      nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDFILELV].HWND, 0,
    -1,
    Scale.Y(325),
    nW + 2,
    nH - Scale.Y(325 + 22),
    nFlags);

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x101E /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, GetCurFocLV(), false);
  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 5 /*WM_SIZE*/, 0, 0);
}

function EnableButtons()
{
  var bContent = oSys.Call("User32::GetWindowTextLengthW", aDlg[IDCONTENTCB].HWND);

  oSys.Call("User32::EnableWindow", aDlg[IDNOTNAME   ].HWND, oSys.Call("User32::GetWindowTextLengthW", aDlg[IDNAMECB].HWND));
  oSys.Call("User32::EnableWindow", aDlg[IDHELP2B    ].HWND, bContentRE);
  oSys.Call("User32::EnableWindow", aDlg[IDMULTILINE ].HWND, bContentRE);
  oSys.Call("User32::EnableWindow", aDlg[IDNOTCONTAIN].HWND, bContent);
  oSys.Call("User32::EnableWindow", aDlg[IDSKIPBINARY].HWND, bContent);
  oSys.Call("User32::EnableWindow", aDlg[IDSKIPLARGER].HWND, bContent);
  oSys.Call("User32::EnableWindow", aDlg[IDMAXSIZEE  ].HWND, bContent && bSkipLarger);
  oSys.Call("User32::EnableWindow", aDlg[IDREPLACES  ].HWND, bContent && (! bNotContain));
  oSys.Call("User32::EnableWindow", aDlg[IDREPLACECB ].HWND, bContent && (! bNotContain));
  oSys.Call("User32::EnableWindow", aDlg[IDHELP3B    ].HWND, bContent && (! bNotContain) && bContentRE);
  oSys.Call("User32::EnableWindow", aDlg[IDREPLACEB  ].HWND, bContent && (! bNotContain));
  oSys.Call("User32::EnableWindow", aDlg[IDEDITB     ].HWND, aFiles.length);
  oSys.Call("User32::EnableWindow", aDlg[IDCOPYB     ].HWND, aFiles.length);
  oSys.Call("User32::EnableWindow", aDlg[IDCLEARB    ].HWND, aFiles.length);
}

function IsCloseCB()
{
  return (! AkelPad.SendMessage(aDlg[IDDIRCB    ].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0)) &&
         (! AkelPad.SendMessage(aDlg[IDNAMECB   ].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0)) &&
         (! AkelPad.SendMessage(aDlg[IDCONTENTCB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0)) &&
         (! AkelPad.SendMessage(aDlg[IDREPLACECB].HWND, 0x0157 /*CB_GETDROPPEDSTATE*/, 0, 0)) &&
         bCloseCBL;
}

function FillCB()
{
  var nPos;
  var i;

  for (i = 0; i < aDirs.length; ++i)
    AkelPad.SendMessage(aDlg[IDDIRCB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, aDirs[i]);

  for (i = 0; i < aNames.length; ++i)
    AkelPad.SendMessage(aDlg[IDNAMECB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, aNames[i]);

  for (i = 0; i < aContents.length; ++i)
    AkelPad.SendMessage(aDlg[IDCONTENTCB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, aContents[i]);

  for (i = 0; i < aReplace.length; ++i)
    AkelPad.SendMessage(aDlg[IDREPLACECB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, aReplace[i]);

  for (i = 0; i < nMaxLenCBL - 1; ++i)
    AkelPad.SendMessage(aDlg[IDDIRLEVELCB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, i.toString());

  nPos = AkelPad.SendMessage(aDlg[IDDIRLEVELCB].HWND, 0x0143 /*CB_ADDSTRING*/, 0, sTxtAll);
  if ((nDirLevel >= 0) && (nDirLevel < nMaxLenCBL))
    nPos = nDirLevel;
  else
    nDirLevel = -1;

  AkelPad.SendMessage(aDlg[IDDIRLEVELCB].HWND, 0x014E /*CB_SETCURSEL*/, nPos, 0);
}

function FindInArray(aArray, sText)
{
  for (var i = 0; i < aArray.length; ++i)
  {
    if (aArray[i] == sText)
      return i;
  }
  return -1;
}

function DeleteItemCB(hWndCB, aItems)
{
  var nPos = AkelPad.SendMessage(hWndCB, 0x0147 /*CB_GETCURSEL*/, 0, 0);

  aItems.splice(nPos, 1);

  AkelPad.SendMessage(hWndCB, 0x0144 /*CB_DELETESTRING*/, nPos, 0);

  if (nPos > aItems.length - 1)
    nPos = aItems.length - 1;

  AkelPad.SendMessage(hWndCB, 0x014E /*CB_SETCURSEL*/, nPos, 0);
}

function GetCurFocLV()
{
  return AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x100C /*LVM_GETNEXTITEM*/, -1, 0x0001 /*LVNI_FOCUSED*/);
}

function GetNextSelLV(nItem)
{
  return AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x100C /*LVM_GETNEXTITEM*/, nItem, 0x0002 /*LVNI_SELECTED*/);
}

function GetSelArrayLV()
{
  var nItem = -1;
  aFilesSel = [];

  while ((nItem = GetNextSelLV(nItem)) >= 0)
    aFilesSel.push(nItem);

  if (! aFilesSel.length)
    aFilesSel = [GetCurFocLV()];
}

function SetSelLV(nItem)
{
  AkelPad.MemCopy(lpLVITEM + 12, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, DT_DWORD);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, DT_DWORD);

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x102B /*LVM_SETITEMSTATE*/, nItem, lpLVITEM);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, nItem, true);
}

function SetSelArrayLV()
{
  AkelPad.MemCopy(lpLVITEM + 12, 0x0002 /*LVIS_SELECTED*/, DT_DWORD);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0002 /*LVIS_SELECTED*/, DT_DWORD);

  for (var i = 0; i < aFilesSel.length; ++i)
    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x102B /*LVM_SETITEMSTATE*/, aFilesSel[i], lpLVITEM);

  AkelPad.MemCopy(lpLVITEM + 12, 0x0001 /*LVIS_FOCUSED*/, DT_DWORD);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0001 /*LVIS_FOCUSED*/, DT_DWORD);

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x102B /*LVM_SETITEMSTATE*/, nFilesFoc, lpLVITEM);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, nFilesFoc, true);
}

function SetSelAllLV()
{
  AkelPad.MemCopy(lpLVITEM + 12, 0x0002 /*LVIS_SELECTED*/, DT_DWORD);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0002 /*LVIS_SELECTED*/, DT_DWORD);

  for (var i = 0; i < aFiles.length; ++i)
    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x102B /*LVM_SETITEMSTATE*/, i, lpLVITEM);
}

function InsertItemLV(nItem, sText)
{
  AkelPad.MemCopy(lpLVITEM + 4, nItem, DT_DWORD); //iItem
  AkelPad.MemCopy(lpLVITEM + 8,     0, DT_DWORD); //iSubItem
  AkelPad.MemCopy(lpBuffer, sText, DT_UNICODE);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x104D /*LVM_INSERTITEMW*/, 0, lpLVITEM);
}

function SetColumnLV()
{
  var lpLVCOLUMN = AkelPad.MemAlloc(_X64 ? 56 : 44); //sizeof(LVCOLUMN)

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1061 /*LVM_INSERTCOLUMNW*/, 0, lpLVCOLUMN);

  AkelPad.MemFree(lpLVCOLUMN);
}

function SetHeaderLV()
{
  var lpHDITEM = AkelPad.MemAlloc(_X64 ? 72 : 48); //sizeof(HDITEM)
  var nFmt     = 0x4000 /*HDF_STRING*/ | (bSortDesc ? 0x0200 /*HDF_SORTDOWN*/ : 0x0400 /*HDF_SORTUP*/);
  var hHeader  = AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x101F /*LVM_GETHEADER*/, 0, 0);

  AkelPad.MemCopy(lpBuffer, bAfterReplace ? sTxtFilesRepl : sTxtFilesFound, DT_UNICODE);

  AkelPad.MemCopy(lpHDITEM, 0x06, DT_DWORD); //mask=HDI_FORMAT|HDI_TEXT
  AkelPad.MemCopy(lpHDITEM + 8, lpBuffer, DT_QWORD); //pszText
  AkelPad.MemCopy(lpHDITEM + (_X64 ? 24 : 16), nBufSize, DT_DWORD); //cchTextMax
  AkelPad.MemCopy(lpHDITEM + (_X64 ? 28 : 20), nFmt, DT_DWORD); //fmt

  AkelPad.SendMessage(hHeader, 0x120C /*HDM_SETITEMW*/, 0, lpHDITEM);

  AkelPad.MemFree(lpHDITEM);
}

function SetPartsSB()
{
  var lpParts = AkelPad.MemAlloc(5 * 4);

  AkelPad.MemCopy(lpParts,      Scale.X( 90), DT_DWORD);
  AkelPad.MemCopy(lpParts +  4, Scale.X(190), DT_DWORD);
  AkelPad.MemCopy(lpParts +  8, Scale.X(310), DT_DWORD);
  AkelPad.MemCopy(lpParts + 12, Scale.X(350), DT_DWORD);
  AkelPad.MemCopy(lpParts + 16,           -1, DT_DWORD);

  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x0404 /*SB_SETPARTS*/, 5, lpParts);

  AkelPad.MemFree(lpParts);
}

function SetTextSB(nItem)
{
  var sText0 = "";
  var sText1 = "";
  var sText2 = "";
  var sText3 = "";
  var sText4 = "";
  var hFile;
  var lpFileInfo;
  var lpDecimalSep;
  var lpThousandSep;
  var lpNUMBERFMT;
  var lpLocalFileTime;
  var lpSysTime;
  var nSizeHi;
  var nSizeLo;

  if ((nItem > -1) && aFiles.length)
  {
    sText0 = "\t\t" + (nItem + 1) + "/" + aFiles.length + " ";
    hFile  = oSys.Call("Kernel32::CreateFileW",
                       aFiles[nItem], //lpFileName
                       0,  //dwDesiredAccess
                       3,  //dwShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE
                       0,  //lpSecurityAttributes
                       3,  //dwCreationDisposition = OPEN_EXISTING
                       0,  //dwFlagsAndAttributes
                       0); //hTemplateFile
    lpFileInfo = AkelPad.MemAlloc(52); //sizeof(BY_HANDLE_FILE_INFORMATION)

    if (hFile && oSys.Call("Kernel32::GetFileInformationByHandle", hFile, lpFileInfo))
    {
      //file size
      nSizeHi = AkelPad.MemRead(lpFileInfo + 32, DT_DWORD);
      nSizeLo = AkelPad.MemRead(lpFileInfo + 36, DT_DWORD);
      if (nSizeLo < 0)
        nSizeLo += 0xFFFFFFFF + 1;

      lpDecimalSep  = AkelPad.MemAlloc(4 * 2);
      lpThousandSep = AkelPad.MemAlloc(4 * 2);
      lpNUMBERFMT   = AkelPad.MemAlloc(_X64 ? 40 : 24); //sizeof(NUMBERFMT)
      AkelPad.MemCopy(lpNUMBERFMT + 8, 3, DT_DWORD); //Grouping
      AkelPad.MemCopy(lpNUMBERFMT + (_X64 ? 16 : 12), lpDecimalSep,  DT_QWORD);
      AkelPad.MemCopy(lpNUMBERFMT + (_X64 ? 24 : 16), lpThousandSep, DT_QWORD);

      oSys.Call("Kernel32::GetLocaleInfoW", 0x400 /*LOCALE_USER_DEFAULT*/,  0xE /*LOCALE_SDECIMAL*/,  lpDecimalSep,  4);
      oSys.Call("Kernel32::GetLocaleInfoW", 0x400 /*LOCALE_USER_DEFAULT*/,  0xF /*LOCALE_STHOUSAND*/, lpThousandSep, 4);
      oSys.Call("Kernel32::GetNumberFormatW",
                0x400, //LOCALE_USER_DEFAULT
                0,
                (nSizeHi * (0xFFFFFFFF + 1) + nSizeLo).toString(),
                lpNUMBERFMT,
                lpBuffer,
                nBufSize / 2);

      AkelPad.MemFree(lpDecimalSep);
      AkelPad.MemFree(lpThousandSep);
      AkelPad.MemFree(lpNUMBERFMT);

      sText1 = "\t\t" + AkelPad.MemRead(lpBuffer, DT_UNICODE) + " " + sTxtByteSymbol + " ";

      //file date and time
      lpLocalFileTime = AkelPad.MemAlloc(8);  //FILETIME
      lpSysTime       = AkelPad.MemAlloc(16); //SYSTEMTIME

      oSys.Call("Kernel32::FileTimeToLocalFileTime", lpFileInfo + 20, lpLocalFileTime);
      oSys.Call("Kernel32::FileTimeToSystemTime", lpLocalFileTime, lpSysTime);
      oSys.Call("Kernel32::GetDateFormatW",
                0x400, //LOCALE_USER_DEFAULT
                0x1,   //DATE_SHORTDATE
                lpSysTime,
                0,
                lpBuffer,
                64);
      oSys.Call("Kernel32::GetTimeFormatW",
                0x400, //LOCALE_USER_DEFAULT
                0x8,   //TIME_FORCE24HOURFORMAT
                lpSysTime,
                0,
                lpBuffer + 128,
                64);

      AkelPad.MemFree(lpLocalFileTime);
      AkelPad.MemFree(lpSysTime);

      sText2 = "\t" + AkelPad.MemRead(lpBuffer, DT_UNICODE) + "  " + AkelPad.MemRead(lpBuffer + 128, DT_UNICODE);

      //file attributes
      if (AkelPad.MemRead(lpFileInfo, DT_DWORD) & 32 /*FILE_ATTRIBUTE_ARCHIVE*/)
        sText3 += "A";
      if (AkelPad.MemRead(lpFileInfo, DT_DWORD) & 2 /*FILE_ATTRIBUTE_HIDDEN*/)
        sText3 += "H";
      if (AkelPad.MemRead(lpFileInfo, DT_DWORD) & 1 /*FILE_ATTRIBUTE_READONLY*/)
        sText3 += "R";
      if (AkelPad.MemRead(lpFileInfo, DT_DWORD) & 4 /*FILE_ATTRIBUTE_SYSTEM*/)
        sText3 += "S";

      if (aFiles[nItem].lastIndexOf(":") > 2)
        sText4 = sTxtNTFSStream;
    }

    oSys.Call("Kernel32::CloseHandle", hFile);
    AkelPad.MemFree(lpFileInfo);
  }
  else if (nItem == -2)
    sText0 = "\t" + sTxtWait;

  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x040B /*SB_SETTEXTW*/, 0, sText0);
  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x040B /*SB_SETTEXTW*/, 1, sText1);
  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x040B /*SB_SETTEXTW*/, 2, sText2);
  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x040B /*SB_SETTEXTW*/, 3, sText3);
  AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x040B /*SB_SETTEXTW*/, 4, sText4);
}

function FillLV()
{
  var nNameBegin = 0;
  var i;

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x000B /*WM_SETREDRAW*/, 0, 0);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1009 /*LVM_DELETEALLITEMS*/, 0, 0);

  if (aFiles.length)
  {
    if (! bPathShow)
      nNameBegin = nPathLen;

    for (i = 0; i < aFiles.length; ++i)
      InsertItemLV(i, aFiles[i].substr(nNameBegin));

    SetSelArrayLV();
  }
  else
    InsertItemLV(0, sTxtNoFiles);

  if (GetNextSelLV(-1) < 0)
    SetSelLV(0);

  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x101E /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x000B /*WM_SETREDRAW*/, 1, 0);
}

function CurrentDir()
{
  sDir = AkelPad.GetEditFile(0);

  if (sDir)
    sDir = sDir.replace(/\\[^\\]+$/, "");
  else
    sDir = AkelPad.GetAkelDir();

  SetWindowText(aDlg[IDDIRCB].HWND, sDir);
  AkelPad.SendMessage(aDlg[IDDIRCB].HWND, 0x0142 /*CB_SETEDITSEL*/, 0, MkLong(0, -1));
}

function BrowseDirs()
{
  var sSelDir = BrowseForFolder(hDlg, sTxtChooseDir, GetWindowText(aDlg[IDDIRCB].HWND).replace(/(^ +)|( +$)/g, ""));

  if (sSelDir)
  {
    SetWindowText(aDlg[IDDIRCB].HWND, sSelDir);
    AkelPad.SendMessage(aDlg[IDDIRCB].HWND, 0x0142 /*CB_SETEDITSEL*/, 0, MkLong(0, -1));
  }
}

function Help(nID, bPressF1)
{
  var nString = 0x0000; //MF_STRING
  var nBreak  = 0x0060; //MF_MENUBREAK|MF_MENUBARBREAK
  var nSepar  = 0x0800; //MF_SEPARATOR
  var hMenu   = oSys.Call("User32::CreatePopupMenu");
  var oRect   = {};
  var aMenu;
  var nCmd;

  GetWindowPos(aDlg[nID].HWND, oRect);

  if ((nID == IDHELP1B) && (! bNameRE))
    aMenu = [
      [nString, "?",   sHlpAnyChar],
      [nString, "*",   sHlpAnyString],
      [nString, '";"', sHlpSemicolQuot],
      [nSepar],
      [nString, ";",   sHlpListSepar],
      [nSepar],
      [nString, ":",   sHlpStreamSepar]];
  else if (nID == IDHELP3B)
    aMenu = [
      [nString, "$$",      sHlpDollar],
      [nString, "$&&",     sHlpEntireStr],
      [nString, "$`",      sHlpPrecedeStr],
      [nString, "$'",      sHlpFollowStr],
      [nString, "$9",      sHlpSubmatch9],
      [nString, "$99",     sHlpSubmatch99],
      [nSepar],
      [nString, "\\\\",    sHlpBackslash],
      [nString, "\\0",     sHlpNULL],
      [nString, "\\f",     sHlpFF],
      [nString, "\\n",     sHlpNL],
      [nString, "\\r",     sHlpCR],
      [nString, "\\t",     sHlpTab],
      [nString, "\\v",     sHlpVTab],
      [nString, "\\xFF",   sHlpCharHex],
      [nString, "\\u00FF", sHlpUniCharHex]];
  else
  {
    aMenu = [
      [nString, ".",       sHlpAnyChar_NL],
      [nString, "\\d",     sHlpDigit],
      [nString, "\\D",     sHlpNonDigit],
      [nString, "\\s",     sHlpWhiteSp],
      [nString, "\\S",     sHlpNonWhiteSp],
      [nString, "\\w",     sHlpWordChar],
      [nString, "\\W",     sHlpNonWordChar],
      [nString, "\\0",     sHlpNULL],
      [nString, "\\f",     sHlpFF],
      [nString, "\\n",     sHlpNL],
      [nString, "\\r",     sHlpCR],
      [nString, "\\t",     sHlpTab],
      [nString, "\\v",     sHlpVTab],
      [nString, "\\xFF",   sHlpCharHex],
      [nString, "\\u00FF", sHlpUniCharHex],
      [nSepar],
      [nString, "^",       sHlpBegin],
      [nString, "$",       sHlpEnd],
      [nString, "\\b",     sHlpWordBoun],
      [nString, "\\B",     sHlpNonWordBoun],
      [nBreak,  "ab|xy",   sHlpAlternative],
      [nString, "[abc]",   sHlpCharSet],
      [nString, "[^abc]",  sHlpNegCharSet],
      [nString, "[a-z]",   sHlpRange],
      [nString, "[^a-z]",  sHlpNegRange],
      [nSepar],
      [nString, "(ab)",    sHlpCapture],
      //if ((nID == IDHELP1B) && bNameRE) this element should be removed
      [nString, "(?:ab)",  sHlpNotCapture],
      [nString, "(?=ab)",  sHlpFollow],
      [nString, "(?!ab)",  sHlpNotFollow],
      [nString, "\\9",     sHlpBackrefer9],
      [nString, "\\99",    sHlpBackrefer99],
      [nSepar],
      [nString, "?",       sHlpZeroOrOne],
      [nString, "*",       sHlpZeroOrMore],
      [nString, "+",       sHlpOneOrMore],
      [nString, "{3}",     sHlpexactly],
      [nString, "{3,}",    sHlpAtLeast],
      [nString, "{3,7}",   sHlpFromTo],
      [nSepar],
      [nString, "\\(",     sHlpSpecChars]];

    if ((nID == IDHELP1B) && bNameRE)
    {
      aMenu.splice(27, 1);
      aMenu.push([nSepar]);
      aMenu.push([nString, ":", sHlpStreamSepar]);
    }
  }

  for (i = 0; i < aMenu.length; ++i)
    oSys.Call("User32::AppendMenuW", hMenu, aMenu[i][0], i + 1, aMenu[i][1] + "\t" + aMenu[i][2]);

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0188 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_TOPALIGN|TPM_RIGHTALIGN*/, oRect.X + oRect.W, oRect.Y + oRect.H, 0, hDlg, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  --nID;

  if (nCmd)
  {
    aMenu[nCmd - 1][1] = aMenu[nCmd - 1][1].replace(/&&/g, "&");
    AkelPad.SendMessage(aDlg[nID].HWNDEdit, 177 /*EM_SETSEL*/, aDlg[nID].Sel1, aDlg[nID].Sel2);
    AkelPad.SendMessage(aDlg[nID].HWNDEdit, 194 /*EM_REPLACESEL*/, 1, aMenu[nCmd - 1][1]);
    aDlg[nID].Sel1 += aMenu[nCmd - 1][1].length;
    aDlg[nID].Sel2  = aDlg[nID].Sel1;
  }

  if (nCmd || bPressF1)
    oSys.Call("User32::PostMessageW", hDlg, 0x8001 /*WM_APP+1*/, aDlg[nID].HWND, 0);
}



Last edited by KDJ on Thu Jul 03, 2014 5:48 pm; edited 21 times in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1325
Location: Poland

PostPosted: Sun Oct 28, 2012 8:05 pm    Post subject: Reply with quote

Search files by name/content and replace content - part 2.

FindReplaceFiles_part2.js

Code:
function SearchFiles(bReplace)
{
  var aPath;
  var sFile;
  var sStream;
  var rFile;
  var rStream;
  var rContent;
  var sReplaceWith;
  var nMaxLevel;
  var bLevelOK;
  var hFindFile;
  var sFileName;
  var sFullName;
  var nAttr;
  var sFileContent;
  var nCodePage;
  var bBOM;
  var lpFile;
  var lpDetectFile;
  var nDetectFile;
  var nSizeHi;
  var nSizeLo;
  var nSize;
  var nMaxSize;
  var bNTFS;
  var aStreams;
  var i, n;

  sDir     = GetWindowText(aDlg[IDDIRCB].HWND).replace(/(^ +)|( +$)/g, "");
  sName    = GetWindowText(aDlg[IDNAMECB].HWND);
  sContent = GetWindowText(aDlg[IDCONTENTCB].HWND);
  sReplace = GetWindowText(aDlg[IDREPLACECB].HWND);

  if (sDir)
    SetWindowText(aDlg[IDDIRCB].HWND, sDir);
  else
    CurrentDir();

  if (! IsDirExists(sDir))
  {
    WarningBox(sDir + "\n\n" + sTxtDirNoExist);
    oSys.Call("User32::PostMessageW", aDlg[IDDIRCB].HWND, 7 /*WM_SETFOCUS*/, 0, 0);
    return;
  }

  if (sName)
  {
    i = 0;
    n = sName.indexOf(":");

    if (n > -1)
    {
      sFile   = sName.substr(0, n);
      sStream = sName.substr(n + 1);
    }
    else
      sFile = sName;

    if (bNameRE)
    {
      try
      {
        if (sFile)
          rFile = new RegExp(sFile, "i");

        if (sStream)
        {
          i = n + 1;
          n = -1;
          rStream = new RegExp(sStream, "i");
        }
      }
      catch (oError)
      {
        WarningBox(sName + "\n\n" + sTxtErrorRE);
        oSys.Call("User32::PostMessageW", aDlg[IDNAMECB].HWND, 7 /*WM_SETFOCUS*/, 0, 0);
        oSys.Call("User32::PostMessageW", aDlg[IDNAMECB].HWNDEdit, 177 /*EM_SETSEL*/, i, n);
        return;
      }
    }
    else
    {
      if (sFile)
        rFile = GetNameRegExp(sFile);

      if (sStream)
        rStream = GetNameRegExp(sStream);
    }
  }

  if (sContent)
  {
    if (bContentRE)
    {
      try
      {
        rContent = new RegExp(sContent, "g" + (bMatchCase ? "" : "i") + (bMultiline ? "m" : ""));
      }
      catch (oError)
      {
        WarningBox(sContent + "\n\n" + sTxtErrorRE);
        oSys.Call("User32::PostMessageW", aDlg[IDCONTENTCB].HWND, 7 /*WM_SETFOCUS*/, 0, 0);
        oSys.Call("User32::PostMessageW", aDlg[IDCONTENTCB].HWNDEdit, 177 /*EM_SETSEL*/, 0, -1);
        return;
      }
    }
    else
      rContent = new RegExp(sContent.replace(/[\\\/.^$+*?|()\[\]{}]/g, "\\$&"), "g" + (bMatchCase ? "" : "i"));
  }

  if (bReplace)
  {
    if (WarningBox(sTxtWantReplace, true))
    {
      if (bContentRE)
        sReplaceWith = sReplace.replace(/(\\+)([^\\]*)/g, ReplaceFunc);
      else
        sReplaceWith = sReplace.replace(/\$/g, "$$$$");
    }
    else
      return;
  }

  bAfterReplace = bReplace;
  SetHeaderLV();
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1009 /*LVM_DELETEALLITEMS*/, 0, 0);
  AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x101E /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
  oSys.Call("User32::UpdateWindow", aDlg[IDFILELV].HWND);

  SetTextSB(-2);
  InsertToCB();

  aFiles          = [];
  aFilesSel       = [0];
  nFilesFoc       = 0;
  aPath           = [sDir + ((sDir.slice(-1) != "\\") ? "\\" : "")];
  nPathLen        = aPath[0].length;
  nMaxLevel       = (nDirLevel < 0) ? Infinity : nDirLevel;
  nMaxSize        = (nMaxFileSize <= 0) ? Infinity : nMaxFileSize;
  bNTFS           = IsSupportStreams(/^[a-z]:/i.test(sDir) ? sDir.substr(0, 2) : "");
  sLastContent    = sContent;
  bLastContentRE  = bContentRE;
  bLastMatchCase  = bMatchCase;
  bLastMultiline  = bMultiline;
  bLastNotContain = bNotContain;
  lpFile          = AkelPad.MemAlloc((260 + 260 + 36) * 2);
  lpDetectFile    = AkelPad.MemAlloc(_X64 ? 24 : 20); //sizeof(DETECTFILEW)

  AkelPad.MemCopy(lpDetectFile, lpFile, DT_QWORD);
  AkelPad.MemCopy(lpDetectFile + (_X64 ?  8 : 4), 1024, DT_DWORD); //dwBytesToCheck
  AkelPad.MemCopy(lpDetectFile + (_X64 ? 12 : 8), 0x1D, DT_DWORD); //dwFlags=ADT_NOMESSAGES|ADT_DETECT_BOM|ADT_DETECT_CODEPAGE|ADT_BINARY_ERROR

  for (i = 0; i < aPath.length; ++i)
  {
    hFindFile = oSys.Call("Kernel32::FindFirstFileW", aPath[i] + "*.*", lpBuffer);

    if (hFindFile != -1) //INVALID_HANDLE_VALUE
    {
      bLevelOK = ((aPath[i].match(/\\/g).length - aPath[0].match(/\\/g).length) < nMaxLevel);

      do
      {
        sFileName = AkelPad.MemRead(lpBuffer + 44 /*offsetof(WIN32_FIND_DATAW, cFileName)*/, DT_UNICODE);
        sFullName = aPath[i] + sFileName;
        nAttr     = AkelPad.MemRead(lpBuffer, DT_DWORD);

        //files
        if (! (nAttr & 16 /*FILE_ATTRIBUTE_DIRECTORY*/))
        {
          if (((! bSkipReadOnly) || (bSkipReadOnly && (! (nAttr & 1 /*FILE_ATTRIBUTE_READONLY*/)))) &&
              ((! bSkipHidden)   || (bSkipHidden   && (! (nAttr & 2 /*FILE_ATTRIBUTE_HIDDEN*/  )))) &&
              ((! bSkipSystem)   || (bSkipSystem   && (! (nAttr & 4 /*FILE_ATTRIBUTE_SYSTEM*/  )))) &&
              ((! rFile) || ((! bNotName) && rFile.test(sFileName)) || (bNotName && (! rFile.test(sFileName)))))
          {
            if (bInStreams && bNTFS)
            {
              aStreams = EnumStreams(sFullName);

              for (n = 0; n < aStreams.length; ++n)
              {
                if ((bInFiles && (! aStreams[n][0])) ||
                    (aStreams[n][0] && ((! rStream) || ((! bNotName) && rStream.test(aStreams[n][0])) || (bNotName && (! rStream.test(aStreams[n][0]))))))
                {
                  sFullName = aPath[i] + sFileName + (aStreams[n][0] ? (":" + aStreams[n][0]) : "");

                  if (rContent)
                  {
                    AkelPad.MemCopy(lpFile, sFullName, DT_UNICODE);
                    nDetectFile = AkelPad.SendMessage(hMainWnd, 1177 /*AKD_DETECTFILEW*/, 0, lpDetectFile);
 
                    if (((nDetectFile == 0 /*EDT_SUCCESS*/) || ((nDetectFile == -4 /*EDT_BINARY*/) && (! bSkipBinary))) && (aStreams[n][1] <= nMaxSize))
                    {
                      rContent.lastIndex = 0;
                      nCodePage    = AkelPad.MemRead(lpDetectFile + (_X64 ? 16 : 12), DT_DWORD);
                      bBOM         = AkelPad.MemRead(lpDetectFile + (_X64 ? 20 : 16), DT_DWORD);
                      sFileContent = AkelPad.ReadFile(sFullName, 0, nCodePage, bBOM);
 
                      if (rContent.test(sFileContent))
                      {
                        if (! bNotContain)
                        {
                          if (bReplace)
                          {
                            sFileContent = sFileContent.replace(rContent, sReplaceWith);
   
                            if (AkelPad.WriteFile(sFullName, sFileContent, sFileContent.length, nCodePage, bBOM, 0x1 /*WFF_WRITEREADONLY*/) == 0 /*ESD_SUCCESS*/)
                              aFiles.push(sFullName);
                          }
                          else
                            aFiles.push(sFullName);
                        }
                      }
                      else if (bNotContain)
                        aFiles.push(sFullName);
                    }
                  }
                  else
                    aFiles.push(sFullName);
                }
              }
            }
            else if (bInFiles)
            {
              if (rContent)
              {
                nSizeHi = AkelPad.MemRead(lpBuffer + 28 /*offsetof(WIN32_FIND_DATAW, nFileSizeHigh)*/, DT_DWORD);
                nSizeLo = AkelPad.MemRead(lpBuffer + 32 /*offsetof(WIN32_FIND_DATAW, nFileSizeLow)*/,  DT_DWORD);
                if (nSizeLo < 0)
                  nSizeLo += 0xFFFFFFFF + 1;
                nSize = nSizeHi * (0xFFFFFFFF + 1) + nSizeLo;

                AkelPad.MemCopy(lpFile, sFullName, DT_UNICODE);
                nDetectFile = AkelPad.SendMessage(hMainWnd, 1177 /*AKD_DETECTFILEW*/, 0, lpDetectFile);

                if (((nDetectFile == 0 /*EDT_SUCCESS*/) || ((nDetectFile == -4 /*EDT_BINARY*/) && (! bSkipBinary))) && (nSize <= nMaxSize))
                {
                  rContent.lastIndex = 0;
                  nCodePage    = AkelPad.MemRead(lpDetectFile + (_X64 ? 16 : 12), DT_DWORD);
                  bBOM         = AkelPad.MemRead(lpDetectFile + (_X64 ? 20 : 16), DT_DWORD);
                  sFileContent = AkelPad.ReadFile(sFullName, 0, nCodePage, bBOM);

                  if (rContent.test(sFileContent))
                  {
                    if (! bNotContain)
                    {
                      if (bReplace)
                      {
                        sFileContent = sFileContent.replace(rContent, sReplaceWith);

                        if (AkelPad.WriteFile(sFullName, sFileContent, sFileContent.length, nCodePage, bBOM, 0x1 /*WFF_WRITEREADONLY*/) == 0 /*ESD_SUCCESS*/)
                          aFiles.push(sFullName);
                      }
                      else
                        aFiles.push(sFullName);
                    }
                  }
                  else if (bNotContain)
                    aFiles.push(sFullName);
                }
              }
              else
                aFiles.push(sFullName);
            }
          }
        }
        //directories
        else if (bLevelOK && (sFileName != ".") && (sFileName != ".."))
        {
          aPath.push(sFullName + "\\");
        }
      }
      while (oSys.Call("Kernel32::FindNextFileW", hFindFile, lpBuffer));

      oSys.Call("Kernel32::FindClose", hFindFile);
    }
  }

  AkelPad.MemFree(lpFile);
  AkelPad.MemFree(lpDetectFile);

  SortFiles();
  FillLV();
  EnableButtons();

  oSys.Call("User32::PostMessageW", hDlg, 0x8001 /*WM_APP+1*/, aDlg[IDFILELV].HWND, 0);
}

function GetNameRegExp(sName)
{
  var sPattern =
        sName.replace(/"([^"]*)"/g, function() {return arguments[1].replace(/;/g, "\0");})
             .replace(/[\\\/.^$+|()\[\]{}]/g, "\\$&")
             .replace(/\*/g, ".*")
             .replace(/\?/g, ".")
             .replace(/;{2,}/g, ";")
             .replace(/(^;)|(;$)/g, "")
             .replace(/;/g, "|")
             .replace(/\0/g, ";");
  return new RegExp("^(" + sPattern + ")$", "i");
}

function ReplaceFunc(s0, s1, s2)
{
  if (s1.length % 2)
  {
    switch (s2.charAt(0))
    {
      case "0":
        s2 = "\0" + s2.substr(1);
        break;
      case "f":
        s2 = "\f" + s2.substr(1);
        break;
      case "n":
        s2 = "\n" + s2.substr(1);
        break;
      case "r":
        s2 = "\r" + s2.substr(1);
        break;
      case "t":
        s2 = "\t" + s2.substr(1);
        break;
      case "v":
        s2 = "\x0B" + s2.substr(1);
        break;
      default:
        if (/^x[\dA-Fa-f]{2}/.test(s2))
          s2 = String.fromCharCode(parseInt(s2.substr(1, 2), 16)) + s2.substr(3);
        else if (/^u[\dA-Fa-f]{4}/.test(s2))
          s2 = String.fromCharCode(parseInt(s2.substr(1, 4), 16)) + s2.substr(5);
    }
  }

  return s1.substr(0, s1.length / 2) + s2;
}

function InsertToCB()
{
  var aCB = [{HWND: aDlg[IDDIRCB].HWND,     Array: aDirs,     Text: sDir},
             {HWND: aDlg[IDNAMECB].HWND,    Array: aNames,    Text: sName},
             {HWND: aDlg[IDCONTENTCB].HWND, Array: aContents, Text: sContent},
             {HWND: aDlg[IDREPLACECB].HWND, Array: aReplace,  Text: sReplace}];
  var nPos;
  var i;

  for (i = 0; i < aCB.length; ++i)
  {
    if (aCB[i].Text)
    {
      nPos = FindInArray(aCB[i].Array, aCB[i].Text);

      if (nPos == -1)
      {
        if (aCB[i].Array.length == nMaxLenCBE)
        {
          aCB[i].Array.length = nMaxLenCBE - 1;
          AkelPad.SendMessage(aCB[i].HWND, 0x0144 /*CB_DELETESTRING*/, nMaxLenCBE - 1, 0);
        }

        aCB[i].Array.unshift(aCB[i].Text);
        AkelPad.SendMessage(aCB[i].HWND, 0x014A /*CB_INSERTSTRING*/, 0, aCB[i].Text);
      }
      else if (nPos > 0)
      {
        aCB[i].Array.splice(nPos, 1);
        aCB[i].Array.unshift(aCB[i].Text);
        AkelPad.SendMessage(aCB[i].HWND, 0x0144 /*CB_DELETESTRING*/, nPos, 0);
        AkelPad.SendMessage(aCB[i].HWND, 0x014A /*CB_INSERTSTRING*/, 0, aCB[i].Text);
        AkelPad.SendMessage(aCB[i].HWND, 0x014E /*CB_SETCURSEL*/, 0, 0);
      }
    }
  }
}

function SortFiles()
{
  var nSort = bSortDesc ? -1 : 1;
  var nCompare;

  aFiles.sort(
    function(sName1, sName2)
    {
      nCompare = nSort * oSys.Call("Kernel32::lstrcmpiW", sName1.substr(0, sName1.lastIndexOf("\\")), sName2.substr(0, sName2.lastIndexOf("\\")));

      if (nCompare == 0)
        return nSort * oSys.Call("Kernel32::lstrcmpiW", sName1, sName2);
      else
        return nCompare;
    });
}

function OpenFiles()
{
  if (aFiles.length)
  {
    var sFiles = "";
    var i;

    if (! hParent)
    {
      oSys.Call("User32::SetForegroundWindow", hMainWnd);
      oSys.Call("User32::SetForegroundWindow", hDlg);
    }

    GetSelArrayLV();

    if (! aFilesSel.length)
      aFilesSel = [GetCurFocLV()];
 
    for (i = 0; i < aFilesSel.length; ++i)
    {
      if (IsFileExists(aFiles[aFilesSel[i]]))
      {
        AkelPad.OpenFile(aFiles[aFilesSel[i]]);

        if (! AkelPad.IsMDI())
          break;
      }
      else
        sFiles += aFiles[aFilesSel[i]] + "\n";
    }

    if (sFiles)
      WarningBox(sFiles + "\n" + sTxtFileNoExist);
  }
}

function OpenOrCloseFile(bSelect)
{
  if (aFiles.length)
  {
    var nItem = GetCurFocLV();
    var rContent;

    if (nItem >= 0)
    {
      if (! hParent)
      {
        oSys.Call("User32::SetForegroundWindow", hMainWnd);
        oSys.Call("User32::SetForegroundWindow", hDlg);
      }

      if (aFiles[nItem].toUpperCase() == AkelPad.GetEditFile(0).toUpperCase())
      {
        if (AkelPad.IsMDI())
          AkelPad.Command(4318 /*IDM_WINDOW_FRAMECLOSE*/);
        else
          AkelPad.Command(4324 /*IDM_WINDOW_FILECLOSE*/);
      }
      else
      {
        if (IsFileExists(aFiles[nItem]))
        {
          if ((AkelPad.OpenFile(aFiles[nItem]) == 0 /*EOD_SUCCESS*/) && bSelect && sLastContent && (! bLastNotContain))
          {
            if (bLastContentRE)
            {
              rContent = new RegExp(sLastContent, (bLastMatchCase ? "" : "i") + (bLastMultiline ? "m" : ""));
              if (rContent.test(AkelPad.GetTextRange(0, -1, 0 /*new line as is*/)))
                AkelPad.SetSel(ByteOffsetToRichOffset(RegExp.index), ByteOffsetToRichOffset(RegExp.lastIndex));
            }
            else
              AkelPad.TextFind(0, sLastContent, 0x00200001 /*FRF_BEGINNING|FRF_DOWN*/ | (bLastMatchCase ? 0x00000004 /*FRF_MATCHCASE*/ : 0));
          }
        }
        else
          WarningBox(aFiles[nItem] + "\n\n" + sTxtFileNoExist);
      }
    }
  }
}

function ByteOffsetToRichOffset(nByteOffset)
{
  var hEditWnd      = AkelPad.GetEditWnd();
  var lpCharIndex1  = AkelPad.MemAlloc(_X64 ? 24 : 12 /*sizeof(AECHARINDEX)*/);
  var lpCharIndex2  = AkelPad.MemAlloc(_X64 ? 24 : 12 /*sizeof(AECHARINDEX)*/);
  var lpIndexOffset = AkelPad.MemAlloc(_X64 ? 32 : 16 /*sizeof(AEINDEXOFFSET)*/);
  var nRichOffset;

  AkelPad.MemCopy(lpIndexOffset, lpCharIndex1, DT_QWORD);
  AkelPad.MemCopy(lpIndexOffset + (_X64 ? 8 : 4), lpCharIndex2, DT_QWORD);
  AkelPad.MemCopy(lpIndexOffset + (_X64 ? 16 : 8), nByteOffset, DT_QWORD);
  AkelPad.MemCopy(lpIndexOffset + (_X64 ? 24 : 12), 3 /*AELB_ASIS*/, DT_DWORD);

  AkelPad.SendMessage(hEditWnd, 3130 /*AEM_GETINDEX*/, 1 /*AEGI_FIRSTCHAR*/, lpCharIndex1);
  AkelPad.SendMessage(hEditWnd, 3135 /*AEM_INDEXOFFSET*/, 0, lpIndexOffset);

  nRichOffset = AkelPad.SendMessage(hEditWnd, 3136 /*AEM_INDEXTORICHOFFSET*/, 0, lpCharIndex2);

  AkelPad.MemFree(lpIndexOffset);
  AkelPad.MemFree(lpCharIndex1);
  AkelPad.MemFree(lpCharIndex2);

  return nRichOffset;
}

function CopyList()
{
  if (aFiles.length)
    AkelPad.SetClipboardText(aFiles.join("\r\n"));
}

function CopySelected()
{
  if (aFiles.length)
  {
    var sText = "";

    GetSelArrayLV();

    if (! aFilesSel.length)
      aFilesSel = [GetCurFocLV()];

    for (i = 0; i < aFilesSel.length; ++i)
      sText += aFiles[aFilesSel[i]] + "\r\n";

    AkelPad.SetClipboardText(sText);
  }
}

function ClearList()
{
  if (aFiles.length)
  {
    aFiles    = [];
    aFilesSel = [0];

    FillLV();
    EnableButtons();
    oSys.Call("User32::SetFocus", aDlg[IDFILELV].HWND);
  }
}

function RemoveFromList()
{
  if (aFiles.length)
  {
    SetTextSB(-2);
    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x000B /*WM_SETREDRAW*/, 0, 0);
    AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x000B /*WM_SETREDRAW*/, 0, 0);
    GetSelArrayLV();

    if (! aFilesSel.length)
      aFilesSel = [GetCurFocLV()];

    for (i = aFilesSel.length - 1; i >= 0; --i)
    {
      aFiles.splice(aFilesSel[i], 1);
      AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x1008 /*LVM_DELETEITEM*/, aFilesSel[i], 0);
    }

    AkelPad.SendMessage(aDlg[IDFILELV].HWND, 0x000B /*WM_SETREDRAW*/, 1, 0);
    AkelPad.SendMessage(aDlg[IDSTATUS].HWND, 0x000B /*WM_SETREDRAW*/, 1, 0);

    if (aFiles.length)
    {
      SetSelLV(aFilesSel[aFilesSel.length - 1] - aFilesSel.length + 1);
      if (GetNextSelLV(-1) < 0)
        SetSelLV(aFiles.length - 1);
    }
    else
    {
      FillLV();
      EnableButtons();
    }
  }
}

function Settings()
{
  var MF_STRING    = 0x0000;
  var MF_CHECKED   = 0x0008;
  var MF_SEPARATOR = 0x0800;
  var hMenu = oSys.Call("User32::CreatePopupMenu");
  var oRect = {};
  var nCmd;

  GetWindowPos(aDlg[IDSETTINGSB].HWND, oRect);

  oSys.Call("User32::AppendMenuW", hMenu, (bPathShow    ? MF_CHECKED : MF_STRING), 1, sTxtPathShow);
  oSys.Call("User32::AppendMenuW", hMenu, MF_SEPARATOR);
  oSys.Call("User32::AppendMenuW", hMenu, (bKeepFiles   ? MF_CHECKED : MF_STRING), 2, sTxtKeepFiles);
  oSys.Call("User32::AppendMenuW", hMenu, (bSeparateWnd ? MF_CHECKED : MF_STRING), 3, sTxtSeparateWnd);

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0188 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_RIGHTALIGN*/, oRect.X + oRect.W, oRect.Y + oRect.H, 0, hDlg, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  if (nCmd == 1)
  {
    bPathShow = ! bPathShow;
    nFilesFoc = GetCurFocLV();
    GetSelArrayLV();
    FillLV();
  }
  else if (nCmd == 2)
    bKeepFiles = ! bKeepFiles;
  else if (nCmd == 3)
  {
    bSeparateWnd = ! bSeparateWnd;
    bCloseDlg    = false;
    oSys.Call("User32::PostMessageW", hDlg, 16 /*WM_CLOSE*/, 0, 0);
  }
}

function WarningBox(sText, bQuestion)
{
  var nType = 0x0030 /*MB_ICONWARNING*/;

  if (bQuestion)
    nType |= 0x0001 /*MB_OKCANCEL*/ | 0x0100 /*MB_DEFBUTTON2*/;

  if (AkelPad.MessageBox(hDlg, sText, sTxtScriptName, nType) == 1 /*IDOK*/)
    return true;
}

function ReadIni()
{
  var sLngFile = WScript.ScriptFullName.replace(/\.js$/i, "_" + AkelPad.GetLangId(0 /*LANGID_FULL*/).toString() + ".lng");

  if (IsFileExists(sLngFile))
  {
    try
    {
      eval(AkelPad.ReadFile(sLngFile));
    }
    catch (oError)
    {
      GetLangStrings();
    }
  }
  else
    GetLangStrings();

  try
  {
    eval(AkelPad.ReadFile(WScript.ScriptFullName.replace(/js$/i, "ini"), 0x10 /*OD_ADT_NOMESSAGES*/, 1200 /*UTF-16LE*/, true));
  }
  catch (oError)
  {}

  if (aDirs.length > nMaxLenCBE)
    aDirs.length = nMaxLenCBE;
  if (aNames.length > nMaxLenCBE)
    aNames.length = nMaxLenCBE;
  if (aContents.length > nMaxLenCBE)
    aContents.length = nMaxLenCBE;
}

function WriteIni()
{
  var sIniTxt = "";
  var i;

  oWndPos.W   = Scale.UX(oWndPos.W);
  oWndPos.H   = Scale.UY(oWndPos.H);
  oWndPos.Max = oSys.Call("User32::IsZoomed", hDlg);
  sDir        = GetWindowText(aDlg[IDDIRCB].HWND);
  sName       = GetWindowText(aDlg[IDNAMECB].HWND);
  sContent    = GetWindowText(aDlg[IDCONTENTCB].HWND);
  sReplace    = GetWindowText(aDlg[IDREPLACECB].HWND);

  if (bKeepFiles)
  {
    GetSelArrayLV();
    nFilesFoc = GetCurFocLV();
  }
  else
  {
    aFiles    = [];
    aFilesSel = [0];
    nFilesFoc = 0;
  }

  for (i in oWndPos)
    sIniTxt += 'oWndPos.' + i + '=' + oWndPos[i] + ';\r\n';

  sIniTxt +=
    'bSeparateWnd='    + bSeparateWnd + ';\r\n' +
    'bKeepFiles='      + bKeepFiles + ';\r\n' +
    'bPathShow='       + bPathShow + ';\r\n' +
    'nPathLen='        + nPathLen + ';\r\n' +
    'bSortDesc='       + bSortDesc + ';\r\n' +
    'nDirLevel='       + nDirLevel + ';\r\n' +
    'bNameRE='         + bNameRE + ';\r\n' +
    'bNotName='        + bNotName + ';\r\n' +
    'bInFiles='        + bInFiles + ';\r\n' +
    'bInStreams='      + bInStreams + ';\r\n' +
    'bSkipReadOnly='   + bSkipReadOnly + ';\r\n' +
    'bSkipHidden='     + bSkipHidden + ';\r\n' +
    'bSkipSystem='     + bSkipSystem + ';\r\n' +
    'bContentRE='      + bContentRE + ';\r\n' +
    'bMatchCase='      + bMatchCase + ';\r\n' +
    'bMultiline='      + bMultiline + ';\r\n' +
    'bNotContain='     + bNotContain + ';\r\n' +
    'bSkipBinary='     + bSkipBinary + ';\r\n' +
    'bSkipLarger='     + bSkipLarger + ';\r\n' +
    'nMaxFileSize='    + nMaxFileSize + ';\r\n' +
    'sDir="'           + sDir.replace(/[\\"]/g, '\\$&') + '";\r\n' +
    'sName="'          + sName.replace(/[\\"]/g, '\\$&') + '";\r\n' +
    'sContent="'       + sContent.replace(/[\\"]/g, '\\$&') + '";\r\n' +
    'sReplace="'       + sReplace.replace(/[\\"]/g, '\\$&') + '";\r\n' +
    'sLastContent="'   + sLastContent.replace(/[\\"]/g, '\\$&') + '";\r\n' +
    'bLastContentRE='  + bLastContentRE + ';\r\n' +
    'bLastMatchCase='  + bLastMatchCase + ';\r\n' +
    'bLastMultiline='  + bLastMultiline + ';\r\n' +
    'bLastNotContain=' + bLastNotContain + ';\r\n' +
    'bAfterReplace='   + bAfterReplace + ';\r\n' +
    'aDirs=['          + aDirs.join('\t').replace(/[\\"]/g, '\\$&').replace(/\t/g, '","').replace(/.+/, '"$&"') +'];\r\n' +
    'aNames=['         + aNames.join('\t').replace(/[\\"]/g, '\\$&').replace(/\t/g, '","').replace(/.+/, '"$&"') +'];\r\n' +
    'aContents=['      + aContents.join('\t').replace(/[\\"]/g, '\\$&').replace(/\t/g, '","').replace(/.+/, '"$&"') +'];\r\n' +
    'aReplace=['       + aReplace.join('\t').replace(/[\\"]/g, '\\$&').replace(/\t/g, '","').replace(/.+/, '"$&"') +'];\r\n' +
    'aFiles=['         + aFiles.join('\t').replace(/[\\"]/g, '\\$&').replace(/\t/g, '","').replace(/.+/, '"$&"') +'];\r\n' +
    'aFilesSel=['      + aFilesSel +'];\r\n' +
    'nFilesFoc='       + nFilesFoc +';';


  AkelPad.WriteFile(WScript.ScriptFullName.replace(/js$/i, "ini"), sIniTxt, sIniTxt.length, 1200 /*UTF-16LE*/, true);
}

function GetLangStrings()
{
  sTxtScriptName  = "Find/Replace files";
  sTxtDir         = "&Directory";
  sTxtCurrent     = "C&urrent";
  sTxtBrowse      = "&Browse...";
  sTxtSubDirs     = "Subdirectories &level:";
  sTxtAll         = "All";
  sTxtFileName    = "File:Stream &names";
  sTxtRegExp      = "Regular e&xpressions";
  sTxtNotName     = "Not matching names";
  sTxtFiles       = "Files (main streams)";
  sTxtStreams     = "Alternate NTFS streams";
  sTxtTextInFile  = "&Text in file/stream";
  sTxtMatchCase   = "Match &case";
  sTxtMultiline   = "&Multiline";
  sTxtNotContain  = "Not contain text";
  sTxtSkipBinary  = "Skip binary files";
  sTxtSkipLarger  = "Skip larger [B]:";
  sTxtReplaceWith = "Replace &with:";
  sTxtSkip        = "Skip";
  sTxtSearch      = "&Search";
  sTxtReplace     = "&Replace";
  sTxtEdit        = "&Edit";
  sTxtCopyList    = "Copy list";
  sTxtClearList   = "Clear list";
  sTxtSettings    = "Settings";
  sTxtClose       = "Close";
  sTxtFilesFound  = "Files found";
  sTxtFilesRepl   = "Files replaced";
  sTxtNoFiles     = "<no files>";
  sTxtSeparateWnd = "Run in separate window";
  sTxtKeepFiles   = "Keep files list";
  sTxtPathShow    = "Show full path in files list";
  sTxtChooseDir   = "Choose directory:";
  sTxtDirNoExist  = "Directory does not exists.";
  sTxtFileNoExist = "File(s) does not exists.";
  sTxtErrorRE     = "Error in regular expression.";
  sTxtWantReplace = "Do you want to replace contents of files?\n\nWarning: this operation can not be undone.";
  sTxtByteSymbol  = "B";
  sTxtNTFSStream  = "NTFS stream";
  sTxtWait        = "Wait...";
  sHlpAnyChar     = "any single character";
  sHlpAnyString   = "any string of characters";
  sHlpSemicolQuot = "semicolon must be in double quotes";
  sHlpListSepar   = "list separator (semicolon)";
  sHlpStreamSepar = "File:Stream separator (colon)";
  sHlpAnyChar_NL  = "any character, except \\n";
  sHlpDigit       = "digit [0-9]";
  sHlpNonDigit    = "non-digit [^0-9]";
  sHlpWhiteSp     = "whitespace [ \\f\\n\\r\\t\\v]";
  sHlpNonWhiteSp  = "non-whitespace";
  sHlpWordChar    = "word character [A-Za-z0-9_]";
  sHlpNonWordChar = "non-word character";
  sHlpNULL        = "NULL character";
  sHlpFF          = "form feed \\x0C";
  sHlpNL          = "new line \\x0A";
  sHlpCR          = "carriage return \\x0D";
  sHlpTab         = "tab \\x09";
  sHlpVTab        = "vertical tab \\x0B";
  sHlpCharHex     = "character hex code FF";
  sHlpUniCharHex  = "Unicode char hex code 00FF";
  sHlpBegin       = "beginning of string/line";
  sHlpEnd         = "end of string/line";
  sHlpWordBoun    = "word boundary";
  sHlpNonWordBoun = "non-word boundary";
  sHlpAlternative = "alternative ab or xy";
  sHlpCharSet     = "character set, any specified";
  sHlpNegCharSet  = "negative character set";
  sHlpRange       = "range of chars from a to z";
  sHlpNegRange    = "negative range of chars";
  sHlpCapture     = "capture";
  sHlpNotCapture  = "not capture";
  sHlpFollow      = "followed by ab";
  sHlpNotFollow   = "not followed by ab";
  sHlpBackrefer9  = "backreference, range 1-9";
  sHlpBackrefer99 = "backreference, range 01-99";
  sHlpZeroOrOne   = "zero or one times";
  sHlpZeroOrMore  = "zero or more times";
  sHlpOneOrMore   = "one or more times";
  sHlpexactly     = "exactly 3 times";
  sHlpAtLeast     = "at least 3 times";
  sHlpFromTo      = "from 3 to 7 times";
  sHlpSpecChars   = "()[]{}^$.?+*|\\ special chars";
  sHlpDollar      = "dollar character";
  sHlpEntireStr   = "entire string matched";
  sHlpPrecedeStr  = "substring that precedes matched string";
  sHlpFollowStr   = "substring that follows after matched string";
  sHlpSubmatch9   = "9th captured submatch, range 1-9";
  sHlpSubmatch99  = "99th captured submatch, range 01-99";
  sHlpBackslash   = "backslash";
}


Interface language files for FindReplaceFiles.js.
FindReplaceFiles_1033.lng

Code:
/********************************
FindReplaceFiles.js - ver. 2014-07-03
Interface language
Language:      English (1033)
Translated by: KDJ
*********************************/
sTxtScriptName  = "Find/Replace files";
sTxtDir         = "&Directory";
sTxtCurrent     = "C&urrent";
sTxtBrowse      = "&Browse...";
sTxtSubDirs     = "Subdirectories &level:";
sTxtAll         = "All";
sTxtFileName    = "File:Stream &names";
sTxtRegExp      = "Regular e&xpressions";
sTxtNotName     = "Not matching names";
sTxtFiles       = "Files (main streams)";
sTxtStreams     = "Alternate NTFS streams";
sTxtTextInFile  = "&Text in file/stream";
sTxtMatchCase   = "Match &case";
sTxtMultiline   = "&Multiline";
sTxtNotContain  = "Not contain text";
sTxtSkipBinary  = "Skip binary files";
sTxtSkipLarger  = "Skip larger [B]:";
sTxtReplaceWith = "Replace &with:";
sTxtSkip        = "Skip";
sTxtSearch      = "&Search";
sTxtReplace     = "&Replace";
sTxtEdit        = "&Edit";
sTxtCopyList    = "Copy list";
sTxtClearList   = "Clear list";
sTxtSettings    = "Settings";
sTxtClose       = "Close";
sTxtFilesFound  = "Files found";
sTxtFilesRepl   = "Files replaced";
sTxtNoFiles     = "<no files>";
sTxtSeparateWnd = "Run in separate window";
sTxtKeepFiles   = "Keep files list";
sTxtPathShow    = "Show full path in files list";
sTxtChooseDir   = "Choose directory:";
sTxtDirNoExist  = "Directory does not exists.";
sTxtFileNoExist = "Files does not exists.";
sTxtErrorRE     = "Error in regular expression.";
sTxtWantReplace = "Do you want to replace contents of files?\n\nWarning: this operation can not be undone.";
sTxtByteSymbol  = "B";
sTxtNTFSStream  = "NTFS stream";
sTxtWait        = "Wait...";
sHlpAnyChar     = "any single character";
sHlpAnyString   = "any string of characters";
sHlpSemicolQuot = "semicolon must be in double quotes";
sHlpListSepar   = "list separator (semicolon)";
sHlpStreamSepar = "File:Stream separator (colon)";
sHlpAnyChar_NL  = "any character, except \\n";
sHlpDigit       = "digit [0-9]";
sHlpNonDigit    = "non-digit [^0-9]";
sHlpWhiteSp     = "whitespace [ \\f\\n\\r\\t\\v]";
sHlpNonWhiteSp  = "non-whitespace";
sHlpWordChar    = "word character [A-Za-z0-9_]";
sHlpNonWordChar = "non-word character";
sHlpNULL        = "NULL character";
sHlpFF          = "form feed \\x0C";
sHlpNL          = "new line \\x0A";
sHlpCR          = "carriage return \\x0D";
sHlpTab         = "tab \\x09";
sHlpVTab        = "vertical tab \\x0B";
sHlpCharHex     = "character hex code FF";
sHlpUniCharHex  = "Unicode char hex code 00FF";
sHlpBegin       = "beginning of string/line";
sHlpEnd         = "end of string/line";
sHlpWordBoun    = "word boundary";
sHlpNonWordBoun = "non-word boundary";
sHlpAlternative = "alternative ab or xy";
sHlpCharSet     = "character set, any specified";
sHlpNegCharSet  = "negative character set";
sHlpRange       = "range of chars from a to z";
sHlpNegRange    = "negative range of chars";
sHlpCapture     = "capture";
sHlpNotCapture  = "not capture";
sHlpFollow      = "followed by ab";
sHlpNotFollow   = "not followed by ab";
sHlpBackrefer9  = "backreference, range 1-9";
sHlpBackrefer99 = "backreference, range 01-99";
sHlpZeroOrOne   = "zero or one times";
sHlpZeroOrMore  = "zero or more times";
sHlpOneOrMore   = "one or more times";
sHlpexactly     = "exactly 3 times";
sHlpAtLeast     = "at least 3 times";
sHlpFromTo      = "from 3 to 7 times";
sHlpSpecChars   = "()[]{}^$.?+*|\\ special chars";
sHlpDollar      = "dollar character";
sHlpEntireStr   = "entire string matched";
sHlpPrecedeStr  = "substring that precedes matched string";
sHlpFollowStr   = "substring that follows after matched string";
sHlpSubmatch9   = "9th captured submatch, range 1-9";
sHlpSubmatch99  = "99th captured submatch, range 01-99";
sHlpBackslash   = "backslash";
- English template for translation
FindReplaceFiles_1045.lng

Code:
/********************************
FindReplaceFiles.js - ver. 2014-07-03
Interface language
Language:      Polish (1045)
Translated by: KDJ
*********************************/
sTxtScriptName  = "Znajdź/Zamień pliki";
sTxtDir         = "&Katalog";
sTxtCurrent     = "&Bieżący";
sTxtBrowse      = "&Przeglądaj...";
sTxtSubDirs     = "Poziom podkata&logów:";
sTxtAll         = "Wszystkie";
sTxtFileName    = "&Nazwy Plik:Strumień";
sTxtRegExp      = "Wyrażenia &regularne";
sTxtNotName     = "Nie pasujące nazwy";
sTxtFiles       = "Pliki (główne strumienie)";
sTxtStreams     = "Alternatywne strumienie NTFS";
sTxtTextInFile  = "&Tekst w pliku/strumieniu";
sTxtMatchCase   = "Uwzględnij wielkość liter";
sTxtMultiline   = "&Multiline";
sTxtNotContain  = "Nie zawiera tekstu";
sTxtSkipBinary  = "Pomiń pliki binarne";
sTxtSkipLarger  = "Pomiń większe [B]:";
sTxtReplaceWith = "Zamień na:";
sTxtSkip        = "Pomiń";
sTxtSearch      = "&Szukaj";
sTxtReplace     = "&Zamień";
sTxtEdit        = "&Edytuj";
sTxtCopyList    = "Kopiuj listę";
sTxtClearList   = "Wyczyść listę";
sTxtSettings    = "Ustawienia";
sTxtClose       = "Zamknij";
sTxtFilesFound  = "Pliki znalezione";
sTxtFilesRepl   = "Pliki zamienione";
sTxtNoFiles     = "<brak plików>";
sTxtSeparateWnd = "Uruchom w oddzielnym oknie";
sTxtKeepFiles   = "Zachowaj listę plików";
sTxtPathShow    = "Pokazuj pełną ścieżkę na liście plików";
sTxtChooseDir   = "Wybierz katalog:";
sTxtDirNoExist  = "Katalog nie istnieje.";
sTxtFileNoExist = "Pliki nie istnieją.";
sTxtErrorRE     = "Błąd w wyrażeniu regularnym.";
sTxtWantReplace = "Czy chcesz zamienić zawartość plików?\n\nOstrzeżenie: tej operacji nie można cofnąć.";
sTxtByteSymbol  = "B";
sTxtNTFSStream  = "Strumień NTFS";
sTxtWait        = "Czekaj...";
sHlpAnyChar     = "dowolny pojedynczy znak";
sHlpAnyString   = "dowolny ciąg znaków";
sHlpSemicolQuot = "średnik musi być w podwójnych cudzysłowach";
sHlpListSepar   = "separator listy (średnik)";
sHlpStreamSepar = "separator Plik:Strumień (dwukropek)";
sHlpAnyChar_NL  = "dowolny znak, oprócz \\n";
sHlpDigit       = "cyfra [0-9]";
sHlpNonDigit    = "nie cyfra [^0-9]";
sHlpWhiteSp     = "biały znak [ \\f\\n\\r\\t\\v]";
sHlpNonWhiteSp  = "nie biały znak";
sHlpWordChar    = "znak słowa [A-Za-z0-9_]";
sHlpNonWordChar = "inny niż znak słowa";
sHlpNULL        = "znak NULL";
sHlpFF          = "wysuw strony \\x0C";
sHlpNL          = "nowy wiersz \\x0A";
sHlpCR          = "powrót karetki \\x0D";
sHlpTab         = "tab \\x09";
sHlpVTab        = "pionowy tab \\x0B";
sHlpCharHex     = "znak o kodzie hex FF";
sHlpUniCharHex  = "znak Unicode o kodzie 00FF";
sHlpBegin       = "początek tekstu/wiersza";
sHlpEnd         = "koniec tekstu/wiersza";
sHlpWordBoun    = "granica słowa";
sHlpNonWordBoun = "brak granicy słowa";
sHlpAlternative = "alternatywa ab lub xy";
sHlpCharSet     = "zestaw znaków, dowolny z abc";
sHlpNegCharSet  = "zaprzeczenie zestawu znaków";
sHlpRange       = "zakres znaków od a do z";
sHlpNegRange    = "zaprzeczenie zakresu znaków";
sHlpCapture     = "przechwytuje";
sHlpNotCapture  = "nie przechwytuje";
sHlpFollow      = "za ciągiem jest ab";
sHlpNotFollow   = "za ciągiem nie ma ab";
sHlpBackrefer9  = "odwołanie wsteczne, zakres 1-9";
sHlpBackrefer99 = "odwołanie wsteczne, zakres 01-99";
sHlpZeroOrOne   = "zero lub jeden raz";
sHlpZeroOrMore  = "zero lub więcej razy";
sHlpOneOrMore   = "jeden lub więcej razy";
sHlpexactly     = "dokładnie 3 razy";
sHlpAtLeast     = "co najmniej 3 razy";
sHlpFromTo      = "od 3 do 7 razy";
sHlpSpecChars   = "()[]{}^$.?+*|\\ znaki specjalne";
sHlpDollar      = "znak dolara";
sHlpEntireStr   = "cały dopasowany ciąg";
sHlpPrecedeStr  = "tekst poprzedzający dopasowany ciąg";
sHlpFollowStr   = "tekst za dopasowanym ciągiem";
sHlpSubmatch9   = "9-ty dopasowany podciąg, zakres 1-9";
sHlpSubmatch99  = "99-ty dopasowany podciąg, zakres 01-99";
sHlpBackslash   = "backslash";
- Polish
FindReplaceFiles_1049.lng

Code:
/*****************************************
FindReplaceFiles.js - ver. 2014-07-03
Interface language
Language:      Russian (1049)
Translated by: Averin Andrey & F. Phoenix
******************************************/
sTxtScriptName  = "Поиск файлов";                                    //changed in English: "Find/Replace files"
sTxtDir         = "&Каталог";
sTxtCurrent     = "&Текущий";
sTxtBrowse      = "&Выбрать...";
sTxtSubDirs     = "Подкаталоги &уровень:";
sTxtAll         = "Все";
sTxtFileName    = "&Имя файла";                                      //changed in English: "File:Stream &names"
sTxtRegExp      = "Регулярные выражения";
sTxtNotName     = "Кроме этих имён";
sTxtFiles       = "Files (main streams)";                            //new
sTxtStreams     = "Alternate NTFS streams";                          //new
sTxtTextInFile  = "&Текст в файле";                                  //changed in English: "&Text in file/stream"
sTxtMatchCase   = "С учетом регистра";
sTxtMultiline   = "Многострочно";
sTxtNotContain  = "Не содержащие текст";
sTxtSkipBinary  = "Не искать в бинарных";                            //changed in English: "Skip binary files"
sTxtSkipLarger  = "Skip larger [B]:";                                //changed, previously it was "Не искать в файлах крупнее:"
sTxtReplaceWith = "Replace with:";                                   //new
sTxtSkip        = "Skip";                                            //new
sTxtSearch      = "Искать";
sTxtReplace     = "Replace";                                         //new
sTxtEdit        = "Правка";
sTxtCopyList    = "Копировать";
sTxtClearList   = "Очистить";
sTxtSettings    = "Настройки";
sTxtClose       = "Закрыть";
sTxtFilesFound  = "Files found";                                     //new
sTxtFilesRepl   = "Files replaced";                                  //new
sTxtNoFiles     = "<нет файлов>";
sTxtSeparateWnd = "Запустить в отдельном окне";
sTxtKeepFiles   = "Вывод списка файлов";
sTxtPathShow    = "Показать полный путь в списке файлов";
sTxtChooseDir   = "Выберите каталог:";
sTxtDirNoExist  = "Каталог не существует.";
sTxtFileNoExist = "Файлы не существуют.";
sTxtErrorRE     = "Ошибка в регулярном выражении.";
sTxtWantReplace = "Do you want to replace contents of files?\n\nWarning: this operation can not be undone.";        //new
sTxtByteSymbol  = "Б";
sTxtNTFSStream  = "Поток NTFS";
sTxtWait        = "Подождите...";
sHlpAnyChar     = "любой одиночный символ";
sHlpAnyString   = "любая подстрока";
sHlpSemicolQuot = "точка с запятой (если внутри кавычек)";
sHlpListSepar   = "разделитель списка имен (вне кавычек)";
sHlpStreamSepar = "File:Stream separator (colon)";                   //new
sHlpAnyChar_NL  = "любой символ, кроме \\n";
sHlpDigit       = "цифра [0-9]";
sHlpNonDigit    = "не цифра [^0-9]";
sHlpWhiteSp     = "пробельный символ [ \\f\\n\\r\\t\\v]";
sHlpNonWhiteSp  = "непробельный символ";
sHlpWordChar    = "словесный символ [A-Za-z0-9_]";
sHlpNonWordChar = "несловесный символ";
sHlpNULL        = "нулевой символ";
sHlpFF          = "перевод страницы \\x0C";
sHlpNL          = "перевод строки \\x0A";
sHlpCR          = "возврат каретки \\x0D";
sHlpTab         = "табуляция \\x09";
sHlpVTab        = "вертикальная табуляция \\x0B";
sHlpCharHex     = "символ с кодом FF";
sHlpUniCharHex  = "символ юникода 00FF";
sHlpBegin       = "начало строки или текста";
sHlpEnd         = "конец строки или текста";
sHlpWordBoun    = "граница слова";
sHlpNonWordBoun = "не граница слова";
sHlpAlternative = "одна из альтернатив: ab либо xy";
sHlpCharSet     = "набор символов, нужен любой из них";
sHlpNegCharSet  = "исключающий набор символов";
sHlpRange       = "диапазон символов от a до z";
sHlpNegRange    = "исключающий диапазон";
sHlpCapture     = "запоминающая скобка";
sHlpNotCapture  = "незапоминающая скобка";
sHlpFollow      = "далее следует ab";
sHlpNotFollow   = "далее не следует ab";
sHlpBackrefer9  = "обратная ссылка, диапазон 1-9";
sHlpBackrefer99 = "обратная ссылка, диапазон 01-99";
sHlpZeroOrOne   = "0 или 1 раз";
sHlpZeroOrMore  = "0 или более раз";
sHlpOneOrMore   = "1 или более раз";
sHlpexactly     = "ровно 3 раза";
sHlpAtLeast     = "не менее 3 раз";
sHlpFromTo      = "от 3 до 7 раз";
sHlpSpecChars   = "()[]{}^$.?+*|\\ специальные символы";
sHlpDollar      = "dollar character";                                //new
sHlpEntireStr   = "вся захваченная строка";
sHlpPrecedeStr  = "substring that precedes matched string";          //new
sHlpFollowStr   = "substring that follows after matched string";     //new
sHlpSubmatch9   = "9я подстрока (диапазон 1-9)";
sHlpSubmatch99  = "99я подстрока (диапазон 01-99)";
sHlpBackslash   = "обратный слеш";
- Russian by Andrey_A_A & F. Phoenix
FindReplaceFiles_2052.lng

Code:
/********************************
FindReplaceFiles.js - ver. 2014-07-03
Interface language
Language:      ChineseSimplified (2052)
Translated by: cnnnc
*********************************/
sTxtScriptName  = "查找文件";                                            //changed in English: "Find/Replace files"
sTxtDir         = "目录(&D)";
sTxtCurrent     = "当前(&C)";
sTxtBrowse      = "浏览(&B)...";
sTxtSubDirs     = "子目录层数(&L):";
sTxtAll         = "所有";
sTxtFileName    = "文件名称(&N)";                                        //changed in English: "File:Stream &names"
sTxtRegExp      = "正则表达式";
sTxtNotName     = "不匹配名称";
sTxtFiles       = "Files (main streams)";                            //new
sTxtStreams     = "Alternate NTFS streams";                          //new
sTxtTextInFile  = "文件内容(&T)";                                        //changed in English: "&Text in file/stream"
sTxtMatchCase   = "区分大小写";
sTxtMultiline   = "多行";
sTxtNotContain  = "不包含文字";
sTxtSkipBinary  = "不在二进制文件中搜索";                                      //changed in English: "Skip binary files"
sTxtSkipLarger  = "不搜索文件\n大小大于:";                                    //changed in English: "Skip larger [B]:"
sTxtReplaceWith = "Replace with:";                                   //new
sTxtSkip        = "Skip";                                            //new
sTxtSearch      = "搜索";
sTxtReplace     = "Replace";                                         //new
sTxtEdit        = "编辑";
sTxtCopyList    = "复制列表";
sTxtClearList   = "清空列表";
sTxtSettings    = "设置";
sTxtClose       = "关闭";
sTxtFilesFound  = "Files found";                                     //new
sTxtFilesRepl   = "Files replaced";                                  //new
sTxtNoFiles     = "<无文件>";
sTxtSeparateWnd = "在独立窗口运行";
sTxtKeepFiles   = "保留文件列表";
sTxtPathShow    = "文件列表中显示完整路径";
sTxtChooseDir   = "请选择目录:";
sTxtDirNoExist  = "目录不存在。";
sTxtFileNoExist = "文件不存在。";
sTxtErrorRE     = "正则表达式错误。";
sTxtWantReplace = "Do you want to replace contents of files?\n\nWarning: this operation can not be undone.";        //new
sTxtByteSymbol  = "字节";
sTxtNTFSStream  = "NTFS 数据流";
sTxtWait        = "请稍候...";
sHlpAnyChar     = "任意单一字符";
sHlpAnyString   = "任意个字符的字符串";
sHlpSemicolQuot = "分号必须在双引号中";
sHlpListSepar   = "列表分隔符(分号)";
sHlpStreamSepar = "File:Stream separator (colon)";                   //new
sHlpAnyChar_NL  = "任意单一字符,除了 \\n";
sHlpDigit       = "数字 [0-9]";
sHlpNonDigit    = "非数字 [^0-9]";
sHlpWhiteSp     = "空白字符 [ \\f\\n\\r\\t\\v]";
sHlpNonWhiteSp  = "非空白字符";
sHlpWordChar    = "单词字符 [A-Za-z0-9_]";
sHlpNonWordChar = "非单词字符";
sHlpNULL        = "NULL 字符";
sHlpFF          = "换页符 \\x0C";
sHlpNL          = "换行符 \\x0A";
sHlpCR          = "回车符 \\x0D";
sHlpTab         = "制表符 \\x09";
sHlpVTab        = "垂直制表符 \\x0B";
sHlpCharHex     = "字符 16 进制编码 FF";
sHlpUniCharHex  = "Unicode 字符 16 进制编码 00FF";
sHlpBegin       = "字串/行的开头";
sHlpEnd         = "字串/行的末尾";
sHlpWordBoun    = "单词边界";
sHlpNonWordBoun = "非单词边界";
sHlpAlternative = "匹配 ab 或 xy";
sHlpCharSet     = "字符集合, 匹配所包含的任意一个字符";
sHlpNegCharSet  = "负值字符集合,匹配未包含的任意字符";
sHlpRange       = "匹配 a 到 z 范围内的任意小写字母字符";
sHlpNegRange    = "匹配任何不在 a 到 z 范围内的任意字符";
sHlpCapture     = "匹配 ab 并获取这一匹配";
sHlpNotCapture  = "匹配 ab 但不获取匹配";
sHlpFollow      = "在任何匹配 ab 的字符串开始处匹配查找字符串";
sHlpNotFollow   = "在任何不匹配 ab 的字符串开始处匹配查找字符串";
sHlpBackrefer9  = "向后引用, 范围 1-9";
sHlpBackrefer99 = "向后引用, 范围 01-99";
sHlpZeroOrOne   = "匹配前面的子表达式零次或一次";
sHlpZeroOrMore  = "匹配前面的子表达式零次或多次";
sHlpOneOrMore   = "匹配前面的子表达式一次或多次";
sHlpexactly     = "精确匹配 3 次";
sHlpAtLeast     = "最少匹配 3 次";
sHlpFromTo      = "匹配 3 到 7 次的";
sHlpSpecChars   = "()[]{}^$.?+*|\\ 特殊符号";
sHlpDollar      = "dollar character";                                //new
sHlpEntireStr   = "匹配整个字符串";
sHlpPrecedeStr  = "substring that precedes matched string";          //new
sHlpFollowStr   = "substring that follows after matched string";     //new
sHlpSubmatch9   = "第 9 个捕捉子匹配, 范围 1-9";
sHlpSubmatch99  = "第 99 个捕捉子匹配, 范围 01-99";
sHlpBackslash   = "反斜线";
- Chinese-Simplified by cnnnc


Last edited by KDJ on Thu Jul 03, 2014 5:52 pm; edited 20 times in total
Back to top
View user's profile Send private message
VladSh



Joined: 29 Nov 2006
Posts: 2602
Location: Киев, Русь

PostPosted: Mon Nov 05, 2012 12:32 pm    Post subject: Reply with quote

ParagraphCreate.js

Code:
/// Formation paragraph by previous line indented
/// Формирование отступа по предыдущей строке
//  http://akelpad.sourceforge.net/forum/viewtopic.php?p=20315#20315
//  Version: 1.1 (2012.11.05)

if (AkelPad.IsAkelEdit()) {
   if (! AkelPad.Include("selCompleteLine.js")) WScript.Quit();
   var paragraph = "";
   var nPos = AkelPad.GetSelStart();
   var oRange = getRangeCompleteLine(nPos, nPos);
   var sLine = getTextbyRange(oRange);
   var oValues = separateRow(sLine);
   if (oValues.right) {
      // находимся на строке с текстом
      paragraph = pBreak + oValues.left + addedShiftBlock(oValues.right);
      nPos = oRange[1];
   }
   else {
      // находимся на пустой строке или это первая строка файла
      if (oValues.left || oRange[0] == 0) {
         // начальный отступ уже имеется - проставляем обычный отступ, беря из настроек
         paragraph = getShift();
      }
      else {
         // начальный отступ отсутствует - пытаемся взять его с предыдущей строки, как это делает Eclipse
         nPos = oRange[0] - 1;
         oRange = getRangeCompleteLine(nPos, nPos);
         sLine = getTextbyRange(oRange);
         oValues = separateRow(sLine);
         if (oValues.left)
            paragraph = oValues.left + addedShiftBlock(oValues.right);
         else
            paragraph = getShift();
         nPos = oRange[1] + 1;
      }
   }
   AkelPad.SetSel(nPos, nPos);
   AkelPad.ReplaceSel(paragraph);
}

// Определяем, необходим ли дополнительный отступ;
// необходим когда предыдущая строка является началом блока
function addedShiftBlock(lineValuePrev) {
   var sh = "";
   if (lineValuePrev.charAt(lineValuePrev.length - 1) == "{")
         sh = getShift();
   return sh;
}

Script used selCompleteLine.js.
Back to top
View user's profile Send private message Visit poster's website
Fr0sT



Joined: 24 Jul 2007
Posts: 876

PostPosted: Tue Nov 27, 2012 11:03 am    Post subject: Reply with quote

OpenAsEmail.js
Code:

// Open raw email file in associated mailer ("eml" extension must be registered in OS)

var fso=new ActiveXObject("Scripting.FileSystemObject");
var sh=new ActiveXObject("Shell.Application");

var hMainWnd=AkelPad.GetMainWnd();
var pFileFullName=AkelPad.GetEditFile(0);

if (hMainWnd && pFileFullName && fso && sh)
{
   // construct new file name in TEMP folder with .eml extension
   pNewFileName = fso.BuildPath(fso.GetSpecialFolder(2), fso.GetBaseName(pFileFullName) + ".eml");
   // create temporary copy of the file
   fso.CopyFile(pFileFullName, pNewFileName, true);
   // open it in associated app
   sh.ShellExecute(pNewFileName);
}
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1325
Location: Poland

PostPosted: Mon Dec 17, 2012 8:27 pm    Post subject: Reply with quote

Switch between different views of AkelPad screen - part 1.
Part 2 - in the next post.
Required to include: ChooseFont_function.js and InputBox_function.js
All in one: KDJ.zip

ScreenView.js

Code:
// ScreenView.js - ver. 2014-01-03 (x86/x64)
//
// Switch between different views of AkelPad screen.
//
// Usage:
// Call("Scripts::Main", 1, "ScreenView.js") - dialog box with settings
// Call("Scripts::Main", 1, "ScreenView.js", '-View="ViewName"')
// Call("Scripts::Main", 1, "ScreenView.js", '-FullScreen=1')
// Call("Scripts::Main", 1, "ScreenView.js", '-View="ViewName" -FullScreen=-1')
//
// Arguments:
//   View:
//     name of view to set (default is "Default")
//   FullScreen:
//    -1 - switch on/off
//     0 - full screen off
//     1 - full screen on
//     2 - not change (default)
//
// Required to include: ChooseFont_function.js and InputBox_function.js
//
// Some keyboard shortcuts in dialog box:
// TAB      - switch between "View name" and "View settings" windows
// INS      - New
// F2       - Rename
// DEL      - Delete
// Alt+->   - plugin settings
// Ctrl+INS - copy view name to the clipboard
// Pressing the font button with Ctrl or Shift key, displays only monospace fonts.

var oSys       = AkelPad.SystemFunction();
var hInstance  = AkelPad.GetInstanceDll();
var sClassName = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstance;
var hWndDlg    = oSys.Call("User32::FindWindowExW", 0, 0, sClassName, 0);

if (hWndDlg)
{
  if (! oSys.Call("User32::IsWindowVisible", hWndDlg))
    oSys.Call("User32::ShowWindow", hWndDlg, 8 /*SW_SHOWNA*/);
  if (oSys.Call("User32::IsIconic", hWndDlg))
    oSys.Call("User32::ShowWindow", hWndDlg, 9 /*SW_RESTORE*/);

  oSys.Call("User32::SetForegroundWindow", hWndDlg);
}
else
{
  if (!(AkelPad.Include("ChooseFont_function.js") && AkelPad.Include("InputBox_function.js")))
    WScript.Quit();

  var DT_UNICODE   = 1;
  var DT_QWORD     = 2;
  var DT_DWORD     = 3;
  var DT_BYTE      = 5;

  var sScriptName  = "ScreenView";
  var hMainWnd     = AkelPad.GetMainWnd();
  var hEditWnd     = AkelPad.GetEditWnd();
  var oFSO         = new ActiveXObject("Scripting.FileSystemObject");
  var nBufSize     = 1024;
  var oView        = {};
  var aTB          = GetToolBarsArray();
  var oPlug        = GetPluginsObject();
  var sFullScr     = "FullScreen";
  var sFullScrFunc = sFullScr + "::Main";
  var nWndMinW     = 330;
  var nWndPosX     = 240;
  var nWndPosY     = 110;
  var nWndPosW     = nWndMinW;
  var nWndPosH     = 550 + aTB.length * 20;
  var nView        = 0;
  var hFocus;
  var hFocus1;
  var i;

  if (! hEditWnd)
    WScript.Quit();

  ReadWriteIni(false);
  CheckViewObject();

  if (WScript.Arguments.length)
  {
    if (ApplyView(AkelPad.GetArgValue("View", "Default"), AkelPad.GetArgValue(sFullScr, 2)))
      WScript.Quit();
  }

  if (nWndPosW < nWndMinW)
    nWndPosW = nWndMinW;

  var CLASS = 0;
  var HWND  = 1;
  var STYLE = 2;
  var TXT   = 3;
  var LINK  = 4;
  var NAME  = 5;

  var aWnd             = [];
  var IDNAMES          = 2000;
  var IDNAMELB         = 2001;
  var IDFULLSCREEN     = 2002;
  var IDNEW            = 2003;
  var IDRENAME         = 2004;
  var IDDELETE         = 2005;
  var IDAPPLY          = 2006;
  var IDOK             = 2007;
  var IDTHEMESET       = 2008;
  var IDCODERTHEMESET  = 2009;
  var IDCLIPBOARDSET   = 2010;
  var IDCODEFOLDSET    = 2011;
  var IDLINEBOARDSET   = 2012;
  var IDLOGSET         = 2013;
  var IDMENUSET        = 2014;
  var IDSPECCHARSET    = 2015;
  var IDVIEWSET        = 2016;
  var IDFONT           = 2017;
  var IDFONTSET        = 2018;
  var IDTHEME          = 2019;
  var IDTHEMENAME      = 2020;
  var IDCODERTHEME     = 2021;
  var IDCODERTHEMENAME = 2022;
  var IDCLIPBOARD      = 2023;
  var IDCODEFOLD       = 2024;
  var IDCODELIST       = 2025;
  var IDEXPLORER       = 2026;
  var IDHEXSEL         = 2027;
  var IDLINEBOARD      = 2028;
  var IDLOG            = 2029;
  var IDMENU           = 2030;
  var IDQSEARCH        = 2031;
  var IDSCROLLBARH     = 2032;
  var IDSCROLLBARV     = 2033;
  var IDSPECCHAR       = 2034;
  var IDSPEECH         = 2035;
  var IDSTATUSBAR      = 2036;
  var IDTABBAR         = 2037;
  var IDTABBARTOP      = 2038;
  var IDTOOLBAR        = 2039;

  //0x50000000 - WS_VISIBLE|WS_CHILD
  //0x50000001 - WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON
  //0x50000003 - WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX
  //0x50004000 - WS_VISIBLE|WS_CHILD|BS_NOTIFY
  //0x50004003 - WS_VISIBLE|WS_CHILD|BS_NOTIFY|BS_AUTOCHECKBOX
  //0x50004006 - WS_VISIBLE|WS_CHILD|BS_NOTIFY|BS_AUTO3STATE
  //0x50000007 - WS_VISIBLE|WS_CHILD|BS_GROUPBOX
  //0x50800080 - WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL
  //0x50A10103 - WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_BORDER|WS_TABSTOP|LBS_NOINTEGRALHEIGHT|LBS_SORT|LBS_NOTIFY
  //Windows               CLASS,    HWND,      STYLE, TXT,               LINK,            NAME (in oView, oPlug)
  aWnd[IDNAMES         ]=["STATIC",    0, 0x50000000, "View name",       0];
  aWnd[IDNAMELB        ]=["LISTBOX",   0, 0x50A00103, "",                0];
  aWnd[IDFULLSCREEN    ]=["BUTTON",    0, 0x50000003, "&" + sFullScr,    0];
  aWnd[IDNEW           ]=["BUTTON",    0, 0x50000000, "&New",            0];
  aWnd[IDRENAME        ]=["BUTTON",    0, 0x50000000, "&Rename",         0];
  aWnd[IDDELETE        ]=["BUTTON",    0, 0x50000000, "&Delete",         0];
  aWnd[IDAPPLY         ]=["BUTTON",    0, 0x50000000, "&Apply",          0];
  aWnd[IDOK            ]=["BUTTON",    0, 0x50000001, "OK",              0];
  aWnd[IDTHEMESET      ]=["BUTTON",    0, 0x50000000, ">",               IDTHEME];
  aWnd[IDCODERTHEMESET ]=["BUTTON",    0, 0x50000000, ">",               IDCODERTHEME];
  aWnd[IDCLIPBOARDSET  ]=["BUTTON",    0, 0x50000000, ">",               IDCLIPBOARD];
  aWnd[IDCODEFOLDSET   ]=["BUTTON",    0, 0x50000000, ">",               IDCODEFOLD];
  aWnd[IDLINEBOARDSET  ]=["BUTTON",    0, 0x50000000, ">",               IDLINEBOARD];
  aWnd[IDLOGSET        ]=["BUTTON",    0, 0x50000000, ">",               IDLOG];
  aWnd[IDMENUSET       ]=["BUTTON",    0, 0x50000000, ">",               IDMENU];
  aWnd[IDSPECCHARSET   ]=["BUTTON",    0, 0x50000000, ">",               IDSPECCHAR];
  aWnd[IDVIEWSET       ]=["BUTTON",    0, 0x50000007, "View settings",   0];
  aWnd[IDFONT          ]=["BUTTON",    0, 0x50004003, "Font",            0,               "Font"];
  aWnd[IDFONTSET       ]=["BUTTON",    0, 0x50004000, "",                0,               "FontSet"];
  aWnd[IDTHEME         ]=["BUTTON",    0, 0x50004003, "ColorTheme",      IDTHEMESET,      "Theme"];
  aWnd[IDTHEMENAME     ]=["BUTTON",    0, 0x50004000, "",                IDTHEMESET,      "ThemeName"];
  aWnd[IDCODERTHEME    ]=["BUTTON",    0, 0x50004006, "ColorCoderTheme", IDCODERTHEMESET, "CoderTheme"];
  aWnd[IDCODERTHEMENAME]=["BUTTON",    0, 0x50004000, "",                IDCODERTHEMESET, "CoderThemeName"];
  aWnd[IDCLIPBOARD     ]=["BUTTON",    0, 0x50004006, "Clipboard",       IDCLIPBOARDSET,  "Clipboard"];
  aWnd[IDCODEFOLD      ]=["BUTTON",    0, 0x50004006, "CodeFold",        IDCODEFOLDSET,   "CodeFold"];
  aWnd[IDCODELIST      ]=["BUTTON",    0, 0x50004006, "CodeFoldList",    0,               "CodeList"];
  aWnd[IDEXPLORER      ]=["BUTTON",    0, 0x50004006, "Explorer",        0,               "Explorer"];
  aWnd[IDHEXSEL        ]=["BUTTON",    0, 0x50004006, "HexSel",          0,               "HexSel"];
  aWnd[IDLINEBOARD     ]=["BUTTON",    0, 0x50004006, "LineBoard",       IDLINEBOARDSET,  "LineBoard"];
  aWnd[IDLOG           ]=["BUTTON",    0, 0x50004006, "Log",             IDLOGSET,        "Log"];
  aWnd[IDMENU          ]=["BUTTON",    0, 0x50004006, "MenuMain",        IDMENUSET,       "Menu"];
  aWnd[IDQSEARCH       ]=["BUTTON",    0, 0x50004006, "QSearch",         0,               "QSearch"];
  aWnd[IDSCROLLBARH    ]=["BUTTON",    0, 0x50004006, "ScrollBarH",      0,               "ScrollBarH"];
  aWnd[IDSCROLLBARV    ]=["BUTTON",    0, 0x50004006, "ScrollBarV",      0,               "ScrollBarV"];
  aWnd[IDSPECCHAR      ]=["BUTTON",    0, 0x50004006, "SpecialChar",     IDSPECCHARSET,   "SpecChar"];
  aWnd[IDSPEECH        ]=["BUTTON",    0, 0x50004006, "Speech",          0,               "Speech"];
  aWnd[IDSTATUSBAR     ]=["BUTTON",    0, 0x50004006, "StatusBar",       0,               "StatusBar"];
  aWnd[IDTABBAR        ]=["BUTTON",    0, 0x50004006, "TabBar",          0,               "TabBar"];
  aWnd[IDTABBARTOP     ]=["BUTTON",    0, 0x50004003, "Top",             0,               "TabBarTop"];

  for (i = 0; i < aTB.length; ++i)
  {
    aWnd[IDTOOLBAR + i                 ]=["BUTTON", 0, 0x50004006, aTB[i], 0, aTB[i]];
    aWnd[IDTOOLBAR + aTB.length + i    ]=["EDIT",   0, 0x50800080, "",     0, aTB[i] + "Rows"];
    aWnd[IDTOOLBAR + aTB.length * 2 + i]=["STATIC", 0, 0x50000000, "Rows", 0];
  }

  AkelPad.WindowRegisterClass(sClassName);

  hWndDlg =
    oSys.Call("User32::CreateWindowExW",
      0,               //dwExStyle
      sClassName,      //lpClassName
      sScriptName,     //lpWindowName
      0x90CE0000,      //WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX
      nWndPosX,        //x
      nWndPosY,        //y
      nWndPosW,        //nWidth
      nWndPosH,        //nHeight
      hMainWnd,        //hWndParent
      0,               //ID
      hInstance,       //hInstance
      DialogCallback); //Script function callback. To use it class must be registered by WindowRegisterClass.

  //Allow other scripts running
  AkelPad.ScriptNoMutex();

  //Message loop
  AkelPad.WindowGetMessage();

  AkelPad.WindowUnregisterClass(sClassName);
}

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    var hGuiFont = oSys.Call("gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
    var i;

    for (i = 2000; i < aWnd.length; ++i)
    {
      aWnd[i][HWND] =
        oSys.Call("User32::CreateWindowExW",
          0,              //dwExStyle
          aWnd[i][CLASS], //lpClassName
          0,              //lpWindowName
          aWnd[i][STYLE], //dwStyle
          0,              //x
          0,              //y
          0,              //nWidth
          0,              //nHeight
          hWnd,           //hWndParent
          i,              //ID
          hInstance,      //hInstance
          0);             //lpParam

      //Set font and text
      SendMessage(aWnd[i][HWND], 48 /*WM_SETFONT*/, hGuiFont, true);
      oSys.Call("User32::SetWindowTextW", aWnd[i][HWND], aWnd[i][TXT]);
    }

    for (i = 0; i < aTB.length; ++i)
      SendMessage(aWnd[IDTOOLBAR + aTB.length + i][HWND], 0x00C5 /*EM_SETLIMITTEXT*/, 23, 0);

    //fill list box
    for (i in oView)
      SendMessage(aWnd[IDNAMELB][HWND], 0x0180 /*LB_ADDSTRING*/, 0, i);

    if (nView >= GetCountLB())
      nView = GetCountLB() - 1;

    SetCurSelLB(nView);
    SendMessage(aWnd[IDNAMELB][HWND], 0x0197 /*LB_SETTOPINDEX*/, nView, 0);

    hFocus  = aWnd[IDNAMELB][HWND];
    hFocus1 = aWnd[IDFONT][HWND];
  }

  else if (uMsg == 7) //WM_SETFOCUS
  {
    EnablePluginButtons();
    CheckButtons();
    SendMessage(aWnd[IDFULLSCREEN][HWND], 0x00F1 /*BM_SETCHECK*/, IsFullScreen(), 0);
    oSys.Call("User32::SetFocus", hFocus);
  }

  else if (uMsg == 36) //WM_GETMINMAXINFO
  {
    var oRect = {};
    GetWindowPos(oSys.Call("User32::GetDesktopWindow"), oRect);
    AkelPad.MemCopy(lParam + 24, nWndMinW,     DT_DWORD); //ptMinTrackSize_x
    AkelPad.MemCopy(lParam + 28, nWndPosH,     DT_DWORD); //ptMinTrackSize_y
    AkelPad.MemCopy(lParam + 32, oRect.W - 30, DT_DWORD); //ptMaxTrackSize_x
    AkelPad.MemCopy(lParam + 36, nWndPosH,     DT_DWORD); //ptMaxTrackSize_y
  }

  else if (uMsg == 5) //WM_SIZE
    ResizeWindow(hWnd);

  else if (uMsg == 15) //WM_PAINT
    PaintSizeGrip(hWnd);

  else if (uMsg == 256 /*WM_KEYDOWN*/)
  {
    if (wParam == 0x09 /*VK_TAB*/)
    {
      if (hFocus == aWnd[IDNAMELB][HWND])
      {
        while (! oSys.Call("User32::IsWindowEnabled", hFocus1))
          hFocus1 = aWnd[oSys.Call("User32::GetDlgCtrlID", hFocus1) - 1][HWND];

        oSys.Call("User32::SetFocus", hFocus1);
      }
      else
      {
        var nID = oSys.Call("User32::GetDlgCtrlID", hFocus);
        if (nID < IDTOOLBAR)
          oSys.Call("User32::SetFocus", aWnd[IDNAMELB][HWND]);
        else if (nID < IDTOOLBAR + aTB.length)
          oSys.Call("User32::SetFocus", aWnd[nID + aTB.length][HWND]);
        else
          oSys.Call("User32::SetFocus", aWnd[IDNAMELB][HWND]);
      }
    }
    else if (wParam == 0x2D /*VK_INSERT*/)
    {
      if ((! Ctrl()) && (! Shift()))
        NewView();
      else if (Ctrl() && (! Shift()))
        AkelPad.SetClipboardText(GetCurTextLB());
    }
    else if (wParam == 0x71 /*VK_F2*/)
    {
      if ((! Ctrl()) && (! Shift()))
        RenameView();
    }
    else if (wParam == 0x2E /*VK_DELETE*/)
    {
      if ((! Ctrl()) && (! Shift()) && (oSys.Call("User32::GetDlgCtrlID", hFocus) < IDTOOLBAR + aTB.length))
        DeleteView();
    }
    else if (wParam == 0x0D /*VK_RETURN*/)
    {
      if ((! Ctrl()) && (! Shift()))
      {
        if ((hFocus != aWnd[IDFONTSET][HWND]) && (hFocus != aWnd[IDTHEMENAME][HWND]) && (hFocus != aWnd[IDCODERTHEMENAME][HWND]))
          PostMessage(hWnd, 273 /*WM_COMMAND*/, IDOK, 0);
      }
    }
    else if (wParam == 0x7A /*VK_F11*/)
    {
      if ((! Ctrl()) && (! Shift()))
        PostMessage(hWnd, 273 /*WM_COMMAND*/, IDFULLSCREEN, 0);
    }
    else if (wParam == 0x1B /*VK_ESCAPE*/)
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if (wParam == 0x27 /*VK_RIGHT*/)
    {
      var nID = oSys.Call("User32::GetDlgCtrlID", hFocus);

      if (aWnd[nID][LINK] && oSys.Call("User32::IsWindowEnabled", aWnd[aWnd[nID][LINK]][HWND]))
        PostMessage(hWnd, 273 /*WM_COMMAND*/, aWnd[nID][LINK], 0);
    }
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    var nLowParam = LoWord(wParam);
    var nHiwParam = HiWord(wParam);

    if (nLowParam == IDNAMELB)
    {
      if (nHiwParam == 1 /*LBN_SELCHANGE*/)
        CheckButtons();
      else if (nHiwParam == 4 /*LBN_SETFOCUS*/)
        hFocus = lParam;
    }
    else if (nLowParam == IDFULLSCREEN)
    {
      FullScreenSwitch();
      oSys.Call("User32::SetFocus", hFocus);
    }
    else if ((nLowParam >= IDNEW) && (nLowParam <= IDSPECCHARSET))
    {
      PostMessage(lParam, 0x00F4 /*BM_SETSTYLE*/, 0 /*BS_PUSHBUTTON*/, 1);
      PostMessage(aWnd[IDOK][HWND], 0x00F4 /*BM_SETSTYLE*/, 1 /*BS_DEFPUSHBUTTON*/, 1);

      if (nLowParam == IDNEW)
        NewView();
      else if (nLowParam == IDRENAME)
        RenameView();
      else if (nLowParam == IDDELETE)
        DeleteView();
      else if (nLowParam == IDAPPLY)
        ApplyView(GetCurTextLB(), 2);
      else if (nLowParam == IDOK)
      {
        ApplyView(GetCurTextLB(), 2);
        PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
      }
      else
      {
        oSys.Call("User32::ShowWindow", hWnd, 6 /*SW_MINIMIZE*/); //for Win7
        oSys.Call("User32::ShowWindow", hWnd, 0 /*SW_HIDE*/);

        if (nLowParam == IDTHEMESET)
          AkelPad.Command(4202);
        else
          oPlug[aWnd[aWnd[nLowParam][LINK]][NAME]].Settings();

        oSys.Call("User32::ShowWindow", hWnd, 9 /*SW_RESTORE*/);
      }

      oSys.Call("User32::SetFocus", hFocus);
    }
    else if (nLowParam >= IDFONT)
    {
      if (nHiwParam == 6 /*BN_SETFOCUS*/)
      {
        hFocus  = lParam;
        hFocus1 = lParam;
        if ((nLowParam == IDFONTSET) || (nLowParam == IDTHEMENAME) || (nLowParam == IDCODERTHEMENAME))
        {
          PostMessage(lParam, 0x00F4 /*BM_SETSTYLE*/, 1 /*BS_DEFPUSHBUTTON*/, 1);
          PostMessage(aWnd[IDOK][HWND], 0x00F4 /*BM_SETSTYLE*/, 0 /*BS_PUSHBUTTON*/, 1);
        }
      }
      else if (nHiwParam == 7 /*BN_KILLFOCUS*/)
      {
        if ((nLowParam == IDFONTSET) || (nLowParam == IDTHEMENAME) || (nLowParam == IDCODERTHEMENAME))
        {
          PostMessage(lParam, 0x00F4 /*BM_SETSTYLE*/, 0 /*BS_PUSHBUTTON*/, 1);
          PostMessage(aWnd[IDOK][HWND], 0x00F4 /*BM_SETSTYLE*/, 1 /*BS_DEFPUSHBUTTON*/, 1);
        }
      }
      else if (nHiwParam == 0x0100 /*EN_SETFOCUS*/)
      {
        hFocus  = lParam;
        hFocus1 = aWnd[nLowParam - aTB.length][HWND];
      }
      else
        GetButtonState(nLowParam);
    }
  }

  else if (uMsg == 16) //WM_CLOSE
  {
    ReadWriteIni(true);
    oSys.Call("User32::DestroyWindow", hWnd); //Destroy dialog
  }

  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("User32::PostQuitMessage", 0); //Exit message loop

  return 0;
}

function LoWord(nParam)
{
  return (nParam & 0xFFFF);
}

function HiWord(nParam)
{
  return ((nParam >> 16) & 0xFFFF);
}

function Ctrl()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x11 /*VK_CONTROL*/) & 0x8000);
}

function Shift()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000);
}

function SendMessage(hWnd, uMsg, wParam, lParam)
{
  return oSys.Call("User32::SendMessageW", hWnd, uMsg, wParam, lParam);
}

function PostMessage(hWnd, uMsg, wParam, lParam)
{
  return oSys.Call("User32::PostMessageW", hWnd, uMsg, wParam, lParam);
}

function GetWindowPos(hWnd, oRect)
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)

  oSys.Call("User32::GetWindowRect", hWnd, lpRect);

  oRect.X = AkelPad.MemRead(lpRect,      DT_DWORD);
  oRect.Y = AkelPad.MemRead(lpRect +  4, DT_DWORD);
  oRect.W = AkelPad.MemRead(lpRect +  8, DT_DWORD) - oRect.X;
  oRect.H = AkelPad.MemRead(lpRect + 12, DT_DWORD) - oRect.Y;

  AkelPad.MemFree(lpRect);
}

function GetCurSelLB()
{
  return SendMessage(aWnd[IDNAMELB][HWND], 0x0188 /*LB_GETCURSEL*/, 0, 0);
}

function SetCurSelLB(nPos)
{
  SendMessage(aWnd[IDNAMELB][HWND], 0x0186 /*LB_SETCURSEL*/, nPos, 0);
}

function GetCurTextLB()
{
  var lpText = AkelPad.MemAlloc(1024);
  var sText;

  SendMessage(aWnd[IDNAMELB][HWND], 0x0189 /*LB_GETTEXT*/, GetCurSelLB(), lpText);
  sText = AkelPad.MemRead(lpText, DT_UNICODE);
  AkelPad.MemFree(lpText);

  return sText;
}

function GetCountLB()
{
  return SendMessage(aWnd[IDNAMELB][HWND], 0x018B /*LB_GETCOUNT*/, 0, 0);
}

function PaintSizeGrip(hWnd)
{
  var lpPaint = AkelPad.MemAlloc(_X64 ? 72 : 64); //sizeof(PAINTSTRUCT)
  var lpRect  = AkelPad.MemAlloc(16); //sizeof(RECT)
  var hDC;

  if (hDC = oSys.Call("User32::BeginPaint", hWnd, lpPaint))
  {
    oSys.Call("User32::GetClientRect", hWnd, lpRect);

    AkelPad.MemCopy(lpRect,     AkelPad.MemRead(lpRect +  8, DT_DWORD) - oSys.Call("User32::GetSystemMetrics",  2 /*SM_CXVSCROLL*/), DT_DWORD);
    AkelPad.MemCopy(lpRect + 4, AkelPad.MemRead(lpRect + 12, DT_DWORD) - oSys.Call("User32::GetSystemMetrics", 20 /*SM_CYVSCROLL*/), DT_DWORD);

    oSys.Call("User32::DrawFrameControl", hDC, lpRect, 3 /*DFC_SCROLL*/, 0x8 /*DFCS_SCROLLSIZEGRIP*/);
    oSys.Call("User32::EndPaint", hWnd, lpPaint);
  }

  AkelPad.MemFree(lpPaint);
  AkelPad.MemFree(lpRect);
}

function ResizeWindow(hWnd)
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
  var nW, nH, nBW;
  var i;

  oSys.Call("User32::GetClientRect", hWnd, lpRect);
  nW  = AkelPad.MemRead(lpRect +  8, DT_DWORD);
  nH  = AkelPad.MemRead(lpRect + 12, DT_DWORD);
  nBW = (nW - 20 - (IDOK - IDNEW) * 3) / (IDOK - IDNEW + 1);
  AkelPad.MemFree(lpRect);

  oSys.Call("User32::SetWindowPos", aWnd[IDNAMES][HWND], 0,
            10,
            10,
            100,
            13,
            0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  oSys.Call("User32::SetWindowPos", aWnd[IDNAMELB][HWND], 0,
            10,
            30,
            nW - 200 - 30,
            nH - 30 - 23 - 20,
            0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  oSys.Call("User32::SetWindowPos", aWnd[IDFULLSCREEN][HWND], 0,
            nW - 80,
            10,
            70,
            16,
            0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  for (i = IDNEW; i <= IDOK; ++i)
    oSys.Call("User32::SetWindowPos", aWnd[i][HWND], 0,
              10 + (i - IDNEW) * (nBW + 3),
              nH - 23 - 10,
              nBW,
              23,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  for (i = IDTHEMESET; i <= IDSPECCHARSET; ++i)
    oSys.Call("User32::SetWindowPos", aWnd[i][HWND], 0,
              nW - 35,
              90 + (aWnd[i][LINK] - IDTHEME) * 20,
              15,
              20,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  oSys.Call("User32::SetWindowPos", aWnd[IDVIEWSET][HWND], 0,
            nW - 210,
            30,
            200,
            nH - 30 - 23 - 20,
            0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  for (i = IDFONT; i <= IDCODERTHEME; i += 2)
  {
    oSys.Call("User32::SetWindowPos", aWnd[i][HWND], 0,
              nW - 200,
              50 + (i - IDFONT) * 20,
              100,
              20,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
    oSys.Call("User32::SetWindowPos", aWnd[i + 1][HWND], 0,
              nW - 190,
              70 + (i - IDFONT) * 20,
              170,
              20,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  }
  for (i = IDCLIPBOARD; i <= IDTABBAR; ++i)
    oSys.Call("User32::SetWindowPos", aWnd[i][HWND], 0,
              nW - 200,
              170 + (i - IDCLIPBOARD) * 20,
              100,
              20,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  oSys.Call("User32::SetWindowPos", aWnd[IDTABBARTOP][HWND], 0,
            nW - 100,
            170 + (IDTABBAR - IDCLIPBOARD) * 20,
            50,
            20,
            0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  for (i = 0; i < aTB.length; ++i)
  {
    oSys.Call("User32::SetWindowPos", aWnd[IDTOOLBAR + i][HWND], 0,
              nW - 200,
              470 + i * 20,
              100,
              20,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
    oSys.Call("User32::SetWindowPos", aWnd[IDTOOLBAR + aTB.length + i][HWND], 0,
              nW - 100,
              470 + i * 20,
              50,
              18,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
    oSys.Call("User32::SetWindowPos", aWnd[IDTOOLBAR + aTB.length * 2 + i][HWND], 0,
              nW - 47,
              470 + i * 20,
              30,
              13,
              0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
  }
}

function GetToolBarsArray()
{
  var sToolBar  = "ToolBar";
  var lpFind    = AkelPad.MemAlloc(44 + (260 + 14) * 2); //sizeof(WIN32_FIND_DATA)
  var hFindFile = oSys.Call("kernel32::FindFirstFileW", AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/) + "\\" + sToolBar + "*.dll", lpFind);
  var aTB       = [];
  var sPlugName;

  if (hFindFile != -1) //INVALID_HANDLE_VALUE
  {
    do
    {
      sPlugName = AkelPad.MemRead(lpFind + 44 /*offsetof(WIN32_FIND_DATAW, cFileName)*/, DT_UNICODE);
      aTB.push(sPlugName.substring(sPlugName.lastIndexOf("\\") + 1, sPlugName.lastIndexOf(".")));
    }
    while (oSys.Call("kernel32::FindNextFileW", hFindFile, lpFind));

    oSys.Call("kernel32::FindClose", hFindFile);
  }

  if (aTB.length)
    aTB.sort(
      function(sA, sB)
      {
        return oSys.Call("kernel32::lstrcmpiW", sA, sB);
      });
  else
    aTB.push(sToolBar);

  AkelPad.MemFree(lpFind);
  return aTB;
}

function GetPluginsObject()
{
  var oPlug = {
    Clipboard:  {Name: "Clipboard",   State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Capture");},   Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Capture");},   Settings: function(){AkelPad.Call(this.Name + "::Settings");}},
    CodeFold:   {Name: "Coder",       State:  2, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::CodeFold");},  Switch: function(){AkelPad.CallEx(0x14, this.Name + "::CodeFold");},  Settings: function(){AkelPad.Call(this.Name + "::Settings", 3, 2);}},
    CoderTheme: {Name: "Coder",       State: -1, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::HighLight");}, Switch: function(){AkelPad.CallEx(0x14, this.Name + "::HighLight");}, Settings: function(){AkelPad.Call(this.Name + "::Settings", 3, 0);}},
    Explorer:   {Name: "Explorer",    State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main");}},
    HexSel:     {Name: "HexSel",      State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main");}},
    LineBoard:  {Name: "LineBoard",   State:  2, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main", 1);},   Settings: function(){AkelPad.Call(this.Name + "::Settings");}},
    Log:        {Name: "Log",         State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Output");},    Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Output");},    Settings: function(){AkelPad.Call(this.Name + "::Settings");}},
    Menu:       {Name: "ContextMenu", State: -1, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main", 10);},  Settings: function(){AkelPad.Call(this.Name + "::Main", 1, 1);}},
    QSearch:    {Name: "QSearch",     State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::QSearch");},   Switch: function(){AkelPad.CallEx(0x14, this.Name + "::QSearch");}},
    SpecChar:   {Name: "SpecialChar", State:  2, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main");},      Settings: function(){AkelPad.Call(this.Name + "::Settings");}},
    Speech:     {Name: "Speech",      State:  0, IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");},      Switch: function(){AkelPad.CallEx(0x14, this.Name + "::Main");}}
    };

  for (var i = 0; i < aTB.length; ++i)
    oPlug[aTB[i]] = {State: 0, Name: aTB[i], IsRunning: function(){return AkelPad.IsPluginRunning(this.Name + "::Main");}};

  return oPlug;
}

function CheckViewObject()
{
  var sDefault = "Default";
  var aFont    = ConvertFontFormat(SendMessage(hEditWnd, 0x0031 /*WM_GETFONT*/, 0, 0), 2, 3);
  var oTemp = {
    Font:           0,
    FontName:       aFont[0],
    FontStyle:      aFont[1],
    FontSize:       aFont[2],
    Theme:          0,
    ThemeName:      "<Standard>",
    CoderThemeName: "Default",
    CodeList:       2,
    ScrollBarH:     2,
    ScrollBarV:     2,
    StatusBar:      2,
    TabBar:         2,
    TabBarTop:      1};
  var i, n;

  for (i in oPlug)
    oTemp[i] = 2;

  oTemp.CoderTheme = 2;

  for (i = 0; i < aTB.length; ++i)
    oTemp[aTB[i] + "Rows"] = "";

  for (i in oView)
  {
    for (n in oView[i])
    {
      if (! (n in oTemp))
        delete oView[i][n];
    }
  }

  for (n in oTemp)
  {
    for (i in oView)
    {
      if (! (n in oView[i]))
        oView[i][n] = oTemp[n];
    }
  }

  if (! (sDefault in oView))
  {
    oView[sDefault] = {};
    for (n in oTemp)
      oView[sDefault][n] = oTemp[n];
  }
}

function EnablePluginButtons()
{
  var i;

  oSys.Call("User32::EnableWindow", aWnd[IDFULLSCREEN][HWND], IsPluginExists(sFullScr));
  oSys.Call("User32::EnableWindow", aWnd[IDCODERTHEME][HWND], IsPluginExists(oPlug.CoderTheme.Name));

  for (i = IDCLIPBOARD; i < IDTOOLBAR + aTB.length; ++i)
  {
    if ((aWnd[i][NAME] in oPlug) && (oPlug[aWnd[i][NAME]].State >= 0))
      oSys.Call("User32::EnableWindow", aWnd[i][HWND], IsPluginExists(oPlug[aWnd[i][NAME]].Name));
  }

  for (i = 0; i < aTB.length; ++i)
  {
    oSys.Call("User32::EnableWindow", aWnd[IDTOOLBAR + aTB.length + i    ][HWND], IsPluginExists(oPlug[aWnd[IDTOOLBAR + i][NAME]].Name));
    oSys.Call("User32::EnableWindow", aWnd[IDTOOLBAR + aTB.length * 2 + i][HWND], IsPluginExists(oPlug[aWnd[IDTOOLBAR + i][NAME]].Name));
  }

  for (i = IDCODERTHEMESET; i <= IDSPECCHARSET; ++i)
    oSys.Call("User32::EnableWindow", aWnd[i][HWND], IsPluginExists(oPlug[aWnd[aWnd[i][LINK]][NAME]].Name));
}

function CheckButtons()
{
  var sName = GetCurTextLB();
  var i;

  SendMessage(aWnd[IDFONT][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName].Font, 0);
  oSys.Call("User32::EnableWindow", aWnd[IDFONTSET][HWND], oView[sName].Font);
  oSys.Call("User32::SetWindowTextW", aWnd[IDFONTSET][HWND], oView[sName].FontName + "," + oView[sName].FontStyle + "," + oView[sName].FontSize);

  SendMessage(aWnd[IDTHEME][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName].Theme, 0);
  oSys.Call("User32::EnableWindow", aWnd[IDTHEMENAME][HWND], oView[sName].Theme);
  oSys.Call("User32::SetWindowTextW", aWnd[IDTHEMENAME][HWND], oView[sName].ThemeName);

  SendMessage(aWnd[IDCODERTHEME][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName].CoderTheme, 0);
  oSys.Call("User32::EnableWindow", aWnd[IDCODERTHEMENAME][HWND], (oView[sName].CoderTheme == 1) && oSys.Call("User32::IsWindowEnabled", aWnd[IDCODERTHEME][HWND]));
  oSys.Call("User32::SetWindowTextW", aWnd[IDCODERTHEMENAME][HWND], oView[sName].CoderThemeName);

  for (i = IDCLIPBOARD; i < IDTOOLBAR + aTB.length; ++i)
    SendMessage(aWnd[i][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName][aWnd[i][NAME]], 0);

  for (i = 0; i < aTB.length; ++i)
    oSys.Call("User32::SetWindowTextW", aWnd[IDTOOLBAR + aTB.length + i][HWND], oView[sName][aWnd[IDTOOLBAR + aTB.length + i][NAME]]);

  oSys.Call("User32::EnableWindow", aWnd[IDCODELIST ][HWND], oView[sName].CodeFold && oSys.Call("User32::IsWindowEnabled", aWnd[IDCODEFOLD][HWND]));
  oSys.Call("User32::EnableWindow", aWnd[IDTABBAR   ][HWND], AkelPad.IsMDI());
  oSys.Call("User32::EnableWindow", aWnd[IDTABBARTOP][HWND], (oView[sName].TabBar == 1) && AkelPad.IsMDI());
  oSys.Call("User32::EnableWindow", aWnd[IDRENAME   ][HWND], sName != "Default");
  oSys.Call("User32::EnableWindow", aWnd[IDDELETE   ][HWND], sName != "Default");
}

function GetButtonState(nID)
{
  var sName = GetCurTextLB();
  var lpText;

  if (! sName)
    return;

  if (nID == IDFONTSET)
  {
    var aFont = ChooseFont(hWndDlg, 3, [oView[sName].FontName, oView[sName].FontStyle, oView[sName].FontSize], 0, (Ctrl() || Shift()), 3);
    if (aFont)
    {
      oView[sName].FontName  = aFont[0];
      oView[sName].FontStyle = aFont[1];
      oView[sName].FontSize  = aFont[2];
      oSys.Call("User32::SetWindowTextW", aWnd[IDFONTSET][HWND], oView[sName].FontName + "," + oView[sName].FontStyle + "," + oView[sName].FontSize);
    }
  }
  else if (nID == IDTHEMENAME)
    SetThemeName(sName);
  else if (nID == IDCODERTHEMENAME)
    SetCoderThemeName(sName);
  else if ((nID >= IDTOOLBAR + aTB.length) && (nID < IDTOOLBAR + aTB.length * 2))
  {
    lpText = AkelPad.MemAlloc(48);
    oSys.Call("User32::GetWindowTextW", aWnd[nID][HWND], lpText, 24);
    oView[sName][aWnd[nID][NAME]] = AkelPad.MemRead(lpText, DT_UNICODE);
    AkelPad.MemFree(lpText);
  }
  else
  {
    oView[sName][aWnd[nID][NAME]] = SendMessage(aWnd[nID][HWND], 0x00F0 /*BM_GETCHECK*/, 0, 0);

    if (nID == IDTHEME)
    {
      if (oView[sName].Theme)
      {
        oView[sName].CoderTheme = 0;
        SendMessage(aWnd[IDCODERTHEME][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName].CoderTheme, 0);
      }
    }
    else if (nID == IDCODERTHEME)
    {
      if (oView[sName].CoderTheme)
      {
        oView[sName].Theme = 0;
        SendMessage(aWnd[IDTHEME][HWND], 0x00F1 /*BM_SETCHECK*/, oView[sName].Theme, 0);
      }
    }

    oSys.Call("User32::EnableWindow", aWnd[IDFONTSET       ][HWND], oView[sName].Font);
    oSys.Call("User32::EnableWindow", aWnd[IDTHEMENAME     ][HWND], oView[sName].Theme);
    oSys.Call("User32::EnableWindow", aWnd[IDCODERTHEMENAME][HWND], (oView[sName].CoderTheme == 1) && oSys.Call("User32::IsWindowEnabled", aWnd[IDCODERTHEME][HWND]));
    oSys.Call("User32::EnableWindow", aWnd[IDCODELIST      ][HWND], oView[sName].CodeFold && oSys.Call("User32::IsWindowEnabled", aWnd[IDCODEFOLD][HWND]));
    oSys.Call("User32::EnableWindow", aWnd[IDTABBARTOP     ][HWND], oView[sName].TabBar == 1);
  }
}

function IsPluginExists(sPlugName)
{
  return oFSO.FileExists(AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/) + "\\" + sPlugName + ".dll");
}

function IsFullScreen()
{
  return AkelPad.IsPluginRunning(sFullScrFunc);
}

function IsSettingsInRegistry()
{
  return (SendMessage(AkelPad.GetMainWnd(), 1222 /*AKD_GETMAININFO*/, 5 /*MI_SAVESETTINGS*/, 0) == 1 /*SS_REGISTRY*/);
}

function NewView()
{
  var sCurName = GetCurTextLB();
  var sNewName = InputBox(hWndDlg, "New view", "Input name:", sCurName, 0, "CheckInputName");
  var nPos;
  var n;

  if ((sNewName) && (sNewName = sNewName.replace(/\s+$/, "")))
  {
    oView[sNewName] = {};

    for (n in oView[sCurName])
      oView[sNewName][n] = oView[sCurName][n];

    nPos = SendMessage(aWnd[IDNAMELB][HWND], 0x0180 /*LB_ADDSTRING*/, 0, sNewName);
    SetCurSelLB(nPos);
  }
}

function CheckInputName(hWnd, aNames)
{
  aNames[0] = aNames[0].replace(/\s+$/, "");

  if (aNames[0] in oView)
  {
    WarningBox(hWnd, '"' + aNames[0] + '" already exists.');
    return 0;
  }

  return -1;
}

function RenameView()
{
  var nPos     = GetCurSelLB();
  var sCurName = GetCurTextLB();
  var sNewName;
  var n;

  if (sCurName != "Default")
  {
    sNewName = InputBox(hWndDlg, "Rename view", "Input name:", sCurName, 0, "CheckInputRename", sCurName);

    if ((sNewName) && (sNewName = sNewName.replace(/\s+$/, "")) && (sNewName != sCurName))
    {
      oView[sNewName] = {};

      for (n in oView[sCurName])
        oView[sNewName][n] = oView[sCurName][n];

      delete oView[sCurName];
      SendMessage(aWnd[IDNAMELB][HWND], 0x0182 /*LB_DELETESTRING*/, nPos, 0);

      nPos = SendMessage(aWnd[IDNAMELB][HWND], 0x0180 /*LB_ADDSTRING*/, 0, sNewName);
      SetCurSelLB(nPos);
    }
  }
}

function CheckInputRename(hWnd, aNames, sCurName)
{
  aNames[0] = aNames[0].replace(/\s+$/, "");

  if ((aNames[0] != sCurName) && (aNames[0] in oView))
  {
    WarningBox(hWnd, '"' + aNames[0] + '" already exists.');
    return 0;
  }

  return -1;
}

function DeleteView()
{
  var nPos  = GetCurSelLB();
  var sName = GetCurTextLB();

  if (sName != "Default")
  {
    if (AkelPad.MessageBox(hWndDlg, 'Do you want to delete "' + sName + '"?', sScriptName, 0x00000023 /*MB_ICONQUESTION|MB_YESNOCANCEL*/) == 6 /*IDYES*/)
    {
      delete oView[sName];
      SendMessage(aWnd[IDNAMELB][HWND], 0x0182 /*LB_DELETESTRING*/, nPos, 0);

      if (nPos == GetCountLB())
        --nPos;

      SetCurSelLB(nPos);
      CheckButtons();
    }
  }
}

function ApplyView(sViewName, nFullScrAction)
{
  if (! (sViewName in oView))
  {
    WarningBox(hMainWnd, '"' + sViewName + '" does not exists.');
    return 0;
  }

  var hMenu = oSys.Call("User32::GetMenu", hMainWnd);
  var bCodeList;
  var bStatBar;
  var i;

  for (i = 0; i < aTB.length; ++i)
    oPlug[aTB[i]].Switch = function(){
      if (this.IsRunning())
        AkelPad.CallEx(0x14, this.Name + "::Main");
      else
        AkelPad.CallEx(0x14, this.Name + "::Main", 1, oView[sViewName][this.Name + "Rows"]);
      };

  //full screen
  if (IsPluginExists(sFullScr) &&
      ((nFullScrAction == 1) ||
       ((nFullScrAction == -1) && (! IsFullScreen())) ||
       ((nFullScrAction == 2) && IsFullScreen())))
  {
    bCodeList = ShowCodeList(0);
    bStatBar  = ShowStatusBar(0);

    for (i in oPlug)
    {
      if ((oPlug[i].State == 0) || (oPlug[i].State == 1))
      {
        if (oPlug[i].State = oPlug[i].IsRunning())
          oPlug[i].Switch();
      }
    }
  }
  //not full screen
  else
  {
    bCodeList = ShowCodeList(2);
    bStatBar  = ShowStatusBar(2);

    for (i in oPlug)
    {
      if ((oPlug[i].State == 0) || (oPlug[i].State == 1))
        oPlug[i].State = oPlug[i].IsRunning();
    }

    for (i = 0; i < aTB.length; ++i)
    {
      if (oPlug[aTB[i]].State == 1)
        oPlug[aTB[i]].Switch();
    }
  }

  if (IsPluginExists(sFullScr) && (nFullScrAction < 2) && (nFullScrAction != IsFullScreen()))
  {
    AkelPad.Call(sFullScrFunc);
    WScript.Sleep(80);
  }

  for (i in oPlug)
  {
    if ((oPlug[i].State >= 0) && IsPluginExists(oPlug[i].Name))
    {
      if (((oView[sViewName][i] == 0) && oPlug[i].IsRunning()) ||
          ((oView[sViewName][i] == 1) && (! oPlug[i].IsRunning())) ||
          ((oView[sViewName][i] == 2) && (oPlug[i].State < 2) && (oPlug[i].State != oPlug[i].IsRunning())))
        oPlug[i].Switch();
    }
  }

  ShowMenu(oView[sViewName].Menu, hMenu);
  ShowCodeList((oView[sViewName].CodeList == 2) ? bCodeList : oView[sViewName].CodeList);
  ShowStatusBar((oView[sViewName].StatusBar == 2) ? bStatBar : oView[sViewName].StatusBar);
  ShowScrollBar(oView[sViewName].ScrollBarH, oView[sViewName].ScrollBarV);
  ShowTabBar(oView[sViewName].TabBar, oView[sViewName].TabBarTop);
  ChangeFont(sViewName);
  ChangeTheme(sViewName);
  ChangeCoderTheme(sViewName);

  return 1;
}

function FullScreenSwitch()
{
  if (IsPluginExists(sFullScr))
  {
    var hMenu     = oSys.Call("User32::GetMenu", hMainWnd);
    var bCodeList = ShowCodeList(0);
    var bStatBar  = ShowStatusBar(0);
    var i;

    for (i = 0; i < aTB.length; ++i)
      oPlug[aTB[i]].Switch = function(){AkelPad.CallEx(0x14, this.Name + "::Main");};

    for (i in oPlug)
    {
      if ((oPlug[i].State == 0) || (oPlug[i].State == 1))
      {
        if (oPlug[i].State = oPlug[i].IsRunning())
          oPlug[i].Switch();
      }
    }

    AkelPad.Call(sFullScrFunc);
    WScript.Sleep(80);

    for (i in oPlug)
    {
      if (oPlug[i].State == 1)
        oPlug[i].Switch();
    }

    oSys.Call("User32::SetMenu", hMainWnd, hMenu);
    ShowCodeList(bCodeList);
    ShowStatusBar(bStatBar);

    ShowTabBar(2);
  }
}

function ShowCodeList(nShow)
{
  var bState  = 0;
  var lpState;

  if (oPlug.CodeFold.IsRunning())
  {
    lpState = AkelPad.MemAlloc(4);
    AkelPad.Call(oPlug.CodeFold.Name + "::CodeFold", 1, lpState);

    bState = AkelPad.MemRead(lpState, DT_DWORD);
    AkelPad.MemFree(lpState);

    if ((nShow < 2) && (nShow != bState))
      AkelPad.Call(oPlug.CodeFold.Name + "::CodeFold", 1);
  }

  return bState;
}

function ShowMenu(nShow, hMenu)
{
  var hMainMenu = SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 21 /*MI_MENUMAIN*/, 0);
  var hCurMenu  = oSys.Call("User32::GetMenu", hMainWnd);

  if (nShow == 2)
    oSys.Call("User32::SetMenu", hMainWnd, hMenu);
  else if (((nShow == 0) && hCurMenu) || ((nShow == 1) && (! hCurMenu)))
  {
    if (IsPluginExists(oPlug.Menu.Name))
    {
      if (nShow)
      {
        if (oPlug.Menu.IsRunning())
        {
          oPlug.Menu.Switch();
          oPlug.Menu.Switch();

          if (oPlug.LineBoard.IsRunning())
          {
            oPlug.LineBoard.Switch();
            oPlug.LineBoard.Switch();
          }
        }

        if (! oSys.Call("User32::GetMenu", hMainWnd))
          oSys.Call("User32::SetMenu", hMainWnd, hMainMenu);
      }
      else
        oSys.Call("User32::SetMenu", hMainWnd, 0);
    }
    else
      oSys.Call("User32::SetMenu", hMainWnd, nShow ? hMainMenu : 0);
  }
}

function ShowScrollBar(nShowH, nShowV)
{
  if ((nShowH < 2) || (nShowV < 2))
  {
    var lpPOINT = AkelPad.MemAlloc(8);

    SendMessage(hEditWnd, 1245 /*EM_GETSCROLLPOS*/, 0, lpPOINT);

    if (nShowH < 2)
      SendMessage(hEditWnd, 3375 /*AEM_SHOWSCROLLBAR*/, 0 /*SB_HORZ*/, nShowH);

    if (nShowV < 2)
      SendMessage(hEditWnd, 3375 /*AEM_SHOWSCROLLBAR*/, 1 /*SB_VERT*/, nShowV);

    SendMessage(hEditWnd, 1246 /*EM_SETSCROLLPOS*/, 0, lpPOINT);
    AkelPad.MemFree(lpPOINT);
  }
}

function ShowStatusBar(nShow)
{
  var bState = SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 142 /*MI_STATUSBAR*/, 0);

  if ((nShow < 2) && (nShow != bState))
    AkelPad.Command(4211 /*IDM_VIEW_SHOW_STATUSBAR*/);

  return bState;
}

function ShowTabBar(nShow, bTop)
{
  var IDM_WINDOW_TABVIEW_NONE   = 4303;
  var IDM_WINDOW_TABVIEW_TOP    = 4301;
  var IDM_WINDOW_TABVIEW_BOTTOM = 4302;
  var TAB_VIEW_NONE   = 1;
  var TAB_VIEW_TOP    = 2;
  var TAB_VIEW_BOTTOM = 4;
  var nState = SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 157 /*MI_TABOPTIONSMDI*/, 0);

  AkelPad.Command(IDM_WINDOW_TABVIEW_NONE);

  if (nShow == 1)
  {
    if (bTop)
      AkelPad.Command(IDM_WINDOW_TABVIEW_TOP);
    else
      AkelPad.Command(IDM_WINDOW_TABVIEW_BOTTOM);
  }
  else if ((nShow == 2) && (! (nState & TAB_VIEW_NONE)))
  {
    if (nState & TAB_VIEW_TOP)
      AkelPad.Command(IDM_WINDOW_TABVIEW_TOP);
    else
      AkelPad.Command(IDM_WINDOW_TABVIEW_BOTTOM);
  }
}

function ChangeFont(sViewName)
{
  if (oView[sViewName].Font)
    AkelPad.Font(oView[sViewName].FontName, oView[sViewName].FontStyle, oView[sViewName].FontSize);
}

function ChangeTheme(sViewName)
{
  if (! oView[sViewName].Theme)
    return;

  var nColorsSize = 17 * 4; //sizeof(AECOLORS)
  var lpColors    = AkelPad.MemAlloc(nColorsSize);

  if (oView[sViewName].ThemeName == "<Standard>")
    AkelPad.MemCopy(lpColors, 0x0001FFFF /*AECLR_DEFAULT|AECLR_ALL*/, DT_DWORD);

  else
  {
    if (IsSettingsInRegistry())
    {
      var hKey       = GetRegKeyHandle(0x80000001 /*HKEY_CURRENT_USER*/, "Software\\Akelsoft\\AkelPad\\Themes", 0x0001 /*KEY_QUERY_VALUE*/);
      var lpDataSize = AkelPad.MemAlloc(4);

      if (hKey)
      {
        AkelPad.MemCopy(lpDataSize, nColorsSize, DT_DWORD);

        if (oSys.Call("Advapi32::RegQueryValueExW", hKey, oView[sViewName].ThemeName, 0, 0, lpColors, lpDataSize) == 0 /*ERROR_SUCCESS*/)
          AkelPad.MemCopy(lpColors, 0x0001FFFE /*AECLR_ALL*/, DT_DWORD);

        oSys.Call("Advapi32::RegCloseKey", hKey);
      }

      AkelPad.MemFree(lpDataSize);
    }
    else
    {
      var nBufSize = (nColorsSize * 2 + 1) * 2;
      var lpBuffer = AkelPad.MemAlloc(nBufSize);
      var sThemeData;
      var i;

      oSys.Call("Kernel32::GetPrivateProfileStringW", "Themes", oView[sViewName].ThemeName, 0, lpBuffer, nBufSize / 2, AkelPad.GetAkelDir(0 /*ADTYPE_ROOT*/) + "\\AkelPad.ini");

      if (sThemeData = AkelPad.MemRead(lpBuffer, DT_UNICODE))
      {
        sThemeData = "FEFF0100" + sThemeData.substr(8); //0x0001FFFE = AECLR_ALL (AEM_SETCOLORS flags)

        for (i = 0; i < sThemeData.length; i += 2)
          AkelPad.MemCopy(lpColors + i / 2, parseInt("0x" + sThemeData.substr(i, 2)), DT_BYTE);
      }

      AkelPad.MemFree(lpBuffer);
    }
  }

  if (oPlug.CoderTheme.IsRunning())
    AkelPad.Call("Coder::Settings", 5, "Default");

  AkelPad.SetFrameInfo(0, 72 /*FIS_COLORS*/, lpColors);
  AkelPad.MemFree(lpColors);
}

function ChangeCoderTheme(sViewName)
{
  if ((oView[sViewName].CoderTheme < 2) && IsPluginExists(oPlug.CoderTheme.Name))
  {
    if (oView[sViewName].CoderTheme == 1)
    {
      if (! oPlug.CoderTheme.IsRunning())
        oPlug.CoderTheme.Switch();

      AkelPad.Call("Coder::Settings", 5, oView[sViewName].CoderThemeName);
    }
    else
    {
      if (oPlug.CoderTheme.IsRunning())
        oPlug.CoderTheme.Switch();
    }
  }
}

function SetThemeName(sName)
{
  var aTheme = ["<Standard>"];
  var oRect  = {};
  var hMenu  = oSys.Call("User32::CreatePopupMenu");
  var nCmd;
  var nX, nY;
  var i;

  FillThemeArray(aTheme);

  GetWindowPos(aWnd[IDTHEMENAME][HWND], oRect);

  for (i = 0; i < aTheme.length; ++i)
    oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, i + 1, aTheme[i]);

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0184 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_CENTERALIGN*/, oRect.X + oRect.W / 2, oRect.Y + oRect.H, 0, hWndDlg, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  if (nCmd)
  {
    oView[sName].ThemeName = aTheme[nCmd - 1];
    oSys.Call("User32::SetWindowTextW", aWnd[IDTHEMENAME][HWND], oView[sName].ThemeName);
  }
}

function FillThemeArray(aTheme)
{
  if (IsSettingsInRegistry())
  {
    var nNameMaxLen = 16383;
    var lpNameLen   = AkelPad.MemAlloc(4);
    var lpName      = AkelPad.MemAlloc((nNameMaxLen + 1) * 2);
    var hKey        = GetRegKeyHandle(0x80000001 /*HKEY_CURRENT_USER*/, "Software\\Akelsoft\\AkelPad\\Themes", 0x0001 /*KEY_QUERY_VALUE*/);
    var nIndex      = 0;
    var sValueName;

    if (hKey)
    {
      AkelPad.MemCopy(lpNameLen, nNameMaxLen, DT_DWORD);

      while (oSys.Call("Advapi32::RegEnumValueW", hKey, nIndex, lpName, lpNameLen, 0, 0, 0, 0) == 0 /*ERROR_SUCCESS*/)
      {
        if (sValueName = AkelPad.MemRead(lpName, DT_UNICODE))
          aTheme.push(sValueName);

        AkelPad.MemCopy(lpNameLen, nNameMaxLen, DT_DWORD);
        ++nIndex;
      }

      oSys.Call("Advapi32::RegCloseKey", hKey);
    }

    AkelPad.MemFree(lpNameLen);
    AkelPad.MemFree(lpName);
  }
  else
  {
    var nBufSize = 32767 * 2;
    var lpBuffer = AkelPad.MemAlloc(nBufSize);
    var lpKey    = lpBuffer;
    var sKey;

    if (oSys.Call("Kernel32::GetPrivateProfileSectionW", "Themes", lpBuffer, nBufSize / 2, AkelPad.GetAkelDir(0 /*ADTYPE_ROOT*/) + "\\AkelPad.ini"))
    {
      do
      {
        if (sKey = AkelPad.MemRead(lpKey, DT_UNICODE))
        {
          lpKey += (sKey.length + 1) * 2;
          if (sKey = sKey.substr(0, sKey.indexOf("=")))
            aTheme.push(sKey);
        }
      }
      while (sKey);
    }

    AkelPad.MemFree(lpBuffer);
  }
}


Last edited by KDJ on Fri Jan 03, 2014 3:13 pm; edited 3 times in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1325
Location: Poland

PostPosted: Mon Dec 17, 2012 8:30 pm    Post subject: Reply with quote

Switch between different views of AkelPad screen - part 2.

ScreenView_part2.js

Code:
function SetCoderThemeName(sName)
{
  var aTheme = [
    "Default",
    "Active4D",
    "Bespin",
    "Cobalt",
    "Dawn",
    "Earth",
    "iPlastic",
    "Lazy",
    "Mac Classic",
    "Monokai",
    "Solarized Light",
    "Solarized Dark",
    "SpaceCadet",
    "Sunburst",
    "Twilight",
    "Zenburn"];
  var oRect = {};
  var hMenu = oSys.Call("User32::CreatePopupMenu");
  var nCmd;
  var nX, nY;
  var i;

  FillCoderThemeArray(aTheme);

  GetWindowPos(aWnd[IDCODERTHEMENAME][HWND], oRect);

  for (i = 0; i < aTheme.length; ++i)
  {
    if (aTheme[i])
      oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, i + 1, aTheme[i]);
    else
      oSys.Call("User32::AppendMenuW", hMenu, 0x0800 /*MF_SEPARATOR*/, 0);
  }

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0184 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_CENTERALIGN*/, oRect.X + oRect.W / 2, oRect.Y + oRect.H, 0, hWndDlg, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  if (nCmd)
  {
    oView[sName].CoderThemeName = aTheme[nCmd - 1];
    oSys.Call("User32::SetWindowTextW", aWnd[IDCODERTHEMENAME][HWND], oView[sName].CoderThemeName);
  }
}

function FillCoderThemeArray(aTheme)
{
  var nBufSize = 4096;
  var lpBuffer = AkelPad.MemAlloc(nBufSize);
  var lpDataSize;
  var hKey;
  var sThemes;
  var aTemp;
  var i;

  if (IsSettingsInRegistry())
  {
    if (hKey = GetRegKeyHandle(0x80000001 /*HKEY_CURRENT_USER*/, "Software\\Akelsoft\\AkelPad\\Plugs\\Coder", 0x0001 /*KEY_QUERY_VALUE*/))
    {
      lpDataSize = AkelPad.MemAlloc(4);
      AkelPad.MemCopy(lpDataSize, nBufSize, DT_DWORD);

      oSys.Call("Advapi32::RegQueryValueExW", hKey, "VarThemeList", 0, 0, lpBuffer, lpDataSize);

      oSys.Call("Advapi32::RegCloseKey", hKey);
      AkelPad.MemFree(lpDataSize);
    }
  }
  else
    oSys.Call("Kernel32::GetPrivateProfileStringW", "Options", "VarThemeList", 0, lpBuffer, nBufSize / 2, AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/) + "\\Coder.ini");

  if (sThemes = AkelPad.MemRead(lpBuffer, DT_UNICODE))
  {
    aTemp = sThemes.split("|");
    aTheme.push("");
    for (i = 0; i < aTemp.length; ++i)
      aTheme.push(aTemp[i]);
  }

  AkelPad.MemFree(lpBuffer);
}

function GetRegKeyHandle(hParentKey, sSubKey, nAccess)
{
  var hKey   = 0;
  var lpKey  = AkelPad.MemAlloc(_X64 ? 8 : 4);
  var nError = oSys.Call("Advapi32::RegOpenKeyExW",
                         hParentKey, //hKey
                         sSubKey,    //lpSubKey
                         0,          //ulOptions
                         nAccess,    //samDesired
                         lpKey);     //phkResult

  if (! nError)
    hKey = AkelPad.MemRead(lpKey, DT_QWORD);

  AkelPad.MemFree(lpKey);

  return hKey;
}

function WarningBox(hWnd, sText)
{
  AkelPad.MessageBox(hWnd, sText, sScriptName, 0x00000030 /*MB_ICONWARNING*/);
}

function ReadWriteIni(bWrite)
{
  var sIniFile = WScript.ScriptFullName.substring(0, WScript.ScriptFullName.lastIndexOf(".")) + ".ini";
  var oFile;
  var oRect;
  var sIniTxt;
  var i, n;

  if (bWrite)
  {
    GetWindowPos(hWndDlg, oRect = {});

    sIniTxt = 'nWndPosX=' + oRect.X + ';\r\n' +
              'nWndPosY=' + oRect.Y + ';\r\n' +
              'nWndPosW=' + oRect.W + ';\r\n' +
              'nView='    + GetCurSelLB() + ';\r\n';

    for (i in oView)
    {
      sIniTxt += 'oView["' + i.replace(/[\\"]/g, "\\$&") + '"]={';
      for (n in oView[i])
        sIniTxt += '"' + n + '":' + ((typeof oView[i][n] == 'string') ? '"' : '') + oView[i][n] + ((typeof oView[i][n] == 'string') ? '"' : '') + ',';

      if (sIniTxt.slice(-1) == ",")
        sIniTxt = sIniTxt.slice(0, -1);

      sIniTxt += '};\r\n';
    }

    oFile = oFSO.OpenTextFile(sIniFile, 2, true, -1);
    oFile.Write(sIniTxt);
    oFile.Close();
  }

  else if (oFSO.FileExists(sIniFile))
  {
    try
    {
      eval(AkelPad.ReadFile(sIniFile));
    }
    catch (oError)
    {
    }
  }
}


Last edited by KDJ on Fri Jan 03, 2014 3:15 pm; edited 3 times in total
Back to top
View user's profile Send private message
cnnnc



Joined: 12 Jan 2008
Posts: 116
Location: Shantou, China

PostPosted: Tue Dec 18, 2012 1:54 am    Post subject: InsertNum.js Reply with quote

InsertNum.js
Code:
// InsertNum.js - 2012-12-20 by cnnnc
// Insert a sequence of number.
//
// Example:
// Call("Scripts::Main", 1, "InsertNum.js")

try
{
  var hMainWnd=AkelPad.GetMainWnd();
}
catch (oError)
{
  WScript.Quit();
}

if (!(AkelPad.Include("InputBox_function.js")))
{
  WScript.Quit();
}

var sCaption =WScript.ScriptName;
var oSys     =AkelPad.SystemFunction();
var nAkelEdit=AkelPad.IsAkelEdit();
var hWndEdit =AkelPad.GetEditWnd();

var sLng=AkelPad.GetLangId(0 /*LANGID_FULL*/);
if (sLng==2052) //Chinese Simplified
{
  var vLabel     =["开始","结束","增量","宽度","填充","分隔符","十六进制","前缀","后缀"];
  var sTxtWarning="警告:次数太多,可能会内存不足。是否继续?";
  var sTxtError="错误!\n";
  var sTxtError1="仅允许数值类型。";
  var sTxtError2="不能等于";
  var sTxtError3="不能等于 0";
  var sTxtSeconds="耗时 %s 秒。";
}
else // English
{
  var vLabel     =["Start","End","Step","Width","Pad","Seperator","Hex","Prefix","Subfix"];
  var sTxtWarning="Warning: Times is so big, may be result to out of memory. Continue?";
  var sTxtError="Error!\n";
  var sTxtError1="allow number type only.";
  var sTxtError2="should not same as";
  var sTxtError3="should not be 0";
  var sTxtSeconds="It's take %s Seconds.";
}

var vEdit    =[];
var nFocus   =0;
var sFunction="CheckNum";
var vFuncArg ="";

SetRedraw(hWndEdit, false);

if (WScript.Arguments.length)
{
  eval(AkelPad.GetArgLine(0));
  if (vEdit.length!=9)
  {
    vEdit=["1","9","1","1","0","\\n","0","",""];
  }
}
else
{
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin(WScript.ScriptBaseName, 0x1 /*POB_READ*/))
  {
    //Read settings
    vEdit.push(oSet.Read("Start"    , 3 /*PO_STRING*/, "1"));
    vEdit.push(oSet.Read("End"      , 3 /*PO_STRING*/, "9"));
    vEdit.push(oSet.Read("Step"     , 3 /*PO_STRING*/, "1"));
    vEdit.push(oSet.Read("Width"    , 3 /*PO_STRING*/, "1"));
    vEdit.push(oSet.Read("Pad"      , 3 /*PO_STRING*/, "0"));
    vEdit.push(oSet.Read("Seperator", 3 /*PO_STRING*/, "\\n"));
    vEdit.push(oSet.Read("Hex"      , 3 /*PO_STRING*/, "0"));
    vEdit.push(oSet.Read("Prefix"   , 3 /*PO_STRING*/, ""));
    vEdit.push(oSet.Read("Subfix"   , 3 /*PO_STRING*/, ""));

    oSet.End();
  }
  else
  {
    vEdit=["1","9","1","1","0","\\n","0","",""];
  }
  vEdit = InputBox(hMainWnd, sCaption, vLabel, vEdit, nFocus, sFunction, vFuncArg);
  if (vEdit == undefined)
  {
    SetRedraw(hWndEdit, true);
    WScript.Quit();
  }
}

var d=new Date();
var t=d.getTime();

var nStart    =Number(vEdit[0]);
var nEnd      =Number(vEdit[1]);
var nStep     =Number(vEdit[2]);

if (nStart==nEnd || nStep==0)
{
  SetRedraw(hWndEdit, true);
  WScript.Quit();
}

var nCurVal=Math.floor(Math.abs(nEnd-nStart)/nStep);
if (nCurVal>9999999)
{
  if(AkelPad.MessageBox(hMainWnd, sTxtWarning, sCaption, 52)!=6)
  {
    SetRedraw(hWndEdit, true);
    WScript.Quit();
  }
}

if (vEdit[4]=="")
{
  vEdit[3]="1";
}
var sStart    =vEdit[0];
var sEnd      =vEdit[1];
var sStep     =vEdit[2];
var nWidth    =parseInt(vEdit[3]);
var sPad      =vEdit[4];
var sSeperator=vEdit[5];
var bHex      =vEdit[6];
var sPrefix   =vEdit[7];
var sSubfix   =vEdit[8];

var m=0;
var sStr="";
var oneStop=0xFFF;


if (nStart!=parseInt(sStart) || nEnd!=parseInt(sEnd) || nStep!=parseInt(sStep))
{
  var r1,r2,r3;
  try{r1=sStart.split(".")[1].length;}catch(e){r1=0;}
  try{r2=sEnd.split(".")[1].length;}catch(e){r2=0;}
  try{r3=sStep.split(".")[1].length;}catch(e){r3=0;}
  m=Math.max(r1,r2,r3);
}

if (m==0 && bHex=="1")
{
  bHex=true;
}
else
{
  bHex=false;
}

if (sSeperator) sSeperator=TranslateEscapeString(sSeperator);
if (sPrefix) sPrefix=TranslateEscapeString(sPrefix);
if (sSubfix) sSubfix=TranslateEscapeString(sSubfix);

if (nStart<nEnd)
{
  for (;;)
  {
    if (nCurVal>oneStop)
    {
      sStr=sStr+SequenceNum(oneStop,0);
      CollectGarbage();
      nStart=nStart+(oneStop+1)*nStep;
      nCurVal=nCurVal-(oneStop+1);
    }
    else
    {
      sStr=sStr+SequenceNum(nCurVal,0);
      CollectGarbage();
      break;
    }
  }
}
else if (nStart>nEnd)
{
  for (;;)
  {
    if (nCurVal>oneStop)
    {
      sStr=sStr+SequenceNum(oneStop,1);
      CollectGarbage();
      nStart=nStart-(oneStop+1)*nStep;
      nCurVal=nCurVal-(oneStop+1);
    }
    else
    {
      sStr=sStr+SequenceNum(nCurVal,1);
      CollectGarbage();
      break;
    }
  }
}
SetRedraw(hWndEdit, true);

AkelPad.ReplaceSel(sStr);

if (!WScript.Arguments.length)
{
  if (oSet.Begin(WScript.ScriptBaseName, 0x2 /*POB_SAVE*/))
  {
    //Save settings
    oSet.Write("Start"    , 3 /*PO_STRING*/, vEdit[0]);
    oSet.Write("End"      , 3 /*PO_STRING*/, vEdit[1]);
    oSet.Write("Step"     , 3 /*PO_STRING*/, vEdit[2]);
    oSet.Write("Width"    , 3 /*PO_STRING*/, vEdit[3]);
    oSet.Write("Pad"      , 3 /*PO_STRING*/, vEdit[4]);
    oSet.Write("Seperator", 3 /*PO_STRING*/, vEdit[5]);
    oSet.Write("Hex"      , 3 /*PO_STRING*/, vEdit[6]);
    oSet.Write("Prefix"   , 3 /*PO_STRING*/, vEdit[7]);
    oSet.Write("Subfix"   , 3 /*PO_STRING*/, vEdit[8]);

    oSet.End();
  }
}

var d=new Date();
t=(d.getTime()-t)/1000;

if (Math.round(t)>1) AkelPad.MessageBox(hMainWnd, prepareString(sTxtSeconds, [t]), sCaption, 0 /*MB_OK*/);

sStr=null;
CollectGarbage();

//function
function Pad(nCurrentNum)
{
  var pNumText;
  var nLen;
  var cPadding="";

  if (bHex)
  {
    pNumText=nCurrentNum.toString(16);
  }
  else
  {
    pNumText=nCurrentNum.toFixed(m);
  }

  if (nCurrentNum<0) pNumText="-"+pNumText.substr(1);

  nLen=Math.abs(nWidth)-pNumText.length+1;

  while ((nLen-=1)>0)
  {
    cPadding+=sPad;
  }

  if (nWidth<0) pNumText += cPadding;
  else pNumText=cPadding+pNumText;

  return pNumText;
}

function CheckNum(hWnd, vEdit, nIndex)
{
  for (i=0; i<4; ++i)
  {
    if (isNaN(parseInt(vEdit[i])))
    {
      AkelPad.MessageBox(hWnd, sTxtError + "\""+vLabel[i]+"\" "+sTxtError1, sCaption, 0 /*MB_OK*/);
      return i;
    }
  }
  if (vEdit[0]==vEdit[1])
  {
    AkelPad.MessageBox(hWnd, sTxtError + "\""+vLabel[1]+"\" "+sTxtError2 + "\""+vLabel[0]+"\" ", sCaption, 0 /*MB_OK*/);
    return 1;
  }
  if (vEdit[2]==0)
  {
    AkelPad.MessageBox(hWnd, sTxtError + "\""+vLabel[2]+"\" "+sTxtError3, sCaption, 0 /*MB_OK*/);
    return 2;
  }
  return -1;
}

function SequenceNum(nStop,bMax)
{
  var aStr=null;
  aStr=[];

  if (bMax)
  {
    if (!bHex && (nWidth==1 || nWidth==0 || nWidth ==-1))
    {
      for (i=0; i<=nStop; i++)
      {
        aStr[i]=(nStart-i*nStep).toFixed(m);
      }
    }
    else
    {
      for (i=0; i<=nStop; i++)
      {
        aStr[i]=Pad(nStart-i*nStep);
      }
    }
  }
  else
  {
    if (!bHex && (nWidth==1 || nWidth==0 || nWidth ==-1))
    {
      for (i=0; i<=nStop; i++)
      {
        aStr[i]=(nStart+i*nStep).toFixed(m);
      }
    }
    else
    {
      for (i=0; i<=nStop; i++)
      {
        aStr[i]=Pad(nStart+i*nStep);
      }
    }
  }

  if (sPrefix=="" && sSubfix=="")
  {
    return aStr.join(sSeperator)+sSeperator;
  }
  else if (sPrefix=="" && sSubfix!="")
  {
    return aStr.join(sSubfix+sSeperator)+sSubfix+sSeperator;
  }
  else if (sPrefix!="" && sSubfix=="")
  {
    return sPrefix+aStr.join(sSeperator+sPrefix)+sSeperator;
  }
  else
  {
    return sPrefix+aStr.join(sSubfix+sSeperator+sPrefix)+sSubfix+sSeperator;
  }
}

function TranslateEscapeString(pString)
{
  pString=pString.replace(/\\\\/g, "\0");
  pString=pString.replace(/\\n|\\r/g,"\n");
  pString=pString.replace(/\\t/g,"\t");
  return pString.replace(/\0/g,"\\");
}

function prepareString(pString, aVar)
{
  pString=pString.replace(/%%/g,"←■→");
  if (pString.indexOf("%s") >= 0)
  {
    pString = pString.split("%s");
    for (i=0;i<pString.length-1;i+=1)
    {
      pString[i] = pString[i]+aVar[i].toString();
    }
    pString=pString.join("");
  }
  pString=pString.replace(/←■→/g,"%%");
  return pString;
}

function SetRedraw(hWnd, bRedraw)
{
  if (nAkelEdit)
  {
    AkelPad.SendMessage(hWnd, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, !bRedraw);
  }

  AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
  if (bRedraw)
  {
    oSys.Call("user32::InvalidateRect", hWnd, 0, true);
  }
}
, insert a sequence of number. Need Inputbox_function.js.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins All times are GMT
Goto page Previous  1, 2, 3 ... 15, 16, 17, 18  Next
Page 16 of 18

 
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


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group