import win.ui;
/*DSG{{*/
var winform = win.form( text="请拖动需要监视的文件到下面的文件列表内";bottom=387;max=false;right=599;parent=...)
winform.add( 
btnWatch={ bottom=379;text="开始监视";left=377;top=342;z=1;right=529;cls="button" };
lvChange={ bgcolor=16777215;bottom=334;right=587;left=7;top=6;acceptfiles=1;z=2;edge=1;cls="listview" }
)
/*}}*/

import fsys.watch; 

var watchObj;
watchFiles = function(){
	watchObj = fsys.watch(winform.files) 
	watchObj.onChange = function(path) {   
		var item = winform.lvChange.findItem(path);
		io.print( item )
		if( item ){
			winform.lvChange.setItemText("改变",item,2);
			winform.lvChange.setItemText(tostring(time.now()),item,3);
		}
	} 
	watchObj.run() 	
}
stopWatchFiles = function(){
	watchObj.stop()
}


winform.btnWatch.oncommand = function(id,event){
	if( winform.btnWatch.text == "开始监视"){
		winform.btnWatch.text = "停止监视";
		winform.setTimeout( watchFiles ); 
	}
	else { 
		winform.btnWatch.text = "开始监视"; 
		winform.setTimeout(stopWatchFiles);
	} 
} 

winform.lvChange.wndproc = {
	[0x233/*_WM_DROPFILES*/] = function(hwnd,message,wParam,lParam){
		var files = win.getDropFile(wParam)
		for(i=1;#files;1){
			winform.lvChange.addItem(files[i])  
		}
		winform.files = table.concat(files,winform.files : {} );
	}
}  
winform.lvChange.insertColumn("文件",100) 
winform.lvChange.insertColumn("状态",100) 
winform.lvChange.insertColumn("时间",200) 
winform.lvChange.fillParent(1);

winform.show() 
win.loopMessage();
