Scripts discussion (2)

Discuss and announce AkelPad plugins
Locked
  • Author
  • Message
Offline
Posts: 1862
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Lenchik wrote:Только лишний раз проверить по той же википедии, потому что, например, электронвольты сокращаются эВ (В большая).
Спасибо, исправил.
Там и так почти все из википедии. И часть из конвертера, прилагающегося к Компасу.


Пока вот так:
Add symbols for some units
Add English symbols to Russian translation
Fix Russian symbol for electronvolt

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

cnnnc
Script InsertNum.js
In order to avoid the suspension of the script, I would suggest a slight amendment.
In line 237, instead of:
AkelPad.MessageBox(hMainWnd, "\""+vLabel+"\" "+sTxtNeedNum, sCaption, 0 /*MB_OK*/);
type:
AkelPad.MessageBox(hWnd, "\""+vLabel+"\" "+sTxtNeedNum, sCaption, 0 /*MB_OK*/);

Offline
Posts: 119
Joined: Sat Jan 12, 2008 10:16 am
Location: Shantou, China

Post by cnnnc »

KDJ
Done. Thanks!
Update InsertNum.js:
1) improve CheckNum function;
2) add SetReDraw function.

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

Пофиксил FullScreenEx.js, т.к. был баг при такой передаче параметра: `-ToolBar=["ToolBar","1"]`.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

FindFiles.js
Added:
- Ctrl+Enter, Shift+Enter - open focused file for editing and select the found text (or close file if is currently edited),
- info on status bar: "NTFS stream".

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

KDJ
GoToEx.js: better to use AKD_GETMODELESS with MLT_GOTO instead of "User32::GetForegroundWindow".

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

FullScreenEx.js обновлён; параметры изменилось правило задания аргументов на такое, как указано Instructor'ом.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Thanks Instructor. AKD_GETMODELESS - this is what was needed!
Improved: GoToEx.js

Offline
Posts: 119
Joined: Sat Jan 12, 2008 10:16 am
Location: Shantou, China

Post by cnnnc »

KDJ
FindReplaceEx.js
Good job!
And I'd like to see that Integrate "GotoEx.js" into "FindReplaceEx.js", then I can use it instead of "QSearch::DialogSwitcher". :wink:

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

KDJ
FindReplaceEx.js
I agree, good job!
But the script will beautiful, if add the argument, which can be set focus on specified button. Repeatedly been big debate about this, for example here.

It would also be good to get the inscription "Find" and "Replace" from the program, ie to be localized.
cnnnc wrote:And I'd like to see that Integrate "GotoEx.js" into "FindReplaceEx.js", then I can use it instead of "QSearch::DialogSwitcher".
I do not vote for this proposal, because I think that these dialogues are completely different tasks.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

cnnnc, VladSh
All ideas are very good. Showing "Goto" can be parameterized (in .ini file).
I will try to do.
I don't know how to read by the script the localized strings "Find", "Replace", "Go to" from languages dlls.
Does anyone know how to do it?

Offline
Posts: 119
Joined: Sat Jan 12, 2008 10:16 am
Location: Shantou, China

Post by cnnnc »

KDJ
It's needn't a ini file. I do the change to

Code: Select all

// FindReplaceEx_Mod.js - ver. 2012-12-27
//
// "Find/Replace" dialog extended version
//
// Usage:
// Call("Scripts::Main", 1, "FindReplaceEx.js")      - Find dialog
// Call("Scripts::Main", 1, "FindReplaceEx.js", "H") - Replace dialog

if (AkelPad.ScriptHandle(AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/), 13 /*SH_GETMESSAGELOOP*/) /*script already running*/
   || (! AkelPad.GetEditWnd()))
  WScript.Quit();

var DT_DWORD = 3;
var IDCANCEL = 2;
var IDLINK   = 3099;

var sTxtFind     = "Find";
var sTxtReplace  = "Replace";
var oSys         = AkelPad.SystemFunction();
var hInstanceDLL = AkelPad.GetInstanceDll();
var hGuiFont     = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
var DLG_FIND     = 0;
var DLG_REPLACE  = 1;
var DLG_GOTO     = 2;
var nDlgType     = DLG_FIND;
var bContinue    = true;
var hWndFR;
var hWndCancel;
var hSubClass;

if (WScript.Arguments.length)
{
  if (WScript.Arguments(0).toUpperCase() == "H")
    nDlgType = DLG_REPLACE;
  else if (WScript.Arguments(0).toUpperCase() == "G")
    nDlgType = DLG_GOTO;
}

while (bContinue)
{
  bContinue = false;

  if (nDlgType==DLG_FIND)
  {
    AkelPad.Command(4158 /*IDM_EDIT_FIND*/);
  }
  else if(nDlgType==DLG_REPLACE)
  {
    AkelPad.Command(4161 /*IDM_EDIT_REPLACE*/);
  }
  else if(nDlgType==DLG_GOTO)
  {
    AkelPad.Command(4162 /*IDM_EDIT_GOTO*/);
  }

  if ((! (hWndFR = GetFindReplaceDialog())) || (! (hWndCancel = oSys.Call("User32::GetDlgItem", hWndFR, IDCANCEL))))
    break;

  if (nDlgType==DLG_FIND)
  {
    sLink = sTxtReplace + " (Ctrl+H)";
  }
  else if(nDlgType==DLG_REPLACE)
  {
    sLink = sTxtFind + " (Ctrl+F)";
  }
  else if(nDlgType==DLG_GOTO)
  {
    sLink = "";
  }

  oSys.Call("User32::CreateWindowExW",
            0,                      //dwExStyle
            "SysLink",              //lpClassName
            "<a>" + sLink + "</a>", //lpWindowName
            0x50000000,             //dwStyle=WS_VISIBLE|WS_CHILD
            GetLinkX(),             //x
            GetLinkY(),             //y
            GetLinkW(sLink),        //nWidth
            13,                     //nHeight
            hWndFR,                 //hWndParent
            IDLINK,                 //ID
            hInstanceDLL,           //hInstance
            0);                     //lpParam
  oSys.Call("User32::UpdateWindow", hWndFR);

  hSubClass = AkelPad.WindowSubClass(hWndFR, FindReplaceCallback, 78 /*WM_NOTIFY*/, 256 /*WM_KEYDOWN*/, 2 /*WM_DESTROY*/);

  AkelPad.ScriptNoMutex();
  AkelPad.WindowGetMessage();
  AkelPad.WindowUnsubClass(hWndFR);
}

function FindReplaceCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 78) //WM_NOTIFY
  {
    if ((wParam == IDLINK) && (AkelPad.MemRead(lParam + 8, DT_DWORD) == -2 /*NM_CLICK*/))
    {
      if (nDlgType==DLG_FIND)
      {
        nDlgType=DLG_REPLACE;
        SwitchFindReplace();
      }
      else
      {
        nDlgType=DLG_FIND;
        SwitchFindReplace();
      }
    }
  }
  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (Ctrl() && (! Shift()))
    {
      if (((wParam == 0x46 /*F key*/) && !(nDlgType==DLG_FIND)))
      {
        nDlgType  = DLG_FIND;
        SwitchFindReplace();
      }
      else if(((wParam == 0x48 /*H key*/) && !(nDlgType==DLG_REPLACE)))
      {
        nDlgType  = DLG_REPLACE;
        SwitchFindReplace();
      }
      else if(((wParam == 0x47 /*G key*/) && !(nDlgType==DLG_GOTO)))
      {
        nDlgType  = DLG_GOTO;
        SwitchFindReplace();
      }
    }
  }
  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("User32::PostQuitMessage", 0); //Exit message loop

  return 0;
}

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 GetLinkX()
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
  var nX;

  oSys.Call("User32::GetWindowRect", hWndCancel, lpRect);
  oSys.Call("User32::ScreenToClient", hWndFR, lpRect);
  nX = AkelPad.MemRead(lpRect, DT_DWORD);
  AkelPad.MemFree(lpRect);

  return nX;
}

function GetLinkY()
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
  var nY;

  oSys.Call("User32::GetClientRect", hWndFR, lpRect);
  nY = AkelPad.MemRead(lpRect + 12, DT_DWORD) - 28;
  AkelPad.MemFree(lpRect);

  return nY;
}

function GetLinkW(sText)
{
  var hDC    = AkelPad.SystemFunction().Call("User32::GetDC", hWndCancel);
  var lpSize = AkelPad.MemAlloc(8); //sizeof(SIZE)
  var nW;

  AkelPad.SystemFunction().Call("Gdi32::SelectObject", hDC, hGuiFont);

  AkelPad.SystemFunction().Call("Gdi32::SetMapMode", hDC, 1 /*MM_TEXT*/);
  AkelPad.SystemFunction().Call("Gdi32::GetTextExtentPoint32W", hDC, sText, sText.length, lpSize);

  nW = AkelPad.MemRead(lpSize, DT_DWORD);

  AkelPad.SystemFunction().Call("User32::ReleaseDC", hWndCancel, hDC);
  AkelPad.MemFree(lpSize);

  return nW;
}

function GetFindReplaceDialog()
{
  var lpMLT = AkelPad.MemAlloc(4);
  var hWnd  = AkelPad.SendMessage(AkelPad.GetMainWnd(), 1275 /*AKD_GETMODELESS*/, 0, lpMLT);
  var hDlg  = 0;

  if (AkelPad.MemRead(lpMLT, 3 /*DT_DWORD*/) == 3 /*MLT_FIND*/)
  {
    nDlgType = DLG_FIND;
    hDlg     = hWnd;
  }
  else if (AkelPad.MemRead(lpMLT, 3 /*DT_DWORD*/) == 4 /*MLT_REPLACE*/)
  {
    nDlgType = DLG_REPLACE;
    hDlg     = hWnd;
  }
  else if (AkelPad.MemRead(lpMLT, 3 /*DT_DWORD*/) == 5 /*MLT_GOTO*/)
  {
    nDlgType = DLG_GOTO;
    hDlg     = hWnd;
  }

  AkelPad.MemFree(lpMLT);

  return hDlg;
}

function SwitchFindReplace()
{
  bContinue = true;
  AkelPad.SendMessage(hWndFR, 273 /*WM_COMMAND*/, IDCANCEL, hWndCancel);
}
.
And I think there need to keep the changed of IDC_SEARCH_FIND when Switching between Dlg_Find and Dlg_Replace without click "Find Next" to rember that.

Offline
Posts: 2247
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

cnnnc, I'm going to disappoint You. Concept of configuration files was made in order to ease life for users and developers. They made in order to tune up functionality and behaviour of program not cloning it. It will be hell for developer - to support dozen different sources, propagating all tiny changes into each of them. It will be hell for user - to keep updated all versions of program and not to use wrong version. So ini file is preferred, if not required.

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

cnnnc
I support FeyFre, as have nearly identical 100500 scripts does not matter. Variant with the option in ini is better.
And it is always better to allocate the common code in Include, not a copy of the script in the script.

Offline
Posts: 2247
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

KDJ, typical code is

Code: Select all

HMODULE hModule = LoadLibrary("lang.dll");
HRSRC hRes = FindResourceEx(hModule, IDS_STRING, RT_STRING, langid);
HGLOBAL hResData = LoadResource(hModule,hRes);
LPVOID pointer= LockResource(hResData);//! Actual pointer to string. String may not include ending zero AFAIR.
DWORD sz = SizeofResource(hModule,hRes);//! Actual size of string
//! Copy string from pointer to separate memory
FreeLibrary(hModule); //! Free when not needed, if handle was obtained by LoadLibrary. 
HMODULE , HRSRC, HGLOBAL - typical windows handles of size equal to size of pointer in running architecture.
DWORD - 4 bytes in all architectures.
All function located in kernel32.dll See more at MSDN
Locked