#language = "VBScript"
'            ____       __       
'    ___     \   \     / /       
'   |   |     \   \   / /      
'   |   |      \   \ / /         
'   |   |       \  // /        
'   |   | _     / //  \          
'   |   || |   / / \   \       
'   |   || |  / /   \   \        
'   |   || | /_/     \___\     
'   |   || |___                  
'   |___||_____| www.lxasp.com   
'                                
'############################################################
'* : 򿪹괦ļ V1.0 For EmEditor Pro v6 Marco
'* ˵: Դ INCLUDE FILE ѡıļ
'* : 2007-11-28  : pkmaster  ״̬: 
'############################################################

On Error Resume Next
sText = document.selection.Text

If Len(sText)=0 Then
'Check if is ASP's INCLUDE FILE
	xPos = document.selection.GetActivePointX(eePosLogical)
	yPos = document.selection.GetActivePointY(eePosLogical)
	document.selection.SelectLine
	sText = document.selection.Text

	Set regEx = New RegExp
	regEx.Pattern = "<!--\s*#INCLUDE\s*FILE\s*=\s*""(.+)""\s*-->"
	regEx.IgnoreCase = True
	If regEx.Test(sText) Then sText=regEx.Replace(sText,"$1")
	sText=Replace(sText,vbCrLf,"")
	sText=Replace(sText,vbCr,"")
	sText=Replace(sText,vbLf,"")

	document.selection.SetActivePoint eePosLogical, xPos, yPos

	Set fso = CreateObject("Scripting.FileSystemObject")

	fPath = Left(document.FullName,InstrRev(document.FullName,"\"))
	sText = fPath & Replace(sText,"/","\")
	If fso.FileExists(sText) Then editor.OpenFile sText,0,eeOpenAllowNewWindow

	Set fso=Nothing
	Set regEx=Nothing

Else
'Check if is local hard disk address (C:\abc\1.txt) or network address (\\abc\1.txt)

	Set fso = CreateObject("Scripting.FileSystemObject")

	Set regEx = New RegExp
	regEx.Pattern = "^(?:[A-Z]\:\\|\\\\)[^\s\\]"
	regEx.IgnoreCase = True
	If regEx.Test(sText) Then
		'absolute address
		If fso.FileExists(sText) Then editor.OpenFile sText,0,eeOpenAllowNewWindow
	Else
		'relative address
		fPath = Left(document.FullName,InstrRev(document.FullName,"\"))
		sText = fPath & Replace(sText,"/","\")
		If fso.FileExists(sText) Then editor.OpenFile sText,0,eeOpenAllowNewWindow
	End If

	Set fso=Nothing
	Set regEx=Nothing

End If

