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 ... 16, 17, 18
 
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Andrey_A_A



Joined: 03 Jun 2010
Posts: 535
Location: Сочи, Хоста

PostPosted: Fri Jan 10, 2014 1:30 pm    Post subject: Reply with quote

На днях готовил релиз AkelPad Image, собралось немало интересных наработок.

Выкладываю одним архивом 130 скриптов, написанных с 2010 года на vbs (возможно что-то из этого списка понравится и принесёт пользу)

Архив скриптов

Список с описанием всех скриптов

Если нужно будет, то архив можно залить на внутренний ресурс и добавить ссылку на первую страницу.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KDJ



Joined: 06 Mar 2010
Posts: 1263
Location: Poland

PostPosted: Fri Jan 10, 2014 8:30 pm    Post subject: Reply with quote

Right click on LineBoard panel, calls any script or ContextMenu::Show instead of LineBoard menu.

LineBoardRClickPanel.js

Code:
/*
LineBoardRClickPanel.js - ver. 2014-02-02 (x86/x64)

Right click on LineBoard panel, calls any script or ContextMenu::Show instead of LineBoard menu.

Usage:
  Call("Scripts::Main", 1, "LineBoardRClickPanel.js", '"ScriptOrMenu" "Parameters"')

Arguments (are optional):
  "ScriptOrMenu"
    script name or submenu defined in ContextMenu::Show, default is "LineBoardBookmarks.js"
  "Parameters"
    parameters passed to the script; if script is "LineBoardBookmarks.js", default parameter is "MM"

Notes:
  After first call, the script resides in the memory.
  Second script call, closes the script.

For autostart, in AkelPad.ini or registry CmdLineBegin key, need to add eg:
  /Call("Scripts::Main", 1, "LineBoardRClickPanel.js")
    show menu from script LineBoardBookmarks.js at mouse cursor position
  /Call("Scripts::Main", 1, "LineBoardRClickPanel.js", '"Bookmarks"')
    show user submenu "Bookmarks" from ContextMenu plugin at cursor position
      #menu example
      "Bookmarks"
      {
        "Set bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "BS")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "B")
        }
        "Delete bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "US")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "U"')
        }
        "Inverse bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "IS")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "I"')
        }
        SEPARATOR
        "Settings" Call("LineBoard::Settings")
      }
*/

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);

if (hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
{
  //script already is running, close it
  AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
}
else
{
  var hSubClassEdit = AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 123 /*WM_CONTEXTMENU*/);
  var sArg0, sArg1;
  var bMenu;

  if (hSubClassEdit)
  {
    if (WScript.Arguments.length)
    {
      sArg0 = WScript.Arguments(0).toUpperCase();

      if ((sArg0.slice(-3) == ".JS") || (sArg0.slice(-4) == ".VBS"))
      {
        if (WScript.Arguments.length > 1)
          sArg1 = WScript.Arguments(1);
        else if (sArg0 == "LINEBOARDBOOKMARKS.JS")
          sArg1 = "MM";
      }
      else
        bMenu = true;
    }
    else
    {
      sArg0 = "LineBoardBookmarks.js";
      sArg1 = "MM";
    }

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

    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if ((uMsg == 123 /*WM_CONTEXTMENU*/) && AkelPad.IsPluginRunning("LineBoard::Main") && IsRClickPanel(hWnd, lParam & 0xFFFF, (lParam >> 16) & 0xFFFF))
  {
    AkelPad.WindowNoNextProc(hSubClassEdit);

    if (bMenu)
      AkelPad.Call("ContextMenu::Show", 1, "-6", "-6", -1, sArg0);
    else
      AkelPad.Call("Scripts::Main", 1, sArg0, sArg1);

    AkelPad.WindowNoNextProc(hSubClassEdit);
  }

  return 0;
}

function IsRClickPanel(hWnd, nCursorX, nCursorY)
{
  var lpRect = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);

  //get rectangle outside panels
  AkelPad.CallW("LineBoard::Main", 11, hWnd, 0, lpRect);

  AkelPad.SystemFunction().Call("User32::ClientToScreen", hWnd, lpRect);
  AkelPad.SystemFunction().Call("User32::ClientToScreen", hWnd, lpRect + 8);

  var nX = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
  var nY = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
  var nH = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/);
  AkelPad.MemFree(lpRect);

  if ((nCursorX <= nX) && (nCursorY >= nY) && (nCursorY <= nH))
    return true;

  return false;
}


Last edited by KDJ on Sun Feb 02, 2014 7:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1263
Location: Poland

PostPosted: Wed Jan 29, 2014 7:24 pm    Post subject: Reply with quote

Preview of AkelPad docs files (...\AkelPad\AkelFiles\Docs\).

AkelPadDocsView.js

Code:
// AkelPadDocsView.js - ver. 2014-03-24 (x86/x64)
//
// Preview of AkelPad docs files (...\AkelPad\AkelFiles\Docs\)
//
// Usage:
// Call("Scripts::Main", 1, "AkelPadDocsView.js")
// Required to include: BrowseForFolder_function.js and InputBox_function.js
//
// Hotkeys:
// Tab - rigth <-> left panel
// Ctrl(+Shift)+Tab - next/previous file
// F1 - menu
// F4 - maximize/restore window
//
// Remarks:
// The script should be saved in Unicode format.
// For proper operation of function "AkelHelp" on Windows 7, AkelPad must be run as administrator.

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

if (hDlg)
  SetForegroundWindow(hDlg);

else
{
  if (! (AkelPad.Include("BrowseForFolder_function.js") && AkelPad.Include("InputBox_function.js")))
    WScript.Quit();

  GetLangStrings();

  var hMainWnd     = AkelPad.GetMainWnd();
  var hGuiFont     = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
  var oFSO         = new ActiveXObject("Scripting.FileSystemObject");
  var nDlgMinW     = 640;
  var nDlgMinH     = 300;
  var oDlgPos      = {"X": 100, "Y": 100, "W": nDlgMinW, "H": nDlgMinH, "Max": 0};
  var nIEX         = 100;
  var nIEY         = 100;
  var nIEW         = 600;
  var nIEH         = 400;
  var bIEMax       = false;
  var bSeparateWnd = false;
  var nAPDSel      = 0;
  var nLang        = 0;
  var bMatchCase   = false;
  var bWordWrap    = false;
  var sFindText    = "";
  var sAltDir      = "";
  var aAPD         = [];
  var aAESel       = [{}, {}];
  var aIsLang;
  var sAkelHelpFile;
  var oIE;
  var hSubClass;
  var hWndParent;
  var hFocus;

  ReadIni();
  GetArrayAPD(hMainWnd);
  if (! aAPD.length) WScript.Quit();

  var nTextMax = 512;
  var lpTextLV = AkelPad.MemAlloc(nTextMax * 2);
  var lpLVITEM = AkelPad.MemAlloc(_X64 ? (72) : (60)); //sizeof(LVITEM)
  AkelPad.MemCopy(lpLVITEM, 0x0001 /*LVIF_TEXT*/, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpLVITEM + (_X64 ? 24 : 20), lpTextLV, 2 /*DT_QWORD*/);
  AkelPad.MemCopy(lpLVITEM + (_X64 ? 32 : 24), nTextMax, 3 /*DT_DWORD*/);

  var aDlg     = [];
  var IDFILES  = 1000;
  var IDNAMELV = 1001;
  var IDTEXTAE = 1002;
  var IDLANG1B = 1003;
  var IDLANG2B = 1004;
  var IDHELPB  = 1005;
  var IDMENUB  = 1006;
  var IDCLOSEB = 1007;

  aDlg[IDFILES  ] = {Txt: "",          Class: "STATIC",        Style: 0x50000001 /*WS_VISIBLE|WS_CHILD|SS_CENTER*/};
  aDlg[IDNAMELV ] = {Txt: "",          Class: "SysListView32", Style: 0x5080800D /*WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_NOSORTHEADER|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT*/};
  aDlg[IDTEXTAE ] = {Txt: "",          Class: "AkelEditW",     Style: 0x50B00804 /*WS_VISIBLE|WS_CHILD|WS_BORDER|WS_VSCROLL|WS_HSCROLL|ES_READONLY|ES_MULTILINE*/};
  aDlg[IDLANG1B ] = {Txt: sTxtEnglish, Class: "BUTTON",        Style: 0x50000009 /*WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON*/};
  aDlg[IDLANG2B ] = {Txt: sTxtRussian, Class: "BUTTON",        Style: 0x50000009 /*WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON*/};
  aDlg[IDHELPB  ] = {Txt: "&AkelHelp", Class: "BUTTON",        Style: 0x50000000 /*WS_VISIBLE|WS_CHILD*/};
  aDlg[IDMENUB  ] = {Txt: sTxtMenu,    Class: "BUTTON",        Style: 0x50000000 /*WS_VISIBLE|WS_CHILD*/};
  aDlg[IDCLOSEB ] = {Txt: sTxtClose,   Class: "BUTTON",        Style: 0x50000000 /*WS_VISIBLE|WS_CHILD*/};

  AkelPad.WindowRegisterClass(sClassName);

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

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

  AkelPad.ScriptNoMutex();
  AkelPad.WindowGetMessage();

  AkelPad.WindowUnregisterClass(sClassName);
  AkelPad.MemFree(lpTextLV);
  AkelPad.MemFree(lpLVITEM);

  SetForegroundWindow(hMainWnd);

  if (oIE && (typeof oIE.Application == "object"))
    oIE.Quit();
}

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    var i;

    for (i = IDFILES; i < aDlg.length; ++i)
    {
      aDlg[i].Handle = oSys.Call("User32::CreateWindowExW",
        0,            //dwExStyle
        aDlg[i].Class,//lpClassName
        aDlg[i].Txt,  //lpWindowName
        aDlg[i].Style,//dwStyle
        0, 0, 0, 0,   //x, y, nWidth, nHeight
        hWnd,         //hWndParent
        i,            //ID
        hInstance,    //hInstance
        0);           //lpParam
      SetWindowFont(aDlg[i].Handle, hGuiFont);
    }

    CheckButtons();

    hSubClass = AkelPad.WindowSubClass(aDlg[IDTEXTAE].Handle, EditCallback, 135 /*WM_GETDLGCODE*/, 256 /*WM_KEYDOWN*/);
    SetOptionsAE();

    InsertColumnLV();
    FillLV(nAPDSel, AkelPad.GetSelText().toUpperCase());

    oSys.Call("User32::SetFocus", aDlg[IDTEXTAE].Handle);
    oSys.Call("User32::SetFocus", aDlg[IDNAMELV].Handle);

    PostMessage(hWnd, 0x8000 /*WM_APP*/, 0, 0);
  }

  else if (uMsg == 0x8000 /*WM_APP*/)
  {
    if (aAESel[nLang][aAPD[nAPDSel][0]])
      SetSelAE(aAESel[nLang][aAPD[nAPDSel][0]][0], aAESel[nLang][aAPD[nAPDSel][0]][1]);
  }

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

  else if (uMsg == 36) //WM_GETMINMAXINFO
  {
    AkelPad.MemCopy(lParam + 24, nDlgMinW, 3 /*DT_DWORD*/); //ptMinTrackSize_x
    AkelPad.MemCopy(lParam + 28, nDlgMinH, 3 /*DT_DWORD*/); //ptMinTrackSize_y
  }

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

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

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

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

  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 9 /*VK_TAB*/)
    {
      if (Ctrl())
      {
        if (Shift())
        {
          if (nAPDSel > 0)
            --nAPDSel;
          else
            nAPDSel = aAPD.length - 1;
        }
        else
        {
          if (nAPDSel < aAPD.length - 1)
            ++nAPDSel;
          else
            nAPDSel = 0;
        }
        SetCurSelLV(nAPDSel);
        oSys.Call("User32::SetFocus", hFocus);
      }
      else
      {
        if (hFocus == aDlg[IDNAMELV].Handle)
          oSys.Call("User32::SetFocus", aDlg[IDTEXTAE].Handle);
        else
          oSys.Call("User32::SetFocus", aDlg[IDNAMELV].Handle);
      }
    }
    else if ((wParam >= 0x21 /*VK_PRIOR*/) && (wParam <= 0x28 /*VK_DOWN*/))
    {
      if (Ctrl() && (! Shift()) && Alt())
        MoveDlg(wParam);
    }
    else if ((wParam == 0x43 /*C key*/) || (wParam == 0x2D /*VK_INSERT*/))
    {
      if  (Ctrl() && (! Alt()))
      {
        if (hFocus == aDlg[IDNAMELV].Handle)
          InsertNameTo(! Shift(), wParam == 0x2D /*VK_INSERT*/);
        else
          InsertTextTo(! Shift());
      }
    }
    else if (wParam == 0x46 /*F key*/)
    {
      if (Ctrl() && (! Alt()))
        FindText(Shift() ? 2 : 0);
    }
    else if (wParam == 0x55 /*U key*/)
    {
      if (Ctrl() && (! Shift()) && (! Alt()))
      {
        bWordWrap = ! bWordWrap;
        SetWordWrapAE();
      }
    }
    else if (wParam == 0x70 /*VK_F1*/)
    {
      if ((! Ctrl()) && (! Shift()))
        MenuMain();
    }
    else if (wParam == 0x72 /*VK_F3*/)
    {
      if (! Ctrl())
        FindTextNext(Shift() ? 3 : 1);
    }
    else if (wParam == 0x73 /*VK_F4*/)
    {
      if ((! Ctrl()) && (! Shift()))
        oSys.Call("User32::ShowWindow", hWnd, oSys.Call("User32::IsZoomed", hWnd) ? 9 /*SW_RESTORE*/ : 3 /*SW_MAXIMIZE*/);
    }
    else if (wParam == 27 /*VK_ESCAPE*/)
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if (wParam == 0x46 /*F key*/)
      FindText(Shift() ? 3 : 1);
    else if (wParam == 13 /*VK_RETURN*/)
    {
      if (! Shift())
        oSys.Call("User32::ShowWindow", hWnd, oSys.Call("User32::IsZoomed", hWnd) ? 9 /*SW_RESTORE*/ : 3 /*SW_MAXIMIZE*/);
    }
  }

  else if ((uMsg == 0x004E /*WM_NOTIFY*/) && (wParam == IDNAMELV))
  {
    switch (AkelPad.MemRead(lParam + (_X64 ? 16 : 8), 3 /*DT_DWORD*/))
    {
      case -101 : //LVN_ITEMCHANGED
        if (AkelPad.MemRead(lParam + (_X64 ? 32 : 20) /*NMLISTVIEW.uNewState*/, 3 /*DT_DWORD*/) & 0x2 /*LVIS_SELECTED*/)
        {
          nAPDSel = GetCurSelLV();
          SetWindowText(aDlg[IDFILES].Handle, aAPD[nAPDSel][2]);
          SetWindowText(aDlg[IDTEXTAE].Handle, aAPD[nAPDSel][1]);

          if (aAESel[nLang][aAPD[nAPDSel][0]])
            SetSelAE(aAESel[nLang][aAPD[nAPDSel][0]][0], aAESel[nLang][aAPD[nAPDSel][0]][1]);
        }
        break;
      case -2 : //NM_CLICK
      case -3 : //NM_DBLCLK
      case -5 : //NM_RCLICK
      case -6 : //NM_RDBLCLK
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, 3 /*DT_DWORD*/) == -1)
          SetCurSelLV(GetCurFocLV());
        break;
      case -7 : //NM_SETFOCUS
        hFocus = aDlg[IDNAMELV].Handle;
        break;
    }
  }

  else if (uMsg == 123) //WM_CONTEXTMENU
  {
    if (wParam == aDlg[IDNAMELV].Handle)
      MenuName(LoWord(lParam), HiWord(lParam));
    else if (wParam == aDlg[IDTEXTAE].Handle)
    {
      oSys.Call("User32::SetFocus", aDlg[IDTEXTAE].Handle);
      MenuText(LoWord(lParam), HiWord(lParam));
    }
  }

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

    if (nLowParam == IDTEXTAE)
    {
      if (nHiwParam == 0x0100 /*EN_SETFOCUS*/)
      {
        if (SendMessage(AkelPad.GetEditWnd(), 3227 /*AEM_GETOPTIONS*/, 0, 0) & 0x00000800 /*AECO_ACTIVELINE*/)
          SendMessage(lParam, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00000800 /*AECO_ACTIVELINE*/);
        hFocus = lParam;
      }
      if (nHiwParam == 0x0200 /*EN_KILLFOCUS*/)
      {
        SendMessage(lParam, 3228 /*AEM_SETOPTIONS*/, 4 /*AECOOP_XOR*/, 0x00000800 /*AECO_ACTIVELINE*/);
        aAESel[nLang][aAPD[nAPDSel][0]] = [GetSelStartAE(), GetSelEndAE()];
      }
    }
    else if ((nLowParam >= IDLANG1B) && (nLowParam <= IDLANG2B))
    {
      sFind = aAPD[nAPDSel][0].toUpperCase();

      CheckButtons(nLowParam);
      GetArrayAPD(hWnd);

      if (aAPD.length)
      {
        CheckButtons();
        FillLV(nAPDSel, sFind);
        oSys.Call("User32::SetFocus", hFocus);

        if (oIE && (typeof oIE.Application == "object"))
        {
          if (sAkelHelpFile)
            oIE.Navigate(sAkelHelpFile);
          else
          {
            try
            {
              GetIEPos();
              oIE.Quit();
            }
            catch (oError)
            {}
          }
        }
      }
      else
        PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
    }
    else if (nLowParam == IDHELPB)
    {
      oSys.Call("User32::SetFocus", hFocus);
      AkelHelp();
    }
    else if (nLowParam == IDMENUB)
    {
      oSys.Call("User32::SetFocus", hFocus);
      MenuMain();
    }
    else if (nLowParam == IDCLOSEB)
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 16) //WM_CLOSE
  {
    aAESel[nLang][aAPD[nAPDSel][0]] = [GetSelStartAE(), GetSelEndAE()];
    WriteIni();
    AkelPad.WindowUnsubClass(aDlg[IDTEXTAE].Handle);
    oSys.Call("User32::DestroyWindow", hWnd);
  }

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

  return 0;
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 135) //WM_GETDLGCODE
  {
    AkelPad.WindowNoNextProc(hSubClass);
    return 0x1; //DLGC_WANTARROWS
  }

  if (uMsg == 256) //WM_KEYDOWN
  {
    if ((wParam >= 0x21 /*VK_PRIOR*/) && (wParam <= 0x28 /*VK_DOWN*/) && Ctrl() && (!Shift()) && Alt())
      AkelPad.WindowNoNextProc(hSubClass);
  }

  return 0;
}

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 LoWord(nDwNum)
{
  return nDwNum & 0xFFFF;
}

function HiWord(nDwNum)
{
  return (nDwNum >> 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)

  if (hWnd)
    oSys.Call("User32::GetWindowRect", hWnd, lpRect);
  else
    oSys.Call("User32::SystemParametersInfoW", 0x30 /*SPI_GETWORKAREA*/, 0, lpRect, 0);

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

  AkelPad.MemFree(lpRect);
}

function GetIEPos()
{
  if (oSys.Call("User32::IsWindowVisible", oIE.HWND) && (! oSys.Call("User32::IsIconic", oIE.HWND)))
  {
    if (! (bIEMax = oSys.Call("User32::IsZoomed", oIE.HWND)))
    {
      nIEX = oIE.Left;
      nIEY = oIE.Top;
      nIEW = oIE.Width;
      nIEH = oIE.Height;
    }
  }
}

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

function SetWindowFont(hWnd, hFont)
{
  SendMessage(hWnd, 48 /*WM_SETFONT*/, hFont, true);
}

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

  oSys.Call("User32::SetForegroundWindow", hWnd);
}

function GetSelStartAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXTAE].Handle);
  var nSelStart = AkelPad.GetSelStart();
  AkelPad.SetEditWnd(0);
  return nSelStart;
}

function GetSelEndAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXTAE].Handle);
  var nSelEnd = AkelPad.GetSelEnd();
  AkelPad.SetEditWnd(0);
  return nSelEnd;
}

function SetSelAE(nSelStart, nSelEnd)
{
  AkelPad.SetEditWnd(aDlg[IDTEXTAE].Handle);
  AkelPad.SetSel(nSelStart, nSelEnd);
  AkelPad.SetEditWnd(0);
}

function GetSelTextAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXTAE].Handle);
  var sText = AkelPad.GetSelText(0);
  AkelPad.SetEditWnd(0);
  return sText;
}

function SetWordWrapAE()
{
  SendMessage(aDlg[IDTEXTAE].Handle, 0x0CAA /*AEM_SETWORDWRAP*/, bWordWrap ? 1 /*AEWW_WORD*/ : 0 /*AEWW_NONE*/, 0);
}

function SetOptionsAE()
{
  var hEditWnd = AkelPad.GetEditWnd();

  SetWindowFont(aDlg[IDTEXTAE].Handle, SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, 0, 0));
  SetWordWrapAE();

  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
  AkelPad.MemCopy(lpRect,      4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect +  4, 4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect +  8, 4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect + 12, 4, 3 /*DT_DWORD*/);
  SendMessage(aDlg[IDTEXTAE].Handle, 3178 /*AEM_SETRECT*/, 0x03 /*AERC_MARGINS|AERC_UPDATE*/, lpRect);
  AkelPad.MemFree(lpRect);

  if (hEditWnd)
  {
    var lpAECOLORS = AkelPad.MemAlloc(17 * 4);
    AkelPad.MemCopy(lpAECOLORS, 0x0001FFFE /*AECLR_ALL*/, 3 /*DT_DWORD*/);
    SendMessage(hEditWnd, 3231 /*AEM_GETCOLORS*/, 0, lpAECOLORS);
    SendMessage(aDlg[IDTEXTAE].Handle, 3232 /*AEM_SETCOLORS*/, 0, lpAECOLORS);
    AkelPad.MemFree(lpAECOLORS);

    if (SendMessage(hEditWnd, 3227 /*AEM_GETOPTIONS*/, 0, 0) & 0x00001000 /*AECO_ACTIVELINEBORDER*/)
      SendMessage(aDlg[IDTEXTAE].Handle, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00001000 /*AECO_ACTIVELINEBORDER*/);

    var lpPOINT = AkelPad.MemAlloc(8);
    SendMessage(hEditWnd, 3237 /*AEM_GETCARETWIDTH*/, 0, lpPOINT);
    SendMessage(aDlg[IDTEXTAE].Handle, 3238 /*AEM_SETCARETWIDTH*/, 0, lpPOINT);
    AkelPad.MemFree(lpPOINT);

    SendMessage(aDlg[IDTEXTAE].Handle, 3260 /*AEM_SETLINEGAP*/, SendMessage(hEditWnd, 3259 /*AEM_GETLINEGAP*/, 0, 0), 0);
  }
}

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

function GetCurSelLV()
{
  return SendMessage(aDlg[IDNAMELV].Handle, 0x100C /*LVM_GETNEXTITEM*/, -1, 0x0002 /*LVNI_SELECTED*/);
}

function SetCurSelLV(nItem)
{
  AkelPad.MemCopy(lpLVITEM + 12, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/);
  SendMessage(aDlg[IDNAMELV].Handle, 0x102B /*LVM_SETITEMSTATE*/, nItem, lpLVITEM);
  SendMessage(aDlg[IDNAMELV].Handle, 0x1013 /*LVM_ENSUREVISIBLE*/, nItem, false);
}

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

  AkelPad.MemCopy(lpLVCOLUMN, 4 /*mask=LVCF_TEXT*/, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpLVCOLUMN + (_X64 ? 16 : 12), lpTextLV, 2 /*DT_QWORD*/);
  AkelPad.MemCopy(lpTextLV, sTxtDocument, 1 /*DT_UNICODE*/);

  SendMessage(aDlg[IDNAMELV].Handle, 0x1036 /*LVM_SETEXTENDEDLISTVIEWSTYLE*/, 0x0020 /*LVS_EX_FULLROWSELECT*/, 0x0020);
  SendMessage(aDlg[IDNAMELV].Handle, 0x1061 /*LVM_INSERTCOLUMNW*/, 0, lpLVCOLUMN);
  AkelPad.MemFree(lpLVCOLUMN);
}

function FillLV(nSel, sFind)
{
  var i;

  SendMessage(aDlg[IDNAMELV].Handle, 0x000B /*WM_SETREDRAW*/, false, 0);
  SendMessage(aDlg[IDNAMELV].Handle, 0x1009 /*LVM_DELETEALLITEMS*/, 0, 0);

  for (i = 0; i < aAPD.length; ++i)
  {
    AkelPad.MemCopy(lpLVITEM + 4, i, 3 /*DT_DWORD*/);
    AkelPad.MemCopy(lpTextLV, aAPD[i][0], 1 /*DT_UNICODE*/);
    SendMessage(aDlg[IDNAMELV].Handle, 0x104D /*LVM_INSERTITEMW*/, 0, lpLVITEM);

    if (aAPD[i][0].toUpperCase() == sFind)
      nSel  = i;
  }

  if (nSel >= aAPD.length)
    nSel = aAPD.length - 1;
  if (nSel < 0)
    nSel = 0;

  SetCurSelLV(nSel);
  SendMessage(aDlg[IDNAMELV].Handle, 0x000B /*WM_SETREDRAW*/, true, 0);
}

function GetArrayAPD(hWnd)
{
  var aDoc = [
        "AkelHistory",
        "Clipboard",
        "Coder",
        "ContextMenu",
        "Exit",
        "Explorer",
        "Fonts",
        "Format",
        "FullScreen",
        "HexSel",
        "Hotkeys",
        "LineBoard",
        "Log",
        "Macros",
        "MinimizeToTray",
        "QSearch",
        "RecentFiles",
        "SaveFile",
        "Scripts",
        "Scroll",
        "Sessions",
        "SmartSel",
        "Sounds",
        "SpecialChar",
        "Speech",
        "SpellCheck",
        "Stats",
        "Templates",
        "ToolBar",
        "XBrackets"];

  var aLang    = ["-Eng", "-Rus"];
  var sExt     = ".txt";
  var sDocsDir = AkelPad.GetAkelDir(2 /*ADTYPE_DOCS*/) + "\\";
  var lpFile;
  var lpDetectFile;
  var sFile;
  var nCodePage;
  var bBOM;
  var i, n;

  aIsLang     = [false, false];
  aAPD.length = 0;

  while (! (aIsLang[0] || aIsLang[1]))
  {
    if (sAltDir)
    {
      for (i = 0; i < 2; ++i)
      {
        for (n = 0; n < aDoc.length; ++n)
        {
          if (oFSO.FileExists(sAltDir + aDoc[n] + aLang[i] + sExt))
          {
            aIsLang[i] = true;
            break;
          }
        }
      }
    }

    if (aIsLang[0] || aIsLang[1])
      sDocsDir = sAltDir;
    else
    {
      for (i = 0; i < 2; ++i)
      {
        for (n = 0; n < aDoc.length; ++n)
        {
          if (oFSO.FileExists(sDocsDir + aDoc[n] + aLang[i] + sExt))
          {
            aIsLang[i] = true;
            break;
          }
        }
      }

      if (! (aIsLang[0] || aIsLang[1]))
      {
        AkelPad.MessageBox(hWnd, sTxtNoFiles + "\n" + ((sAltDir && (sAltDir.toUpperCase() != sDocsDir.toUpperCase())) ? (sAltDir + "\n") : "") + sDocsDir, sTxtDlgTitle, 0x30 /*MB_ICONWARNING*/);

        if (! sAltDir)
          sAltDir = AkelPad.GetAkelDir(1 /*ADTYPE_AKELFILES*/) + "\\";

        sAltDir = BrowseForFolder(hWnd, sTxtChooseDir, sAltDir);

        if (! sAltDir)
          return;
        else if (sAltDir.slice(-1) != "\\")
          sAltDir += "\\";
      }
    }
  }

  if (! aIsLang[nLang])
    nLang = Number(! nLang);

  sAkelHelpFile = sDocsDir + "AkelHelp" + aLang[nLang] + ".htm";
  if (! oFSO.FileExists(sAkelHelpFile))
    sAkelHelpFile = "";

  lpFile       = AkelPad.MemAlloc(260 * 2 /*MAX_PATH * sizeof(wchar_t)*/);
  lpDetectFile = AkelPad.MemAlloc(_X64 ? 24 : 20 /*sizeof(DETECTFILEW)*/);

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

  for (n = 0; n < aDoc.length; ++n)
  {
    sFile = sDocsDir + aDoc[n] + aLang[nLang] + sExt;
    AkelPad.MemCopy(lpFile, sFile, 1 /*DT_UNICODE*/);
    AkelPad.MemCopy(lpDetectFile + (_X64 ? 16 : 12), 0, 3 /*DT_DWORD*/); //nCodePage
    AkelPad.MemCopy(lpDetectFile + (_X64 ? 20 : 16), 0, 3 /*DT_DWORD*/); //bBOM

    if (SendMessage(hMainWnd, 1177 /*AKD_DETECTFILEW*/, 0, lpDetectFile) == 0 /*EDT_SUCCESS*/)
    {
      nCodePage = AkelPad.MemRead(lpDetectFile + (_X64 ? 16 : 12), 3 /*DT_DWORD*/);
      bBOM      = AkelPad.MemRead(lpDetectFile + (_X64 ? 20 : 16), 3 /*DT_DWORD*/);

      if ((nCodePage != 65000) && (nCodePage != 65001) && (nCodePage != 1200) && (nCodePage != 1201) && (nCodePage != 12000) && (nCodePage != 12001))
        nCodePage = 1251 /*ANSI Cyrillic*/;

      aAPD.push([aDoc[n], AkelPad.ReadFile(sFile, 0, nCodePage, bBOM).replace(/\r\n/g, "\n"), sFile]);
    }
  }

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


function CheckButtons(nButton)
{
  if ((nButton == IDLANG1B) || (nButton == IDLANG2B))
    nLang = nButton - IDLANG1B;

  SendMessage(aDlg[IDLANG1B].Handle, 241 /*BM_SETCHECK*/, (nLang == 0), 0);
  SendMessage(aDlg[IDLANG2B].Handle, 241 /*BM_SETCHECK*/, (nLang == 1), 0);

  oSys.Call("User32::EnableWindow", aDlg[IDLANG1B].Handle, aIsLang[0]);
  oSys.Call("User32::EnableWindow", aDlg[IDLANG2B].Handle, aIsLang[1]);
  oSys.Call("User32::EnableWindow", aDlg[IDHELPB].Handle, sAkelHelpFile ? 1 : 0);
}

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

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

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

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

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

function ResizeDlg(nW, nH)
{
  var nFlags = 0x14; //SWP_NOACTIVATE|SWP_NOZORDER
  var nLVW   = 110;
  var nAEW   = nW - nLVW - 30;
  var i;

  oSys.Call("User32::SetWindowPos",
    aDlg[IDFILES].Handle, 0,
    nW - nAEW - 10,
    13,
    nAEW,
    13,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDNAMELV].Handle, 0,
    10,
    10,
    nLVW,
    nH - 148,
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDTEXTAE].Handle, 0,
    nW - nAEW - 10,
    30,
    nAEW,
    nH - 40,
    nFlags);
  for (i = IDLANG1B; i <= IDLANG2B; ++i)
  {
    oSys.Call("User32::SetWindowPos",
      aDlg[i].Handle, 0,
      30,
      nH - 105 - 20 * (IDLANG2B - i),
      70,
      16,
      nFlags);
  }
  for (i = IDHELPB; i <= IDCLOSEB; ++i)
  {
    oSys.Call("User32::SetWindowPos",
      aDlg[i].Handle, 0,
      10,
      nH - 31 - 23 * (IDCLOSEB - i),
      110,
      21,
      nFlags);
  }

  SendMessage(aDlg[IDNAMELV].Handle, 0x101E /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
  SendMessage(aDlg[IDNAMELV].Handle, 0x1013 /*LVM_ENSUREVISIBLE*/, GetCurSelLV(), false);
}

function MoveDlg(nKey)
{
  var oRectWA = {};
  var oRect   = {};

  GetWindowPos(0, oRectWA);
  GetWindowPos(hDlg, oRect);

  if (nKey == 0x21 /*VK_PRIOR*/)
    oRect.Y = oRectWA.Y;
  else if (nKey == 0x22 /*VK_NEXT*/)
    oRect.Y = oRectWA.Y + oRectWA.H - oRect.H;
  else if (nKey == 0x23 /*VK_END*/)
    oRect.X = oRectWA.X + oRectWA.W - oRect.W;
  else if (nKey == 0x24 /*VK_HOME*/)
    oRect.X = oRectWA.X;
  else if (nKey == 0x25 /*VK_LEFT*/)
  {
    if (oRect.X > oRectWA.X)
      oRect.X = (oRect.X - oRectWA.X > 20) ? oRect.X - 20 : oRectWA.X;
  }
  else if (nKey == 0x26 /*VK_UP*/)
  {
    if (oRect.Y > oRectWA.Y)
      oRect.Y = (oRect.Y - oRectWA.Y > 20) ? oRect.Y - 20 : oRectWA.Y;
  }
  else if (nKey == 0x27 /*VK_RIGHT*/)
  {
    if (oRect.X + oRect.W < oRectWA.X + oRectWA.W)
      oRect.X = (oRectWA.X + oRectWA.W - oRect.X - oRect.W > 20) ? oRect.X + 20 : oRectWA.X + oRectWA.W - oRect.W;
  }
  else if (nKey == 0x28 /*VK_DOWN*/)
  {
    if (oRect.Y + oRect.H < oRectWA.Y + oRectWA.H)
      oRect.Y = (oRectWA.Y + oRectWA.H - oRect.Y - oRect.H > 20) ? oRect.Y + 20 : oRectWA.Y + oRectWA.H - oRect.H;
  }

  oSys.Call("user32::SetWindowPos", hDlg, 0, oRect.X, oRect.Y, 0, 0, 0x15 /*SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE*/);
}

function FindText(nDirection)
{
  var sText = GetSelTextAE();

  if (! sText)
    sText = sFindText;

  if(InputBox(aDlg[IDTEXTAE].Handle, sTxtFindText, [sTxtDownFromBeg, sTxtDownFromCur, sTxtUpFromEnd, sTxtUpFromCur][nDirection] + "\n\n" + sTxtText + ":", sText, 0, CheckFindText, nDirection, 0, (bMatchCase ? sTxtMatchCase : sTxtIgnoreCase)))
    oSys.Call("User32::SetFocus", aDlg[IDTEXTAE].Handle);
}

function CheckFindText(hWnd, aText, nDirection)
{
  if (aText[0])
  {
    sFindText = aText[0];
    if (! FindTextNext(nDirection))
    {
      AkelPad.MessageBox(hWnd, sTxtNotFound, sTxtDlgTitle, 0x30 /*MB_ICONWARNING*/);
      return 0;
    }
  }

  return -1;
}

function FindTextNext(nDirection)
{
  var bFound = false;
  var nNameStart;
  var nTextStart;
  var nSel;
  var i;

  oSys.Call("User32::SetFocus", aDlg[IDTEXTAE].Handle);

  if (nDirection < 2)
  {
    if (nDirection == 0)
    {
      nNameStart = 0;
      nTextStart = 0;
    }
    else
    {
      nNameStart = GetCurSelLV();
      nTextStart = GetSelEndAE();
    }

    for (i = nNameStart; i < aAPD.length; ++i)
    {
      if (bMatchCase)
        nSel = aAPD[i][1].indexOf(sFindText, (i == nNameStart) ? nTextStart : 0);
      else
        nSel = aAPD[i][1].toUpperCase().indexOf(sFindText.toUpperCase(), (i == nNameStart) ? nTextStart : 0);

      if (nSel > -1)
      {
        SetCurSelLV(i);
        SetSelAE(nSel, nSel + sFindText.length);
        bFound = true;
        break;
      }
    }
  }
  else
  {
    if (nDirection == 2)
    {
      nNameStart = aAPD.length - 1;
      nTextStart = aAPD[nNameStart][1].length;
    }
    else
    {
      nNameStart = GetCurSelLV();
      nTextStart = GetSelStartAE() - sFindText.length;

      if ((nTextStart < 0) && (--nNameStart >= 0))
        nTextStart = aAPD[nNameStart][1].length;
    }

    for (i = nNameStart; i >= 0; --i)
    {
      if (bMatchCase)
        nSel = aAPD[i][1].lastIndexOf(sFindText, (i == nNameStart) ? nTextStart : aAPD[i][1].length);
      else
        nSel = aAPD[i][1].toUpperCase().lastIndexOf(sFindText.toUpperCase(), (i == nNameStart) ? nTextStart : aAPD[i][1].length);

      if (nSel > -1)
      {
        SetCurSelLV(i);
        SetSelAE(nSel, nSel + sFindText.length);
        bFound = true;
        break;
      }
    }
  }

  return bFound;
}

function InsertNameTo(bClipboard, bFull)
{
  if (nAPDSel >= 0)
  {
    var sName = aAPD[nAPDSel][2];

    if (! bFull)
      sName = sName.replace(/.+\\/, "");

    if (bClipboard)
      AkelPad.SetClipboardText(sName);
    else if (AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)))
      AkelPad.ReplaceSel(sName, true);
  }
}

function InsertTextTo(bClipboard)
{
  var sText = GetSelTextAE();

  if (sText)
  {
    if (bClipboard)
      AkelPad.SetClipboardText(sText);
    else
      AkelPad.ReplaceSel(sText, true);
  }
}

function AkelHelp()
{
  if (! oFSO.FileExists(sAkelHelpFile))
  {
    sAkelHelpFile = "";
    CheckButtons();
    return;
  }

  if (oIE && (typeof oIE.Application == "object"))
    SetForegroundWindow(oIE.HWND);
  else
  {
    try
    {
      oIE = new ActiveXObject("InternetExplorer.Application");

      oIE.Left   = nIEX;
      oIE.Top    = nIEY;
      oIE.Width  = nIEW;
      oIE.Height = nIEH;

      oIE.AddressBar = false;
      oIE.MenuBar    = false;
      oIE.StatusBar  = false;
      oIE.ToolBar    = false;
      oIE.Visible    = true;

      SetForegroundWindow(oIE.HWND);

      if (bIEMax)
        oSys.Call("User32::ShowWindow", oIE.HWND, 3 /*SW_MAXIMIZE*/);

      oIE.Navigate(sAkelHelpFile);
    }
    catch (oError)
    {
      AkelPad.MessageBox(hDlg, sTxtNoIE, sTxtDlgTitle, 0x30 /*MB_ICONWARNING*/);
      return;
    }
  }
}

function MenuMain()
{
  var MF_STRING    = 0x0000;
  var MF_CHECKED   = 0x0008;
  var MF_POPUP     = 0x0010;
  var MF_SEPARATOR = 0x0800;
  var hMenu1 = oSys.Call("User32::CreatePopupMenu");
  var hMenu2 = oSys.Call("User32::CreatePopupMenu");
  var hMenu  = oSys.Call("User32::CreatePopupMenu");
  var oRect  = {};
  var nCmd;
  var nCmd1;

  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0001, sTxtDownFromBeg + "\tCtrl+F");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0201, sTxtUpFromEnd   + "\tCtrl+Shift+F");
  oSys.Call("user32::AppendMenuW", hMenu1, MF_SEPARATOR, 0);
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0101, sTxtDownFromCur + "\tAlt+F");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0301, sTxtUpFromCur   + "\tShift+Alt+F");
  oSys.Call("user32::AppendMenuW", hMenu1, MF_SEPARATOR, 0);
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0401, sTxtNext     + "\tF3");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0501, sTxtPrevious + "\tShift+F3");

  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2502 /*VK_LEFT*/,  sTxtLeft  + "\tCtrl+Alt+Left");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2702 /*VK_RIGHT*/, sTxtRight + "\tCtrl+Alt+Right");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2602 /*VK_UP*/,    sTxtUp    + "\tCtrl+Alt+Up");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2802 /*VK_DOWN*/,  sTxtDown  + "\tCtrl+Alt+Down");
  oSys.Call("user32::AppendMenuW", hMenu2, MF_SEPARATOR, 0);
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2402 /*VK_HOME*/,  sTxtToLeftEdge   + "\tCtrl+Alt+Home");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2302 /*VK_END*/,   sTxtToRightEdge  + "\tCtrl+Alt+End");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2102 /*VK_PRIOR*/, sTxtToTopEdge    + "\tCtrl+Alt+PgUp");
  oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, 0x2202 /*VK_NEXT*/,  sTxtToBottomEdge + "\tCtrl+Alt+PgDn");

  oSys.Call("User32::AppendMenuW", hMenu, MF_POPUP,  hMenu1, sTxtFindText);
  oSys.Call("User32::AppendMenuW", hMenu, MF_POPUP,  hMenu2, sTxtMoveWindow);
  oSys.Call("user32::AppendMenuW", hMenu, MF_SEPARATOR, 0);
  oSys.Call("User32::AppendMenuW", hMenu, (bMatchCase ? MF_CHECKED : MF_STRING), 0x0003, sTxtFindCase);
  oSys.Call("User32::AppendMenuW", hMenu, (bWordWrap ? MF_CHECKED : MF_STRING), 0x0004, sTxtWrapLines + "\tCtrl+U");
  oSys.Call("User32::AppendMenuW", hMenu, (bSeparateWnd ? MF_CHECKED : MF_STRING), 0x0005, sTxtSeparateWnd);

  GetWindowPos(aDlg[IDMENUB].Handle, oRect);

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x01A0 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_BOTTOMALIGN*/, oRect.X, oRect.Y, 0, hDlg, 0);

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

  nCmd1 = (nCmd >> 8) & 0xFF;
  nCmd  = nCmd & 0xFF;

  if (nCmd == 1)
  {
    if (nCmd1 < 4)
      FindText(nCmd1);
    else if (nCmd1 == 4)
      FindTextNext(1);
    else if (nCmd1 == 5)
      FindTextNext(3);
  }
  else if (nCmd == 2)
    MoveDlg(nCmd1);
  else if (nCmd == 3)
    bMatchCase = ! bMatchCase;
  else if (nCmd == 4)
  {
    bWordWrap = ! bWordWrap;
    SetWordWrapAE();
  }
  else if (nCmd == 5)
    bSeparateWnd = ! bSeparateWnd;
}

function MenuName(nX, nY)
{
  var lpRect;
  var nX1, nY1, nY2;
  var hMenu;
  var nCmd;

  if ((nAPDSel < 0) || (aAPD[nAPDSel][0].charAt(0) == "*"))
    return;

  //menu from keyboard
  if (nX == 0xFFFF)
    SendMessage(aDlg[IDNAMELV].Handle, 0x1013 /*LVM_ENSUREVISIBLE*/, nAPDSel, false);

  lpRect = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);
  SendMessage(aDlg[IDNAMELV].Handle, 0x100E /*LVM_GETITEMRECT*/, nAPDSel, lpRect);
  oSys.Call("User32::ClientToScreen", aDlg[IDNAMELV].Handle, lpRect);
  oSys.Call("User32::ClientToScreen", aDlg[IDNAMELV].Handle, lpRect + 8);
  nX1 = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
  nY1 = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
  nY2 = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/);
  AkelPad.MemFree(lpRect);

  if (nX == 0xFFFF)
  {
    nX = nX1;
    nY = nY2;
  }
  else if ((nY < nY1) || (nY > nY2))
    return;

  hMenu = oSys.Call("User32::CreatePopupMenu");
  oSys.Call("User32::AppendMenuW", hMenu, 0x01 /*MF_GRAYED*/, 1, sTxtFileName);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 1, "   " + sTxtCopyToCB + "\tCtrl+C");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 2, "   " + sTxtInsertToAP + "\tCtrl+Shift+C");
  oSys.Call("User32::AppendMenuW", hMenu, 0x01 /*MF_GRAYED*/, 1, sTxtFileNamePath);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 3, "   " + sTxtCopyToCB + "\tCtrl+Ins");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 4, "   " + sTxtInsertToAP + "\tCtrl+Shift+Ins");

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0180 /*TPM_NONOTIFY|TPM_RETURNCMD*/, nX, nY, 0, hDlg, 0);

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

  if (nCmd == 1)
    InsertNameTo(true, false);
  else if (nCmd == 2)
    InsertNameTo(false, false);
  if (nCmd == 3)
    InsertNameTo(true, true);
  else if (nCmd == 4)
    InsertNameTo(false, true);
}

function MenuText(nX, nY)
{
  var bSel  = SendMessage(aDlg[IDTEXTAE].Handle, 3125 /*AEM_GETSEL*/, 0, 0);
  var hMenu = oSys.Call("User32::CreatePopupMenu");
  var lpPoint;
  var nCmd;

  //menu from keyboard
  if (nX == 0xFFFF)
  {
    lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/);
    oSys.Call("User32::GetCaretPos", lpPoint);
    oSys.Call("User32::ClientToScreen", aDlg[IDTEXTAE].Handle, lpPoint);
    nX = AkelPad.MemRead(lpPoint,     3 /*DT_DWORD*/);
    nY = AkelPad.MemRead(lpPoint + 4, 3 /*DT_DWORD*/) + SendMessage(aDlg[IDTEXTAE].Handle, 3188 /*AEM_GETCHARSIZE*/, 0 /*AECS_HEIGHT*/, 0);
    AkelPad.MemFree(lpPoint);
  }

  oSys.Call("User32::AppendMenuW", hMenu, bSel ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 1, sTxtCopyToCB + "\tCtrl+C");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) && bSel ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 2, sTxtInsertToAP + "\tCtrl+Shift+C");
  oSys.Call("user32::AppendMenuW", hMenu, 0x0800 /*MF_SEPARATOR*/, 0);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 3, sTxtSelectAll + "\tCtrl+A");

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0180 /*TPM_NONOTIFY|TPM_RETURNCMD*/, nX, nY, 0, hDlg, 0);

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

  if (nCmd == 1)
    InsertTextTo(true);
  else if (nCmd == 2)
    InsertTextTo(false);
  else if (nCmd == 3)
    SetSelAE(0, -1);
}

function ReadIni()
{
  var sIniFile = WScript.ScriptFullName.substring(0, WScript.ScriptFullName.lastIndexOf(".")) + ".ini";

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

  oDlgPos.W  = Math.max(oDlgPos.W, nDlgMinW);
  oDlgPos.H  = Math.max(oDlgPos.H, nDlgMinH);
  hWndParent = bSeparateWnd ? 0 : hMainWnd;
}

function WriteIni()
{
  var oFile   = oFSO.OpenTextFile(WScript.ScriptFullName.substring(0, WScript.ScriptFullName.lastIndexOf(".")) + ".ini", 2, true, -1);
  var sIniTxt = "";
  var i;

  if (oIE && (typeof oIE.Application == "object"))
    GetIEPos();

  oDlgPos.Max = oSys.Call("User32::IsZoomed", hDlg);

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

  sIniTxt +=
    'nIEX='         + nIEX + ';\r\n' +
    'nIEY='         + nIEY + ';\r\n' +
    'nIEW='         + nIEW + ';\r\n' +
    'nIEH='         + nIEH + ';\r\n' +
    'bIEMax='       + bIEMax + ';\r\n' +
    'bMatchCase='   + bMatchCase + ';\r\n' +
    'bWordWrap='    + bWordWrap + ';\r\n' +
    'bSeparateWnd=' + bSeparateWnd + ';\r\n' +
    'nAPDSel='      + nAPDSel + ';\r\n' +
    'nLang='        + nLang + ';\r\n' +
    'sFindText="'   + EscapeStr(sFindText) + '";\r\n' +
    'sAltDir="'     + EscapeStr(sAltDir) + '";\r\n' +
    'aAESel[0]={';

  for (i in aAESel[0])
    sIniTxt += '"' + i + '":[' + aAESel[0][i] + '],';

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

  sIniTxt += '};\r\naAESel[1]={';

  for (i in aAESel[1])
    sIniTxt += '"' + i + '":[' + aAESel[1][i] + '],';

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

  sIniTxt += '};';
   
  oFile.Write(sIniTxt);
  oFile.Close();
}

function EscapeStr(sText)
{
  return sText.replace(/[\\"]/g, '\\$&').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
}

function GetLangStrings()
{
//  if (AkelPad.GetLangId(0 /*LANGID_FULL*/) == 1049 /*Russian*/)
//  {
//  }
//  else
  {
    sTxtDlgTitle     = "AkelPad docs view";
    sTxtNoFiles      = "Files not found in directory:";
    sTxtChooseDir    = "Choose directory with AkelPad documentation:";
    sTxtEnglish      = "&English";
    sTxtRussian      = "&Russian";
    sTxtMenu         = "&Menu";
    sTxtClose        = "Close";
    sTxtDocument     = "Document";
    sTxtText         = "Text";
    sTxtFindText     = "Find text";
    sTxtDownFromBeg  = "Down from beginning";
    sTxtDownFromCur  = "Down from current position";
    sTxtUpFromEnd    = "Up from end";
    sTxtUpFromCur    = "Up from current position";
    sTxtNext         = "Next";
    sTxtPrevious     = "Previous";
    sTxtMatchCase    = "Match case";
    sTxtIgnoreCase   = "Ignore case";
    sTxtNotFound     = "Not found.";
    sTxtMoveWindow   = "Move window";
    sTxtLeft         = "Left";
    sTxtRight        = "Right";
    sTxtUp           = "Up";
    sTxtDown         = "Down";
    sTxtToLeftEdge   = "To left edge";
    sTxtToRightEdge  = "To right edge";
    sTxtToTopEdge    = "To top edge";
    sTxtToBottomEdge = "To bottom edge";
    sTxtFindCase     = "Find - match case";
    sTxtWrapLines    = "Wrap lines";
    sTxtSeparateWnd  = "Run in separate window";
    sTxtFileName     = "File name:";
    sTxtFileNamePath = "Full  file name with path:";
    sTxtCopyToCB     = "Copy to clipboard";
    sTxtInsertToAP   = "Insert to AkelPad";
    sTxtSelectAll    = "Select all";
    sTxtNoIE         = "Internet Explorer not available.";
  }
}


Last edited by KDJ on Mon Mar 24, 2014 6:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1263
Location: Poland

PostPosted: Thu Feb 06, 2014 8:23 pm    Post subject: Reply with quote

Select tab by pressing Ctrl/Shift/Alt+Number (MDI/PMDI).

TabNumberByKeyboard.js

Code:
/*
TabNumberByKeyboard.js - ver. 2014-02-06 (x86/x64)

Select tab by pressing Ctrl/Shift/Alt+Number (MDI/PMDI)

Usage:
  Call("Scripts::Main", 1, "TabNumberByKeyboard.js")
  Call("Scripts::Main", 1, "TabNumberByKeyboard.js", "Argument")

Argument:
  "A" - Alt (default)
  "C" - Ctrl
  "S" - Shift (only in combination with Ctrl and/or Alt)
  can be: "C", "A", "CS", "CA", "CSA", "SA"

Notes:
  After first call, the script resides in the memory.
  Second script call, closes the script.

For autostart, in AkelPad.ini or registry CmdLineBegin key, need to add eg:
  /Call("Scripts::Main", 1, "TabNumberByKeyboard.js", "SC")
*/

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);

if (hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
{
  //script already is running, close it
  AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
}
else if (AkelPad.IsMDI())
{
  var oSys     = AkelPad.SystemFunction();
  var hMainWnd = AkelPad.GetMainWnd();
  var bCtrl    = false;
  var bShift   = false;
  var bAlt     = false;
  var sArg;
  var hSubClass;
  var lpFrame;
  var nTab;

  if (WScript.Arguments.length)
  {
    sArg = WScript.Arguments(0).toUpperCase();

    if (sArg.indexOf("C") >= 0)
      bCtrl = true;
    if (sArg.indexOf("S") >= 0)
      bShift = true;
    if (sArg.indexOf("A") >= 0)
      bAlt = true;

    if (bShift && (! bCtrl) && (! bAlt))
    {
      bShift = false;
      bAlt   = true;
    }
  }
  else
    bAlt = true;

  hSubClass = AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, bCtrl ? 256 /*WM_KEYDOWN*/ : 260 /*WM_SYSKEYDOWN*/);

  if (hSubClass)
  {
    //Allow other scripts running
    AkelPad.ScriptNoMutex();

    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if ((uMsg == 256 /*WM_KEYDOWN*/) && (wParam >= 0x30 /*0 key*/) && (wParam <= 0x39 /*9 key*/) && Ctrl())
  {
    if ((bShift == Shift()) && (bAlt == Alt()))
      FrameActivate(wParam);
  }
  else if ((uMsg == 260 /*WM_SYSKEYDOWN*/) && (wParam >= 0x30 /*0 key*/) && (wParam <= 0x39 /*9 key*/))
  {
    if (bShift == Shift())
      FrameActivate(wParam);
  }

  return 0;
}

function FrameActivate(nKey)
{
  nTab = ((nKey == 0x30) ? 10 : nKey - 0x30) - 1;

  if (lpFrame = AkelPad.SendMessage(hMainWnd, 1290 /*AKD_FRAMEFINDW*/, 8 /*FWF_BYTABINDEX*/, nTab))
    AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrame);
}

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);
}
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1570

PostPosted: Sat Mar 01, 2014 6:54 pm    Post subject: Reply with quote

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

// (c) Infocatcher 2014
// version 0.1.1 - 2014-03-03

//===================
// Close tabs to the left or right (temporary check "Switch tabs: right-left" option)
// Based on Instructor's code: http://akelpad.sourceforge.net/forum/viewtopic.php?p=4222#4222

// Usage:
//   Call("Scripts::Main", 1, "closeLeftOrRightTabs.js")           - close tabs to the right
//   Call("Scripts::Main", 1, "closeLeftOrRightTabs.js", "-left")  - close tabs to the left
//===================

var toRight = WScript.Arguments.length ? WScript.Arguments(0) != "-left" : true;

var hMainWnd = AkelPad.GetMainWnd();
if(hMainWnd && AkelPad.IsMDI()) {
   var tabOpts = AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 157 /*MI_TABOPTIONSMDI*/, 0);
   var forceRightLeft = !(tabOpts & 0x20000 /*TAB_SWITCH_RIGHTLEFT*/);
   if(forceRightLeft)
      AkelPad.Command(4311 /*IDM_WINDOW_TABSWITCH_RIGHTLEFT*/);

   closeTabs(toRight);

   if(forceRightLeft)
      AkelPad.SendMessage(hMainWnd, 1219 /*AKD_SETMAININFO*/, 157 /*MIS_TABOPTIONSMDI*/, tabOpts);
}
else {
   AkelPad.MessageBox(hMainWnd, "MDI or PMDI window mode required!", WScript.ScriptName, 48 /*MB_ICONEXCLAMATION*/);
}

function closeTabs(toRight) {
   var nextFrameCmd = toRight ? 4316 /*IDM_WINDOW_FRAMENEXT*/ : 4317 /*IDM_WINDOW_FRAMEPREV*/;
   var lpFrameInitial = AkelPad.SendMessage(hMainWnd, 1288 /*AKD_FRAMEFIND*/, 1 /*FWF_CURRENT*/, 0);
   var frameIndexInitial = AkelPad.SendMessage(hMainWnd, 1294 /*AKD_FRAMEINDEX*/, 0, lpFrameInitial);
   for(;;) {
      var restoreSelected = true;
      AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, nextFrameCmd, 0);
      var lpFrame = AkelPad.SendMessage(hMainWnd, 1288 /*AKD_FRAMEFIND*/, 1 /*FWF_CURRENT*/, 0);
      //if(lpFrame == lpFrameInitial)
      //   break;
      var frameIndex = AkelPad.SendMessage(hMainWnd, 1294 /*AKD_FRAMEINDEX*/, 0, lpFrame);
      if(toRight ? frameIndex <= frameIndexInitial : frameIndex >= frameIndexInitial--)
         break; // Overflow
      if(!AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, 4318 /*IDM_WINDOW_FRAMECLOSE*/, 0))
         return; // Cancel
      restoreSelected = false;
      AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrameInitial);
   }
   restoreSelected && AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrameInitial);
}
<download | mirror | development version>
Close tabs to the left or right (temporary check "Switch tabs: right-left" option).
Required MDI or PMDI window mode!
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1570

PostPosted: Wed Apr 02, 2014 10:13 pm    Post subject: Reply with quote

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

// (c) Infocatcher 2014
// version 0.1.0 - 2014-04-03

// Just like full screen mode, but preserve window size and position
// Required FullScreen plugin!

var hMainWnd = AkelPad.GetMainWnd();
var oSys = AkelPad.SystemFunction();

if(hMainWnd) {
   var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
   if(lpRect) {
      oSys.Call("user32::GetWindowRect", hMainWnd, lpRect);
      var x = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
      var y = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
      var w = AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/) - x;
      var h = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/) - y;
      AkelPad.MemFree(lpRect);

      AkelPad.Call("FullScreen::Main");
      oSys.Call("user32::SetWindowPos", hMainWnd, 0, x, y, w, h, 0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
   }
}
<download | mirror | development version>
Just like full screen mode, but preserve window size and position.
Required FullScreen plugin!
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1570

PostPosted: Sat Apr 12, 2014 7:50 pm    Post subject: Reply with quote

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

// (c) Infocatcher 2014
// version 0.1.1 - 2014-04-22

// Helper functions for user32::SetTimer()
// Usage example:
/*
var hMainWnd = AkelPad.GetMainWnd();
if(AkelPad.Include("timer.js")) {
   _log("Started");
   setTimeout(function() {
      _log("Finished");
      oSys.Call("user32::PostQuitMessage", 0);
   }, 2000);
   AkelPad.ScriptNoMutex();
   AkelPad.WindowGetMessage();
}
function _log(s) {
   oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
}
*/

// Be careful: 3rd argument is an ID of already created timer!
function setTimeout(fn, delay, id) {
   return timers.set(fn, delay, true, id);
}
function setInterval(fn, delay, id) {
   return timers.set(fn, delay, false, id);
}
function clearTimeout(id) {
   timers.clear(id);
}
function clearInterval(id) {
   timers.clear(id);
}

if(!hMainWnd)
   var hMainWnd = AkelPad.GetMainWnd();
if(!oSys)
   var oSys = AkelPad.SystemFunction();

var timers = {
   _id: 1000,
   getId: function() {
      return AkelPad.SendMessage(hMainWnd, 1319 /*AKD_UNIQUEID*/, 0, 0) // AkelPad 4.8.8+
         || ++this._id;
   },
   funcs: {}, // IDs of all timers
   timeouts: {}, // IDs of single-time timers
   lpTimerCallback: 0,
   init: function() {
      if(!this.lpTimerCallback) try { // AkelPad 4.8.8+
         this.lpTimerCallback = oSys.RegisterCallback(timerProc);
      }
      catch(e) {
         this.lpTimerCallback = oSys.RegisterCallback("", timerProc, timerProc.length);
      }
      this.hWndTimer = AkelPad.ScriptHandle(0, 17 /*SH_GETSERVICEWINDOW*/) || hMainWnd;
      return this.lpTimerCallback;
   },
   destroy: function() {
      if(!this.lpTimerCallback)
         return;
      for(var id in this.funcs)
         this._clear(id);
      oSys.UnregisterCallback(this.lpTimerCallback);
      this.lpTimerCallback = 0;
      this._log("destroy");
   },
   has: function() {
      for(var id in this.funcs)
         return true;
      return false;
   },
   set: function(fn, delay, isSingle, id) {
      if(!this.init()) {
         AkelPad.MessageBox(hMainWnd, "oSys.RegisterCallback() failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
         return 0;
      }
      if(!id)
         id = this.getId();
      this.funcs[id] = fn;
      if(isSingle)
         this.timeouts[id] = true;
      this._log("set(" + isSingle + ") " + id);
      oSys.Call("user32::SetTimer", this.hWndTimer, id, delay, this.lpTimerCallback);
      return id;
   },
   clear: function(id, isSingle) {
      this._clear(id);
      if(!this.has())
         this.destroy();
   },
   _clear: function(id) {
      this._log("_clear(" + id + ")");
      oSys.Call("user32::KillTimer", this.hWndTimer, id);
      delete this.funcs[id];
      delete this.timeouts[id];
   },
   _prev: [],
   _log: function(s) {
      return; // disable logs
      var prev = this._prev;
      var last = prev[prev.length - 1];
      RegExp.$1 = 0;
      if(last && s == last.replace(/ #(\d+)$/, ""))
         prev[prev.length - 1] = s + " #" + ((+RegExp.$1 || 1) + 1);
      else {
         while(prev.length > 8)
            prev.shift();
         prev.push(s);
      }
      s = prev.join(" -> ");
      oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
   }
};

function timerProc(hWnd, uMsg, nIDEvent, dwTime) {
   var fn = timers.funcs[nIDEvent];
   if(timers.timeouts[nIDEvent])
      timers.clear(nIDEvent);
   fn();
}
<download | mirror | development version>
Helper functions for user32::SetTimer(), for AkelPad.Include().


Last edited by Infocatcher on Tue Apr 22, 2014 9:14 am; edited 2 times in total
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1570

PostPosted: Sat Apr 12, 2014 8:29 pm    Post subject: Reply with quote

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

// (c) Infocatcher 2012-2014
// version 0.2.1 - 2014-04-22

// Automatically saves current session after selection or scroll changes
// Required Sessions plugin!

// Arguments:
//   -startupDelay=1500    - (in ms) ignore all changes just after startup
//   -minDelay=8000        - (in ms) minimum interval between two saves
//   -smallDelay=500       - (in ms) minimum daley between change and save
//   -session="OnExit"     - name of session file
//   -debug=true           - show debug messages in window title

// Usage:
//   CmdLineBegin=/Call("Scripts::Main", 1, "autoSaveSession.js")
//   CmdLineBegin=/Call("Scripts::Main", 1, "autoSaveSession.js", '-startupDelay=2000 -minDelay=12000 -session="OnExit"')
// (see AkelHelp*.htm for manual settings)

var isMDI = AkelPad.IsMDI();
if(!isMDI) // We silently ignore SDI mode to allow use the same settings in any mode!
   WScript.Quit();

var startupDelay = AkelPad.GetArgValue("startupDelay", 1500);
var stopWait = new Date().getTime() + startupDelay;

var hMainWnd = AkelPad.GetMainWnd();
var oSys = AkelPad.SystemFunction();
var minDelay = AkelPad.GetArgValue("minDelay", 8e3);
var smallDelay = AkelPad.GetArgValue("smallDelay", 500);
var sessionName = AkelPad.GetArgValue("session", "OnExit");
var debug = AkelPad.GetArgValue("debug", false);

var timer = 0;
var lastSave = 0;

var lpTimerCallback = 0;
var nIDEvent;
var hWndTimer;
var error = "";

debug && _log("start");

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);
if(hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/)) {
   // Script is running, second call close it
   debug && _log("quit");
   AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
   WScript.Quit();
}

if(hMainWnd) {
   if(
      AkelPad.WindowSubClass(
         1 /*WSC_MAINPROC*/,
         mainCallback,
         0x4E /*WM_NOTIFY*/,
         0x416 /*AKDN_FRAME_ACTIVATE*/,
         0x418 /*AKDN_FRAME_DESTROY*/
         //0x436 /*AKDN_OPENDOCUMENT_FINISH*/
         //0x406 /*AKDN_MAIN_ONFINISH*/
      )
   ) {
      if(
         isMDI != 1 /*WMD_MDI*/
         || AkelPad.WindowSubClass(
            3 /*WSC_FRAMEPROC*/,
            mainCallback,
            0x4E /*WM_NOTIFY*/
         )
      ) {
         AkelPad.ScriptNoMutex(); // Allow other scripts running
         AkelPad.WindowGetMessage(); // Message loop

         AkelPad.WindowUnsubClass(1 /*WSC_MAINPROC*/);
         AkelPad.WindowUnsubClass(3 /*WSC_FRAMEPROC*/);
         destroyTimer();
         error && AkelPad.MessageBox(hMainWnd, error, WScript.ScriptName, 16 /*MB_ICONERROR*/);
      }
      else {
         AkelPad.WindowUnsubClass(1 /*WSC_MAINPROC*/);
         AkelPad.MessageBox(hMainWnd, "AkelPad.WindowSubClass(WSC_FRAMEPROC) failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
      }
   }
   else {
      AkelPad.MessageBox(hMainWnd, "AkelPad.WindowSubClass(WSC_MAINPROC) failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
   }
}

function mainCallback(hWnd, uMsg, wParam, lParam) {
   //if(uMsg == 0x406 /*AKDN_MAIN_ONFINISH*/) {
   //   oSys.Call("user32::PostQuitMessage", 0); // Exit message loop
   //   return;
   //}

   if(timer) // Already scheduled
      return;

   if(uMsg == 0x4E /*WM_NOTIFY*/) {
      var cmd = AkelPad.MemRead(lParam + 8, 3 /*DT_DWORD*/);
      switch(cmd) {
         case 0x804 /*AEN_HSCROLL*/:
         case 0x805 /*AEN_VSCROLL*/:
         case 0x81E /*AEN_SELCHANGED*/:
            uMsg = cmd;
         break;
         default: return;
      }
   }

   if(stopWait) {
      if(new Date().getTime() < stopWait)
         return;
      stopWait = 0;
   }
   if(!AkelPad.GetEditFile(0))
      return;

   var delay = new Date().getTime() - lastSave > minDelay ? smallDelay : minDelay;
   timer = saveSessionDelayed(delay);
}
function saveSession() {
   if(!oSys.Call("user32::IsWindowEnabled", hMainWnd)) {
      timer = saveSessionDelayed(minDelay);
      return;
   }
   timer = 0;
   lastSave = new Date().getTime();
   AkelPad.Call("Sessions::Main", 2, sessionName);
   debug && _log("saved at " + new Date().toLocaleString());
}
function saveSessionDelayed(delay) {
   try { // AkelPad 4.8.8+
      lpTimerCallback = oSys.RegisterCallback(saveSessionTimerProc);
   }
   catch(e) {
      lpTimerCallback = oSys.RegisterCallback("saveSessionTimerProc");
   }
   if(!lpTimerCallback) {
      error = "oSys.RegisterCallback() failed!\nScript was terminated.";
      oSys.Call("user32::PostQuitMessage", 0); // Exit message loop
      return 0;
   }
   nIDEvent = AkelPad.SendMessage(hMainWnd, 1319 /*AKD_UNIQUEID*/, 0, 0) || 10;
   hWndTimer = AkelPad.ScriptHandle(0, 17 /*SH_GETSERVICEWINDOW*/) || hMainWnd;
   saveSessionDelayed = function(delay) {
      return oSys.Call("user32::SetTimer", hWndTimer, nIDEvent, delay, lpTimerCallback);
   };
   return saveSessionDelayed(delay);
}
function saveSessionTimerProc(hWnd, uMsg, nIDEvent, dwTime) {
   oSys.Call("user32::KillTimer", hWndTimer, nIDEvent);
   saveSession();
}
function destroyTimer() {
   if(lpTimerCallback) {
      oSys.Call("user32::KillTimer", hWndTimer, nIDEvent);
      oSys.UnregisterCallback(lpTimerCallback);
      lpTimerCallback = 0;
   }
}
function _log(s) {
   oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
}
<download | mirror | development version>
Automatically saves current session after selection or scroll changes
Required Sessions plugin!
Beware: may cause bugs and crashes, use at your own risk!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins All times are GMT
Goto page Previous  1, 2, 3 ... 16, 17, 18
Page 18 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