Artifact
3f79a22813e07538d4580b08edec35f18830f186:
Attachment "scriptdev.js" to
ticket [05faeed476]
added by
kuntashov
2011-08-23 12:51:35.
$engine JScript
$uname scriptdev
$dname ���������� ��������
/*
* �����:
*
* ��������� ��������, kuntashov@compaud.ru
*
* ���� ��������:
*
* 18.08.2011
*
* ��������:
*
* - ��������� � ����������� ���� ���� ��������� ����� "������������� ������",
* ��� ������ �������� �������� ��� ������� ����������� � ������������� � ����������
* ��������� ���������.
*
* - ����������� ��������� � �������� �� �������������� ����� ������� � �������������
* ������������� ���, ����� �������, ���������, ��������� � ������ �������� ����� ���
* ������������� ������������ �������.
*/
/* **********************************************************
* ��������� �������.
* ********************************************************* */
// �������� �������� ������������� ������.
var checkInterval = 2;
// ������ ������������� ������ ��������.
var devFiles = new Array();
// ������� ��� ������� ��������� �������.
var runEditorCmd = '"D:\\�������\\Dropbox\\Apps\\Notepad++Portable\\Notepad++Portable.exe" "%1"';//'notepad.exe "%1"';
/* **********************************************************
* �������.
* ********************************************************* */
function macros�������()
{
Message("����");
}
/* **********************************************************
* ���������� ����������� �������.
* ********************************************************* */
// ����� ��������� ��������
var lastCheckTime = new Date().getTime() / 1000;
// ���������� ���������� ���������.
addins.byUniqueName("global").object.connectGlobals(SelfScript);
function Designer::onIdle()
{
var curTime = new Date().getTime() / 1000;
if (curTime - lastCheckTime > checkInterval)
{
CheckFiles();
}
}
function CheckFiles()
{
for(var i=0; i<devFiles.length; i++)
{
if (devFiles[i].CheckIfModified())
devFiles[i].Reload();
}
}
function getModificationStamp(f)
{
if (f.����������())
{
return new Date(f.����������������������()).getTime();
}
return null;
}
function OnSnegopatWndEditScriptMenuItem(currentRow)
{
var isAddin = currentRow.Picture != 0;
if (!isAddin)
return;
var addinObject = currentRow.object;
var fullPath = GetAddinFilePath(addinObject);
var command = runEditorCmd.replace(/%1/, fullPath);
devFiles.push(new AddinInfo(addinObject));
�������������������(command);
}
function InitScriptAndRun()
{
/* ���� ��������, ����������� �� ��� ���������. */
//runEditorCmd = '"D:\Dropbox\Apps\Notepad++Portable\Notepad++Portable.exe" "%1"';
//devFiles.push(new AddinInfo("D:\\kuntashov\\Dropbox\\Apps\\Snegopat\\SnegopatRepo\\scripts\\hello.js"));
var snegopatWnd = addins.byUniqueName("snegopatwnd").object.getSnegopatWnd();
snegopatWnd.AddContextMenuItem("������������� ������...", OnSnegopatWndEditScriptMenuItem);
}
function GetAddinFilePath(addinObject)
{
return addinObject.fullPath.replace(/^\w+:/,'');
}
/* **********************************************************
* ����� AddinInfo. ������ ���������� � ������������� ������.
* ********************************************************* */
function AddinInfo(addinObject)
{
this.object = addinObject;
this.file = v8New("����", GetAddinFilePath(addinObject));
this.lastModified = getModificationStamp(this.file);
}
AddinInfo.prototype.Reload = function()
{
var uniqueName = this.object.uniqueName;
var displayName = this.object.displayName;
var loadString = this.object.fullPath;
var addinGroup = this.object.group;
try
{
addins.unloadAddin(this.object);
}
catch(e)
{
Message("������ ��� �������� ������ " + displayName + ": " + e.description);
}
if(!this.object.uniqueName.length) // ����� ������� ����������
{
try
{
addins.loadAddin(loadString, addinGroup);
}
catch(e)
{
Message("������ ��� ��������: " + e.description);
}
}
delete this.object;
// ���� ����� ����� ������ ������ �� ��� ����� � ���������:
this.object = addins.byUniqueName(uniqueName);
}
AddinInfo.prototype.CheckIfModified = function()
{
var curStamp = getModificationStamp(this.file);
if (curStamp != this.lastModified)
{
this.lastModified = curStamp;
return true;
}
return false;
}
/* **********************************************************
* ������������� �������.
* ********************************************************* */
InitScriptAndRun();