// http://akelpad.sourceforge.net/forum/viewtopic.php?p=9440#9440
// Version: 2016-11-01
// Author: KDJ
//
// *** Open selected text in new tab ***
//
// Usage:
//   Call("Scripts::Main", 1, "SelectionOpenInTab.js")
//
// Can assign shortcut key, eg: Shift+Alt+N

var sSelText;
var sAlias;

if (AkelPad.GetEditWnd() && AkelPad.IsMDI() && (sSelText = AkelPad.GetSelText()))
{
  sAlias = GetAlias();

  AkelPad.Command(4101 /*IDM_FILE_NEW*/, 1 /*lParam=TRUE*/);
  AkelPad.ReplaceSel(sSelText);

  if (sAlias)
    AkelPad.CallW("Coder::Settings", 6, sAlias);
}

function GetAlias()
{
  var lpAlias = AkelPad.MemAlloc(256 * 2 /*sizeof(wchar_t)*/);
  var sAlias;

  AkelPad.CallW("Coder::Settings", 18, 0, 0, lpAlias, 0);
  sAlias = AkelPad.MemRead(lpAlias, 1 /*DT_UNICODE*/);
  AkelPad.MemFree(lpAlias);

  return sAlias;
}
