Page 45 of 96

Posted: Mon Aug 06, 2012 5:11 pm
by Andrey_A_A
Я изменяю скриптом AkelPad.ini
Подскажите можно тут же подгрузить настройки

Posted: Mon Aug 06, 2012 5:53 pm
by FeyFre
Andrey_A_A, низя.

Posted: Mon Aug 06, 2012 8:01 pm
by Andrey_A_A
FeyFre wrote:Andrey_A_A, низя.
А локально, к примеру есть задача быстро подгружать несколько наборов левых и правых символов для правильности отображения Url - секции UrlLeftDelimiters и UrlRightDelimiters

или совсем низя)

Posted: Mon Aug 06, 2012 8:21 pm
by FeyFre
Andrey_A_A, AkelPad.SendMessage + AKD_SETFRAMEINFO + FIS_URLLEFTDELIMITERS/FIS_URLRIGHTDELIMITERS. См. AkelDll.h

Posted: Mon Aug 06, 2012 8:56 pm
by KDJ
Andrey_A_A
See also:
  in AkelEdit.h:
    AEM_GETURLLEFTDELIMITERS
    AEM_SETURLLEFTDELIMITERS
  in AkelDLL.h:
    AKD_GETFRAMEINFO
    FI_URLLEFTDELIMITERS
Script example: ResetUrlDelimiters.js

Posted: Tue Aug 07, 2012 1:41 pm
by DV
Упаковка текущего файла в zip-архив средствами JScript...
ToDo: использование классов?

Code: Select all

var isFileSaved;
var sCurrentFilePath;
var sZipFilePath;

isFileSaved = false;
sCurrentFilePath = AkelPad.GetEditFile(0);
if (sCurrentFilePath)
{
  if (!AkelPad.GetEditModified(0))
    isFileSaved = true;
}
if (!isFileSaved)
{
  WScript.Echo("File is not saved. Please save the file first!");
  WScript.Quit();
}

sZipFilePath = getZipFilePath();
if (!zip_create(sZipFilePath))
{
  WScript.Echo("Failed to create the archive :(");
  WScript.Quit();
}
if (!zip_add_file(sZipFilePath, sCurrentFilePath))
{
  WScript.Echo("Failed to add the file to the archive :(");
  WScript.Quit();
}
WScript.Echo("Archive created!\n" + sZipFilePath);

function getZipFilePath()
{
  var sZipFileDir = getFileDir(sCurrentFilePath);
  var sZipFileName = getFileName(sCurrentFilePath);
  var s = sZipFileDir + "\\" + sZipFileName + ".zip";
  return s;
}

function zip_create(sZipFilePath)
{
  var isOK = false;

  // Creating an empty .zip archive
  try
  {
    var oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
    var oZipFile = oFileSystem.OpenTextFile(sZipFilePath, 2, true);
    var data = String.fromCharCode(80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
    oZipFile.Write(data);
    oZipFile.Close();
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function zip_add_file(sZipFilePath, sFilePath)
{
  var isOK = false;

  // Packing the data
  try
  {
    var oShell = new ActiveXObject("Shell.Application");
    var oDstFolder = oShell.NameSpace(sZipFilePath);
    oDstFolder.CopyHere(sFilePath, 16);
    //WScript.Sleep(1000);
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function zip_add_folder(sZipFilePath, sFolderPath)
{
  var isOK = false;

  // Packing the data
  try
  {
    var oShell = new ActiveXObject("Shell.Application");
    var oDstFolder = oShell.NameSpace(sZipFilePath);
    var oSrcFolder = oShell.NameSpace(sFolderPath);
    var oFolderItems = oSrcFolder.Items();
    oDstFolder.CopyHere(oFolderItems.Item(), 16);
    //WScript.Sleep(1000);
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function getFileExt(filePathName) // file extension w/o leading '.'
{
  var n = filePathName.lastIndexOf(".");
  return (n >= 0) ? filePathName.substr(n + 1) : "";
}

function getFileName(filePathName) // file name w/o extension
{
  var n2 = filePathName.lastIndexOf(".");
  var n1 = filePathName.lastIndexOf("\\");
  var nn = filePathName.lastIndexOf("/");
  if (nn > n1)  n1 = nn;
  var s = "";
  if (n1 < 0 && n2 < 0)
    s = filePathName;
  else if (n1 < 0)
    s = filePathName.substr(0, n2);
  else if (n2 < 0)
    s = filePathName.substr(n1 + 1);
  else if (n2 > n1)
    s = filePathName.substr(n1 + 1, n2 - n1 - 1);
  return s;
}

function getFileDir(filePathName) // file directory w/o trailing '\'
{
  var n = filePathName.lastIndexOf("\\");
  var nn = filePathName.lastIndexOf("/");
  if (nn > n)  n = nn;
  return (n >= 0) ? filePathName.substr(0, n) : filePathName;
}

Posted: Wed Aug 08, 2012 8:53 am
by VladSh
DV
Не знал, что такое возможно. Здорово!
Если бы вывести список всех открытых файлов, поставить галки и запаковать выбранные, то вообще был бы яд! :D
А ещё лучше в аргументах передавать скрипту: текущий или выбор.

Posted: Thu Aug 09, 2012 8:24 pm
by KDJ
How to create Richedit control in ActiveX?
In the following script is not working:

Code: Select all

GetAkelPadObject();

var oSys         = AkelPad.SystemFunction();
var hMainWnd     = AkelPad.GetMainWnd();
var hInstanceDLL = AkelPad.GetInstanceDll();
var sClassName   = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstanceDLL;
var hRichEdit;
var hEdit;
var hButton;

AkelPad.WindowRegisterClass(sClassName);

oSys.Call("user32::CreateWindowExW",
          0,               //dwExStyle
          sClassName,      //lpClassName
          "Richedit test", //lpWindowName
          0x90CA0000,      //dwStyle=WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
          300,             //x
          200,             //y
          300,             //nWidth
          300,             //nHeight
          hMainWnd,        //hWndParent
          0,               //ID
          hInstanceDLL,    //hInstance
          DialogCallback); //Script function callback. To use it class must be registered by WindowRegisterClass.

AkelPad.WindowGetMessage();
AkelPad.WindowUnregisterClass(sClassName);

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    hRichEdit =
      oSys.Call("user32::CreateWindowExW",
                0,             //dwExStyle
                "RichEdit20W", //lpClassName
                0,             //lpWindowName
                0x50311104,    //dwStyle=WS_VISIBLE|WS_CHILD|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP|ES_WANTRETURN|ES_NOHIDESEL|ES_MULTILINE
                10,            //x
                10,            //y
                130,           //nWidth
                200,           //nHeight
                hWnd,          //hWndParent
                0,             //ID
                hInstanceDLL,  //hInstance
                0);            //lpParam
    oSys.Call("user32::SetWindowTextW", hRichEdit, "Rich Edit");

    if (hRichEdit)
      WScript.Echo("Richedit was created");
    else
      WScript.Echo("Richedit was not created");

    hEdit =
      oSys.Call("user32::CreateWindowExW",
                0,             //dwExStyle
                "EDIT",        //lpClassName
                0,             //lpWindowName
                0x50311104,    //dwStyle=WS_VISIBLE|WS_CHILD|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP|ES_WANTRETURN|ES_NOHIDESEL|ES_MULTILINE
                160,           //x
                10,            //y
                130,           //nWidth
                200,           //nHeight
                hWnd,          //hWndParent
                0,             //ID
                hInstanceDLL,  //hInstance
                0);            //lpParam
    oSys.Call("user32::SetWindowTextW", hEdit, "Edit");

    hButton =
      oSys.Call("user32::CreateWindowExW",
                0,            //dwExStyle
                "BUTTON",     //lpClassName
                "Close",      //lpWindowName
                0x50010000,   //dwStyle
                100,          //x
                230,          //y
                100,          //nWidth
                25,           //nHeight
                hWnd,         //hWndParent
                0,            //ID
                hInstanceDLL, //hInstance
                0);           //lpParam
  }
  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("user32::SetFocus", hButton);
  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 27) //VK_ESCAPE
      oSys.Call("user32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }
  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hButton)
      oSys.Call("user32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }
  else if (uMsg == 16) //WM_CLOSE
    oSys.Call("user32::DestroyWindow", hWnd);
  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("user32::PostQuitMessage", 0);

  return 0;
}

function GetAkelPadObject()
{
  if (typeof AkelPad == "undefined")
  {
    var oError;

    try
    {
      AkelPad = new ActiveXObject("AkelPad.Document");
      _TCHAR  = AkelPad.Constants._TCHAR;
      _TSTR   = AkelPad.Constants._TSTR;
      _TSIZE  = AkelPad.Constants._TSIZE;
    }
    catch (oError)
    {
      WScript.Echo("You need register Scripts.dll");
      WScript.Quit();
    }
  }
}

Posted: Thu Aug 09, 2012 11:48 pm
by FeyFre
KDJ
From About Rich Edit Controls on MSDN
Versions of Rich Edit

The original specification for rich edit controls is Microsoft Rich Edit 1.0; the current specification is Microsoft Rich Edit 4.1. Each version of rich edit is a superset of the preceding one, except that only Asian builds of Microsoft Rich Edit 1.0 have a vertical text option. Before creating a rich edit control, you should call the LoadLibrary function to verify which version of Microsoft Rich Edit is installed.
And there is an table of versions of RichEdit functionality.

Code: Select all

Rich Edit version  DLL               Window Class
1.0                Riched32.dll      RICHEDIT_CLASS
2.0                Riched20.dll      RICHEDIT_CLASS
3.0                Riched20.dll      RICHEDIT_CLASS
4.1                Msftedit.dll      MSFTEDIT_CLASS
Where:
RICHEDIT_CLASS for v1.0 is "RICHEDIT" (only ANSI version)
RICHEDIT_CLASS for v2.0 & v3.0 is "RichEdit20" +"A"/"W"
MSFTEDIT_CLASS for v4.1 is "RICHEDIT50W" (only UCS2 version)
(This constants are define in Richedit.h header file in Platform SDK)
So solution for you is probably:
Insert this snippet before first reference to RichEdit control(on the very beginning of script is not bad choice):

Code: Select all

richdll = oSys.Call("kernel32::LoadLibrary"+_TCHAR,"Riched20.dll");
Insert this snippet when You will no need RichEdit any more(after destroying all RichEdit windows You have created)

Code: Select all

oSys.Call("kernel32::FreeLibrary", richdll);
NB: It is essential You not to forget about this last snippet especially when script execution can be terminated, in order to prevent resource leak.(Since module was manually loaded it must be manually unloaded).

PS: By the way, You completely forgot about error checking facility which can explain most of "Why this does not works?":

Code: Select all

if(!oSys.Call("user32::CreateWindowEx"+_TCHAR,...))
{
    WScript.Echo(oSys.GetLastError());
}

Posted: Sat Aug 11, 2012 3:01 pm
by Infocatcher
jsBeautifier.js
Released test version.
Updated: Remove some unneeded get_next_token args (#139)
Added Russian localization for some messages.

Posted: Sat Aug 11, 2012 5:00 pm
by KDJ
FeyFre
Thank you very much for your extensive explanation about RichEdit. Now I understand almost everything.
AkelPad does not use Riched20.dll library.
1. To create AkelEdit control in AkelPad, you can use the class name AkelEditA/W or RichEdit20A/W.
2. To create original RichEdit control in AkelPad, you must load Riched32.dll (Msftedit.dll) library and create a window with class name RICHEDIT (RICHEDIT50W).
3. To create RichEdit in ActiveX, you must load Riched32.dll (Riched20.dll, Msftedit.dll) and create a window with class name RICHEDIT (RichEdit20A/W, RICHEDIT50W).
4. Question, how to create AkelEdit control in ActiveX?

Posted: Fri Aug 17, 2012 3:23 pm
by KDJ
Instructor
Is it possible to use AkelEdit control in ActiveX?

Posted: Fri Aug 17, 2012 4:11 pm
by Instructor
KDJ
Yes, if you compile AkelEdit.dll from sources and load library as you did with Riched20.dll.

Posted: Fri Aug 17, 2012 7:05 pm
by FeyFre
Oh. Now I understood what KDJ means by "In ActiveX". It does not equals to my(probably more canonical) definition of ActiveX.

Posted: Sat Aug 18, 2012 12:56 pm
by KDJ
Instructor wrote:Yes, if you compile AkelEdit.dll from sources and load library as you did with Riched20.dll.
I have no means to compile AkelEdit source.
Can you compile AkelEdit and put AkelEdit.dll on download page (or put it in Scripts.zip)?.
It will then be available to everyone.
Thank you very much.