aardio - 范例搜索工具

文章展示了光庆编写的范例搜索工具,该工具以独立窗口形式运行,用户可直接操作并关闭,区别于风行者版本的嵌入式风格。代码示例中使用了虚表组件,并提供了关键词输入、搜索、结果显示和文件路径等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

风行者写的一个范例搜索工具,功能挺好用的,运行后搜索界面集成到aardio IDE内部,会一直嵌入到范例列表上方。算是一种嵌入的风格。

我比较习惯直接点的,运行就弹出一个窗口界面直接操作。操作完了直接关闭窗口就OK了。

所以自己抽空写了一个,算是另一种风格。

 

 代码如下:

其中使用了虚表组件,请到 http://chengxu.online 下载。

//📝 范例搜索 V1.0 【光庆】
//与风行者版本不同的另一种风格

import win.ui;
import godking.vlistEx
import fonts.fontAwesome;
/*DSG{{*/
var mainForm = win.form(text="范例搜索 By 光庆";right=1099;bottom=669)
mainForm.add(
checkbox={cls="checkbox";text="忽略大小写";left=290;top=630;right=390;bottom=650;db=1;dl=1;font=LOGFONT(h=-14);z=5};
custom={cls="custom";text="自定义控件";left=620;top=10;right=1090;bottom=600;db=1;dl=1;dr=1;dt=1;z=6};
keyword={cls="edit";left=10;top=630;right=280;bottom=653;border=1;db=1;dl=1;z=2};
search={cls="button";text='\uF002  搜索';left=400;top=620;right=620;bottom=660;db=1;dl=1;font=LOGFONT(name='FontAwesome');z=3};
static={cls="static";text="请输入要搜索的关键词,多个关键词用空格分开。双击搜索结果在IDE中打开。";left=10;top=600;right=610;bottom=620;center=1;color=8421376;db=1;dl=1;transparent=1;z=1};
vlistEx={cls="vlistEx";text="自定义控件";left=10;top=10;right=620;bottom=600;db=1;dl=1;dt=1;edge=1;z=4}
)
/*}}*/
import ide;
import web.form
var wb = web.form(mainForm.custom);
var cols ={ names={"📚","📄 范例名称","📂 文件路径"}, widths={30,150,-1} }
mainForm.vlistEx.setColumns(cols.names,cols.widths);
var lists = {};
var exp;
mainForm.vlistEx.onClick = function(row/*行*/,col/*列*/){
	/*鼠标左键点击项目事件*/
	if !#lists or !#exp or row<1 or row>#lists return ; 
	var file = lists[row][4];
	mainForm.static.text = file;
	import string.html
	var html = ..string.load(file);
	html = string.replace(html,'\t',"        ");
	var html = string.html.fromText(html);
	for(i=1;#exp;1){
		html = string.replace(html,"@"++exp[i],`<span style="background: yellow; color: red; font-size: 20px; font-weight: 700;" >`++exp[i]++"</span>")
	}
	html = ..string.fromto(`<body style="font: 13px arial;">`++html++"</body>",65001,0);
	wb.html = html;
}
mainForm.vlistEx.onDblClick = function(row/*行*/,col/*列*/){
	/*鼠标左键点击项目事件*/
	if !#lists or !#exp or row<1 or row>#lists return ; 
	var path = lists[row][4];
	if !ide.openDocument(path) return ;
	mainForm.hitMin();
}
mainForm.search.oncommand = function(id,event){
	lists = {};
	mainForm.vlistEx.clear();
	var ts = ..string.split(mainForm.keyword.text," ");
	..table.removeByValue(ts,"",true);
	exp = ts;
	var func;
	if mainForm.checkbox.checked {
		for(i=1;#ts;1){
			ts[i]="@@"++ts[i]
		}
		func = ..string.find
	} else {
		func = ..string.indexOf
	}
	if(#ts){
		mainForm.search.disabled = true;
		import fsys;
		fsys.enum( "~\codes\范例程序\", "*.aardio",
			function(dirname,filename,fullpath,findData){ 
				if(filename){ 
	           		var str = string.load(fullpath);
	           		str = string.removeBom(str);
	           		var find = true;
	           		for(i=1;#ts;1){
	           			if !func(filename,ts[i]) {
	           				find = false;
	           				break;
	           			}
	           		}
	           		if find == false {
	           		    find = true;
	           			for(i=1;#ts;1){
	           				if !func(str,ts[i]) {
	           					find = false;
	           					break;
	           				}
	           			}
	           		}          		
	           		if find {
	           			var title = ..string.match(str,"^//(.+?)\n"):io.splitpath(filename).name;
	           			var t = string.split(fullpath,"<\范例程序\>",2);
	           			t = ..string.replace(t[2],"\\"," ➜ ");
	           			..table.push(lists,{"[@rowindex]",title,t,fullpath});
	           		}
				}
				win.delay();
			} 
			,true
		);
		mainForm.vlistEx.setTable(lists,cols.names,cols.widths,/*列格式或数组*/,/*字典转为数组*/,/*字符串转为Utf8*/);
		mainForm.search.disabled = false ;
	}
}
mainForm.keyword.onOk = function(){ 
    mainForm.search.oncommand();
}
mainForm.show();
mainForm.keyword.setFocus();
win.loopMessage();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卢光庆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值