// http://akelpad.sourceforge.net/forum/viewtopic.php?p=23098#23098
// Version: 2015-03-19
// Author: KDJ
// 
// *** Removes/restores file icons on the tabs (MDI/PMDI) ***
// 
// Usage:
//   Call("Scripts::Main", 1, "IconsOnTabs.js")
// 
// Notes:
//   First script call, removes the icons from the tabs.
//   Second script call, restores the icons.
// 
// For autostart, in AkelPad.ini or registry CmdLineBegin/CmdLineEnd key, need to add:
//   /Call("Scripts::Main", 1, "IconsOnTabs.js")

if (! AkelPad.IsMDI()) WScript.Quit();

var hMainWnd   = AkelPad.GetMainWnd();
var hTab       = AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 13 /*MI_WNDTAB*/, 0);
var hImageList = AkelPad.SendMessage(hTab, 0x1302 /*TCM_GETIMAGELIST*/, 0, 0);
var sIniFile   = WScript.ScriptFullName.replace(/\.[^.]+$/, ".ini");
var oFSO       = new ActiveXObject("Scripting.FileSystemObject");
var oFile;

if (hImageList)
{
  oFile = oFSO.OpenTextFile(sIniFile, 2, true, -1);
  oFile.Write("hImageList=" + hImageList + ";")
  oFile.Close();

  AkelPad.SendMessage(hTab, 0x1303 /*TCM_SETIMAGELIST*/, 0, 0);
}
else if (oFSO.FileExists(sIniFile))
{
  try
  {
    eval(AkelPad.ReadFile(sIniFile));

    if ((typeof hImageList == "number") && hImageList && AkelPad.SystemFunction().Call("Comctl32::ImageList_GetImageCount", hImageList))
      AkelPad.SendMessage(hTab, 0x1303 /*TCM_SETIMAGELIST*/, 0, hImageList);
  }
  catch (oError)
  {
  }
}
