/*=========================================================================
* Intro 打开CSS文件,然后运行这个宏
* FileName CSSFormat.jsee
* Author yongfa365
* Version v2.0
* WEB http://www.yongfa365.com
* Email yongfa365[at]qq.com
* FirstWrite http://www.yongfa365.com/Item/CSS-Format-Tool-CSSFormat-For-Emeditor-Macros-yongfa365.html
* LastModify 2007-10-06 03:47:31
*==========================================================================*/
editor.ExecuteCommandByID(4105);//转为CR+LF格式,如果文件没有保存会提示保存
xPos = document.selection.GetActivePointX( eePosLogical );
yPos = document.selection.GetActivePointY( eePosLogical );
function CSSformat(n){
if (document.selection.Text=="") document.selection.SelectAll();
if (n==1){
document.selection.Text = document.selection.Text.replace(/\r\n/g,"").replace(/}/g,"}\r\n").replace(/\*\//g,"*/\r\n").replace(/\t/g,"").replace(/\s*(:|;)\s*/g,"$1").replace(/ {2,}/g," ").replace(/\{ *(.+) *\}/g,"{$1}");
}
if (n==2){
document.selection.Text = document.selection.Text.replace(/\r\n/g,"").replace(/}/g,"}\r\n").replace(/\s*(:|;)\s*/g,"$1").replace(/;/g,";\r\n\t").replace(/{/g,"{\r\n\t").replace(/}/g,"\r\n}").replace(/\*\//g,"*/\r\n");
}
document.selection.SetActivePoint( eePosLogical, xPos, yPos, false );
}
mainMenu=CreatePopupMenu();
mainMenu.Add("功能:对选中文字或全文CSS格式化",0);
mainMenu.Add("一行",1);
mainMenu.Add("多行",2);
mainMenu.Add("关于",3);
mainMenu.Add( "", 0, eeMenuSeparator );
var witchItem=mainMenu.Track();
switch(witchItem)
{
case 1:
CSSformat(1);
break;
case 2:
CSSformat(2);
break;
case 3:
alert("哈哈哈哈,柳永法制作,\nhttp://www.yongfa365.com");
break;
default:
break;
}