/******************************************************************************/ /* Macro : ActiveCompare */ /* Function : Compare the currently edited file with the last saved content */ /* Auther : Takahiro Kawakami */ /* Note : The last saved file is to be opened as a read-only file. */ /* If you want to edit it, delete the line "doc.ReadOnly = true;". */ /******************************************************************************/ var strOrigFilePath; var strNowFilePath; var strFileName; var strFileExt; var strSuffix = "_LastSaved."; var msg1 = "Temporary file cannot be compared."; var msg2 = "To compare, save it first."; if(!document.Untitled){ if( document.FullName !== '' ){ document.Activate(); fso = new ActiveXObject( "Scripting.FileSystemObject" ); strFileName =document.Name.split(".")[0]; strFileExt =document.Name.split(".")[1]; strNowFilePath =document.FullName; strOrigFilePath=fso.GetSpecialFolder(2) + "\\" + strFileName + strSuffix + strFileExt; if( strNowFilePath.indexOf(fso.GetSpecialFolder(2) + "\\" )==0 ){ Window.alert(msg1); } else { // copy saved file to %temp% fso.CopyFile( strNowFilePath, strOrigFilePath); // close if original file in %temp% is opened docs = new Enumerator( editor.Documents ); for( ; !docs.atEnd(); docs.moveNext() ){ doc = docs.item(); if( doc.FullName == strOrigFilePath ){ doc.Activate(); doc.Saved=true; doc.close(); break; } } editor.OpenFile( strOrigFilePath, 0, eeOpenAllowNewWindow ); doc = editor.Documents.item(editor.Documents.Count); doc.Activate(); doc.ReadOnly = true; editor.ExecuteCommandByID(4492); } } } else { Window.alert(msg2); }